From 7d8ee265f841de05e8e4bb5a1bd2b79a69c55b03 Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 14 Jan 2009 00:32:52 +0000 Subject: Update the calculator-osgi example git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@734283 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/calculator/CalculatorActivator.java | 54 ++++++++++++++++++++ .../src/main/java/calculator/CalculatorClient.java | 20 ++------ .../main/java/calculator/CalculatorService.java | 1 - .../java/calculator/CalculatorServiceImpl.java | 1 - .../test/java/calculator/CalculatorTestCase.java | 57 ---------------------- 5 files changed, 59 insertions(+), 74 deletions(-) create mode 100644 java/sca/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java delete mode 100644 java/sca/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java (limited to 'java/sca/samples/calculator-osgi/src') 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() { - } - -} -- cgit v1.2.3