summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main')
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java36
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java75
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java114
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java98
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java31
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java31
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java31
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java31
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java93
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java132
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java37
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml24
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/blueprint/calculator-module.xml43
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/calculator-component.xml36
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/remote-service/calculator-service-descriptions.xml67
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType54
-rw-r--r--tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite56
17 files changed, 989 insertions, 0 deletions
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java
new file mode 100644
index 0000000000..796b1afe61
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java
@@ -0,0 +1,36 @@
+/*
+ * 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.dosgi;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The Calculator service interface.
+ */
+@Remotable
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java
new file mode 100644
index 0000000000..ac49cbcb12
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java
@@ -0,0 +1,75 @@
+/*
+ * 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.dosgi.impl;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.logging.Logger;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+import calculator.dosgi.CalculatorService;
+import calculator.dosgi.operations.AddService;
+
+/**
+ *
+ */
+public class CalculatorActivator implements BundleActivator {
+ private Logger logger = Logger.getLogger(CalculatorActivator.class.getName());
+
+ private Bundle getBundle(BundleContext bundleContext, Class<?> cls) {
+ PackageAdmin packageAdmin = null;
+ // PackageAdmin is used to resolve bundles
+ ServiceReference ref = bundleContext.getServiceReference("org.osgi.service.packageadmin.PackageAdmin");
+ if (ref != null) {
+ packageAdmin = (PackageAdmin)bundleContext.getService(ref);
+ Bundle bundle = packageAdmin.getBundle(cls);
+ if (bundle != null) {
+ logger.info(cls.getName() + " is loaded by bundle: " + bundle.getSymbolicName());
+ }
+ bundleContext.ungetService(ref);
+ return bundle;
+ }
+ return null;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ logger.info("Starting " + context.getBundle());
+ Dictionary<String, Object> props = new Hashtable<String, Object>();
+ props.put("sca.service", "CalculatorComponent#service-name(Calculator)");
+ props.put("calculator", "Calculator");
+ logger.info("Registering " + CalculatorService.class.getName());
+ CalculatorService calculator = new CalculatorServiceImpl(context);
+ context.registerService(CalculatorService.class.getName(), calculator, props);
+
+ getBundle(context, AddService.class);
+
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ logger.info("Stopping " + context.getBundle());
+ // Registered services will be automatically unregistered
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java
new file mode 100644
index 0000000000..9c80c5beb9
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java
@@ -0,0 +1,114 @@
+/*
+ * 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.dosgi.impl;
+
+import org.osgi.service.component.ComponentContext;
+
+import calculator.dosgi.CalculatorService;
+import calculator.dosgi.operations.AddService;
+import calculator.dosgi.operations.DivideService;
+import calculator.dosgi.operations.MultiplyService;
+import calculator.dosgi.operations.SubtractService;
+
+/**
+ * An implementation of the Calculator service.
+ */
+public class CalculatorServiceDSImpl implements CalculatorService {
+ private AddService addService;
+ private SubtractService subtractService;
+ private MultiplyService multiplyService;
+ private DivideService divideService;
+
+ public CalculatorServiceDSImpl() {
+ super();
+ System.out.println("CalculatorServiceDSImpl()");
+ }
+
+ protected void activate(ComponentContext context) {
+ System.out.println("Activating " + context);
+ }
+
+ protected void deactivate(ComponentContext context) {
+ System.out.println("Deactivating " + context);
+ }
+
+ /*
+ * The following setters can be used for DS injection
+ */
+ public void setAddService(AddService addService) {
+ System.out.println("setAddService()");
+ this.addService = addService;
+ }
+
+ public void setSubtractService(SubtractService subtractService) {
+ this.subtractService = subtractService;
+ }
+
+ public void setDivideService(DivideService divideService) {
+ this.divideService = divideService;
+ }
+
+ public void setMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = multiplyService;
+ }
+
+ /*
+ * The following setters can be used for DS injection
+ */
+ public void unsetAddService(AddService addService) {
+ System.out.println("unsetAddService()");
+ this.addService = null;
+ }
+
+ public void unsetSubtractService(SubtractService subtractService) {
+ this.subtractService = null;
+ }
+
+ public void unsetDivideService(DivideService divideService) {
+ this.divideService = null;
+ }
+
+ public void unsetMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = null;
+ }
+ private <T> T getService(Class<T> cls) {
+ for (Object s : new Object[] {addService, subtractService, multiplyService, divideService}) {
+ if (cls.isInstance(s)) {
+ return cls.cast(s);
+ }
+ }
+ throw new IllegalStateException(cls.getSimpleName() + " is not available");
+ }
+
+ public double add(double n1, double n2) {
+ return getService(AddService.class).add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return getService(SubtractService.class).subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return getService(MultiplyService.class).multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return getService(DivideService.class).divide(n1, n2);
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..046e8cf565
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java
@@ -0,0 +1,98 @@
+/*
+ * 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.dosgi.impl;
+
+import static org.osgi.framework.Constants.OBJECTCLASS;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.util.tracker.ServiceTracker;
+
+import calculator.dosgi.CalculatorService;
+import calculator.dosgi.operations.AddService;
+import calculator.dosgi.operations.DivideService;
+import calculator.dosgi.operations.MultiplyService;
+import calculator.dosgi.operations.SubtractService;
+
+/**
+ * An implementation of the Calculator service.
+ */
+public class CalculatorServiceImpl implements CalculatorService {
+ private ServiceTracker remoteServices;
+ private ServiceTracker localServices;
+
+ public CalculatorServiceImpl() {
+ super();
+ }
+
+ public CalculatorServiceImpl(BundleContext context) {
+ super();
+ Filter remoteFilter = null, localFilter = null;
+ try {
+ remoteFilter =
+ context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (sca.reference=*))");
+ localFilter =
+ context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (!(sca.reference=*)))");
+ } catch (InvalidSyntaxException e) {
+ e.printStackTrace();
+ }
+ this.remoteServices = new ServiceTracker(context, remoteFilter, null);
+ remoteServices.open();
+ this.localServices = new ServiceTracker(context, localFilter, null);
+ localServices.open();
+ }
+
+ private <T> T getService(Class<T> cls) {
+ Object[] remoteObjects = remoteServices.getServices();
+ if (remoteObjects != null) {
+ for (Object s : remoteObjects) {
+ if (cls.isInstance(s)) {
+ System.out.println("Remote service: " + s);
+ return cls.cast(s);
+ }
+ }
+ }
+ Object[] localObjects = localServices.getServices();
+ if (localObjects != null)
+ for (Object s : localObjects) {
+ if (cls.isInstance(s)) {
+ System.out.println("Local service: " + s);
+ return cls.cast(s);
+ }
+ }
+ throw new IllegalStateException(cls.getSimpleName() + " is not available");
+ }
+
+ public double add(double n1, double n2) {
+ return getService(AddService.class).add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return getService(SubtractService.class).subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return getService(MultiplyService.class).multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return getService(DivideService.class).divide(n1, n2);
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java
new file mode 100644
index 0000000000..7d68dbd5c5
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the add service
+ */
+@Remotable
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java
new file mode 100644
index 0000000000..998f6e9554
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the divide service
+ */
+@Remotable
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java
new file mode 100644
index 0000000000..7ed6db2e6b
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the multiply service
+ */
+@Remotable
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java
new file mode 100644
index 0000000000..cb98b8fb67
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.dosgi.operations;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * The interface for the subtract service
+ */
+@Remotable
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java
new file mode 100644
index 0000000000..1a3e36f571
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java
@@ -0,0 +1,93 @@
+/*
+ * 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.rmi;
+
+import java.io.Serializable;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.UnicastRemoteObject;
+
+/**
+ *
+ */
+public class OperationsRMIServer implements OperationsRemote, Serializable {
+
+ private static final long serialVersionUID = 6081008315263103012L;
+ private transient Registry registry;
+
+ public OperationsRMIServer() throws RemoteException {
+ super();
+ }
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+ public double divide(double n1, double n2) {
+ return n1 / n2;
+ }
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+ public void start() throws RemoteException {
+ Thread thread = new Thread() {
+ public void run() {
+ try {
+ System.out.println("Starting the RMI server for calculator operations...");
+ Remote stub = UnicastRemoteObject.exportObject(OperationsRMIServer.this);
+ registry = LocateRegistry.createRegistry(8085);
+ registry.bind("AddService", stub);
+ registry.bind("SubtractService", stub);
+ registry.bind("MultiplyService", stub);
+ registry.bind("DivideService", stub);
+ System.out.println("RMI server for calculator operations is now started.");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ thread.start();
+ }
+
+ public void stop() {
+ if (registry != null) {
+ try {
+ registry.unbind("AddService");
+ registry.unbind("SubtractService");
+ registry.unbind("MultiplyService");
+ registry.unbind("DivideService");
+ UnicastRemoteObject.unexportObject(this, false);
+ UnicastRemoteObject.unexportObject(registry, false);
+ registry = null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java
new file mode 100644
index 0000000000..d573f6b8fa
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+// Stub class generated by rmic, do not edit.
+// Contents subject to change without notice.
+package calculator.rmi;
+
+public final class OperationsRMIServer_Stub extends java.rmi.server.RemoteStub implements calculator.rmi.OperationsRemote {
+ private static final long serialVersionUID = 2;
+
+ private static java.lang.reflect.Method $method_add_0;
+ private static java.lang.reflect.Method $method_divide_1;
+ private static java.lang.reflect.Method $method_multiply_2;
+ private static java.lang.reflect.Method $method_subtract_3;
+
+ static {
+ try {
+ $method_add_0 =
+ calculator.rmi.OperationsRemote.class.getMethod("add", new java.lang.Class[] {double.class, double.class});
+ $method_divide_1 =
+ calculator.rmi.OperationsRemote.class.getMethod("divide",
+ new java.lang.Class[] {double.class, double.class});
+ $method_multiply_2 =
+ calculator.rmi.OperationsRemote.class.getMethod("multiply", new java.lang.Class[] {double.class,
+ double.class});
+ $method_subtract_3 =
+ calculator.rmi.OperationsRemote.class.getMethod("subtract", new java.lang.Class[] {double.class,
+ double.class});
+ } catch (java.lang.NoSuchMethodException e) {
+ throw new java.lang.NoSuchMethodError("stub class initialization failed");
+ }
+ }
+
+ // constructors
+ public OperationsRMIServer_Stub(java.rmi.server.RemoteRef ref) {
+ super(ref);
+ }
+
+ // methods from remote interfaces
+
+ // implementation of add(double, double)
+ public double add(double $param_double_1, double $param_double_2) throws java.rmi.RemoteException {
+ try {
+ Object $result =
+ ref.invoke(this,
+ $method_add_0,
+ new java.lang.Object[] {new java.lang.Double($param_double_1),
+ new java.lang.Double($param_double_2)},
+ 864055858262779977L);
+ return ((java.lang.Double)$result).doubleValue();
+ } catch (java.lang.RuntimeException e) {
+ throw e;
+ } catch (java.rmi.RemoteException e) {
+ throw e;
+ } catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ // implementation of divide(double, double)
+ public double divide(double $param_double_1, double $param_double_2) throws java.rmi.RemoteException {
+ try {
+ Object $result =
+ ref.invoke(this,
+ $method_divide_1,
+ new java.lang.Object[] {new java.lang.Double($param_double_1),
+ new java.lang.Double($param_double_2)},
+ 8097593626497421928L);
+ return ((java.lang.Double)$result).doubleValue();
+ } catch (java.lang.RuntimeException e) {
+ throw e;
+ } catch (java.rmi.RemoteException e) {
+ throw e;
+ } catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ // implementation of multiply(double, double)
+ public double multiply(double $param_double_1, double $param_double_2) throws java.rmi.RemoteException {
+ try {
+ Object $result =
+ ref.invoke(this,
+ $method_multiply_2,
+ new java.lang.Object[] {new java.lang.Double($param_double_1),
+ new java.lang.Double($param_double_2)},
+ -346155016949350695L);
+ return ((java.lang.Double)$result).doubleValue();
+ } catch (java.lang.RuntimeException e) {
+ throw e;
+ } catch (java.rmi.RemoteException e) {
+ throw e;
+ } catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+
+ // implementation of subtract(double, double)
+ public double subtract(double $param_double_1, double $param_double_2) throws java.rmi.RemoteException {
+ try {
+ Object $result =
+ ref.invoke(this,
+ $method_subtract_3,
+ new java.lang.Object[] {new java.lang.Double($param_double_1),
+ new java.lang.Double($param_double_2)},
+ -610707357620578750L);
+ return ((java.lang.Double)$result).doubleValue();
+ } catch (java.lang.RuntimeException e) {
+ throw e;
+ } catch (java.rmi.RemoteException e) {
+ throw e;
+ } catch (java.lang.Exception e) {
+ throw new java.rmi.UnexpectedException("undeclared checked exception", e);
+ }
+ }
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java
new file mode 100644
index 0000000000..d735ce8172
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java
@@ -0,0 +1,37 @@
+/*
+ * 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.rmi;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * RMI Remote interface
+ */
+public interface OperationsRemote extends Remote {
+ double add(double n1, double n2) throws RemoteException;
+
+ double subtract(double n1, double n2) throws RemoteException;
+
+ double multiply(double n1, double n2) throws RemoteException;
+
+ double divide(double n1, double n2) throws RemoteException;
+
+}
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..8ba4b85247
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* 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.
+-->
+
+<contribution xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:c="http://calculator.dosgi">
+ <deployable composite="c:CalculatorComposite" />
+</contribution>
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/blueprint/calculator-module.xml b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/blueprint/calculator-module.xml
new file mode 100644
index 0000000000..fe0bbf21df
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/blueprint/calculator-module.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<!-- A sample module-context.xml for OSGI RFC 124 (BluePrint Service) -->
+<components xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+ <component id="CalculatorComponent" class="calculator.dosgi.impl.CalculatorServiceImpl">
+ <property name="addService" ref="AddService" />
+ <property name="subtractService" ref="SubtractService" />
+ <property name="multiplyService" ref="MultiplyService" />
+ <property name="divideService" ref="DivideService" />
+ </component>
+
+ <!-- We can derive the SCA services for the implementation.osgi -->
+ <service id="CalculatorService" ref="CalculatorComponent" interface="calculator.dosgi.CalculatorService">
+ </service>
+
+ <!-- We can derive the SCA references for the implementation.osgi -->
+ <reference id="AddService" interface="calculator.dosgi.operations.AddService">
+ </reference>
+ <reference id="SubtractService" interface="calculator.dosgi.operations.SubtractService">
+ </reference>
+ <reference id="MultiplyService" interface="calculator.dosgi.operations.MultiplyService">
+ </reference>
+ <reference id="DivideService" interface="calculator.dosgi.operations.DivideService">
+ </reference>
+
+</components> \ No newline at end of file
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/calculator-component.xml b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/calculator-component.xml
new file mode 100644
index 0000000000..457588bfb6
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/calculator-component.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<scr:component name="CalculatorComponent"
+ xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+ <implementation class="calculator.dosgi.impl.CalculatorServiceDSImpl" />
+ <service>
+ <provide interface="calculator.dosgi.CalculatorService" />
+ </service>
+
+ <reference name="addService" interface="calculator.dosgi.operations.AddService" bind="setAddService" unbind="unsetAddService"
+ policy="dynamic" />
+ <reference name="subtractService" interface="calculator.dosgi.operations.SubtractService" bind="setSubtractService"
+ unbind="unsetSubtractService" policy="dynamic" />
+ <reference name="multiplyService" interface="calculator.dosgi.operations.MultiplyService" bind="setMultiplyService"
+ unbind="unsetMultiplyService" policy="dynamic" />
+ <reference name="divideService" interface="calculator.dosgi.operations.DivideService" bind="setDivideService"
+ unbind="unsetDivideService" policy="dynamic" />
+
+</scr:component>
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/remote-service/calculator-service-descriptions.xml b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/remote-service/calculator-service-descriptions.xml
new file mode 100644
index 0000000000..1a35665803
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/remote-service/calculator-service-descriptions.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* 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.
+-->
+<!-- A consumer-side service description file for RFC 119 -->
+<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+ <!-- Describe a remote OSGi service -->
+ <service-description>
+ <provide interface="calculator.dosgi.operations.AddService" />
+ <property name="service.intents">sca:SOAP sca:HTTP</property>
+ <property name="osgi.remote.configuration.type">sca</property>
+ <property name="osgi.remote.configuration.sca.componentType">
+ OSGI-INF/sca/bundle.componentType
+ </property>
+ <property name="osgi.remote.configuration.sca.reference">
+ addService
+ </property>
+ </service-description>
+ <service-description>
+ <provide interface="calculator.dosgi.operations.SubtractService" />
+ <property name="service.intents">sca:SOAP sca:HTTP</property>
+ <property name="osgi.remote.configuration.type">sca</property>
+ <property name="osgi.remote.configuration.sca.componentType">
+ OSGI-INF/sca/bundle.componentType
+ </property>
+ <property name="osgi.remote.configuration.sca.reference">
+ subtractService
+ </property>
+ </service-description>
+ <service-description>
+ <provide interface="calculator.dosgi.operations.MultiplyService" />
+ <property name="service.intents">sca:SOAP sca:HTTP</property>
+ <property name="osgi.remote.configuration.type">sca</property>
+ <property name="osgi.remote.configuration.sca.componentType">
+ OSGI-INF/sca/bundle.componentType
+ </property>
+ <property name="osgi.remote.configuration.sca.reference">
+ multiplyService
+ </property>
+ </service-description>
+ <service-description>
+ <provide interface="calculator.dosgi.operations.DivideService" />
+ <property name="service.intents">sca:SOAP sca:HTTP</property>
+ <property name="osgi.remote.configuration.type">sca</property>
+ <property name="osgi.remote.configuration.sca.componentType">
+ OSGI-INF/sca/bundle.componentType
+ </property>
+ <property name="osgi.remote.configuration.sca.reference">
+ divideService
+ </property>
+ </service-description>
+</service-descriptions> \ No newline at end of file
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType
new file mode 100644
index 0000000000..92b0ac7bf9
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1">
+ <!-- The service elment defines an SCA view of the OSGi service -->
+ <service name="CalculatorService">
+ <!-- The interface will be mapped into the OSGi service class -->
+ <interface.java interface="calculator.dosgi.CalculatorService"/>
+ <!-- The list of OSGi properties -->
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </service>
+
+ <!-- The reference elment defines an SCA proxy to a remote OSGi service -->
+ <reference name="addService">
+ <interface.java interface="calculator.dosgi.operations.AddService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="subtractService">
+ <interface.java interface="calculator.dosgi.operations.SubtractService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="multiplyService">
+ <interface.java interface="calculator.dosgi.operations.MultiplyService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+ <reference name="divideService">
+ <interface.java interface="calculator.dosgi.operations.DivideService"/>
+ <t:osgi.property name="prop1">1</t:osgi.property>
+ <t:osgi.property name="prop2">ABC</t:osgi.property>
+ </reference>
+
+</componentType>
diff --git a/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite
new file mode 100644
index 0000000000..7109300293
--- /dev/null
+++ b/tags/java/sca/2.0-M3-RC1/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://calculator.dosgi"
+ name="CalculatorComposite">
+
+ <component name="CalculatorComponent">
+ <tuscany:implementation.osgi bundleSymbolicName="calculator.dosgi" bundleVersion="1.0.0" />
+ <service name="CalculatorService">
+ <binding.ws uri="http://localhost:8086/CalculatorService"/>
+ </service>
+ <reference name="addService">
+ <tuscany:binding.rmi uri="rmi://localhost:8085/AddService"/>
+ </reference>
+ <reference name="subtractService">
+ <tuscany:binding.rmi uri="rmi://localhost:8085/SubtractService"/>
+ </reference>
+ <reference name="multiplyService">
+ <tuscany:binding.rmi uri="rmi://localhost:8085/MultiplyService"/>
+ </reference>
+ <reference name="divideService">
+ <tuscany:binding.rmi uri="rmi://localhost:8085/DivideService"/>
+ </reference>
+
+ <!--
+ <reference name="addService" target="OperationsComponent/AddService">
+ </reference>
+ <reference name="subtractService" target="OperationsComponent/SubtractService">
+ </reference>
+ <reference name="multiplyService" target="OperationsComponent/MultiplyService">
+ </reference>
+ <reference name="divideService" target="OperationsComponent/DivideService">
+ </reference>
+ -->
+ </component>
+
+</composite>