diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-09 01:29:55 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-09 01:29:55 +0000 |
commit | c6448a6c73afdb3874ead87b30b593ef1e48e234 (patch) | |
tree | d53c3004f03ba87fa6cb2fe31a69ef6aed971088 | |
parent | afa459840e00fe9d45319cd21ea8c969144b1739 (diff) |
Use the bundle to load the implementation.node classes
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693336 13f79535-47bb-0310-9956-ffa450edef68
2 files changed, 23 insertions, 9 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java index 807b5cd8f7..f3bb8c04ae 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java @@ -65,7 +65,7 @@ public class NodeLauncher { * @throws LauncherException */ public <T> T createNodeFromURL(String configurationURL) throws LauncherException { - return (T)node(configurationURL, null, null, null, null); + return (T)node(configurationURL, null, null, null, null, bundleContext); } /** @@ -80,7 +80,7 @@ public class NodeLauncher { * @throws LauncherException */ public <T> T createNode(String compositeURI, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, null, contributions, null); + return (T)node(null, compositeURI, null, contributions, null, bundleContext); } /** @@ -94,7 +94,7 @@ public class NodeLauncher { */ public <T> T createNode(String compositeURI, String compositeContent, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, compositeContent, contributions, null); + return (T)node(null, compositeURI, compositeContent, contributions, null, bundleContext); } /** @@ -112,7 +112,7 @@ public class NodeLauncher { * @return A newly created SCA node */ public <T> T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException { - return (T)node(null, compositeURI, null, null, classLoader); + return (T)node(null, compositeURI, null, null, classLoader, bundleContext); } public static void main(String[] args) throws Exception { diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java index e2b457b62c..d0c3e6f4f8 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java @@ -47,6 +47,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; /** * Common functions and constants used by the admin components. @@ -55,6 +56,8 @@ import org.osgi.framework.Bundle; */ final class NodeLauncherUtil { + private static final String LAUNCHER_EQUINOX_LIBRARIES = "org.apache.tuscany.sca.node.launcher.equinox.libraries"; + private static final String SCANODE_FACTORY = "org.apache.tuscany.sca.node.SCANodeFactory"; private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP = @@ -69,18 +72,29 @@ final class NodeLauncherUtil { /** * Collect JAR files under the given directory. * @param contributions - * + * @param bundleContext TODO * @throws LauncherException */ static Object node(String configurationURI, String compositeURI, String compositeContent, Contribution[] contributions, - ClassLoader contributionClassLoader) throws LauncherException { + ClassLoader contributionClassLoader, BundleContext bundleContext) throws LauncherException { try { + Bundle bundle = null; + for (Bundle b : bundleContext.getBundles()) { + if ("org.apache.tuscany.sca.implementation.node.runtime".equals(b.getSymbolicName())) { + bundle = b; + break; + } + } + if (bundle == null) { + throw new IllegalStateException( + "Bundle org.apache.tuscany.sca.implementation.node.runtime is not installed"); + } // Use Java reflection to create the node as only the runtime class // loader knows the runtime classes required by the node - Class<?> bootstrapClass = Class.forName(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP); + Class<?> bootstrapClass = bundle.loadClass(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP); Object bootstrap; if (configurationURI != null) { @@ -256,7 +270,7 @@ final class NodeLauncherUtil { for (String jarFile : jarFiles) { addPackages(jarFile, packages); classpath.append("\"external:"); - classpath.append(file(new URL(jarFile)).getAbsolutePath().replace(File.separatorChar, '/')); + classpath.append(file(new URL(jarFile)).getPath().replace(File.separatorChar, '/')); classpath.append("\","); } @@ -282,7 +296,7 @@ final class NodeLauncherUtil { Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); attributes.putValue(BUNDLE_MANIFESTVERSION, "2"); - attributes.putValue(BUNDLE_SYMBOLICNAME, "org.apache.tuscany.sca.node.launcher.equinox.libraries"); + attributes.putValue(BUNDLE_SYMBOLICNAME, LAUNCHER_EQUINOX_LIBRARIES); attributes.putValue(EXPORT_PACKAGE, exports.substring(0, exports.length() - 1)); attributes.putValue(IMPORT_PACKAGE, imports.substring(0, imports.length() - 1)); attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() - 1)); |