summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-25 04:53:56 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-25 04:53:56 +0000
commit2aa39a40c33cb185382ebfedea10ef0e444e79fc (patch)
tree5058e64091f67a9ff4da6506d7ba1777052b2d5b
parent3913958f543845da0d74beb09b502a1e8712faf2 (diff)
Rationalized how to locate an SCA contribution given a known Java class contained in that contribution, and how to locate an SCA contribution represented by an OSGi bundle.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@698815 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java66
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java6
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java24
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java7
-rw-r--r--branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java3
-rw-r--r--branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java5
-rw-r--r--branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java5
7 files changed, 80 insertions, 36 deletions
diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
new file mode 100644
index 0000000000..fd7aaed4c8
--- /dev/null
+++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.io.File;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * ContributionLocationHelper
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class ContributionLocationHelper {
+
+ /**
+ * Returns the location of the SCA contribution containing the given class.
+ *
+ * @param anchorClass
+ * @return
+ */
+ public static String getContributionLocation(final Class<?> anchorClass) {
+ URL url = AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return anchorClass.getProtectionDomain().getCodeSource().getLocation();
+ }
+ });
+ String uri = url.toString();
+ return uri;
+ }
+
+ /**
+ * Returns the location of the SCA contribution represented by the given bundle.
+ *
+ * @param anchorClass
+ * @return
+ */
+ public static String getContributionLocation(final Bundle bundle) {
+ String uri = bundle.getLocation();
+ uri = uri.substring(uri.indexOf("file:") + 5);
+ File file = new File(uri);
+ uri = file.toURI().toString();
+ return uri;
+ }
+
+}
diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
index 2307e94907..d3c5ee2a9d 100644
--- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
+++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
@@ -48,7 +48,7 @@ import org.osgi.framework.BundleContext;
/**
* Wraps the Equinox runtime.
*/
-public class EquinoxHost {
+class EquinoxHost {
private static Logger logger = Logger.getLogger(EquinoxHost.class.getName());
private BundleContext bundleContext;
@@ -118,7 +118,7 @@ public class EquinoxHost {
*
* @return
*/
- public BundleContext start() {
+ BundleContext start() {
try {
if (!EclipseStarter.isRunning()) {
@@ -292,7 +292,7 @@ public class EquinoxHost {
/**
* Stop the Equinox host.
*/
- public void stop() {
+ void stop() {
try {
// Uninstall all the bundles we've installed
diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
index 790b1ab48c..614c34b01e 100644
--- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
+++ b/branches/sca-equinox/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, bundleContext);
+ return (T)node(configurationURL, 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, bundleContext);
+ return (T)node(null, compositeURI, null, contributions, bundleContext);
}
/**
@@ -94,25 +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, bundleContext);
- }
-
- /**
- * Create a SCA node based on the discovery of the contribution on the classpath for the
- * given classloader. This method should be treated a convenient shortcut with the following
- * assumptions:
- * <ul>
- * <li>This is a standalone application and there is a deployable composite file on the classpath.
- * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy.
- * </ul>
- *
- * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution
- * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null,
- * then thread context classloader will be used
- * @return A newly created SCA node
- */
- public <T> T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException {
- return (T)node(null, compositeURI, null, null, classLoader, bundleContext);
+ return (T)node(null, compositeURI, compositeContent, contributions, bundleContext);
}
public static void main(String[] args) throws Exception {
diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
index c2544a1872..c6379886cc 100644
--- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
+++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
@@ -103,7 +103,6 @@ final class NodeLauncherUtil {
String compositeURI,
String compositeContent,
Contribution[] contributions,
- ClassLoader contributionClassLoader,
BundleContext bundleContext) throws LauncherException {
try {
@@ -129,12 +128,6 @@ final class NodeLauncherUtil {
// Construct the node with a configuration URI
bootstrap = bootstrapClass.getConstructor(String.class).newInstance(configurationURI);
- } else if (contributionClassLoader != null) {
-
- // Construct the node with a compositeURI and a classloader
- Constructor<?> constructor = bootstrapClass.getConstructor(String.class, ClassLoader.class);
- bootstrap = constructor.newInstance(compositeURI, contributionClassLoader);
-
} else if (compositeContent != null) {
// Construct the node with a composite URI, the composite content and
diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java b/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
index b16045a103..b109b690c5 100644
--- a/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
+++ b/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
@@ -50,7 +50,8 @@ public class NodeLauncherTestCase {
@Test
public void testLaunch() throws Exception {
- SCANode node = launcher.createNodeFromClassLoader("HelloWorld.composite", getClass().getClassLoader());
+ String location = ContributionLocationHelper.getContributionLocation(getClass());
+ SCANode node = launcher.createNode("HelloWorld.composite", new Contribution("test", location));
node.start();
node.stop();
}
diff --git a/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java b/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
index dc0da7d20d..706293f262 100644
--- a/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
+++ b/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
@@ -21,6 +21,8 @@ package calculator;
import junit.framework.TestCase;
import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.equinox.launcher.Contribution;
+import org.apache.tuscany.sca.node.equinox.launcher.ContributionLocationHelper;
import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
import org.osoa.sca.annotations.EagerInit;
import org.osoa.sca.annotations.Scope;
@@ -38,7 +40,8 @@ public class CalculatorTestCase extends TestCase {
@Override
protected void setUp() throws Exception {
launcher = NodeLauncher.newInstance();
- node = launcher.createNodeFromClassLoader("Calculator.composite", getClass().getClassLoader());
+ String location = ContributionLocationHelper.getContributionLocation(getClass());
+ node = launcher.createNode("Calculator.composite", new Contribution("test", location));
System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader());
node.start();
}
diff --git a/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java b/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
index 19d4ed5a04..c3122cca7c 100644
--- a/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
+++ b/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
@@ -18,10 +18,9 @@
*/
package calculator.rcp;
-import java.io.File;
-
import org.apache.tuscany.sca.node.SCANode;
import org.apache.tuscany.sca.node.equinox.launcher.Contribution;
+import org.apache.tuscany.sca.node.equinox.launcher.ContributionLocationHelper;
import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -49,7 +48,7 @@ public class Activator extends AbstractUIPlugin {
plugin = this;
launcher = NodeLauncher.newInstance();
- String location = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
+ String location = ContributionLocationHelper.getContributionLocation(getClass());
node = launcher.createNode("Calculator.composite", new Contribution("c1", location));
node.start();
}