Author: jsdelfino
Date: Wed Sep 24 21:53:56 2008
New Revision: 698815
URL: http://svn.apache.org/viewvc?rev=698815&view=rev
Log:
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.
Added:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
Modified:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
tuscany/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
tuscany/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
Added:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java?rev=698815&view=auto
==============================================================================
---
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
(added)
+++
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/ContributionLocationHelper.java
Wed Sep 24 21:53:56 2008
@@ -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;
+ }
+
+}
Modified:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
(original)
+++
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
Wed Sep 24 21:53:56 2008
@@ -48,7 +48,7 @@
/**
* 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 @@
*
* @return
*/
- public BundleContext start() {
+ BundleContext start() {
try {
if (!EclipseStarter.isRunning()) {
@@ -292,7 +292,7 @@
/**
* Stop the Equinox host.
*/
- public void stop() {
+ void stop() {
try {
// Uninstall all the bundles we've installed
Modified:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
(original)
+++
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
Wed Sep 24 21:53:56 2008
@@ -65,7 +65,7 @@
* @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 @@
* @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 <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 {
Modified:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
(original)
+++
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
Wed Sep 24 21:53:56 2008
@@ -103,7 +103,6 @@
String compositeURI,
String compositeContent,
Contribution[] contributions,
- ClassLoader contributionClassLoader,
BundleContext bundleContext) throws LauncherException {
try {
@@ -129,12 +128,6 @@
// 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
Modified:
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
(original)
+++
tuscany/branches/sca-equinox/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
Wed Sep 24 21:53:56 2008
@@ -50,7 +50,8 @@
@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();
}
Modified:
tuscany/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
(original)
+++
tuscany/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java
Wed Sep 24 21:53:56 2008
@@ -21,6 +21,8 @@
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 @@
@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();
}
Modified:
tuscany/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java?rev=698815&r1=698814&r2=698815&view=diff
==============================================================================
---
tuscany/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
(original)
+++
tuscany/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java
Wed Sep 24 21:53:56 2008
@@ -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 @@
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();
}