summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java7
-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
4 files changed, 81 insertions, 1 deletions
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
index a9f75fc8be..05ef39f461 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java
@@ -156,6 +156,13 @@ public abstract class NodeFactory {
}
/**
+ * 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
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");