summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-10 23:55:08 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-03-10 23:55:08 +0000
commitd2a17c57a7e1b6b8fef7a3eba36686c5afffcc13 (patch)
tree9ed14dd36daff332f665a241b8fe3ae7e94a5471 /java/sca/modules/implementation-osgi
parent17d36026254528d1c371bb4e29a0430177a7b4b0 (diff)
Start to build the calculator and operations bundles
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@752310 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi')
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java3
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java4
-rw-r--r--java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java11
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java35
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java47
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorClient.java49
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java35
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java35
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java59
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java35
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java5
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java105
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java65
-rw-r--r--java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java19
14 files changed, 321 insertions, 186 deletions
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java
index abb0f3995a..1bad4102e7 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationActivator.java
@@ -22,6 +22,9 @@ package org.apache.tuscany.sca.implementation.osgi.runtime;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+/**
+ * Bundle activator to receive the BundleContext
+ */
public class OSGiImplementationActivator implements BundleActivator {
private static BundleContext bundleContext;
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index 6ff385db38..47f1775e1f 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -112,7 +112,7 @@ public class OSGiImplementationProvider implements ImplementationProvider, Frame
private MessageFactory messageFactory;
private InterfaceContractMapper mapper;
- public OSGiImplementationProvider(RuntimeComponent definition,
+ public OSGiImplementationProvider(RuntimeComponent component,
OSGiImplementation impl,
DataBindingExtensionPoint dataBindingRegistry,
ScopeRegistry scopeRegistry,
@@ -121,7 +121,7 @@ public class OSGiImplementationProvider implements ImplementationProvider, Frame
InterfaceContractMapper mapper) throws BundleException {
this.implementation = impl;
- this.runtimeComponent = definition;
+ this.runtimeComponent = component;
this.dataBindingRegistry = dataBindingRegistry;
this.scopeRegistry = scopeRegistry;
this.messageFactory = messageFactory;
diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
index 3be61074b0..f6e2eb09ed 100644
--- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
+++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTargetInvoker.java
@@ -28,7 +28,10 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* Java->OSGi references use OSGiTargetInvoker to call methods from OSGi bundles
@@ -48,6 +51,7 @@ public class OSGiTargetInvoker<T> implements Invoker {
protected InstanceWrapper<T> target;
private final OSGiImplementationProvider provider;
+ private final RuntimeComponent component;
private final RuntimeComponentService service;
public OSGiTargetInvoker(Operation operation, OSGiImplementationProvider provider, RuntimeComponentService service) {
@@ -55,6 +59,7 @@ public class OSGiTargetInvoker<T> implements Invoker {
this.operation = operation;
this.service = service;
this.provider = provider;
+ this.component = provider.getRuntimeComponent();
}
@@ -66,10 +71,12 @@ public class OSGiTargetInvoker<T> implements Invoker {
}
try {
+ BundleContext bundleContext = provider.getImplementation().getBundle().getBundleContext();
JavaInterface javaInterface = (JavaInterface)op.getInterface();
// FIXME: What is the filter?
- Object instance = provider.osgiBundle.getBundleContext().getServiceReference(javaInterface.getName());
-
+ String filter = "(sca.service=" + component.getURI() + "#service-name\\(" + service.getName() + "\\))";
+ ServiceReference[] refs = bundleContext.getServiceReferences(javaInterface.getName(), filter);
+ Object instance = bundleContext.getService(refs[0]);
Method m = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
Object ret = invokeMethod(instance, m, msg);
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..0865ddb5fe
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/AddServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Add service
+ */
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.INFO, "Adding " + n1 + " and " + n2);
+ return n1 + n2;
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java
new file mode 100644
index 0000000000..a7b6b748b1
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorActivator.java
@@ -0,0 +1,47 @@
+/*
+ * 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 calculator;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ *
+ */
+public class CalculatorActivator implements BundleActivator {
+ private ServiceRegistration registration;
+
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("sca.service", "CalculatorComponent#service-name(Calculator)");
+ registration = context.registerService(CalculatorService.class.getName(),
+ new CalculatorServiceImpl(),
+ props);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ context.ungetService(registration.getReference());
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorClient.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorClient.java
deleted file mode 100644
index e14cc3dd13..0000000000
--- a/java/sca/modules/implementation-osgi/src/test/java/calculator/CalculatorClient.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 calculator;
-
-import org.apache.tuscany.sca.node.Contribution;
-import org.apache.tuscany.sca.node.ContributionLocationHelper;
-import org.apache.tuscany.sca.node.Node;
-import org.apache.tuscany.sca.node.NodeFactory;
-
-/**
- * This client program shows how to create an SCA runtime, start it,
- * and locate and invoke a SCA component
- */
-public class CalculatorClient {
- public static void main(String[] args) throws Exception {
- String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIReference.composite");
- Contribution contribution = new Contribution("c1", uri);
- Node node = NodeFactory.newInstance().createNode("CalculatorRMIReference.composite", contribution);
- node.start();
- CalculatorService calculatorService = node.getService(CalculatorService.class, "CalculatorServiceComponent");
-
- // Calculate
- System.out.println("3 + 2=" + calculatorService.add(3, 2));
- System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
- System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
- System.out.println("3 / 2=" + calculatorService.divide(3, 2));
-
- node.stop();
-
- }
-
-}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..cb1fe7ed48
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Divide service.
+ */
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.INFO, "Dividing " + n1 + " with " + n2);
+ return n1 / n2;
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..0b86bda2b7
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Multiply service.
+ */
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.INFO, "Multiplying " + n1 + " with " + n2);
+ return n1 * n2;
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java
new file mode 100644
index 0000000000..4968191a0e
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/OperationsActivator.java
@@ -0,0 +1,59 @@
+/*
+ * 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 calculator;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ *
+ */
+public class OperationsActivator implements BundleActivator {
+ private Logger logger = Logger.getLogger(OperationsActivator.class.getName());
+
+ private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
+
+ public void start(BundleContext context) throws Exception {
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("sca.service", "AddComponent#service-name(Add)");
+ registrations.add(context.registerService(AddService.class.getName(), new AddServiceImpl(), props));
+ props.put("sca.service", "SubtractComponent#service-name(Subtract)");
+ registrations.add(context.registerService(SubtractService.class.getName(), new SubtractServiceImpl(), props));
+ props.put("sca.service", "MultiplyComponent#service-name(Multiply)");
+ registrations.add(context.registerService(MultiplyService.class.getName(), new MultiplyServiceImpl(), props));
+ props.put("sca.service", "DivideComponent#service-name(Divide)");
+ registrations.add(context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props));
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ for (ServiceRegistration registration : registrations) {
+ logger.info("Unregistering " + registration);
+ context.ungetService(registration.getReference());
+ }
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java b/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..610803dab7
--- /dev/null
+++ b/java/sca/modules/implementation-osgi/src/test/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the subtract service.
+ */
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.INFO, "Subtracting " + n1 + " from " + n2);
+ return n1 - n2;
+ }
+
+}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
index 7ea598707d..76f41a6021 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiTestCase.java
@@ -51,8 +51,9 @@ public class OSGiTestCase {
className = OSGiTestImpl.class.getName();
compositeName = "osgitest.composite";
OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar",
- OSGiTestInterface.class,
- OSGiTestImpl.class);
+ OSGiTestInterface.class.getName(),
+ OSGiTestImpl.class,
+ OSGiTestInterface.class);
node =
host.createNode("osgitest.composite", new Contribution("c1", new File("target/test-classes").toURI()
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java
index 046eab57ff..882f29126e 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java
@@ -19,15 +19,19 @@
package org.apache.tuscany.sca.implementation.osgi.test;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.URL;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.Constants;
+
/**
*
* Utility class to create OSGi bundles
@@ -41,77 +45,62 @@ public class OSGiTestBundles {
return index == -1 ? "" : name.substring(0, index);
}
- public static void createBundle(String jarName, Class<?> interfaceClass, Class<?> implClass) throws Exception {
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
+ public static void createBundle(String jarName, String bundleName, Class<?>... classes) throws Exception {
+
+ Class<?> activator = null;
+ StringBuffer exports = new StringBuffer();
+ for (Class<?> cls : classes) {
+ if (cls.isAssignableFrom(BundleActivator.class)) {
+ activator = cls;
+ }
+ if (cls.isInterface()) {
+ exports.append(getPackageName(cls)).append(",");
+ }
+ }
+ if (exports.length() > 0) {
+ exports.deleteCharAt(exports.length() - 1);
+ }
- String EOL = System.getProperty("line.separator");
-
- String packageName = getPackageName(interfaceClass);
- String bundleName = interfaceClass.getName();
-
- String manifestStr =
- "Manifest-Version: 1.0" + EOL
- + "Bundle-ManifestVersion: 2"
- + EOL
- + "Bundle-Name: "
- + bundleName
- + EOL
- + "Bundle-SymbolicName: "
- + bundleName
- + EOL
- + "Bundle-Version: "
- + "1.0.0"
- + EOL
- + "Bundle-Localization: plugin"
- + EOL;
-
- StringBuilder manifestBuf = new StringBuilder();
- manifestBuf.append(manifestStr);
- manifestBuf.append("Export-Package: " + packageName + EOL);
- manifestBuf.append("Import-Package: org.osgi.framework" + EOL);
- manifestBuf.append("Bundle-Activator: " + implClass.getName() + EOL);
-
- ByteArrayInputStream manifestStream = new ByteArrayInputStream(manifestBuf.toString().getBytes());
Manifest manifest = new Manifest();
- manifest.read(manifestStream);
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, bundleName);
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.0.0");
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_NAME, bundleName);
+ manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, exports.toString());
+ manifest.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, "org.osgi.framework," + exports.toString());
+
+ if (activator != null) {
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_ACTIVATOR, activator.getName());
+ }
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
JarOutputStream jarOut = new JarOutputStream(out, manifest);
- String interfaceClassName = interfaceClass.getName().replaceAll("\\.", "/") + ".class";
+ for (Class<?> cls : classes) {
+ addClass(jarOut, cls);
+ }
- URL url = interfaceClass.getClassLoader().getResource(interfaceClassName);
- String path = url.getPath();
+ jarOut.close();
+ out.close();
- ZipEntry ze = new ZipEntry(interfaceClassName);
+ FileOutputStream fileOut = new FileOutputStream(jarName);
+ fileOut.write(out.toByteArray());
+ fileOut.close();
- jarOut.putNextEntry(ze);
- FileInputStream file = new FileInputStream(path);
- byte[] fileContents = new byte[file.available()];
- file.read(fileContents);
- jarOut.write(fileContents);
+ }
- String implClassName = implClass.getName().replaceAll("\\.", "/") + ".class";
+ private static void addClass(JarOutputStream jarOut, Class<?> javaClass) throws IOException, FileNotFoundException {
+ String interfaceClassName = javaClass.getName().replaceAll("\\.", "/") + ".class";
- url = implClass.getClassLoader().getResource(implClassName);
- path = url.getPath();
+ URL url = javaClass.getClassLoader().getResource(interfaceClassName);
+ String path = url.getPath();
- ze = new ZipEntry(implClassName);
+ ZipEntry ze = new ZipEntry(interfaceClassName);
jarOut.putNextEntry(ze);
- file = new FileInputStream(path);
- fileContents = new byte[file.available()];
+ FileInputStream file = new FileInputStream(path);
+ byte[] fileContents = new byte[file.available()];
file.read(fileContents);
jarOut.write(fileContents);
-
- file.close();
-
- jarOut.close();
- out.close();
-
- FileOutputStream fileOut = new FileOutputStream(jarName);
- fileOut.write(out.toByteArray());
- fileOut.close();
-
}
}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
deleted file mode 100644
index 59211c1c1e..0000000000
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.implementation.osgi.test;
-
-import java.util.Hashtable;
-
-import org.oasisopen.sca.annotation.Property;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- *
- * Test class - Implementation of an OSGi service
- *
- * @version $Rev$ $Date$
- */
-public class OSGiTestWithPropertyImpl implements OSGiTestInterface, BundleActivator {
-
- @Property
- public double exchangeRate;
-
- private String currency;
-
- @Property
- public void setCurrency(String currency) {
- this.currency = currency;
- }
-
- public String testService() throws Exception {
-
- if (exchangeRate != 2.0)
- throw new Exception("Property exchangeRate not set correctly, expected 2.0, got " + exchangeRate);
- if (!"USD".equals(currency))
- throw new Exception("Property currency not set correctly, expected USD, got " + currency);
- return OSGiTestWithPropertyImpl.class.getName();
-
- }
-
- public void start(BundleContext bc) throws Exception {
-
- bc.registerService(OSGiTestInterface.class.getName(), this, new Hashtable<String, Object>());
-
- }
-
- public void stop(BundleContext bc) throws Exception {
- }
-
-}
diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
index 794cdc4574..c4c7f502ed 100644
--- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
+++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java
@@ -66,11 +66,14 @@ public class OSGiReadImplTestCase {
new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
- compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
+ compositeBuilder =
+ extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class)
+ .getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
OSGiTestBundles.createBundle("target/test-classes/OSGiTestService.jar",
- OSGiTestInterface.class,
- OSGiTestImpl.class);
+ OSGiTestInterface.class.getName(),
+ OSGiTestImpl.class,
+ OSGiTestInterface.class);
}
@@ -94,21 +97,21 @@ public class OSGiReadImplTestCase {
is = getClass().getClassLoader().getResourceAsStream("bundle.componentType");
reader = inputFactory.createXMLStreamReader(is);
ComponentType componentType = (ComponentType)staxProcessor.read(reader);
-
+
assertEquals(1, componentType.getServices().size());
Object prop1 = componentType.getServices().get(0).getExtensions().get(0);
assertTrue(prop1 instanceof OSGiProperty);
- OSGiProperty osgiProp1 = (OSGiProperty) prop1;
+ OSGiProperty osgiProp1 = (OSGiProperty)prop1;
assertEquals("1", osgiProp1.getValue());
assertEquals("prop1", osgiProp1.getName());
-
+
assertEquals(4, componentType.getReferences().size());
Object prop2 = componentType.getReferences().get(0).getExtensions().get(1);
assertTrue(prop2 instanceof OSGiProperty);
- OSGiProperty osgiProp2 = (OSGiProperty) prop2;
+ OSGiProperty osgiProp2 = (OSGiProperty)prop2;
assertEquals("ABC", osgiProp2.getValue());
assertEquals("prop2", osgiProp2.getName());
-
+
ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
staxProcessor.resolve(componentType, resolver);
resolver.addModel(componentType);