diff options
Diffstat (limited to 'branches/sca-equinox/modules/extensibility-equinox')
2 files changed, 28 insertions, 14 deletions
diff --git a/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java index 5ab5a66077..c918ad735d 100644 --- a/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java +++ b/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java @@ -23,6 +23,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; @@ -181,8 +183,17 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { } return attributes; } + + public ServiceDeclaration getFirstServiceDeclaration(String name) throws IOException { + Set<ServiceDeclaration> declarations = getServiceDeclarations(name); + if (declarations.isEmpty()) { + return null; + } else { + return declarations.iterator().next(); + } + } - public Set<ServiceDeclaration> discover(String serviceName, boolean firstOnly) { + public Set<ServiceDeclaration> getServiceDeclarations(String serviceName) throws IOException { boolean debug = logger.isLoggable(Level.FINE); Set<ServiceDeclaration> descriptors = new HashSet<ServiceDeclaration>(); @@ -256,9 +267,6 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, className, attributes); descriptors.add(descriptor); - if (firstOnly) { - return descriptors; - } } } } finally { @@ -278,4 +286,11 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { return descriptors; } + public Object newFactoryClassInstance(String name) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException { + Class<?> factoryClass = Class.forName(name, false, getClass().getClassLoader()); + Method newInstanceMethod = factoryClass.getMethod("newInstance"); + Object factory = newInstanceMethod.invoke(null); + return factory; + } + } diff --git a/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java b/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java index 3126365748..c21e4984f5 100644 --- a/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java +++ b/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.extensibility.equinox; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.util.ArrayList; @@ -131,21 +132,19 @@ public class EquinoxServiceDiscovererTestCase { } @Test - public void testDiscovery() { - Set<ServiceDeclaration> descriptors = - discoverer.discover("test.TestService", false); + public void testDiscovery() throws IOException { + Set<ServiceDeclaration> descriptors = discoverer.getServiceDeclarations("test.TestService"); Assert.assertEquals(1, descriptors.size()); - descriptors = discoverer.discover("notthere", false); + descriptors = discoverer.getServiceDeclarations("notthere"); Assert.assertEquals(0, descriptors.size()); } @Test - public void testDiscoveryFirst() { - Set<ServiceDeclaration> descriptors = - discoverer.discover("test.TestService", true); - Assert.assertEquals(1, descriptors.size()); - descriptors = discoverer.discover("notthere", true); - Assert.assertEquals(0, descriptors.size()); + public void testDiscoveryFirst() throws IOException { + ServiceDeclaration descriptor = discoverer.getFirstServiceDeclaration("test.TestService"); + Assert.assertNotNull(descriptor); + descriptor = discoverer.getFirstServiceDeclaration("notthere"); + Assert.assertNull(descriptor); } |