tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r719565 - in /tuscany/java/sca: modules/node-api/src/main/java/org/apache/tuscany/sca/node/ modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/ samples/calculat...
Date Fri, 21 Nov 2008 12:16:29 GMT
Author: antelder
Date: Fri Nov 21 04:16:29 2008
New Revision: 719565

URL: http://svn.apache.org/viewvc?rev=719565&view=rev
Log:
Simplify the Node API for a common default case so that creating a Node for simple samples
and tests can be:

        node = NodeFactory.newInstance().createNode();

instead of:

        NodeFactory factory = NodeFactory.newInstance();
        String root = ContributionLocationHelper.getContributionLocation("Calculator.composite");
        Contribution contribution = new Contribution(root, root);
        node = factory.createNode("Calculator.composite", contribution);



Modified:
    tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
    tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
    tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
    tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
    tuscany/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java
    tuscany/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java

Modified: tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
(original)
+++ tuscany/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
Fri Nov 21 04:16:29 2008
@@ -156,6 +156,13 @@
     }
 
     /**
+     * Creates a new SCA node using defaults for the contribution location and runnable composite
+     * 
+     * @return a new SCA node.
+     */
+    public abstract Node createNode();
+
+    /**
      * Creates a new SCA node from the configuration URL
      * 
      * @param configurationURL the URL of the node configuration which is the ATOM feed

Modified: tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
(original)
+++ tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
Fri Nov 21 04:16:29 2008
@@ -47,4 +47,8 @@
         return new NodeImpl(compositeURI, compositeContent, contributions);
     }
 
+    @Override
+    public Node createNode() {
+        return new NodeImpl();
+    }
 }

Modified: tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
(original)
+++ tuscany/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
Fri Nov 21 04:16:29 2008
@@ -76,6 +76,7 @@
 import org.apache.tuscany.sca.monitor.Problem;
 import org.apache.tuscany.sca.monitor.Problem.Severity;
 import org.apache.tuscany.sca.node.Client;
+import org.apache.tuscany.sca.node.ContributionLocationHelper;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
@@ -124,6 +125,50 @@
 
     /** 
      * Constructs a new SCA node.
+     */
+    NodeImpl() {
+        configurationName = "default";
+        logger.log(Level.INFO, "Creating node: " + configurationName);
+
+        String root = ContributionLocationHelper.getContributionLocation("META-INF/sca-contribution.xml");
+        if (root == null) {
+            throw new ServiceRuntimeException("no META-INF/sca-contribution.xml found");
+        }
+
+        String compositeURI = null;
+        org.apache.tuscany.sca.node.Contribution[] contributions = new org.apache.tuscany.sca.node.Contribution[]{new
org.apache.tuscany.sca.node.Contribution(root, root)};
+      
+        try {
+            // Initialize the runtime
+            init();
+
+            // Create a node configuration
+            NodeImplementationFactory nodeImplementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
+            ConfiguredNodeImplementation configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
+
+            if (compositeURI != null) {
+                Composite composite = assemblyFactory.createComposite();
+                composite.setURI(compositeURI);
+                composite.setUnresolved(true);
+                configuration.setComposite(composite);
+            }
+  
+                // Create contribution models
+            for (org.apache.tuscany.sca.node.Contribution c : contributions) {
+                Contribution contribution = contribution(contributionFactory, c);
+                configuration.getContributions().add(contribution);
+            }
+
+            // Configure the node
+            configureNode(configuration);
+
+        } catch (Exception e) {
+            throw new ServiceRuntimeException(e);
+        }
+    }
+
+    /** 
+     * Constructs a new SCA node.
      *  
      * @param configurationURI the URI of the node configuration information.
      */
@@ -401,6 +446,10 @@
         
         composite = configuration.getComposite();
         
+        if (composite == null) {
+            setDefaultComposite(configuration, workspace);
+        }
+        
         // Find the composite in the given contributions
         boolean found = false;
         Artifact compositeFile = contributionFactory.createArtifact();
@@ -590,4 +639,20 @@
         }
     }
 
+    /*
+     * Sets a default composite by using any deployable one.
+     */
+    private void setDefaultComposite(ConfiguredNodeImplementation configuration, Workspace
workspace) {
+        // just use the first deployable composte
+        for (Contribution contribution : workspace.getContributions()) {
+            for (Composite c : contribution.getDeployables()) {
+                composite = assemblyFactory.createComposite();
+                composite.setURI(c.getURI());
+                composite.setUnresolved(true);
+                configuration.setComposite(composite);
+                return;
+            }
+        }
+        throw new ServiceRuntimeException("no deployable composite found");
+    }
 }

Modified: tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
(original)
+++ tuscany/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
Fri Nov 21 04:16:29 2008
@@ -25,7 +25,6 @@
 
 import junit.framework.Assert;
 
-import org.apache.tuscany.sca.node.Client;
 import org.apache.tuscany.sca.node.Contribution;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
@@ -63,6 +62,11 @@
         testNode(node);
     }
 
+    @Test
+    public void testDefaultNode() {
+        testNode(new NodeFactoryImpl().createNode());
+    }
+    
     private void testNode(Node node) {
         node.start();
         HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld");

Modified: tuscany/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java (original)
+++ tuscany/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java Fri
Nov 21 04:16:29 2008
@@ -20,8 +20,6 @@
 package calculator;
 
 import org.apache.tuscany.sca.node.Client;
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.ContributionLocationHelper;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
 
@@ -32,10 +30,7 @@
 public class CalculatorClient {
     public static void main(String[] args) throws Exception {
 
-        NodeFactory factory = NodeFactory.newInstance();
-        String root = ContributionLocationHelper.getContributionLocation("Calculator.composite");
-        Contribution contribution = new Contribution(root, root);
-        Node node = factory.createNode("Calculator.composite", contribution);
+        Node node = NodeFactory.newInstance().createNode();
 
         node.start();
         

Modified: tuscany/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java?rev=719565&r1=719564&r2=719565&view=diff
==============================================================================
--- tuscany/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java (original)
+++ tuscany/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java Fri
Nov 21 04:16:29 2008
@@ -21,8 +21,6 @@
 import junit.framework.TestCase;
 
 import org.apache.tuscany.sca.node.Client;
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.ContributionLocationHelper;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
 
@@ -36,11 +34,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        NodeFactory factory = NodeFactory.newInstance();
-        String root = ContributionLocationHelper.getContributionLocation("Calculator.composite");
-        Contribution contribution = new Contribution(root, root);
-        node = factory.createNode("Calculator.composite", contribution);
-
+        node = NodeFactory.newInstance().createNode();
         node.start();
         
         calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent");



Mime
View raw message