summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-impl
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2008-11-21 12:16:29 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2008-11-21 12:16:29 +0000
commit65e3fd65b82c7cd08cfdeee8819f571212b3b1fe (patch)
tree72142bd4e7fbd9becf3f43d09dde26836562d72f /java/sca/modules/node-impl
parent6a9b9b7586fd7a377d57b5ce0117c664beebff25 (diff)
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); git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@719565 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-impl')
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java4
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java65
-rw-r--r--java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java6
3 files changed, 74 insertions, 1 deletions
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
index 62758e8332..5ee68899a9 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -47,4 +47,8 @@ public class NodeFactoryImpl extends NodeFactory {
return new NodeImpl(compositeURI, compositeContent, contributions);
}
+ @Override
+ public Node createNode() {
+ return new NodeImpl();
+ }
}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
index effccd0f4d..73ef98010d 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -76,6 +76,7 @@ import org.apache.tuscany.sca.monitor.MonitorFactory;
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 @@ public class NodeImpl implements Node, Client {
/**
* 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 @@ public class NodeImpl implements Node, Client {
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 @@ public class NodeImpl implements Node, Client {
}
}
+ /*
+ * 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");
+ }
}
diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
index bd760d613d..0ccbd6d30e 100644
--- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
+++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
@@ -25,7 +25,6 @@ import java.io.File;
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 @@ public class NodeImplTestCase {
testNode(node);
}
+ @Test
+ public void testDefaultNode() {
+ testNode(new NodeFactoryImpl().createNode());
+ }
+
private void testNode(Node node) {
node.start();
HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld");