summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-api
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/modules/node-api')
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java11
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java88
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java15
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java51
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java6
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java24
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java1
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/BindingConfigurationImpl.java8
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/ContributionConfigurationImpl.java83
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/DeploymentCompositeImpl.java9
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java3
-rw-r--r--java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationImpl.java75
12 files changed, 323 insertions, 51 deletions
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java
index 3f4998bcc9..d14c1a65ad 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/Node.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.node;
@@ -31,14 +31,15 @@ public interface Node extends Client {
/**
* Start the composite loaded in the node.
+ * @return Return the node itself so that we can call NodeFactory.newInstance().createNode(...).start()
*/
- void start();
+ Node start();
/**
* Stop the composite loaded in the node.
*/
void stop();
-
+
/**
* Destroy the node.
*/
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 426c32bd49..0c1e9bb642 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
@@ -6,21 +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;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
+import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory;
+import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
import org.oasisopen.sca.CallableReference;
import org.oasisopen.sca.ServiceReference;
import org.oasisopen.sca.ServiceRuntimeException;
@@ -28,10 +31,16 @@ import org.oasisopen.sca.ServiceRuntimeException;
/**
* A factory for SCA processing nodes. An SCA processing node can be loaded
* with an SCA composite and the SCA contributions required by the composite.
- *
+ *
* @version $Rev$ $Date$
*/
-public abstract class NodeFactory {
+public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
+
+ protected static NodeFactory nodeFactory;
+
+ protected static void setNodeFactory(NodeFactory factory) {
+ nodeFactory = factory;
+ }
public static class NodeProxy implements Node, Client {
private Object node;
@@ -79,11 +88,12 @@ public abstract class NodeFactory {
}
}
- public void start() {
+ public Node start() {
try {
- node.getClass().getMethod("start").invoke(node);
+ return new NodeProxy(node.getClass().getMethod("start").invoke(node));
} catch (Throwable e) {
handleException(e);
+ return null;
}
}
@@ -121,10 +131,14 @@ public abstract class NodeFactory {
/**
* Returns a new SCA node factory instance.
- *
+ *
* @return a new SCA node factory
*/
public static NodeFactory newInstance() {
+ if (nodeFactory != null) {
+ return nodeFactory;
+ }
+
NodeFactory scaNodeFactory = null;
try {
@@ -133,14 +147,18 @@ public abstract class NodeFactory {
try {
Class<?> discoveryClass = Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery");
Object instance = discoveryClass.getMethod("getInstance").invoke(null);
- Object factoryDeclaration = discoveryClass.getMethod("getFirstServiceDeclaration", String.class).invoke(instance, NodeFactory.class.getName());
+ Object factoryDeclaration =
+ discoveryClass.getMethod("getFirstServiceDeclaration", String.class).invoke(instance,
+ NodeFactory.class
+ .getName());
if (factoryDeclaration != null) {
- Class<?> factoryImplClass = (Class<?>)factoryDeclaration.getClass().getMethod("loadClass").invoke(factoryDeclaration);
+ Class<?> factoryImplClass =
+ (Class<?>)factoryDeclaration.getClass().getMethod("loadClass").invoke(factoryDeclaration);
scaNodeFactory = (NodeFactory)factoryImplClass.newInstance();
return scaNodeFactory;
}
} catch (ClassNotFoundException e) {
- // Ignore
+ // Ignore
}
// Fail back to default impl
@@ -157,43 +175,63 @@ 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
* that contains the URI of the composite and a collection of URLs for the contributions
- *
+ *
* @return a new SCA node.
*/
public abstract Node createNode(String configurationURL);
/**
* Creates a new SCA node.
- *
- * @param compositeURI the URI of the composite to use
- * @param contributions the URI of the contributions that provides the composites and related
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related
* artifacts. If the list is empty, then we will use the thread context classloader to discover
* the contribution on the classpath
- *
+ *
* @return a new SCA node.
*/
public abstract Node createNode(String compositeURI, Contribution... contributions);
/**
* Creates a new SCA node.
- *
- * @param compositeURI the URI of the composite to use
- * @param compositeContent the XML content of the composite to use
- * @param contributions the URI of the contributions that provides the composites and related artifacts
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param compositeContent the XML content of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
* @return a new SCA node.
*/
- public abstract Node createNode(String compositeURI,
- String compositeContent,
- Contribution... contributions);
+ public abstract Node createNode(String compositeURI, String compositeContent, Contribution... contributions);
+
+ /**
+ * Create a new SCA node based on the configuration
+ * @param configuration
+ * @return
+ */
+ public abstract Node createNode(NodeConfiguration configuration);
+ /**
+ * Create the node configuration from the XML document
+ * @param configuration The input stream of the XML document
+ * @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/BindingConfiguration.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java
index 489a3fd2e3..f3be7c5c35 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/BindingConfiguration.java
@@ -28,16 +28,16 @@ import javax.xml.namespace.QName;
*/
public interface BindingConfiguration {
/**
- * Get the QName of the binding
- * @return
+ * Get the QName of the binding type
+ * @return the QName of the binding type
*/
QName getBindingType();
/**
* Set the type of the binding
- * @param type
+ * @param type The QName of the binding type
*/
- void setBindingType(QName type);
+ BindingConfiguration setBindingType(QName type);
/**
* Get a list of base URIs for the binding. For each protocol supported by the binding,
@@ -45,4 +45,11 @@ public interface BindingConfiguration {
* @return A list of base URIs
*/
List<String> getBaseURIs();
+
+ /**
+ * Add a base URI
+ * @param baseURI
+ * @return
+ */
+ BindingConfiguration addBaseURI(String baseURI);
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java
index 0de5e0b473..3e9946fe80 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/ContributionConfiguration.java
@@ -19,6 +19,10 @@
package org.apache.tuscany.sca.node.configuration;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URL;
import java.util.List;
/**
@@ -35,7 +39,7 @@ public interface ContributionConfiguration {
* Set the URI of the contribution
* @param uri The URI of the contribution
*/
- void setURI(String uri);
+ ContributionConfiguration setURI(String uri);
/**
* Get the location of the contribution
@@ -47,11 +51,52 @@ public interface ContributionConfiguration {
* Set the location of the contribution
* @param location The location of the contribution
*/
- void setLocation(String location);
+ ContributionConfiguration setLocation(String location);
/**
* Get the list of deployment composites that are attached to the contribution
- * @return
+ * @return A list of deployment composites
*/
List<DeploymentComposite> getDeploymentComposites();
+
+ /**
+ * Add a deployment composite to this contribution
+ * @param deploymentComposite The deployment composite
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(DeploymentComposite deploymentComposite);
+
+ /**
+ * Create a deployment composite and add it to the contribution configuration
+ * @param location The location is either relative to the contribution or
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(URI location);
+
+ /**
+ * Attach a deployment composite to this contribution
+ * @param location
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(URL location);
+
+ /**
+ * Attach a deployment composite to this contribution
+ * @param content The string that contains the XML description of the SCA composite
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(String content);
+
+ /**
+ * Attach a deployment composite to this contribution
+ * @param content The XML description of the SCA composite from a reader
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(Reader content);
+ /**
+ * Attach a deployment composite to this contribution
+ * @param content The XML description of the SCA composite from an input stream
+ * @return
+ */
+ ContributionConfiguration addDeploymentComposite(InputStream content);
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java
index c322d7ed15..65337abdfb 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/DeploymentComposite.java
@@ -35,7 +35,7 @@ public interface DeploymentComposite {
* Set the location of the deployment composite
* @param location
*/
- void setLocation(String location);
+ DeploymentComposite setLocation(String location);
/**
* Get string content of the deployment composite (XML)
@@ -47,7 +47,7 @@ public interface DeploymentComposite {
* Set the XML content for the composite
* @param compositeXML
*/
- void setContent(String compositeXML);
+ DeploymentComposite setContent(String compositeXML);
/**
* Get the URI of the contribution that the deployment composite is attached to
@@ -59,6 +59,6 @@ public interface DeploymentComposite {
* Set the URI of the contribution that the deployment composite is attached to
* @param contributionURI
*/
- void setContributionURI(String contributionURI);
+ DeploymentComposite setContributionURI(String contributionURI);
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
index f1eeb868ff..4054ffc250 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfiguration.java
@@ -19,8 +19,14 @@
package org.apache.tuscany.sca.node.configuration;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URL;
import java.util.List;
+import javax.xml.namespace.QName;
+
/**
* The configuration for a Node which represents the deployment of an SCA composite application
*/
@@ -35,7 +41,7 @@ public interface NodeConfiguration {
* Set the URI of the SCA domain
* @param domainURI The URI of the SCA domain
*/
- void setDomainURI(String domainURI);
+ NodeConfiguration setDomainURI(String domainURI);
/**
* Get the URI of the node. It uniquely identifies a node within the SCA domain
@@ -47,7 +53,7 @@ public interface NodeConfiguration {
* Set the URI of the node
* @param uri The URI of the node
*/
- void setURI(String uri);
+ NodeConfiguration setURI(String uri);
/**
* Get a list of confiurations for SCA contributions
@@ -60,4 +66,18 @@ public interface NodeConfiguration {
* @return A list of configurations for SCA bindings
*/
List<BindingConfiguration> getBindings();
+
+ NodeConfiguration addContribution(ContributionConfiguration contribution);
+ NodeConfiguration addContribution(String contributionURI, String location);
+ NodeConfiguration addContribution(String contributionURI, URL location);
+ NodeConfiguration addContribution(URI contributionURI, URL location);
+ NodeConfiguration addContribution(URL...location);
+
+ NodeConfiguration addDeploymentComposite(String contributionURI, String location);
+ NodeConfiguration addDeploymentComposite(String contributionURI, Reader content);
+ NodeConfiguration addDeploymentComposite(String contributionURI, InputStream content);
+
+ NodeConfiguration addBinding(BindingConfiguration binding);
+ NodeConfiguration addBinding(QName bindingType, String...baseURIs);
+ NodeConfiguration addBinding(QName bindingType, URI...baseURIs);
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java
index ca1afee923..f03a895114 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/NodeConfigurationFactory.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.node.configuration;
+
/**
* The factory to create java models related to the node 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 eb5ac2915b..dd38f97161 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
@@ -41,8 +41,14 @@ class BindingConfigurationImpl implements BindingConfiguration {
return type;
}
- public void setBindingType(QName type) {
+ public BindingConfiguration setBindingType(QName type) {
this.type = type;
+ return this;
+ }
+
+ public BindingConfiguration addBaseURI(String baseURI) {
+ baseURIs.add(baseURI);
+ return this;
}
}
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 d34fac866c..b863ede5f6 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
@@ -19,6 +19,13 @@
package org.apache.tuscany.sca.node.configuration.impl;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +40,21 @@ class ContributionConfigurationImpl implements ContributionConfiguration {
private String uri;
private String location;
+ public ContributionConfigurationImpl() {
+ super();
+ }
+
+ public ContributionConfigurationImpl(String uri, String location) {
+ super();
+ this.uri = uri;
+ this.location = location;
+ }
+
+ public ContributionConfigurationImpl(String location) {
+ super();
+ this.uri = location;
+ this.location = location;
+ }
/**
* Get the URI of the contribution
@@ -46,8 +68,9 @@ class ContributionConfigurationImpl implements ContributionConfiguration {
* Set the URI of the contribution
* @param uri The URI of the contribution
*/
- public void setURI(String uri) {
+ public ContributionConfiguration setURI(String uri) {
this.uri = uri;
+ return this;
}
/**
@@ -62,8 +85,9 @@ class ContributionConfigurationImpl implements ContributionConfiguration {
* Set the location of the contribution
* @param location The location of the contribution
*/
- public void setLocation(String location) {
+ public ContributionConfiguration setLocation(String location) {
this.location = location;
+ return this;
}
/**
@@ -73,4 +97,59 @@ class ContributionConfigurationImpl implements ContributionConfiguration {
public List<DeploymentComposite> getDeploymentComposites() {
return deploymentComposites;
}
+
+ public ContributionConfiguration addDeploymentComposite(DeploymentComposite deploymentComposite) {
+ deploymentComposites.add(deploymentComposite);
+ if (uri != null) {
+ deploymentComposite.setContributionURI(uri);
+ }
+ return this;
+ }
+
+ public ContributionConfiguration addDeploymentComposite(Reader reader) {
+ try {
+ DeploymentComposite composite = new DeploymentCompositeImpl();
+ char[] buf = new char[8192];
+ StringWriter sw = new StringWriter();
+ int size = 0;
+ while (size >= 0) {
+ size = reader.read(buf);
+ if (size > 0) {
+ sw.write(buf, 0, size);
+ }
+ }
+ reader.close();
+ composite.setContent(sw.toString());
+ return addDeploymentComposite(composite);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public ContributionConfiguration addDeploymentComposite(InputStream content) {
+ try {
+ InputStreamReader reader = new InputStreamReader(content, "UTF-8");
+ return addDeploymentComposite(reader);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public ContributionConfiguration addDeploymentComposite(String content) {
+ DeploymentComposite composite = new DeploymentCompositeImpl();
+ composite.setContent(content);
+ return addDeploymentComposite(composite);
+ }
+
+ public ContributionConfiguration addDeploymentComposite(URI location) {
+ DeploymentComposite composite = new DeploymentCompositeImpl();
+ composite.setLocation(location.toString());
+ return addDeploymentComposite(composite);
+ }
+
+ public ContributionConfiguration addDeploymentComposite(URL location) {
+ DeploymentComposite composite = new DeploymentCompositeImpl();
+ composite.setLocation(location.toString());
+ return addDeploymentComposite(composite);
+ }
}
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 fabba4551e..4edcf75bba 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
@@ -33,24 +33,27 @@ class DeploymentCompositeImpl implements DeploymentComposite {
return location;
}
- public void setLocation(String location) {
+ public DeploymentComposite setLocation(String location) {
this.location = location;
+ return this;
}
public String getContent() {
return content;
}
- public void setContent(String content) {
+ public DeploymentComposite setContent(String content) {
this.content = content;
+ return this;
}
public String getContributionURI() {
return contributionURI;
}
- public void setContributionURI(String contributionURI) {
+ public DeploymentComposite setContributionURI(String contributionURI) {
this.contributionURI = contributionURI;
+ return this;
}
}
diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java
index 96ca3e6199..fe5e9012cf 100644
--- a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java
+++ b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/configuration/impl/NodeConfigurationFactoryImpl.java
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.node.configuration.impl;
import org.apache.tuscany.sca.node.configuration.BindingConfiguration;
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.node.configuration.NodeConfigurationFactory;
/**
@@ -32,7 +33,7 @@ public abstract class NodeConfigurationFactoryImpl implements NodeConfigurationF
* Create a new instance of NodeConfiguration
* @return
*/
- public NodeConfigurationImpl createNodeConfiguration() {
+ public NodeConfiguration createNodeConfiguration() {
return new NodeConfigurationImpl();
}
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 4f13959ced..162918f98d 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
@@ -19,9 +19,15 @@
package org.apache.tuscany.sca.node.configuration.impl;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.namespace.QName;
+
import org.apache.tuscany.sca.node.configuration.BindingConfiguration;
import org.apache.tuscany.sca.node.configuration.ContributionConfiguration;
import org.apache.tuscany.sca.node.configuration.NodeConfiguration;
@@ -39,16 +45,18 @@ class NodeConfigurationImpl implements NodeConfiguration {
return uri;
}
- public void setURI(String uri) {
+ public NodeConfiguration setURI(String uri) {
this.uri = uri;
+ return this;
}
public String getDomainURI() {
return domainURI;
}
- public void setDomainURI(String domainURI) {
+ public NodeConfiguration setDomainURI(String domainURI) {
this.domainURI = domainURI;
+ return this;
}
public List<ContributionConfiguration> getContributions() {
@@ -59,5 +67,68 @@ class NodeConfigurationImpl implements NodeConfiguration {
return bindings;
}
+ public NodeConfiguration addBinding(BindingConfiguration bindingConfiguration) {
+ bindings.add(bindingConfiguration);
+ return this;
+ }
+
+ public NodeConfiguration addContribution(ContributionConfiguration contributionConfiguration) {
+ contributions.add(contributionConfiguration);
+ return this;
+ }
+
+ public NodeConfiguration addBinding(QName bindingType, String... baseURIs) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addBinding(QName bindingType, URI... baseURIs) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addContribution(String contributionURI, String location) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addContribution(String contributionURI, URL location) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addContribution(URI contributionURI, URL location) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addContribution(URL... location) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public NodeConfiguration addDeploymentComposite(String contributionURI, InputStream content) {
+ findContribution(contributionURI).addDeploymentComposite(content);
+ return this;
+ }
+
+ public NodeConfiguration addDeploymentComposite(String contributionURI, Reader content) {
+ findContribution(contributionURI).addDeploymentComposite(content);
+ return this;
+ }
+
+ public NodeConfiguration addDeploymentComposite(String contributionURI, String location) {
+ findContribution(contributionURI).addDeploymentComposite(URI.create(location));
+ return this;
+ }
+
+ private ContributionConfiguration findContribution(String uri) {
+ for (ContributionConfiguration c : contributions) {
+ if (c.getURI() != null && c.getURI().equals(uri)) {
+ return c;
+ }
+ }
+ throw new IllegalArgumentException("Contribution is not found (uri=" + uri + ")");
+ }
}