diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-14 07:00:09 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2011-06-14 07:00:09 +0000 |
commit | 86341a0d865276fac10d6d595cfa6361380559fe (patch) | |
tree | 0bf27a14d184b416fc61cb8667ee2ce76aa789f0 /sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany | |
parent | 745f458002e384d4de784449685e9fc21e667a99 (diff) |
Have a look at creating a domain node from a file system dirctory to see if its possible to do it in a way thats simpler than requiring a node.xml config file
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1135391 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java index 4dbccfbe28..3c34a24ca3 100644 --- a/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java +++ b/sca-java-2.x/trunk/modules/domain-node/src/main/java/org/apache/tuscany/sca/TuscanyRuntime.java @@ -19,13 +19,21 @@ package org.apache.tuscany.sca; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; +import javax.xml.stream.XMLStreamException; + import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; @@ -136,7 +144,7 @@ public class TuscanyRuntime { * @return a Node */ public Node createNode() { - return createNode(null); + return createNode((String)null); } /** @@ -152,6 +160,66 @@ public class TuscanyRuntime { DomainRegistry domainRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName); return new NodeImpl(deployer, compositeActivator, domainRegistry, extensionPointRegistry, null); } + + /* + * Create a node from a file system directory. + * The directory can contain: + * domain.properties + * contributions - jar, zip, or exploded directories + * sca-contribution.xml metaData files to override whats in a contribution + * .composite files to add to contributions as additional deployables + * + * TODO: Review if this is useful? + */ + public Node createNode(File directory) throws ContributionReadException, ValidationException, ActivationException, XMLStreamException, IOException { + + Properties domainProps = new Properties(); + File propsFile = new File(directory, "domain.properties"); + if (propsFile.exists()) { + domainProps.load(new FileInputStream(propsFile)); + } + String domainName = domainProps.getProperty("domainName", directory.getName()); + String domainURI = domainProps.getProperty("domainURI", domainName); + + DomainRegistry domainRegistry = domainRegistryFactory.getEndpointRegistry(domainURI, domainName); + Node node = new NodeImpl(deployer, compositeActivator, domainRegistry, extensionPointRegistry, null); + + + List<String> installed = new ArrayList<String>(); + for (File f : directory.listFiles()) { + if (!f.getName().endsWith(".xml") && !f.getName().endsWith(".composite")) { + String fn = f.getName().lastIndexOf('.') == -1 ? f.getName() : f.getName().substring(0, f.getName().lastIndexOf('.')); + String metaData = null; + for (File f2 : directory.listFiles()) { + if (f2.getName().startsWith(fn) && f2.getName().endsWith(".xml")) { + metaData = f2.getPath(); + break; + } + } + + List<String> dependencyURIs = new ArrayList(); + String dependencyURIprop = domainProps.getProperty(fn + ".dependencies"); + if (dependencyURIprop != null && dependencyURIprop.length() > 0) { + dependencyURIs = Arrays.asList(dependencyURIprop.split(",")); + } + + String curi = node.installContribution(null, f.getPath(), metaData, dependencyURIs); + installed.add(curi); + + for (File f2 : directory.listFiles()) { + if (f2.getName().startsWith(fn) && f2.getName().endsWith(".composite")) { + node.addDeploymentComposite(curi, new FileReader(f2)); + } + } + } + } + + for (String curi : installed) { + node.startDeployables(curi); + } + + return node; + } /** * Creates a Node from an XML configuration file |