summaryrefslogtreecommitdiffstats
path: root/branches/sca-equinox/modules/extensibility-equinox
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-19 05:31:14 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-19 05:31:14 +0000
commit6a633dee838417ed68cf91fbd2e9b3b9fa07bd8f (patch)
tree658d78b2087d2f851518be4d27ed9d913ac47ebb /branches/sca-equinox/modules/extensibility-equinox
parentbd126f649a92dd53cd3b3ccef5029ab273436291 (diff)
Simplified ServiceDiscoverer. Started to use it to create factories to resolve ClassNotFoundExceptions. Renamed calculator-osgi to calculator-equinox and a few fixes to get it working in Eclipse.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@696924 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-equinox/modules/extensibility-equinox')
-rw-r--r--branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java23
-rw-r--r--branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java19
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);
}