diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules')
12 files changed, 58 insertions, 80 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java index a0bfe7409e..fcdef83225 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java @@ -44,11 +44,11 @@ public class AsynchTestCase { try { // create and start nodes Contribution contrib = new Contribution("asynch", "./target/test-classes/asynchReference"); - nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeA.start(); contrib = new Contribution("asynch", "./target/test-classes/asynchService"); - nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeB.start(); } catch (Exception ex) { diff --git a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java index ad272528d8..cb15755708 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java @@ -42,11 +42,11 @@ public class CallbackTestCase { try { // create and start nodes Contribution contrib = new Contribution("reference", "./target/test-classes/callbackReference"); - nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeA.start(); contrib = new Contribution("service", "./target/test-classes/callbackService"); - nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeB.start(); } catch (Exception ex) { diff --git a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java index 30919c5cb0..7357580364 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java @@ -42,11 +42,11 @@ public class PromotionTestCase { try { // create and start nodes Contribution contrib = new Contribution("reference", "./target/test-classes/promotionReference"); - nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeA.start(); contrib = new Contribution("service", "./target/test-classes/promotionService"); - nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeB.start(); } catch (Exception ex) { diff --git a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java index c65e4ea5c9..a0bb50cbf6 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-axis2-runtime/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java @@ -41,11 +41,11 @@ public class SimpleTestCase { try { // create and start nodes Contribution contrib = new Contribution("reference", "./target/test-classes/simpleReference"); - nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeA.start(); contrib = new Contribution("service", "./target/test-classes/simpleService"); - nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib); + nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib); nodeB.start(); } catch (Exception ex) { diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/AsynchTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/AsynchTestCase.java index b68fe7fed4..0dbe8b864b 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/AsynchTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/AsynchTestCase.java @@ -42,11 +42,11 @@ public class AsynchTestCase { try {
// create and start nodes
Contribution contrib = new Contribution("asynch", "./target/test-classes/asynchReference");
- nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeA.start();
contrib = new Contribution("asynch", "./target/test-classes/asynchService");
- nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeB.start();
} catch (Exception ex) {
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/CallbackTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/CallbackTestCase.java index 4c05006ba6..b981bbc943 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/CallbackTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/CallbackTestCase.java @@ -40,11 +40,11 @@ public class CallbackTestCase { try {
// create and start nodes
Contribution contrib = new Contribution("reference", "./target/test-classes/callbackReference");
- nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeA.start();
contrib = new Contribution("service", "./target/test-classes/callbackService");
- nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeB.start();
} catch (Exception ex) {
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/PromotionTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/PromotionTestCase.java index 4f1ad18a31..992850e470 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/PromotionTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/PromotionTestCase.java @@ -41,11 +41,11 @@ public class PromotionTestCase { try {
// create and start nodes
Contribution contrib = new Contribution("reference", "./target/test-classes/promotionReference");
- nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeA.start();
contrib = new Contribution("service", "./target/test-classes/promotionService");
- nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeB.start();
} catch (Exception ex) {
diff --git a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/SimpleTestCase.java b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/SimpleTestCase.java index 73354efbad..a6f4f216d6 100644 --- a/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/SimpleTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-sca-runtime-rmi/src/test/java/org/apache/tuscany/sca/binding/sca/rmi/SimpleTestCase.java @@ -41,11 +41,11 @@ public class SimpleTestCase { try {
// create and start nodes
Contribution contrib = new Contribution("reference", "./target/test-classes/simpleReference");
- nodeA = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeA = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeA.start();
contrib = new Contribution("service", "./target/test-classes/simpleService");
- nodeB = NodeFactory.newInstance().createNode("HelloWorld.composite", contrib);
+ nodeB = NodeFactory.getInstance().createNode("HelloWorld.composite", contrib);
nodeB.start();
} catch (Exception ex) {
diff --git a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java index ea6bb50cd7..d157b5f565 100644 --- a/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java +++ b/sca-java-2.x/trunk/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/ServletHostHelper.java @@ -70,7 +70,6 @@ public class ServletHostHelper { configuration = factory.loadConfiguration(url.openStream(), url); } else { configuration = factory.createNodeConfiguration(); - configuration.setDomainURI(factory.getDomainURI()); Enumeration<String> names = servletContext.getAttributeNames(); while (names.hasMoreElements()) { String name = names.nextElement(); @@ -132,11 +131,7 @@ public class ServletHostHelper { org.apache.tuscany.sca.host.http.ServletHostHelper.setWebappHost(true); try { String domainName = (String)servletContext.getAttribute(DOMAIN_NAME_ATTR); - if (domainName != null) { - factory = NodeFactory.getInstance(domainName); - } else { - factory = NodeFactory.newInstance(); - } + factory = NodeFactory.getInstance(); for (Enumeration<String> e = servletContext.getInitParameterNames(); e.hasMoreElements();) { String name = e.nextElement(); String value = servletContext.getInitParameter(name); diff --git a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java index f650268c73..defb607b16 100644 --- a/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java +++ b/sca-java-2.x/trunk/modules/node-api/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java @@ -31,10 +31,7 @@ import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import org.apache.tuscany.sca.node.configuration.DefaultNodeConfigurationFactory; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; @@ -59,13 +56,10 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { */ private static final String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; - protected static Map<String, NodeFactory> nodeFactories = new HashMap<String, NodeFactory>(); + protected static NodeFactory instance; protected static void setNodeFactory(NodeFactory factory) { -// if (nodeFactories.get(Node.DEFAULT_DOMAIN_URI) != null) { -// throw new IllegalStateException(); -// } - nodeFactories.put(Node.DEFAULT_DOMAIN_URI, factory); + NodeFactory.instance = factory; } public static class NodeProxy implements Node, Client { @@ -162,44 +156,15 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { } /** - * Returns a new SCA node factory instance. + * Returns the SCA node factory instance. * - * @return a new SCA node factory + * @return the SCA node factory */ - public static NodeFactory getInstance(String domainURI) { - NodeFactory nodeFactory = nodeFactories.get(domainURI); - if (nodeFactory == null) { - try { - // Use reflection APIs to call ServiceDiscovery to avoid hard dependency to tuscany-extensibility - try { - Class<?> discoveryClass = Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery"); - Object instance = discoveryClass.getMethod("getInstance").invoke(null); - Object factoryDeclaration = - discoveryClass.getMethod("getServiceDeclaration", Class.class).invoke(instance, - NodeFactory.class); - if (factoryDeclaration != null) { - Class<?> factoryImplClass = - (Class<?>)factoryDeclaration.getClass().getMethod("loadClass").invoke(factoryDeclaration); - nodeFactory = (NodeFactory)factoryImplClass.newInstance(); - } - } catch (ClassNotFoundException e) { - // Ignore - } - - if (nodeFactory == null) { - // Fail back to default impl - String className = "org.apache.tuscany.sca.node.impl.NodeFactoryImpl"; - - Class<?> cls = Class.forName(className); - nodeFactory = (NodeFactory)cls.newInstance(); - } - - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } - nodeFactories.put(domainURI, nodeFactory); + public static NodeFactory getInstance() { + if (NodeFactory.instance == null) { + NodeFactory.instance = newInstance(); } - return nodeFactory; + return NodeFactory.instance; } /** @@ -208,7 +173,36 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { * @return a new SCA node factory */ public static NodeFactory newInstance() { - return getInstance(Node.DEFAULT_DOMAIN_URI); + NodeFactory nodeFactory = null; + try { + // Use reflection APIs to call ServiceDiscovery to avoid hard dependency to tuscany-extensibility + try { + Class<?> discoveryClass = Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery"); + Object instance = discoveryClass.getMethod("getInstance").invoke(null); + Object factoryDeclaration = + discoveryClass.getMethod("getServiceDeclaration", Class.class).invoke(instance, + NodeFactory.class); + if (factoryDeclaration != null) { + Class<?> factoryImplClass = + (Class<?>)factoryDeclaration.getClass().getMethod("loadClass").invoke(factoryDeclaration); + nodeFactory = (NodeFactory)factoryImplClass.newInstance(); + } + } catch (ClassNotFoundException e) { + // Ignore + } + + if (nodeFactory == null) { + // Fail back to default impl + String className = "org.apache.tuscany.sca.node.impl.NodeFactoryImpl"; + + Class<?> cls = Class.forName(className); + nodeFactory = (NodeFactory)cls.newInstance(); + } + + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return nodeFactory; } /** @@ -415,7 +409,6 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { private NodeConfiguration createConfiguration(Contribution... contributions) { NodeConfigurationFactory factory = this; NodeConfiguration configuration = factory.createNodeConfiguration(); - configuration.setDomainURI(getDomainURI()); // Make sure a unique node URI is created for the same node factory configuration.setURI(Node.DEFAULT_NODE_URI+(count++)); if (contributions != null) { @@ -447,18 +440,8 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory { } public void destroy() { - nodeFactories.remove(getDomainURI()); - } - - public String getDomainURI() { - for (Entry<String, NodeFactory> es : nodeFactories.entrySet()) { - if (es.getValue().equals(this)) { - return es.getKey(); - } - } - return Node.DEFAULT_DOMAIN_URI; } - + /** * Create a new SCA node based on the configuration * @param configuration The configuration of a node diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java index 7c9cf8ef6e..5a4b5aa836 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/remoteserviceadmin/impl/AbstractOSGiServiceHandler.java @@ -63,7 +63,7 @@ public class AbstractOSGiServiceHandler implements LifeCycleListener { protected synchronized void init() { if (nodeFactory == null) { - this.nodeFactory = (NodeFactoryImpl)NodeFactory.newInstance(); + this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance(); this.nodeFactory.init(); this.discoveryTracker = LocalDiscoveryService.getTracker(context); discoveryTracker.open(); diff --git a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java index 6f0144a71e..4bbf130c74 100644 --- a/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java +++ b/sca-java-2.x/trunk/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java @@ -102,7 +102,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi } protected ExtensionPointRegistry getExtensionPointRegistry() { - NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.newInstance(); + NodeFactoryImpl factory = (NodeFactoryImpl)NodeFactory.getInstance(); factory.init(); ServiceTracker tracker = new ServiceTracker(context, ExtensionPointRegistry.class.getName(), null); tracker.open(); |