diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-16 19:21:16 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-16 19:21:16 +0000 |
commit | 7eb33fc6b50a9c808d0fc872cb31f42472afb164 (patch) | |
tree | 46c9f6e6dc18ecd178224adc3523da4b4c2649eb /java | |
parent | de588dbe2ea7b1d172aa424736034e51a02fd16c (diff) |
Use classloader to find the FrameworkFactory
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@794789 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
-rw-r--r-- | java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java index 858dbe3885..777ab59df3 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/FrameworkLauncher.java @@ -19,6 +19,10 @@ package org.apache.tuscany.sca.node.equinox.launcher;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Map;
import java.util.logging.Level;
@@ -44,20 +48,46 @@ public class FrameworkLauncher implements BundleActivator { if (factory == null) {
// 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", String.class).invoke(instance,
- FrameworkFactory.class
- .getName());
- if (factoryDeclaration != null) {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ InputStream is =
+ classLoader.getResourceAsStream("META-INF/services/" + FrameworkFactory.class.getName());
+ if (is == null) {
+ classLoader = FrameworkFactory.class.getClassLoader();
+ is = classLoader.getResourceAsStream("META-INF/services/" + FrameworkFactory.class.getName());
+ }
+ if (is == null) {
+ return null;
+ }
+ BufferedReader reader = null;
+ String line = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ while (true) {
+ line = reader.readLine();
+ if (line == null)
+ break;
+ line = line.trim();
+ if (!line.startsWith("#") && !"".equals(line)) {
+ break;
+ }
+ }
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ if (line != null) {
Class<? extends FrameworkFactory> factoryImplClass =
- (Class<? extends FrameworkFactory>)factoryDeclaration.getClass().getMethod("loadClass")
- .invoke(factoryDeclaration);
+ (Class<? extends FrameworkFactory>)Class.forName(line, false, classLoader);
factory = factoryImplClass.newInstance();
if (factory != null && factory.getClass().getName().startsWith("org.eclipse.osgi.")) {
isEquinox = true;
}
+
}
} catch (Throwable e) {
logger.log(Level.SEVERE, e.getMessage(), e);
@@ -68,6 +98,9 @@ public class FrameworkLauncher implements BundleActivator { public Framework newFramework(Map properties) {
FrameworkFactory factory = loadFrameworkFactory();
+ if (factory == null) {
+ return null;
+ }
return factory.newFramework(properties);
}
|