Author: rfeng
Date: Mon Aug 18 12:59:14 2008
New Revision: 686861

URL: http://svn.apache.org/viewvc?rev=686861&view=rev
Log:
Fix the webapp regression where the no explicit deployable composite is passed 
into the Node API

Added:
    tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/
    
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
   (with props)
Modified:
    
tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
    
tuscany/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java

Modified: 
tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=686861&r1=686860&r2=686861&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
 (original)
+++ 
tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
 Mon Aug 18 12:59:14 2008
@@ -51,7 +51,6 @@
 import org.apache.tuscany.sca.contribution.Artifact;
 import org.apache.tuscany.sca.contribution.Contribution;
 import org.apache.tuscany.sca.contribution.ContributionFactory;
-import org.apache.tuscany.sca.contribution.ContributionMetadata;
 import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
 import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
 import 
org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
@@ -101,8 +100,6 @@
     private Monitor monitor;
 
     private List<Contribution> contributions;
-    private ContributionMetadata metadata;
-
     // The composite loaded into this node
     private Composite composite;
 
@@ -168,12 +165,20 @@
         }
     }
 
+    /**
+     * Discover the contribution on the classpath
+     * @param compositeURI
+     * @param classLoader
+     * @return A configured node implementation
+     * @throws Exception
+     */
     private ConfiguredNodeImplementation findNodeConfiguration(final String 
compositeURI, ClassLoader classLoader)
         throws Exception {
         NodeImplementationFactory nodeImplementationFactory =
             modelFactories.getFactory(NodeImplementationFactory.class);
         ConfiguredNodeImplementation config = 
nodeImplementationFactory.createConfiguredNodeImplementation();
 
+        // Default to thread context classloader
         if (classLoader == null) {
             classLoader = Thread.currentThread().getContextClassLoader();
         }
@@ -188,43 +193,25 @@
             Composite composite = createComposite(compositeURI);
             config.setComposite(composite);
         } else {
-
-            // Here the SCADomain was started without any reference to a 
composite file
-            // We are going to look for an sca-contribution.xml or 
sca-contribution-generated.xml
-
-            // Look for META-INF/sca-contribution.xml
+            // No composite is specified, tring to search the SCA metadata 
files
             contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
-            contributionArtifactURL = getResource(classLoader, 
contributionArtifactPath);
+            contributionArtifactURL = getResource(classLoader, 
Contribution.SCA_CONTRIBUTION_META);
 
-            // Look for META-INF/sca-contribution-generated.xml
             if (contributionArtifactURL == null) {
                 contributionArtifactPath = 
Contribution.SCA_CONTRIBUTION_GENERATED_META;
-                contributionArtifactURL = getResource(classLoader, 
contributionArtifactPath);
+                contributionArtifactURL = getResource(classLoader, 
Contribution.SCA_CONTRIBUTION_GENERATED_META);
             }
-
-            // Look for META-INF/sca-deployables directory
             if (contributionArtifactURL == null) {
                 contributionArtifactPath = 
Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
-                contributionArtifactURL = getResource(classLoader, 
contributionArtifactPath);
-            } else {
-                StAXArtifactProcessor<ContributionMetadata> processor =
-                    
artifactProcessors.getProcessor(ContributionMetadata.class);
-                XMLStreamReader reader = 
inputFactory.createXMLStreamReader(contributionArtifactURL.openStream());
-                reader.nextTag();
-                metadata = processor.read(reader);
-                reader.close();
-                if (metadata.getDeployables().isEmpty()) {
-                    throw new IllegalArgumentException(
-                                                       "No deployable 
composite is declared in " + contributionArtifactPath);
-                }
-                Composite composite = metadata.getDeployables().get(0);
-                config.setComposite(composite);
+                contributionArtifactURL = getResource(classLoader, 
Contribution.SCA_CONTRIBUTION_DEPLOYABLES);
             }
-        }
-
-        if (contributionArtifactURL == null) {
-            throw new IllegalArgumentException(
-                                               "Can't determine contribution 
deployables. Either specify a composite file, or use an sca-contribution.xml 
file to specify the deployables.");
+            
+            // No contribution can be discovered
+            if (contributionArtifactURL == null) {
+                throw new IllegalArgumentException("No default contribution 
can be discovered on the classpath");
+            }
+            
+            // No composite will be created, all deployable composites will be 
used later
         }
 
         Contribution c = getContribution(contributionArtifactURL, 
contributionArtifactPath);
@@ -314,10 +301,10 @@
             // Initialize the runtime
             initRuntime();
 
-            URI uri = URI.create(compositeURI);
+            URI uri = compositeURI == null ? null : URI.create(compositeURI);
             ConfiguredNodeImplementation configuration = null;
             if (contributions == null || contributions.length == 0) {
-                if (uri.getScheme() != null) {
+                if (uri != null && uri.getScheme() != null) {
                     throw new IllegalArgumentException("No SCA contributions 
are provided");
                 }
                 configuration = findNodeConfiguration(compositeURI, null);
@@ -328,8 +315,9 @@
                     modelFactories.getFactory(NodeImplementationFactory.class);
                 configuration = 
nodeImplementationFactory.createConfiguredNodeImplementation();
 
-                Composite composite = createComposite(compositeURI);
+                Composite composite = compositeURI == null ? null : 
createComposite(compositeURI);
                 configuration.setComposite(composite);
+  
 
                 // Create contribution models
                 ContributionFactory contributionFactory = 
modelFactories.getFactory(ContributionFactory.class);
@@ -498,32 +486,14 @@
 
         composite = configuration.getComposite();
 
-        // Resolve the metadata within the context of the contribution
-        // FIXME The deployable composite should have been picked by the SCA 
Domain Manager already and we should not
-        // pollute the Node impl to deal with this 
-        if (metadata != null) {
-            StAXArtifactProcessor<ContributionMetadata> processor =
-                artifactProcessors.getProcessor(ContributionMetadata.class);
+        // FIXME: This is a hack to get a list of deployable composites. By 
design, the deployment composite should
+        // has been configured
+        if (composite == null) {
+            List<Composite> deployables = new ArrayList<Composite>();
             for (Contribution c : contributions) {
-                processor.resolve(metadata, c.getModelResolver());
-                if (!metadata.isUnresolved()) {
-                    break;
-                }
-            }
-            List<Composite> composites = metadata.getDeployables();
-            if (composites.size() == 0) {
-                throw new IllegalArgumentException("No deployable composite is 
declared");
-            } else if (composites.size() == 1) {
-                composite = composites.get(0);
-            } else {
-                // This is temporary to include all composites
-                AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
-                Composite tempComposite = assemblyFactory.createComposite();
-                tempComposite.setName(new QName("http://tempuri.org";, 
"aggregated"));
-                tempComposite.setURI("http://tempuri.org/aggregated";);
-                tempComposite.getIncludes().addAll(composites);
-                composite = tempComposite;
+                deployables.addAll(c.getDeployables());
             }
+            aggregate(deployables);
             configuration.setComposite(composite);
         }
 
@@ -592,6 +562,26 @@
     }
 
     /**
+     * Create a deployment composite that includes a list of deployable 
composites
+     * @param composites
+     */
+    private void aggregate(List<Composite> composites) {
+        if (composites.size() == 0) {
+            throw new IllegalArgumentException("No deployable composite is 
declared");
+        } else if (composites.size() == 1) {
+            composite = composites.get(0);
+        } else {
+            // Include all composites
+            AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+            Composite aggregated = assemblyFactory.createComposite();
+            aggregated.setName(new QName("http://tempuri.org";, "aggregated"));
+            aggregated.setURI("http://tempuri.org/aggregated";);
+            aggregated.getIncludes().addAll(composites);
+            composite = aggregated;
+        }
+    }
+
+    /**
      * Returns the artifact representing the given composite.
      * 
      * @param contribution

Modified: 
tuscany/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java?rev=686861&r1=686860&r2=686861&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
 (original)
+++ 
tuscany/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
 Mon Aug 18 12:59:14 2008
@@ -48,24 +48,33 @@
     @Test
     public void testNodeWithCompositeContent() {
         SCANode2Factory factory = new NodeFactoryImpl();
-        SCAContribution contribution = new SCAContribution("c1", new 
File("target/classes").toURI().toString());
+        SCAContribution contribution = new SCAContribution("c1", new 
File("target/test-classes").toURI().toString());
         SCANode2 node = factory.createSCANode("HelloWorld.composite", 
composite, contribution);
-        node.start();
-        HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, 
"HelloWorld");
-        Assert.assertEquals("Hello, Node", hw.hello("Node"));
-        node.stop();
+        testNode(node);
     }
+    
+    @Test
+    public void testNodeWithCompositeContentAndNoContribution() {
+        SCANode2Factory factory = new NodeFactoryImpl();
+        SCANode2 node = factory.createSCANode("HelloWorld.composite", 
composite);
+        testNode(node);
+    }    
 
     @Test
+    public void testNodeWithoutCompositeURI() {
+        SCANode2Factory factory = new NodeFactoryImpl();
+        SCAContribution contribution = new SCAContribution("c1", new 
File("target/test-classes").toURI().toString());
+        SCANode2 node = factory.createSCANode(null, contribution);
+        testNode(node);
+    }
+    
+    @Test
     public void testNodeWithCompositeURI() {
         SCANode2Factory factory = new NodeFactoryImpl();
-        SCAContribution contribution = new SCAContribution("c1", new 
File("target/classes").toURI().toString());
+        SCAContribution contribution = new SCAContribution("c1", new 
File("target/test-classes").toURI().toString());
         String compositeURI = new 
File("target/test-classes/HelloWorld.composite").toURI().toString();
         SCANode2 node = factory.createSCANode(compositeURI, contribution);
-        node.start();
-        HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, 
"HelloWorld");
-        Assert.assertEquals("Hello, Node", hw.hello("Node"));
-        node.stop();
+        testNode(node);
     }
 
     @Test
@@ -74,10 +83,7 @@
         SCAContribution contribution = new SCAContribution("c1", new 
File("target/test-classes").toURI().toString());
         String compositeURI = "HelloWorld.composite";
         SCANode2 node = factory.createSCANode(compositeURI, contribution);
-        node.start();
-        HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, 
"HelloWorld");
-        Assert.assertEquals("Hello, Node", hw.hello("Node"));
-        node.stop();
+        testNode(node);
     }
 
     @Test
@@ -85,10 +91,7 @@
         SCANode2Factory factory = new NodeFactoryImpl();
         String compositeURI = "HelloWorld.composite";
         SCANode2 node = factory.createSCANode(compositeURI, new 
SCAContribution[0]);
-        node.start();
-        HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, 
"HelloWorld");
-        Assert.assertEquals("Hello, Node", hw.hello("Node"));
-        node.stop();
+        testNode(node);
     }
 
     @Test
@@ -96,9 +99,21 @@
         SCANode2Factory factory = new NodeFactoryImpl();
         String compositeURI = "HelloWorld.composite";
         SCANode2 node = factory.createSCANodeFromClassLoader(compositeURI, 
HelloWorld.class.getClassLoader());
+        testNode(node);
+    }
+
+    @Test
+    public void testNodeWithClassLoaderAndNullComposite() {
+        SCANode2Factory factory = new NodeFactoryImpl();
+        SCANode2 node = factory.createSCANodeFromClassLoader(null, 
HelloWorld.class.getClassLoader());
+        testNode(node);
+    }
+    
+    private void testNode(SCANode2 node) {
         node.start();
         HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, 
"HelloWorld");
         Assert.assertEquals("Hello, Node", hw.hello("Node"));
         node.stop();
     }
+        
 }

Added: 
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml?rev=686861&view=auto
==============================================================================
--- 
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
 (added)
+++ 
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
 Mon Aug 18 12:59:14 2008
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+* 
+*   http://www.apache.org/licenses/LICENSE-2.0
+* 
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.    
+-->
+
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
xmlns:sc="http://sample/composite";>
+    <deployable composite="sc:HelloWorld" />
+</contribution>

Propchange: 
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tuscany/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date


Reply via email to