Add back in the getServiceEndpoints method

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@784056 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
antelder 2009-06-12 09:55:38 +00:00
parent 5a356c409f
commit 5f5d20e96b
2 changed files with 43 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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");