summaryrefslogtreecommitdiffstats
path: root/java/sca/samples/calculator-osgi/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-14 00:32:52 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-01-14 00:32:52 +0000
commit7d8ee265f841de05e8e4bb5a1bd2b79a69c55b03 (patch)
tree2bc4cd91a742d973c2080e3332edf77153124c7d /java/sca/samples/calculator-osgi/src
parente0f38b2db6826c17d8e722939037261270f5bcd8 (diff)
Update the calculator-osgi example
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734283 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/samples/calculator-osgi/src')
-rw-r--r--java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java54
-rw-r--r--java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java20
-rw-r--r--java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java1
-rw-r--r--java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java1
-rw-r--r--java/sca/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java57
5 files changed, 59 insertions, 74 deletions
diff --git a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java
new file mode 100644
index 0000000000..4408568629
--- /dev/null
+++ b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Bundle Activator for Calculator
+ *
+ */
+public class CalculatorActivator implements BundleActivator {
+ private Node node;
+
+ public void start(BundleContext context) throws Exception {
+ try {
+ NodeFactory factory = NodeFactory.newInstance();
+ String url = ContributionLocationHelper.getContributionLocation(getClass());
+ Contribution contrib = new Contribution("c1", url);
+ node = factory.createNode("Calculator.composite", contrib);
+ node.start();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ if (node != null) {
+ node.stop();
+ node = null;
+ }
+ }
+
+}
diff --git a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java
index c193b2ce66..adbd18a9e4 100644
--- a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java
+++ b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java
@@ -28,35 +28,25 @@ import org.osoa.sca.annotations.Scope;
* This client program shows how to create an SCA runtime, start it,
* and locate and invoke a SCA component
*/
-@Scope("COMPOSITE") @EagerInit
+@Scope("COMPOSITE")
+@EagerInit
public class CalculatorClient {
-
+
private CalculatorService calculatorService;
@Reference
public void setCalculatorService(CalculatorService calculatorService) {
this.calculatorService = calculatorService;
}
-
+
@Init
public void calculate() {
-
// Calculate
- System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader()));
+ System.out.println("SCA API ClassLoader: " + Reference.class.getClassLoader());
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));
}
-
- private static String print(ClassLoader cl) {
- StringBuffer buf = new StringBuffer();
- for (; cl != null;) {
- buf.append(cl.toString());
- buf.append(' ');
- cl = cl.getParent();
- }
- return buf.toString();
- }
}
diff --git a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java
index 031fa8b912..c89043276e 100644
--- a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java
+++ b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java
@@ -18,7 +18,6 @@
*/
package calculator;
-
/**
* The Calculator service interface.
*/
diff --git a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java
index 3d861f2018..ba897fa301 100644
--- a/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java
+++ b/java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java
@@ -20,7 +20,6 @@ package calculator;
import org.osoa.sca.annotations.Reference;
-
/**
* An implementation of the Calculator service.
*/
diff --git a/java/sca/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java b/java/sca/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java
deleted file mode 100644
index dc0da7d20d..0000000000
--- a/java/sca/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java
+++ /dev/null
@@ -1,57 +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 junit.framework.TestCase;
-
-import org.apache.tuscany.sca.node.SCANode;
-import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
-import org.osoa.sca.annotations.EagerInit;
-import org.osoa.sca.annotations.Scope;
-
-/**
- * This shows how to test the Calculator composition.
- */
-@Scope("COMPOSITE")
-@EagerInit
-public class CalculatorTestCase extends TestCase {
-
- private NodeLauncher launcher;
- private SCANode node;
-
- @Override
- protected void setUp() throws Exception {
- launcher = NodeLauncher.newInstance();
- node = launcher.createNodeFromClassLoader("Calculator.composite", getClass().getClassLoader());
- System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader());
- node.start();
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (launcher != null) {
- node.stop();
- launcher.destroy();
- }
- }
-
- public void testDummy() {
- }
-
-}