summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-15 03:41:05 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-15 03:41:05 +0000
commitf2c134b2c1dfd5fedd472bafe53155db55ad9d70 (patch)
treeb90e132d2337330b8491968a1ffff034f6301837 /java/sca/modules
parentc35965ba40d5bd2fa3f840a4a7878c0313230db7 (diff)
Integrate the NodeConfiguration with NodeImpl
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@774994 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java21
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java9
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java2
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java41
-rw-r--r--java/sca/modules/node-impl/META-INF/MANIFEST.MF1
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java72
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java344
-rw-r--r--java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java25
8 files changed, 252 insertions, 263 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java
index 62ed95cb01..d077bc63a0 100644
--- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java
+++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.assembly.xml;
@@ -40,35 +40,36 @@ public class CompositeModelResolver implements ModelResolver {
private Contribution contribution;
private Map<QName, Composite> map = new HashMap<QName, Composite>();
-
+
public CompositeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
this.contribution = contribution;
}
public void addModel(Object resolved) {
Composite composite = (Composite)resolved;
+ // FIXME: What if two composites with the same QName are added?
map.put(composite.getName(), composite);
}
-
+
public Object removeModel(Object resolved) {
return map.remove(((Composite)resolved).getName());
}
-
+
public <T> T resolveModel(Class<T> modelClass, T unresolved) {
-
+
// Lookup a definition for the given namespace
QName qname = ((Composite)unresolved).getName();
Composite resolved = (Composite) map.get(qname);
if (resolved != null) {
return modelClass.cast(resolved);
}
-
+
// No definition found, delegate the resolution to the imports
for (Import import_ : this.contribution.getImports()) {
if (import_ instanceof NamespaceImport) {
NamespaceImport namespaceImport = (NamespaceImport)import_;
if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) {
-
+
// Delegate the resolution to the import resolver
resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved);
if (!resolved.isUnresolved()) {
@@ -79,5 +80,5 @@ public class CompositeModelResolver implements ModelResolver {
}
return (T)unresolved;
}
-
+
}
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 0c1e9bb642..1f30045bd1 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
@@ -225,13 +225,4 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
* @return The node configuration
*/
public abstract NodeConfiguration loadConfiguration(InputStream xml);
-
- public static void main(String args[]) {
- NodeFactory factory = NodeFactory.newInstance();
- NodeConfiguration nodeConfiguration =
- factory.createNodeConfiguration().setDomainURI("http://d1").setURI("http://node1")
- .addContribution("http://c1", "file:/a.jar");
- Node node = factory.createNode(nodeConfiguration).start();
-
- }
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java
index a14a4ac9eb..53e26fc9ad 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DefaultNodeConfigurationFactory.java
@@ -24,5 +24,5 @@ import org.apache.tuscany.sca.node.configuration.impl.NodeConfigurationFactoryIm
/**
* Default NodeConfigurationFactory
*/
-public class DefaultNodeConfigurationFactory extends NodeConfigurationFactoryImpl {
+public class DefaultNodeConfigurationFactory extends NodeConfigurationFactoryImpl implements NodeConfigurationFactory {
}
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 162918f98d..acbf3d5246 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
@@ -78,33 +78,40 @@ class NodeConfigurationImpl implements NodeConfiguration {
}
public NodeConfiguration addBinding(QName bindingType, String... baseURIs) {
- // TODO Auto-generated method stub
- return null;
+ BindingConfiguration binding = new BindingConfigurationImpl().setBindingType(bindingType);
+ for (String u : baseURIs) {
+ binding.addBaseURI(u);
+ }
+ return addBinding(binding);
}
public NodeConfiguration addBinding(QName bindingType, URI... baseURIs) {
- // TODO Auto-generated method stub
- return null;
+ BindingConfiguration binding = new BindingConfigurationImpl().setBindingType(bindingType);
+ for (URI u : baseURIs) {
+ binding.addBaseURI(u.toString());
+ }
+ return addBinding(binding);
}
public NodeConfiguration addContribution(String contributionURI, String location) {
- // TODO Auto-generated method stub
- return null;
+ ContributionConfiguration contribution = new ContributionConfigurationImpl(contributionURI, location);
+ return addContribution(contribution);
}
public NodeConfiguration addContribution(String contributionURI, URL location) {
- // TODO Auto-generated method stub
- return null;
+ return addContribution(contributionURI, location.toString());
}
public NodeConfiguration addContribution(URI contributionURI, URL location) {
- // TODO Auto-generated method stub
- return null;
+ return addContribution(contributionURI.toString(), location.toString());
}
- public NodeConfiguration addContribution(URL... location) {
- // TODO Auto-generated method stub
- return null;
+ public NodeConfiguration addContribution(URL... locations) {
+ for (URL url : locations) {
+ ContributionConfiguration contribution = new ContributionConfigurationImpl(url.toString(), url.toString());
+ addContribution(contribution);
+ }
+ return this;
}
public NodeConfiguration addDeploymentComposite(String contributionURI, InputStream content) {
@@ -131,4 +138,12 @@ class NodeConfigurationImpl implements NodeConfiguration {
throw new IllegalArgumentException("Contribution is not found (uri=" + uri + ")");
}
+ public String toString() {
+ if (domainURI != null) {
+ return "{" + domainURI + "}" + uri;
+ } else {
+ return uri;
+ }
+ }
+
}
diff --git a/java/sca/modules/node-impl/META-INF/MANIFEST.MF b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
index f04a4d5443..5feccbf81d 100644
--- a/java/sca/modules/node-impl/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-impl/META-INF/MANIFEST.MF
@@ -32,6 +32,7 @@ Import-Package: javax.xml.namespace,
org.apache.tuscany.sca.definitions;version="2.0.0",
org.apache.tuscany.sca.definitions.util;version="2.0.0",
org.apache.tuscany.sca.definitions.xml;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.monitor;version="2.0.0",
org.apache.tuscany.sca.node;version="2.0.0",
org.apache.tuscany.sca.node.configuration;version="2.0.0",
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 292839fe3a..38376a584f 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
@@ -19,16 +19,24 @@
package org.apache.tuscany.sca.node.impl;
+import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
+
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamReader;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
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;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
+import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory;
import org.apache.tuscany.sca.node.configuration.xml.NodeConfigurationProcessor;
import org.oasisopen.sca.ServiceRuntimeException;
@@ -43,34 +51,84 @@ public class NodeFactoryImpl extends NodeFactory {
@Override
public Node createNode(String configurationURI) {
- return new NodeImpl(configurationURI);
+ try {
+ URL url = new URL(configurationURI);
+ InputStream is = openStream(url);
+ NodeConfiguration configuration = loadConfiguration(is);
+ is.close();
+ return new NodeImpl(configuration);
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
}
@Override
public Node createNode(String compositeURI, Contribution... contributions) {
- return new NodeImpl(compositeURI, contributions);
+ NodeConfigurationFactory factory = this;
+ NodeConfiguration configuration = factory.createNodeConfiguration();
+ for (Contribution c : contributions) {
+ configuration.addContribution(c.getURI(), c.getLocation());
+ }
+ if (compositeURI != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(NodeUtil.createURI(compositeURI));
+ }
+ return new NodeImpl(configuration);
}
@Override
public Node createNode(String compositeURI, String compositeContent, Contribution... contributions) {
- return new NodeImpl(compositeURI, compositeContent, contributions);
+ NodeConfigurationFactory factory = this;
+ NodeConfiguration configuration = factory.createNodeConfiguration();
+ for (Contribution c : contributions) {
+ configuration.addContribution(c.getURI(), c.getLocation());
+ }
+ if (compositeContent != null && configuration.getContributions().size() > 0) {
+ configuration.getContributions().get(0).addDeploymentComposite(compositeContent);
+ }
+ return new NodeImpl(configuration);
}
@Override
public Node createNode() {
- return new NodeImpl();
+ String location =
+ ContributionLocationHelper
+ .getContributionLocation(org.apache.tuscany.sca.contribution.Contribution.SCA_CONTRIBUTION_META);
+ if (location == null) {
+ location =
+ ContributionLocationHelper
+ .getContributionLocation(org.apache.tuscany.sca.contribution.Contribution.SCA_CONTRIBUTION_GENERATED_META);
+ }
+ if (location == null) {
+ throw new ServiceRuntimeException("No SCA contributions are found on the classpath");
+ }
+ return createNode(null, new Contribution("http://contributions/default", location));
}
@Override
public Node createNode(NodeConfiguration configuration) {
- return null;
+ return new NodeImpl(configuration);
+ }
+
+ /**
+ * @param <T>
+ * @param factory
+ * @return
+ * @throws Exception
+ */
+ private <T> T getFactory(Class<T> factory) throws Exception {
+ ServiceDeclaration sd = ServiceDiscovery.getInstance().getFirstServiceDeclaration(factory.getName());
+ if (sd != null) {
+ return factory.cast(sd.loadClass().newInstance());
+ } else {
+ return factory.cast(factory.getMethod("newInstance").invoke(null));
+ }
}
@Override
public NodeConfiguration loadConfiguration(InputStream xml) {
try {
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+ XMLInputFactory inputFactory = getFactory(XMLInputFactory.class);
+ XMLOutputFactory outputFactory = getFactory(XMLOutputFactory.class);
XMLStreamReader reader = inputFactory.createXMLStreamReader(xml);
NodeConfigurationProcessor processor = new NodeConfigurationProcessor(this, inputFactory, outputFactory);
reader.nextTag();
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 22fd8bce84..15794d9581 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
@@ -21,25 +21,28 @@ package org.apache.tuscany.sca.node.impl;
import static java.lang.System.currentTimeMillis;
import static org.apache.tuscany.sca.node.impl.NodeUtil.createURI;
+import static org.apache.tuscany.sca.node.impl.NodeUtil.openStream;
-import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
import java.net.URI;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.tuscany.sca.assembly.AssemblyFactory;
@@ -56,11 +59,11 @@ import org.apache.tuscany.sca.contribution.ContributionFactory;
import org.apache.tuscany.sca.contribution.DefaultImport;
import org.apache.tuscany.sca.contribution.Export;
import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
-import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
import org.apache.tuscany.sca.contribution.resolver.DefaultImportModelResolver;
@@ -88,8 +91,10 @@ 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.node.configuration.ContributionConfiguration;
+import org.apache.tuscany.sca.node.configuration.DeploymentComposite;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.apache.tuscany.sca.provider.DefinitionsProvider;
import org.apache.tuscany.sca.provider.DefinitionsProviderException;
import org.apache.tuscany.sca.provider.DefinitionsProviderExtensionPoint;
@@ -117,10 +122,6 @@ public class NodeImpl implements Node, Client, SCAClient {
// The node configuration name, used for logging
private String configurationName;
- // The composite loaded into this node
- private Composite composite;
- private boolean useDeploymentComposite;
-
private ExtensionPointRegistry extensionPoints;
private Monitor monitor;
private ExtendedURLArtifactProcessor<Contribution> contributionProcessor;
@@ -139,97 +140,15 @@ public class NodeImpl implements Node, Client, SCAClient {
private WorkScheduler workScheduler;
private Contribution systemContribution;
private Definitions systemDefinitions;
- private URLArtifactProcessor<Composite> compositeDocumentProcessor;
-
- /**
- * 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");
- }
+ NodeImpl(NodeConfiguration configuration) {
+ logger.log(Level.INFO, "Creating node: " + configuration.getURI());
try {
// Initialize the runtime
init();
- Map<String, String> contributions = new HashMap<String, String>();
- contributions.put(root, root);
-
// Configure the node
- configureNode(contributions, null, null);
-
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- /**
- * Constructs a new SCA node.
- *
- * @param configurationURI the URI of the node configuration information.
- */
- NodeImpl(String configurationURI) {
- throw new IllegalStateException("not supported");
- }
-
- /**
- * Constructs a new SCA node.
- *
- * @param compositeURI
- * @param nodeContributions
- */
- NodeImpl(String compositeURI, org.apache.tuscany.sca.node.Contribution[] nodeContributions) {
- configurationName = compositeURI;
- logger.log(Level.INFO, "Creating node: " + configurationName);
-
- try {
- // Initialize the runtime
- init();
-
- // Create contribution models
- Map<String, String> contributions = new HashMap<String, String>();
- for (org.apache.tuscany.sca.node.Contribution c : nodeContributions) {
- contributions.put(c.getURI(), c.getLocation());
- }
-
- // Configure the node
- configureNode(contributions, compositeURI, null);
-
- } catch (Exception e) {
- throw new ServiceRuntimeException(e);
- }
- }
-
- /**
- * Constructs a new SCA node.
- *
- * @param compositeURI
- * @param compositeContent
- * @param nodeContributions
- */
- NodeImpl(String compositeURI, String compositeContent, org.apache.tuscany.sca.node.Contribution[] nodeContributions) {
- configurationName = compositeURI;
- logger.log(Level.INFO, "Creating node: " + configurationName);
-
- try {
- // Initialize the runtime
- init();
-
- // Read the composite model
- logger.log(Level.INFO, "Loading composite: " + compositeURI);
-
- Map<String, String> contributions = new HashMap<String, String>();
- for (org.apache.tuscany.sca.node.Contribution c : nodeContributions) {
- contributions.put(c.getURI(), c.getLocation());
- }
-
- // Configure the node
- configureNode(contributions, compositeURI, compositeContent);
+ configureNode(configuration);
} catch (Exception e) {
throw new ServiceRuntimeException(e);
@@ -298,9 +217,6 @@ public class NodeImpl implements Node, Client, SCAClient {
URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
- // Create Composite Document processor
- compositeDocumentProcessor = docProcessorExtensions.getProcessor(Composite.class);
-
// Get the model resolvers
modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
@@ -367,17 +283,16 @@ public class NodeImpl implements Node, Client, SCAClient {
}
}
- private void configureNode(Map<String, String> contributionLocations, String defaultCompositeURI, String defaultCompositeContent) throws Exception {
-
+ private void configureNode(NodeConfiguration configuration) throws Exception {
List<Contribution> contributions = new ArrayList<Contribution>();
// Load the specified contributions
- for (String c : contributionLocations.keySet()) {
- URI contributionURI = NodeUtil.createURI(c);
+ for (ContributionConfiguration contrib : configuration.getContributions()) {
+ URI contributionURI = createURI(contrib.getURI());
- URI uri = createURI(contributionLocations.get(c));
+ URI uri = createURI(contrib.getLocation());
if (uri.getScheme() == null) {
- uri = new File(contributionLocations.get(c)).toURI();
+ uri = new File(contrib.getLocation()).toURI();
}
URL contributionURL = uri.toURL();
@@ -385,6 +300,42 @@ public class NodeImpl implements Node, Client, SCAClient {
logger.log(Level.INFO, "Loading contribution: " + contributionURL);
Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
contributions.add(contribution);
+
+ boolean attached = false;
+ for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
+ if (dc.getContent() != null) {
+ Reader xml = new StringReader(dc.getContent());
+ attached = attachDeploymentComposite(contribution, xml, null, attached);
+ } else if (dc.getLocation() != null) {
+ URI dcURI = createURI(dc.getLocation());
+ if (!dcURI.isAbsolute()) {
+ Composite composite = null;
+ // The location is pointing to an artifact within the contribution
+ for (Artifact a : contribution.getArtifacts()) {
+ if (dcURI.toString().equals(a.getURI())) {
+ composite = (Composite)a.getModel();
+ if (!attached) {
+ contribution.getDeployables().clear();
+ attached = true;
+ }
+ contribution.getDeployables().add(composite);
+ break;
+ }
+ }
+ if (composite == null) {
+ // Not found
+ throw new ServiceRuntimeException("Deployment composite " + dcURI
+ + " cannot be found within contribution "
+ + contribution.getLocation());
+ }
+ } else {
+ URL url = dcURI.toURL();
+ InputStream is = openStream(url);
+ Reader xml = new InputStreamReader(is, "UTF-8");
+ attached = attachDeploymentComposite(contribution, xml, url.toString(), attached);
+ }
+ }
+ }
analyzeProblems();
}
@@ -439,78 +390,29 @@ public class NodeImpl implements Node, Client, SCAClient {
}
}
- composite = getDefaultComposite(contributions, defaultCompositeURI, defaultCompositeContent);
-
- // Find the composite in the given contributions
- boolean found = false;
- if (!useDeploymentComposite) {
- Artifact compositeFile = contributionFactory.createArtifact();
- compositeFile.setUnresolved(true);
- compositeFile.setURI(composite.getURI());
- for (Contribution contribution : contributions) {
- ModelResolver resolver = contribution.getModelResolver();
-
- Artifact resolvedArtifact = resolver.resolveModel(Artifact.class, compositeFile);
- if (!resolvedArtifact.isUnresolved() && resolvedArtifact.getModel() instanceof Composite) {
-
- if (!composite.isUnresolved()) {
+ // Create a top level composite to host our composite
+ // This is temporary to make the activator happy
+ Composite tempComposite = assemblyFactory.createComposite();
+ tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
+ tempComposite.setURI(SCA11_TUSCANY_NS);
- // The composite content was passed into the node and read into a composite model,
- // don't use the composite found in the contribution, use that composite, but just resolve
- // it within the context of the contribution
- compositeProcessor.resolve(composite, resolver);
+ for (Contribution contribution : contributions) {
+ for (Composite composite : contribution.getDeployables()) {
- } else {
+ // Build the composite and wire the components included in it
+ compositeBuilder.build(composite, systemDefinitions, monitor);
+ analyzeProblems();
- // Use the resolved composite we've found in the contribution
- composite = (Composite)resolvedArtifact.getModel();
- }
- found = true;
- break;
- } // end if
- } // end for
- }
+ // build the endpoint references
+ endpointReferenceBuilder.build(composite, systemDefinitions, monitor);
+ analyzeProblems();
- if (!found) {
- if (!useDeploymentComposite) {
- // If the composite was not found, then it must be a separate composite file outside any of the contributions
- // - a "composite by value" - this requires its URI to be absolute and pointing at the composite file itself.
- // First read in the composite file to create a composite model object...
- URI compositeURI = new URI(composite.getURI());
- URL compositeURL = compositeURI.toURL();
- composite = compositeDocumentProcessor.read(compositeURL, compositeURI, compositeURL);
- if (composite == null) {
- throw new IllegalArgumentException("Composite not found: " + compositeURI);
- }
- }
+ // Include the node composite in the top-level composite
+ tempComposite.getIncludes().add(composite);
- // Resolve the "composite by value" against the FIRST contribution
- Contribution contribution = contributions.get(0);
- ModelResolver resolver = contribution.getModelResolver();
- compositeProcessor.resolve(composite, resolver);
- if (composite.isUnresolved()) {
- throw new IllegalArgumentException("Could not resolve composite: " + composite.getURI()
- + " in contribution "
- + contribution.getURI());
}
- } // end if
- // Build the composite and wire the components included in it
- compositeBuilder.build(composite, systemDefinitions, monitor);
- analyzeProblems();
-
- // build the endpoint references
- endpointReferenceBuilder.build(composite, systemDefinitions, monitor);
- analyzeProblems();
-
- // Create a top level composite to host our composite
- // This is temporary to make the activator happy
- Composite tempComposite = assemblyFactory.createComposite();
- tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
- tempComposite.setURI(SCA11_TUSCANY_NS);
-
- // Include the node composite in the top-level composite
- tempComposite.getIncludes().add(composite);
+ }
// Set the top level composite on the composite activator as
// logic in callable reference resolution relies on this being
@@ -519,6 +421,41 @@ public class NodeImpl implements Node, Client, SCAClient {
}
+ private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached)
+ throws XMLStreamException, ContributionReadException {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(xml);
+ reader.nextTag();
+
+ // Read the composite model
+ Composite composite = (Composite)compositeProcessor.read(reader);
+ reader.close();
+
+ // Create an artifact for the deployment composite
+ Artifact artifact = contributionFactory.createArtifact();
+ String uri = composite.getName().getLocalPart() + ".composite";
+ artifact.setURI(uri);
+ // Set the location to avoid NPE
+ if (location == null) {
+ location = uri;
+ }
+ artifact.setLocation(location);
+ artifact.setModel(composite);
+ artifact.setUnresolved(false);
+ // Add it to the contribution
+ contribution.getArtifacts().add(artifact);
+
+ // Replace the deployable composites with the deployment composites
+ // Clear the deployable composites if it's the first deployment composite
+ if (!attached) {
+ contribution.getDeployables().clear();
+ attached = true;
+ }
+ contribution.getDeployables().add(composite);
+ // REVIEW: Is it needed?
+ contribution.getModelResolver().addModel(composite);
+ return attached;
+ }
+
private void buildDependencies(Contribution contribution, List<Contribution> contributions, Monitor monitor) {
contribution.getDependencies().clear();
@@ -603,11 +540,13 @@ public class NodeImpl implements Node, Client, SCAClient {
try {
- // Activate the composite
- compositeActivator.activate(composite);
+ for (Composite composite : compositeActivator.getDomainComposite().getIncludes()) {
+ // Activate the composite
+ compositeActivator.activate(composite);
- // Start the composite
- compositeActivator.start(composite);
+ // Start the composite
+ compositeActivator.start(composite);
+ }
SCAClientImpl.addDomain(getDomainName(), this);
@@ -625,12 +564,17 @@ public class NodeImpl implements Node, Client, SCAClient {
try {
SCAClientImpl.removeDomain(getDomainName());
+ List<Composite> composites = compositeActivator.getDomainComposite().getIncludes();
+ for (Composite composite : composites) {
+
+ // Stop the composite
+ compositeActivator.stop(composite);
- // Stop the composite
- compositeActivator.stop(composite);
+ // Deactivate the composite
+ compositeActivator.deactivate(composite);
- // Deactivate the composite
- compositeActivator.deactivate(composite);
+ }
+ composites.clear();
} catch (ActivationException e) {
throw new IllegalStateException(e);
@@ -690,9 +634,11 @@ public class NodeImpl implements Node, Client, SCAClient {
// Lookup the component
Component component = null;
- for (Component compositeComponent : composite.getComponents()) {
- if (compositeComponent.getName().equals(componentName)) {
- component = compositeComponent;
+ for (Composite composite : compositeActivator.getDomainComposite().getIncludes()) {
+ for (Component compositeComponent : composite.getComponents()) {
+ if (compositeComponent.getName().equals(componentName)) {
+ component = compositeComponent;
+ }
}
}
@@ -749,46 +695,6 @@ public class NodeImpl implements Node, Client, SCAClient {
}
}
- /*
- * Sets a default composite by using any deployable one.
- */
- private Composite getDefaultComposite(List<Contribution> contributions, String defaultCompositeURI, String content) throws Exception {
- Composite composite = assemblyFactory.createComposite();
- composite.setUnresolved(true);
-
- if (content != null && content.length() > 0) {
-
- XMLStreamReader reader = inputFactory.createXMLStreamReader(new ByteArrayInputStream(content.getBytes("UTF-8")));
- reader.nextTag();
-
- // Read the composite model
- composite = (Composite)compositeProcessor.read(reader);
- if (composite != null && defaultCompositeURI != null) {
- composite.setURI(defaultCompositeURI);
- }
- analyzeProblems();
- useDeploymentComposite = true;
- return composite;
-
- } else if (defaultCompositeURI != null && defaultCompositeURI.length() > 0) {
- composite.setURI(defaultCompositeURI);
- return composite;
-
- } else {
- // just use the first deployable composte
- for (Contribution contribution : contributions) {
- for (Composite c : contribution.getDeployables()) {
- // Ensure that we pick a composite that has actually been found in its contribution!!
- if( c.getURI() != null ) {
- composite.setURI(c.getURI());
- return composite;
- }
- }
- }
- }
- throw new ServiceRuntimeException("no deployable composite found");
- }
-
public ExtensionPointRegistry getExtensionPoints() {
return extensionPoints;
}
diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
index 67486b0ab3..beb378ff5d 100644
--- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
+++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeUtil.java
@@ -6,20 +6,24 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.node.impl;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
import java.util.logging.Logger;
import org.apache.tuscany.sca.contribution.Contribution;
@@ -48,7 +52,7 @@ public class NodeUtil {
*/
static URI createURI(String uri) {
URI returnURI = null;
-
+
try {
returnURI = URI.create(uri);
} catch( Exception e) {
@@ -61,4 +65,17 @@ public class NodeUtil {
return returnURI;
}
+ /**
+ * Open a URL connection without cache
+ * @param url
+ * @return
+ * @throws IOException
+ */
+ static InputStream openStream(URL url) throws IOException {
+ InputStream is = null;
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ return is;
+ }
}