diff options
Diffstat (limited to 'java/sca/modules/node-impl')
2 files changed, 43 insertions, 0 deletions
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 fdf6f18e7b..6737a16d3a 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 @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.node.impl; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -27,6 +28,8 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.ActivationException; @@ -38,6 +41,7 @@ import org.apache.tuscany.sca.node.NodeFinder; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentContext; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.oasisopen.sca.CallableReference; import org.oasisopen.sca.ServiceReference; import org.oasisopen.sca.ServiceRuntimeException; @@ -204,4 +208,29 @@ public class NodeImpl implements Node, Client { return manager.getExtensionPoints(); } + /** + * Get the service endpoints in this Node + * TODO: needs review, works for the very simple testcase but i expect there are + * other endpoints to be included + */ + public List<Endpoint> getServiceEndpoints() { + List<Endpoint> endpoints = new ArrayList<Endpoint>(); + if (compositeActivator != null) { + Composite domainComposite = compositeActivator.getDomainComposite(); + if (domainComposite != null) { + for (Composite composite : domainComposite.getIncludes()) { + for (Component component : composite.getComponents()) { + for (Service service : component.getServices()) { + // MJE 28/05/2009 - changed to RuntimeComponentService from RuntimeComponentServiceImpl + // - no need to access the Impl directly here + if (service instanceof RuntimeComponentService) { + endpoints.addAll(((RuntimeComponentService)service).getEndpoints()); + } + } + } + } + } + } + return endpoints; + } } diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java index dc4baeb390..aa7933630a 100644 --- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java @@ -24,7 +24,9 @@ import hello.HelloWorld; import java.io.File; import java.io.StringReader; import java.net.MalformedURLException; +import java.util.List; +import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; @@ -77,6 +79,18 @@ public class NodeImplTestCase { testNode(new NodeFactoryImpl().createNode()); } + @Test + public void testGetServiceEndpoints() { + NodeFactory factory = new NodeFactoryImpl(); + Contribution contribution = new Contribution("c1", new File("target/test-classes").toURI().toString()); + NodeImpl node = (NodeImpl)factory.createNode(new StringReader(composite), contribution); + node.start(); + List<Endpoint> es = node.getServiceEndpoints(); + Assert.assertEquals(1, es.size()); + Assert.assertEquals("HelloWorld2", es.get(0).getComponent().getName()); + node.stop(); + } + private void testNode(Node node) { node.start(); HelloWorld hw = node.getService(HelloWorld.class, "HelloWorld"); |