From bfc5133237c096260597a01f186188e9331cc34b Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 15 May 2009 22:37:25 +0000 Subject: Update the node launcher to use the NodeFactory git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@775369 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/node/NodeFactory.java | 51 +++++++++++++++++++--- .../impl/BindingConfigurationImpl.java | 4 +- .../impl/ContributionConfigurationImpl.java | 2 +- .../impl/DeploymentCompositeImpl.java | 2 +- .../configuration/impl/NodeConfigurationImpl.java | 4 +- 5 files changed, 51 insertions(+), 12 deletions(-) (limited to 'java/sca/modules/node-api/src') 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 485c159287..781fd2688c 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 @@ -30,6 +30,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory; @@ -279,7 +280,11 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { throw new ServiceRuntimeException("No SCA contribution is provided or discovered"); } // Try to find contributions on the classpath by the composite URI - contributions = getContributions(getContributionLocations(null, deploymentCompositeURI)); + List locations = getContributionLocations(null, deploymentCompositeURI); + if (locations.isEmpty()) { + throw new ServiceRuntimeException("No SCA contributions are found on the classpath"); + } + contributions = getContributions(locations); } NodeConfiguration configuration = createConfiguration(contributions); if (deploymentCompositeURI != null && configuration.getContributions().size() > 0) { @@ -288,6 +293,29 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { return createNode(configuration); } + /** + * The following methods are used by the node launcher + */ + public final Node createNode(String deploymentCompositeURI, String[] uris, String locations[]) { + return createNode(deploymentCompositeURI, getContributions(Arrays.asList(uris), Arrays.asList(locations))); + } + + public final Node createNode(String deploymentCompositeURI, String locations[]) { + return createNode(deploymentCompositeURI, getContributions(Arrays.asList(locations))); + } + + public final Node createNode(Reader deploymentCompositeContent, String[] uris, String locations[]) { + return createNode(deploymentCompositeContent, getContributions(Arrays.asList(uris), Arrays.asList(locations))); + } + + public final Node createNode(String compositeURI, ClassLoader classLoader) { + List locations = ContributionLocationHelper.getContributionLocations(classLoader, compositeURI); + return createNode(compositeURI, locations.toArray(new String[locations.size()])); + } + /** + * ------------------- end of methods ----------------- + */ + /** * Create a new SCA node using the list of SCA contributions * @param contributions @@ -371,14 +399,14 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { List locations = new ArrayList(); locations.addAll(getContributionLocations(null, SCA_CONTRIBUTION_META)); locations.addAll(getContributionLocations(null, SCA_CONTRIBUTION_GENERATED_META)); + if (locations.isEmpty()) { + throw new ServiceRuntimeException("No SCA contributions are found on the classpath"); + } Contribution[] contributions = getContributions(locations); return createNode(contributions); } private Contribution[] getContributions(List locations) { - if (locations.isEmpty()) { - throw new ServiceRuntimeException("No SCA contributions are found on the classpath"); - } Contribution[] contributions = new Contribution[locations.size()]; int index = 0; for (String location : locations) { @@ -387,10 +415,21 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { return contributions; } + private Contribution[] getContributions(List uris, List locations) { + if (uris.size() != locations.size()) { + throw new IllegalArgumentException("The number of URIs does not match the number of locations"); + } + Contribution[] contributions = new Contribution[locations.size()]; + for (int i = 0, n = locations.size(); i < n; i++) { + contributions[i] = new Contribution(uris.get(i), locations.get(i)); + } + return contributions; + } + /** * Create a new SCA node based on the configuration - * @param configuration - * @return + * @param configuration The configuration of a node + * @return The SCA node */ public abstract Node createNode(NodeConfiguration configuration); diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java index dd38f97161..8fba4ee6a3 100644 --- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java +++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java @@ -27,9 +27,9 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.node.configuration.BindingConfiguration; /** - * + * Default implementation of BindingConfiguration */ -class BindingConfigurationImpl implements BindingConfiguration { +public class BindingConfigurationImpl implements BindingConfiguration { private QName type; private List baseURIs = new ArrayList(); diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java index b863ede5f6..b08a4e6cff 100644 --- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java +++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java @@ -35,7 +35,7 @@ import org.apache.tuscany.sca.node.configuration.DeploymentComposite; /** * Configuration for an SCA contribution used by the SCA node */ -class ContributionConfigurationImpl implements ContributionConfiguration { +public class ContributionConfigurationImpl implements ContributionConfiguration { private List deploymentComposites = new ArrayList(); private String uri; private String location; diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java index 4edcf75bba..e94f195931 100644 --- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java +++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java @@ -24,7 +24,7 @@ import org.apache.tuscany.sca.node.configuration.DeploymentComposite; /** * Configuration for a deployment composite */ -class DeploymentCompositeImpl implements DeploymentComposite { +public class DeploymentCompositeImpl implements DeploymentComposite { private String location; private String content; private String contributionURI; diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java index acbf3d5246..e9bd791f96 100644 --- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java +++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java @@ -33,9 +33,9 @@ import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; /** - * + * Default implementation of NodeConfiguration */ -class NodeConfigurationImpl implements NodeConfiguration { +public class NodeConfigurationImpl implements NodeConfiguration { private String uri; private String domainURI; private List contributions = new ArrayList(); -- cgit v1.2.3