From a2c3f4546c0c32c3d40c52c81b5fd5131ba19145 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 3 Nov 2009 08:26:19 +0000 Subject: Tag 2.0 M4 RC2 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@832340 13f79535-47bb-0310-9956-ffa450edef68 --- tags/java/sca/2.0-M4-RC2/samples/README | 232 ++++++++++++ .../samples/binding-ws-calculator/README | 97 +++++ .../samples/binding-ws-calculator/build.xml | 67 ++++ .../samples/binding-ws-calculator/calculator.png | Bin 0 -> 20552 bytes .../samples/binding-ws-calculator/calculator.svg | 329 ++++++++++++++++ .../samples/binding-ws-calculator/pom.xml | 89 +++++ .../src/main/java/calculator/AddService.java | 31 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 ++ .../main/java/calculator/CalculatorClientImpl.java | 66 ++++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 70 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 ++ .../src/main/java/sample/SampleClient.java | 26 ++ .../src/main/java/sample/SampleClientImpl.java | 45 +++ .../src/main/resources/Calculator.composite | 59 +++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../test/java/calculator/CalculatorTestCase.java | 34 ++ tags/java/sca/2.0-M4-RC2/samples/build-common.xml | 102 +++++ .../2.0-M4-RC2/samples/calculator-equinox/README | 97 +++++ .../samples/calculator-equinox/build.xml | 78 ++++ .../samples/calculator-equinox/calculator.png | Bin 0 -> 20552 bytes .../samples/calculator-equinox/calculator.svg | 329 ++++++++++++++++ .../2.0-M4-RC2/samples/calculator-equinox/pom.xml | 84 +++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 ++ .../src/main/java/calculator/CalculatorClient.java | 62 ++++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 70 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 ++ .../src/main/resources/Calculator.composite | 54 +++ .../test/java/calculator/CalculatorTestCase.java | 65 ++++ .../samples/calculator-osgi/META-INF/MANIFEST.MF | 19 + .../sca/2.0-M4-RC2/samples/calculator-osgi/README | 97 +++++ .../2.0-M4-RC2/samples/calculator-osgi/build.xml | 78 ++++ .../sca/2.0-M4-RC2/samples/calculator-osgi/pom.xml | 116 ++++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 ++ .../main/java/calculator/CalculatorActivator.java | 54 +++ .../src/main/java/calculator/CalculatorClient.java | 52 +++ .../main/java/calculator/CalculatorService.java | 34 ++ .../java/calculator/CalculatorServiceImpl.java | 69 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 ++ .../src/main/resources/Calculator.composite | 54 +++ .../test/java/calculator/CalculatorTestCase.java | 55 +++ .../samples/calculator-rmi-reference/README | 138 +++++++ .../samples/calculator-rmi-reference/build.xml | 84 +++++ .../calculator-rmi-reference.png | Bin 0 -> 23615 bytes .../calculator-rmi-reference.svg | 412 +++++++++++++++++++++ .../samples/calculator-rmi-reference/pom.xml | 82 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/CalculatorClient.java | 49 +++ .../main/java/calculator/CalculatorService.java | 39 ++ .../java/calculator/CalculatorServiceImpl.java | 68 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../resources/CalculatorRMIReference.composite | 42 +++ .../calculator/CalculatorRMIReferenceTestCase.java | 70 ++++ .../java/calculator/CalculatorRMIServiceImpl.java | 52 +++ .../samples/calculator-rmi-service/README | 147 ++++++++ .../samples/calculator-rmi-service/build.xml | 76 ++++ .../calculator-rmi-service.png | Bin 0 -> 20814 bytes .../calculator-rmi-service.svg | 330 +++++++++++++++++ .../samples/calculator-rmi-service/pom.xml | 67 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 30 ++ .../src/main/java/calculator/CalculatorClient.java | 40 ++ .../src/main/java/calculator/CalculatorServer.java | 45 +++ .../main/java/calculator/CalculatorService.java | 36 ++ .../java/calculator/CalculatorServiceImpl.java | 68 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 30 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 30 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 30 ++ .../main/resources/CalculatorRMIServer.composite | 53 +++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../calculator/CalculatorRMIServerTestCase.java | 63 ++++ tags/java/sca/2.0-M4-RC2/samples/calculator/README | 97 +++++ .../sca/2.0-M4-RC2/samples/calculator/build.xml | 65 ++++ .../2.0-M4-RC2/samples/calculator/calculator.png | Bin 0 -> 20552 bytes .../2.0-M4-RC2/samples/calculator/calculator.svg | 329 ++++++++++++++++ .../java/sca/2.0-M4-RC2/samples/calculator/pom.xml | 78 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 38 ++ .../src/main/java/calculator/CalculatorClient.java | 48 +++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 72 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 38 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 38 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 38 ++ .../src/main/resources/Calculator.composite | 49 +++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../test/java/calculator/CalculatorTestCase.java | 63 ++++ .../samples/dosgi-calculator-operations/LICENSE | 205 ++++++++++ .../META-INF/MANIFEST.MF | 22 ++ .../samples/dosgi-calculator-operations/NOTICE | 6 + .../OSGI-INF/add-component.xml | 25 ++ .../OSGI-INF/blueprint/operations-module.xml | 40 ++ .../OSGI-INF/divide-component.xml | 25 ++ .../OSGI-INF/multiply-component.xml | 25 ++ .../OSGI-INF/sca/bundle.componentType | 47 +++ .../OSGI-INF/sca/bundle.composite | 43 +++ .../OSGI-INF/subtract-component.xml | 25 ++ .../samples/dosgi-calculator-operations/README | 183 +++++++++ .../samples/dosgi-calculator-operations/pom.xml | 141 +++++++ .../calculator/dosgi/operations/AddService.java | 31 ++ .../calculator/dosgi/operations/DivideService.java | 31 ++ .../dosgi/operations/MultiplyService.java | 31 ++ .../dosgi/operations/SubtractService.java | 31 ++ .../dosgi/operations/impl/AddServiceImpl.java | 37 ++ .../dosgi/operations/impl/DivideServiceImpl.java | 37 ++ .../dosgi/operations/impl/MultiplyServiceImpl.java | 37 ++ .../dosgi/operations/impl/OperationsActivator.java | 88 +++++ .../dosgi/operations/impl/SubtractServiceImpl.java | 37 ++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../dosgi/operations/test/OSGiTestUtils.java | 105 ++++++ .../dosgi/operations/test/OperationsNode.java | 43 +++ .../test/OperationsOSGiNodeTestCase.java | 104 ++++++ .../2.0-M4-RC2/samples/dosgi-calculator/LICENSE | 205 ++++++++++ .../samples/dosgi-calculator/META-INF/MANIFEST.MF | 20 + .../sca/2.0-M4-RC2/samples/dosgi-calculator/NOTICE | 6 + .../OSGI-INF/blueprint/calculator-module.xml | 43 +++ .../OSGI-INF/calculator-component.xml | 36 ++ .../OSGI-INF/sca/bundle.componentType | 54 +++ .../dosgi-calculator/OSGI-INF/sca/bundle.composite | 45 +++ .../sca/2.0-M4-RC2/samples/dosgi-calculator/README | 155 ++++++++ .../samples/dosgi-calculator/dosgi-calculator.png | Bin 0 -> 85103 bytes .../2.0-M4-RC2/samples/dosgi-calculator/pom.xml | 146 ++++++++ .../java/calculator/dosgi/CalculatorService.java | 36 ++ .../calculator/dosgi/impl/CalculatorActivator.java | 76 ++++ .../dosgi/impl/CalculatorServiceDSImpl.java | 114 ++++++ .../dosgi/impl/CalculatorServiceImpl.java | 105 ++++++ .../calculator/dosgi/operations/AddService.java | 31 ++ .../calculator/dosgi/operations/DivideService.java | 31 ++ .../dosgi/operations/MultiplyService.java | 31 ++ .../dosgi/operations/SubtractService.java | 31 ++ .../java/calculator/rmi/OperationsRMIServer.java | 93 +++++ .../calculator/rmi/OperationsRMIServer_Stub.java | 132 +++++++ .../main/java/calculator/rmi/OperationsRemote.java | 37 ++ .../main/resources/META-INF/sca-contribution.xml | 24 ++ .../java/calculator/dosgi/test/CalculatorNode.java | 43 +++ .../dosgi/test/CalculatorOSGiNodeTestCase.java | 144 +++++++ .../java/calculator/dosgi/test/OSGiTestUtils.java | 105 ++++++ .../dosgi-dynamic-calculator-operations/LICENSE | 205 ++++++++++ .../META-INF/MANIFEST.MF | 23 ++ .../dosgi-dynamic-calculator-operations/NOTICE | 6 + .../OSGI-INF/add-component.xml | 25 ++ .../OSGI-INF/blueprint/operations-module.xml | 40 ++ .../OSGI-INF/divide-component.xml | 25 ++ .../OSGI-INF/multiply-component.xml | 25 ++ .../OSGI-INF/sca-config/operations-config.xml | 29 ++ .../OSGI-INF/subtract-component.xml | 25 ++ .../dosgi-dynamic-calculator-operations/README | 183 +++++++++ .../dosgi-dynamic-calculator-operations/pom.xml | 141 +++++++ .../calculator/dosgi/operations/AddService.java | 31 ++ .../calculator/dosgi/operations/DivideService.java | 31 ++ .../dosgi/operations/MultiplyService.java | 31 ++ .../dosgi/operations/SubtractService.java | 31 ++ .../dosgi/operations/impl/AddServiceImpl.java | 37 ++ .../dosgi/operations/impl/DivideServiceImpl.java | 37 ++ .../dosgi/operations/impl/MultiplyServiceImpl.java | 37 ++ .../dosgi/operations/impl/OperationsActivator.java | 94 +++++ .../dosgi/operations/impl/SubtractServiceImpl.java | 37 ++ .../dosgi/operations/test/OSGiTestUtils.java | 105 ++++++ .../dosgi/operations/test/OperationsNode.java | 43 +++ .../test/OperationsOSGiNodeTestCase.java | 104 ++++++ .../samples/dosgi-dynamic-calculator/LICENSE | 205 ++++++++++ .../dosgi-dynamic-calculator/META-INF/MANIFEST.MF | 23 ++ .../samples/dosgi-dynamic-calculator/NOTICE | 6 + .../OSGI-INF/blueprint/calculator-module.xml | 43 +++ .../OSGI-INF/calculator-component.xml | 36 ++ .../calculator-service-descriptions.xml | 61 +++ .../OSGI-INF/sca-config/calculator-config.xml | 32 ++ .../samples/dosgi-dynamic-calculator/README | 155 ++++++++ .../dosgi-dynamic-calculator/dosgi-calculator.png | Bin 0 -> 85103 bytes .../samples/dosgi-dynamic-calculator/pom.xml | 146 ++++++++ .../java/calculator/dosgi/CalculatorService.java | 36 ++ .../calculator/dosgi/impl/CalculatorActivator.java | 78 ++++ .../dosgi/impl/CalculatorServiceDSImpl.java | 114 ++++++ .../dosgi/impl/CalculatorServiceImpl.java | 105 ++++++ .../calculator/dosgi/operations/AddService.java | 31 ++ .../calculator/dosgi/operations/DivideService.java | 31 ++ .../dosgi/operations/MultiplyService.java | 31 ++ .../dosgi/operations/SubtractService.java | 31 ++ .../java/calculator/rmi/OperationsRMIServer.java | 93 +++++ .../calculator/rmi/OperationsRMIServer_Stub.java | 132 +++++++ .../main/java/calculator/rmi/OperationsRemote.java | 37 ++ .../java/calculator/dosgi/test/CalculatorNode.java | 43 +++ .../dosgi/test/CalculatorOSGiNodeTestCase.java | 144 +++++++ .../java/calculator/dosgi/test/OSGiTestUtils.java | 105 ++++++ .../sca/2.0-M4-RC2/samples/helloworld-bpel/README | 151 ++++++++ .../2.0-M4-RC2/samples/helloworld-bpel/build.xml | 95 +++++ .../samples/helloworld-bpel/helloworld-bpel.png | Bin 0 -> 8897 bytes .../samples/helloworld-bpel/helloworld-bpel.svg | 179 +++++++++ .../sca/2.0-M4-RC2/samples/helloworld-bpel/pom.xml | 115 ++++++ .../src/main/java/helloworld/BPELClient.java | 45 +++ .../src/main/java/helloworld/Hello.java | 29 ++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../src/main/resources/helloworld.bpel | 78 ++++ .../src/main/resources/helloworld.composite | 29 ++ .../src/main/resources/helloworld.wsdl | 82 ++++ .../src/main/resources/log4j.properties | 35 ++ .../java/helloworld/BPELHelloWorldTestCase.java | 65 ++++ .../samples/implementation-java-calculator/README | 96 +++++ .../implementation-java-calculator/build.xml | 59 +++ .../implementation-java-calculator/calculator.png | Bin 0 -> 20552 bytes .../implementation-java-calculator/calculator.svg | 329 ++++++++++++++++ .../samples/implementation-java-calculator/pom.xml | 65 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 ++ .../src/main/java/calculator/CalculatorClient.java | 62 ++++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 70 ++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 ++ .../src/main/resources/Calculator.composite | 54 +++ .../test/java/calculator/CalculatorTestCase.java | 73 ++++ .../java/sca/2.0-M4-RC2/samples/logging.properties | 25 ++ tags/java/sca/2.0-M4-RC2/samples/pom.xml | 78 ++++ .../samples/webapps/helloworld-bpel/pom.xml | 130 +++++++ .../src/main/java/sample/HelloworldService.java | 28 ++ .../src/main/resources/helloworld.bpel | 66 ++++ .../src/main/resources/helloworld.wsdl | 82 ++++ .../src/main/webapp/WEB-INF/web.composite | 37 ++ .../src/main/webapp/WEB-INF/web.xml | 41 ++ .../helloworld-bpel/src/main/webapp/hello.jsp | 36 ++ .../samples/webapps/helloworld-jms/README | 131 +++++++ .../samples/webapps/helloworld-jms/pom.xml | 80 ++++ .../src/main/java/sample/HelloWorldClient.java | 37 ++ .../src/main/java/sample/HelloWorldService.java | 29 ++ .../main/java/sample/HelloWorldServiceImpl.java | 31 ++ .../src/main/webapp/META-INF/context.xml | 34 ++ .../src/main/webapp/WEB-INF/jetty-env.xml | 48 +++ .../src/main/webapp/WEB-INF/web.composite | 44 +++ .../helloworld-jms/src/main/webapp/WEB-INF/web.xml | 66 ++++ .../helloworld-jms/src/main/webapp/hello.jsp | 41 ++ .../samples/webapps/helloworld-js-client/pom.xml | 62 ++++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 28 ++ .../src/main/webapp/WEB-INF/web.composite | 36 ++ .../src/main/webapp/WEB-INF/web.xml | 41 ++ .../src/main/webapp/hello.html | 51 +++ .../samples/webapps/helloworld-jsf/pom.xml | 69 ++++ .../src/main/java/sample/HelloWorldController.java | 56 +++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 27 ++ .../src/main/webapp/WEB-INF/faces-config.xml | 51 +++ .../src/main/webapp/WEB-INF/web.composite | 34 ++ .../helloworld-jsf/src/main/webapp/WEB-INF/web.xml | 191 ++++++++++ .../helloworld-jsf/src/main/webapp/helloWorld.jsp | 40 ++ .../helloworld-jsf/src/main/webapp/index.jsp | 23 ++ .../helloworld-jsf/src/main/webapp/page2.jsp | 38 ++ .../samples/webapps/helloworld-jsp/pom.xml | 62 ++++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 28 ++ .../src/main/webapp/WEB-INF/web.composite | 34 ++ .../helloworld-jsp/src/main/webapp/WEB-INF/web.xml | 41 ++ .../helloworld-jsp/src/main/webapp/hello.jsp | 37 ++ .../samples/webapps/helloworld-rest/README | 37 ++ .../samples/webapps/helloworld-rest/pom.xml | 111 ++++++ .../java/helloworldrest/ClientJavaTestService.java | 29 ++ .../helloworldrest/ClientTestServiceWebapp.java | 108 ++++++ .../java/helloworldrest/HelloWorldService.java | 13 + .../java/helloworldrest/HelloWorldServiceImpl.java | 44 +++ .../src/main/resources/rest.composite | 37 ++ .../src/main/webapp/HelloWorldJSONRPC.html | 75 ++++ .../src/main/webapp/META-INF/sca-contribution.xml | 26 ++ .../src/main/webapp/WEB-INF/web.xml | 35 ++ .../helloworld-rest/src/main/webapp/style.css | 22 ++ .../helloworld-rest/target/classes/rest.composite | 37 ++ .../samples/webapps/helloworld-servlet/pom.xml | 61 +++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 27 ++ .../src/main/java/sample/HelloworldServlet.java | 64 ++++ .../src/main/webapp/WEB-INF/web.composite | 34 ++ .../src/main/webapp/WEB-INF/web.xml | 44 +++ .../helloworld-servlet/src/main/webapp/hello.html | 46 +++ .../samples/webapps/helloworld-stripes/pom.xml | 72 ++++ .../main/java/mystripes/action/BaseActionBean.java | 33 ++ .../main/java/mystripes/action/HomeActionBean.java | 45 +++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 28 ++ .../src/main/resources/StripesResources.properties | 57 +++ .../src/main/resources/log4j.properties | 31 ++ .../src/main/webapp/WEB-INF/jsp/home.jsp | 26 ++ .../src/main/webapp/WEB-INF/jsp/layout.jsp | 39 ++ .../src/main/webapp/WEB-INF/jsp/taglibs.jsp | 29 ++ .../src/main/webapp/WEB-INF/web.composite | 34 ++ .../src/main/webapp/WEB-INF/web.xml | 61 +++ .../helloworld-stripes/src/main/webapp/index.html | 24 ++ .../samples/webapps/helloworld-wicket/pom.xml | 83 +++++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 28 ++ .../src/main/java/sample/wicket/HomePage.html | 48 +++ .../src/main/java/sample/wicket/HomePage.java | 66 ++++ .../src/main/java/sample/wicket/IMyService.java | 35 ++ .../src/main/java/sample/wicket/MyService.java | 38 ++ .../main/java/sample/wicket/WicketApplication.java | 47 +++ .../src/main/resources/log4j.properties | 29 ++ .../src/main/webapp/WEB-INF/web.composite | 34 ++ .../src/main/webapp/WEB-INF/web.xml | 50 +++ .../2.0-M4-RC2/samples/webapps/helloworld/pom.xml | 62 ++++ .../src/main/java/sample/HelloworldService.java | 25 ++ .../main/java/sample/HelloworldServiceImpl.java | 38 ++ .../src/main/webapp/WEB-INF/web.composite | 29 ++ .../helloworld/src/main/webapp/WEB-INF/web.xml | 37 ++ 330 files changed, 19376 insertions(+) create mode 100644 tags/java/sca/2.0-M4-RC2/samples/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/Calculator.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/build-common.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/resources/Calculator.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/META-INF/MANIFEST.MF create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/resources/Calculator.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/Calculator.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/LICENSE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/META-INF/MANIFEST.MF create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/NOTICE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/add-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/divide-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/multiply-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/subtract-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/LICENSE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/META-INF/MANIFEST.MF create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/NOTICE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/calculator-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.componentType create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/dosgi-calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/OSGiTestUtils.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/LICENSE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/NOTICE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/LICENSE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/META-INF/MANIFEST.MF create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/NOTICE create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/dosgi-calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/OSGiTestUtils.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/BPELClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/Hello.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.bpel create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.wsdl create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/log4j.properties create mode 100644 tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/test/java/helloworld/BPELHelloWorldTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/build.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.png create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.svg create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/resources/Calculator.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/logging.properties create mode 100644 tags/java/sca/2.0-M4-RC2/samples/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.bpel create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.wsdl create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/hello.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldClient.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/META-INF/context.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/jetty-env.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/hello.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/hello.html create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloWorldController.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/helloWorld.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/index.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/page2.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/hello.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/README create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/resources/rest.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/HelloWorldJSONRPC.html create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/style.css create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/target/classes/rest.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/hello.html create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/BaseActionBean.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/HomeActionBean.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/StripesResources.properties create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/log4j.properties create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/home.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/layout.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/taglibs.jsp create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/index.html create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.html create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/IMyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/MyService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/WicketApplication.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/resources/log4j.properties create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/pom.xml create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldService.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldServiceImpl.java create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.composite create mode 100644 tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.xml (limited to 'tags/java/sca/2.0-M4-RC2/samples') diff --git a/tags/java/sca/2.0-M4-RC2/samples/README b/tags/java/sca/2.0-M4-RC2/samples/README new file mode 100644 index 0000000000..4ccefa3695 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/README @@ -0,0 +1,232 @@ +The Apache Tuscany SCA Samples +============================== +The Apache Tuscany SCA samples are built as part of the main Maven build and +run, using the provided JUnit test cases, as tests in the Maven build. + +In the binary distribution of Apache Tuscany most samples can also +be run using the provided Ant build.xml files. These show the samples running +from a simple main() method without the need for a JUnit test case. + +In these notes text that appears in angled brackets like this means +that you need to make a choice and provide your own text at that point. + +These simple samples have been created with the intention of illustrating the +usage of the SCA API and annotations and certainly not to levels of SCA component +abstraction. In real life situations you should use SCA to assemble real and +usually bigger components, and when you do that you'll get all the benefits of +SCA, bindings, policies, integration in an SOA environment etc.. + +Sample Overview +--------------- +The samples generally show off different features of the SCA runtime +and the extensions that come packaged with it. + +binding-ws-calculator - Calculator running inside a web app also + showing webservices binding + +calculator - Calculator built with java components and + local wires. + +calculator-equinox - Calculator running inside a Equinox OSGi runtime + +calculator-osgi - Calculator running inside a OSGi runtime + +calculator-rmi-reference - The calculator configured to talk RMI to + the calculator-rmi-service sample +calculator-rmi-service - The calculator configured to accept RMI + requests from calculator-rmi-reference + +implementation-java-calculator + + +Sample Layout +------------- +All sample directories are organized in the same way based on the default +project template provided by Maven. For example, take a look at the calculator +sample; + +calculator/ + src/ - Holds all of the source files for the sample + main/ - Groups together the files that implement the sample + java/ - Java source files + resources/ - Non java resource files such as composte files + test/ - Groups together files that provide sample tests + java - Java test sources files. Usually JUnit test cases + target/ - Holds the files generated when the sample is built + classes/ - For example, Java class files + test-classes/ - classes from src/test and other test files + +Getting Ready To Build +---------------------- +You will need to install the following software before you start. + +J2SE Development Kit (JDK) 5.0 +Apache Ant 1.7.1 - if you are going to use Ant +Apache Maven 2.0.9 - if you are going to use Maven + +Java and Ant and/or Maven binary directories must be present in your PATH so +that their executable programs are available in your environment. You may +find it useful to use a script to set up your environment, for example; + +For UNIX: + JAVA_HOME=/ + ANT_HOME=//apache-ant-1.7.0 + MAVEN_HOME=//maven-2.0.6 + export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$MAVEN_HOME/bin:$PATH + +For Windows: + set JAVA_HOME=C:\ + set ANT_HOME=C:\\apache-ant-1.7.0 + set MAVEN_HOME=C:\\maven-2.0.6 + set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%MAVEN_HOME%\bin;%PATH% + + +Building And Running The SCA Samples Using Ant +---------------------------------------------- +The build.xml files provided with the Apache Tuscany SCA samples are designed +to work with the binary distribution. They rely on the tuscany-sca-manifest.jar +to describe the class path and this jar is only provided as part of the +binary distribution. + +The binary distribution of SCA also includes precompiled versions of each sample. +If you look in the target directory of each sample you will see this jar file. To +run a sample based on all of the precompiled artifacts all you have to do is: + +cd +ant run + +Check each /README file as some samples require that two progams are +run to get the desired result, for example, the two samples that show how +to build extensions are run from their associated application samples. + +If you want to rebuild a sample, for example, if you have changed it, do the +following: + +cd +ant compile + +Once the sample is built you have the option of running the sample in whatever +way best suits you. Two alternatives are provided in the ant build files. + +The compile target builds the class files and then builds the jar so you can use +the same command as before: + +ant run + +This will use the generated jar to run the samples. The command line version of +this is: + +on Windows + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\ + +for example : java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient + +on *nix + +java -cp ../../features/tuscany-sca-manifest.jar:target/ + +for example : java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + + +You can use the compiled classes directly using + +ant run-classes + +The command line version of this is: + +on Windows + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\classes + +for example : java -cp ..\..\features\tuscany-sca-manifest.jar;target\classes calculator.CalculatorClient + +on *nix + +java -cp ../../features/tuscany-sca-manifest.jar:target/classes + +for example : java -cp ../../features/tuscany-sca-manifest.jar:target/classes calculator.CalculatorClient + +The class specified on the command of course depends on which sample you want to +run. In the examples we have used we are running the CalculatorClient from the calculator sample. + + +Building And Running The SCA Samples Using Maven +------------------------------------------------ + +The Maven build process will work from both source and binary distributions. +To build and test all of the Apache Tuscany SCA sources, including the samples, +do the following. + +cd sca +mvn + +This will take a little while to complete. Experience with Maven tells us that +sometimes there are problems downloading the dependencies that Apache Tuscany +SCA requires. If Maven reports that it cannot download required dependencies +try running the Maven build again. + +Once you have all of the source built you can build and run each sample +independently if required. + +cd +mvn + +When using Maven the samples are run within JUnit test cases and so you will +sometimes not see any test output. You will always see an indication of test +success or failure. + +Using The Samples In An IDE +--------------------------------------------- +The easiest way to use the samples in an IDE is to use Maven to generate all +of the IDE project files for you automatically. This works best if you +generate IDE projects for all of the Apache Tuscany modules. You can then +include the ones you are interested in working with in you IDE. + +To build IDE project files for all of the modules in Apache Tuscany SCA; + +cd sca + +If you are an Eclipse user do the following + +mvn -Peclipse + +If you are an IDEA user do the following + +mvn idea:idea + +These commands generate project files for each module in Apache Tuscany SCA. +The modules you are interested in can now be included in your IDE, for example, +in Eclipse, if you create a new Java project and use the option to "create a +new project from existing source" you can specify an SCA module directory, +which includes the generated project files, and Eclipse will treat it like any +other Java project. + +Using The Samples In An IDE Without Maven +----------------------------------------- +We don't provide any IDE project files with our distributions so you will have to +import the sample files into your IDE manually. Here's an example of how it can be +done using Eclipse. + +In a new or existing workspace + Create a new java project to represent the sample you want to work on, e.g. + calculator + Import all of the sample code and resources into this project, e.g. + File, Import and then select tuscany-sca-1.0-incubating\samples\calculator from the filesystem + Configure the source path to include + src/main/java + src/main/resources + Configure the output folder to be + calculator/target + Configure the build path to include the manifest jar tuscany-sca-manifiest.jar provided in + features + If you select calculator.CalculatorClient.java and run as "Java Application" you should see + 3 + 2=5.0 + 3 - 2=1.0 + 3 * 2=6.0 + 3 / 2=1.5 + +The details of how to do this for other development environments will +vary but the process will be similar. + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/README b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/README new file mode 100644 index 0000000000..fb5afcc7ec --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-binding-ws-calculator.jar sample.SampleClientImpl + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-binding-ws-calculator.jar sample.SampleClientImpl + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/build.xml b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/build.xml new file mode 100644 index 0000000000..e13ec494b0 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.png b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.svg b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.svg new file mode 100644 index 0000000000..af34f07e04 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/pom.xml new file mode 100644 index 0000000000..67cdee5815 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/pom.xml @@ -0,0 +1,89 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-binding-ws-calculator + Apache Tuscany SCA Sample Binding WS Calculator + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-feature-ejava + pom + 2.0-M4 + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..dd7ecb827d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/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; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The Add service interface + */ +@Remotable +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/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.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java new file mode 100644 index 0000000000..7e5ff160f0 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorClientImpl.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +import sample.SampleClient; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@Scope("COMPOSITE") +public class CalculatorClientImpl implements SampleClient { + + private CalculatorService calculatorService; + + @Reference + public void setCalculatorService(CalculatorService calculatorService) { + this.calculatorService = calculatorService; + } + + /** + * This code used to be in an @Init method which removed the need for a JSE client + * to prod the compoite. However OASIS is debating whether to allow references to be used + * inside @Init methods and it can cause deadlocks in our runtime. So rather than make + * changes in the runtime we are falling backon the JSE drive mechanism until we know + * which way the specs are going + */ + public void runSample() { + System.out.println("SCA API ClassLoader: " + print(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/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorService.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; + + +/** + * The Calculator service interface. + */ +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-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..17fad7de6b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,70 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/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.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/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.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/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.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java new file mode 100644 index 0000000000..6620f6a5e7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClient.java @@ -0,0 +1,26 @@ +/* + * 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 sample; + +/** + * The sample service interface. + */ +public interface SampleClient { + void runSample(); +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java new file mode 100644 index 0000000000..000c108934 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/java/sample/SampleClientImpl.java @@ -0,0 +1,45 @@ +/* + * 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 sample; + +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 SampleClientImpl { + public static void main(String[] args) throws Exception { + String location = ContributionLocationHelper.getContributionLocation(SampleClient.class); + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", location)); + + node.start(); + + SampleClient sampleClient = node.getService(SampleClient.class, "SampleClient"); + sampleClient.runSample(); + + node.stop(); + + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/Calculator.composite b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..29dd7e3b6f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..27a1ee74e4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..8f6b5e4845 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/binding-ws-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,34 @@ +/* + * 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.junit.Test; + +import sample.SampleClientImpl; + +/** + * Test the Calculator composition. + */ +public class CalculatorTestCase { + + @Test + public void testSample() throws Exception { + SampleClientImpl.main(null); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/build-common.xml b/tags/java/sca/2.0-M4-RC2/samples/build-common.xml new file mode 100644 index 0000000000..64d23d3793 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/build-common.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + Distribution: ${distro.root} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/README b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/README new file mode 100644 index 0000000000..7f76542622 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator-equinox.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator-equinox.jar calculator.CalculatorClient + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/build.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/build.xml new file mode 100644 index 0000000000..75c4839cfa --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/build.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.png b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.svg b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.svg new file mode 100644 index 0000000000..af34f07e04 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/pom.xml new file mode 100644 index 0000000000..78c4f2c0e2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/pom.xml @@ -0,0 +1,84 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-calculator-equinox + Apache Tuscany SCA Sample Calculator Equinox + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-extensibility-equinox + 2.0-M4 + runtime + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/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.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..84c98d7f70 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,62 @@ +/* + * 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.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@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("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/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorService.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; + + +/** + * The Calculator service interface. + */ +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-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..17fad7de6b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,70 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/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.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/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.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/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.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/resources/Calculator.composite b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..9450558145 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/main/resources/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..b49e1da130 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,65 @@ +/* + * 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.Node; +import org.apache.tuscany.sca.node.equinox.launcher.Contribution; +import org.apache.tuscany.sca.node.equinox.launcher.ContributionLocationHelper; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator composition. + */ +public class CalculatorTestCase { + + private static NodeLauncher launcher; + private static Node node; + + public static void main(String[] args) throws Exception { + setUpBeforeClass(); + tearDownAfterClass(); + } + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + launcher = NodeLauncher.newInstance(); + String location = ContributionLocationHelper.getContributionLocation(CalculatorClient.class); + node = launcher.createNode("Calculator.composite", new Contribution("test", location)); + System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader()); + node.start(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (node != null) { + node.stop(); + node.destroy(); + } + if (launcher != null) { + launcher.destroy(); + } + } + + @Test + public void testDummy() throws Exception { + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/META-INF/MANIFEST.MF b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..1ebd35b30a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Private-Package: calculator;version="2.0.0" +Tool: Bnd-0.0.255 +Bundle-Name: Apache Tuscany SCA Calculator OSGi Sample +Created-By: 1.6.0_07 (Sun Microsystems Inc.) +Bundle-Vendor: The Apache Software Foundation +Eclipse-LazyStart: false +Bundle-Version: 2.0.0 +Bnd-LastModified: 1223949424781 +Bundle-Activator: calculator.CalculatorActivator +Bundle-ManifestVersion: 2 +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-Description: Apache Tuscany SCA Calculator OSGi Sample +Import-Package: org.apache.tuscany.sca.node;version="2.0.0", + org.oasisopen.sca.annotation;version="2.0.0", + org.osgi.framework;version="1.4" +Bundle-SymbolicName: sample-calculator-osgi +Bundle-DocURL: http://www.apache.org/ +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/README b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/README new file mode 100644 index 0000000000..332526d43a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components and run it in a OSGi environment. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -jar ..\..\features\tuscany-sca-equinox-manifest.jar -composite Calculator.composite -config ..\..\features\configuration\ -ttl 0 target\sample-calculator-osgi.jar + +and on *nix do + +java -jar ../../features/tuscany-sca-equinox-manifest.jar -composite Calculator.composite -config ../../features/configuration/ -ttl 0 target/sample-calculator-osgi.jar + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/build.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/build.xml new file mode 100644 index 0000000000..46522211f9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/build.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/pom.xml new file mode 100644 index 0000000000..35a302e68b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/pom.xml @@ -0,0 +1,116 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-calculator-osgi + Apache Tuscany SCA Sample Calculator OSGi + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + + org.apache.tuscany.sca + tuscany-feature-api + 2.0-M4 + pom + + + + org.apache.tuscany.sca + tuscany-feature-core + 2.0-M4 + pom + + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + org.apache.tuscany.maven.plugins + maven-osgi-junit-plugin + 1.0 + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + ${pom.version} + + + + + osgi-test + test + + test + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/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.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorActivator.java new file mode 100644 index 0000000000..4408568629 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..afd5ea48fc --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,52 @@ +/* + * 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.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@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: " + 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)); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..c89043276e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,34 @@ +/* + * 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; + +/** + * The Calculator service interface. + */ +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-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..39f55ca31f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,69 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/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.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/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.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/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.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/resources/Calculator.composite b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..9450558145 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/main/resources/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..9d9b0a9ffb --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,55 @@ +/* + * 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.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator composition. + */ +public class CalculatorTestCase { + + private static Node node; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + String location = ContributionLocationHelper.getContributionLocation(CalculatorClient.class); + node = NodeFactory.newInstance().createNode("Calculator.composite", new Contribution("test", location)); + System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader()); + node.start(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (node != null) { + node.stop(); + node.destroy(); + } + } + + @Test + public void testDummy() throws Exception { + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/README b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/README new file mode 100644 index 0000000000..07b6dd9713 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/README @@ -0,0 +1,138 @@ +Calculator RMI Reference Sample +=============================== + +This sample illustrates the use of Tuscany RMI Binding to call reference +services that are hosted as Java RMI services. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, first +navigate to the calculator-rmi-service sample and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator-rmi-service.jar calculator.CalculatorServer + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator-rmi-service.jar calculator.CalculatorServer + +Now you have the server running you need to open another command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator-rmi-reference.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator-rmi-reference.jar calculator.CalculatorClient + +Sample Overview +--------------- +This sample extends the calculator sample by replacing the local wired +connections with RMI bindings. Instead of local add, subtract, multiply and +divide components, an RMI service implementation now provides the +add, subtract, multiply and divide interfaces and is hosted as an RMI server. +References specified in the .composite file include an RMI binding which targets +this RMI server. + +This sample adds a number of classes to the basic calculator sample: + +calculator-rmi-reference/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - as calculator sample + AddService.java - as calculator sample + SubtractService.java - as calculator sample + MultipleService.java - as calculator sample + DivideService.java - as calculator sample + CalculatorClient.java - as calculator sample + CalculatorServiceImpl.java - calls the RMI service + that provides the target for the + RMI bindings in the composite + resources/ + CalculatorRMIReference.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorRMIReferenceTestCase.java - JUnit test case + CalculatorRMIServiceImpl.java - test RMI service to call + calculator-rmi-reference.png - a pictorial representation of the + .composite file + build.xml - the Ant build file for the client + pom.xml - the Maven build file + +Note. As this test creates and uses local network connections you may need to +configure your firewall, if you are running one, to allow the test to run +successfully. + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant. + +The server provides an RMI server that the acts as a target for the SCA RMI +bindings. Start a new console and use the following commands. + +cd calculator-rmi-service +ant compile +ant run + +This will run up the server and display the following. + +run: + [java] Starting of the SCA Calculator Application exposed as RMI Services... + [java] ...Press Enter to Exit... + +The client is very similar to the calculator sample. It starts the SCA runtime +and calls each of the calculator operations. In doing this the RMI bindings +make calls out to the RMI server you started in the previous step. Start +a new console and use the following commands. + +cd calculator-rmi-reference +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +If you now return to the console window running the server and press enter the +server should stop. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-rmi-reference +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorRMIReferenceTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.308 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/build.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/build.xml new file mode 100644 index 0000000000..e95ad1610b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/build.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.png b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.png new file mode 100644 index 0000000000..8c76b77a9f Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.svg b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.svg new file mode 100644 index 0000000000..ba802e6717 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/calculator-rmi-reference.svg @@ -0,0 +1,412 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + CalculatorServiceRMIImpl + addService + subtractService + multiplyService + divideService + + + + + AddReference + SubtractReference + MultiplyReference + DivideReference + RMIRegistry + + + + + RMI RMI RMI RMI + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/pom.xml new file mode 100644 index 0000000000..01166487f9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-calculator-rmi-reference + Apache Tuscany SCA Sample Calculator RMI Reference + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-M4 + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M4 + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-M4 + runtime + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + calculator.CalculatorClient + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the add service + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..e14cc3dd13 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,49 @@ +/* + * 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/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..0f7dec116f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,39 @@ +/* + * 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.rmi.Remote; +import java.rmi.RemoteException; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The Calculator service interface. + */ +@Remotable +public interface CalculatorService 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-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..bcfd8871b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,68 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite new file mode 100644 index 0000000000..a5510954e0 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java new file mode 100644 index 0000000000..39d4b2fd28 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java @@ -0,0 +1,70 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +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.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorRMIReferenceTestCase { + + private static Node node; + private static CalculatorService calculatorService; + + @BeforeClass + public static void setUp() throws Exception { + CalculatorRMIServiceImpl rmiCalculatorImpl = new CalculatorRMIServiceImpl(); + Registry rmiRegistry = LocateRegistry.createRegistry(8099); + rmiRegistry.bind("CalculatorRMIService", rmiCalculatorImpl); + + String uri = ContributionLocationHelper.getContributionLocation(CalculatorService.class); + Contribution contribution = new Contribution("c1", uri); + node = NodeFactory.newInstance().createNode("CalculatorRMIReference.composite", contribution); + node.start(); + calculatorService = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + LocateRegistry.getRegistry(8099).unbind("CalculatorRMIService"); + } + + @Test + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0, 0.0); + assertEquals(calculatorService.subtract(3, 2), 1.0, 0.0); + assertEquals(calculatorService.multiply(3, 2), 6.0, 0.0); + assertEquals(calculatorService.divide(3, 2), 1.5, 0.0); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java new file mode 100644 index 0000000000..d8ded42cb2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java @@ -0,0 +1,52 @@ +/* + * 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.rmi.RemoteException; +import java.rmi.server.UnicastRemoteObject; + + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorRMIServiceImpl extends UnicastRemoteObject implements CalculatorService { + + private static final long serialVersionUID = -1543948944662001428L; + + public CalculatorRMIServiceImpl() throws RemoteException { + super(); + } + + public double add(double n1, double n2) throws RemoteException { + return n1 + n2; + } + + public double subtract(double n1, double n2) { + return n1 - n2; + } + + public double multiply(double n1, double n2) { + return n1 * n2; + } + + public double divide(double n1, double n2) { + return n1 / n2; + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/README b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/README new file mode 100644 index 0000000000..144881134b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/README @@ -0,0 +1,147 @@ +Calculator RMI Service Sample +============================= + +This sample illustrates the use of Tuscany RMI Binding to expose component +services as Java RMI Services. It also demonstrates how a simple Java RMI +Client application invokes the SCA Application's services exposed as RMI +Services. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator-rmi-service.jar calculator.CalculatorServer + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator-rmi-service.jar calculator.CalculatorServer + +Now you have the server running you need to open another command prompt, navigate +to the calculator-rmi-reference sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-reference.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-reference.jar calculator.CalculatorClient + + +Sample Overview +--------------- +This sample extends the calculator sample by replacing the local service +binding with an RMI binding. SO a java client can call the service exposed +by the SCA application using an RMI client. + +This sample adds a number of classes to the basic calculator sample: + +calculator-rmi-service/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - as calculator sample + CalculatorServiceImpl.java + AddService.java - as calculator sample + AddServiceImpl.java + SubtractService.java - as calculator sample + SubtractServiceImpl.java + MultiplyService.java - as calculator sample + MultiplyServiceImpl.java + DivideService.java - as calculator sample + DivideServiceImpl.java + CalculatorClient.java - (Not currently used) Uses the + java naming service to + look up the Calculator RMI service. + It then calls add, subtract, multiple + and divide methods on the service + CalculatorServer.java - starts the SCA Runtime and deploys + the CalculatorRMIServer.composite. + In doing this the SCA RMI binding + acts to expose the CalculatorService + over RMI. + resources/ + CalculatorRMIServer.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorRMIServerTestCase.java - JUnit test case + calculator-rmi-service.png - a pictorial representation of the + .composite file + build.xml - the Ant build file for the server + pom.xml - the Maven build file + +Note. As this test creates and uses local network connections you may need to +configure your firewall, if you are running one, to allow the test to run +successfully. + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant. Two +build files are used to support client and server functions. + +The server starts the SCA runtime and loads the SCA calculator application +which exposes an RMI service. Start a new console and use the following +commands. + +cd calculator-rmi-service +ant compile +ant run + +This will run up the server and display the following. + +run: + [java] Starting of the SCA Calculator Application exposed as RMI Services... + [java] ...Press Enter to Exit... + +The client is very similar to the calculator sample + +It locates the RMI service that the SCA runtime is exposing and calls each of +the calculator operations. Start a new console and use the following commands. + +cd calculator-rmi-reference +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +If you now return to the console window running the server and press enter the +server should stop. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-rmi-service +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorRMIServerTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.819 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/build.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/build.xml new file mode 100644 index 0000000000..a0889ccc8a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/build.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.png b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.png new file mode 100644 index 0000000000..574f5eb14b Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.svg b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.svg new file mode 100644 index 0000000000..9253110f98 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/calculator-rmi-service.svg @@ -0,0 +1,330 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService(RMI) + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/pom.xml new file mode 100644 index 0000000000..f3f8ed5644 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-calculator-rmi-service + Apache Tuscany SCA Sample Calculator RMI Service + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-M4 + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + test + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M4 + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-M4 + runtime + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the add service + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..8b6fe066a6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..2b99485b68 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,40 @@ +/* + * 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.rmi.Naming; + +/** + * 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 { + CalculatorService calculatorService = (CalculatorService)Naming.lookup("//localhost:8099/CalculatorRMIService"); + + // 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)); + + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java new file mode 100644 index 0000000000..b77015bcae --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java @@ -0,0 +1,45 @@ +/* + * 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; + +/** + * A claculator service server. Starts up the SCA runtime which + * will start listening for RMI service requests. + */ +public class CalculatorServer { + public static void main(String[] args) throws Exception { + System.out.println("Starting of the SCA Calculator Application exposed as RMI Services..."); + String uri = ContributionLocationHelper.getContributionLocation("CalculatorRMIServer.composite"); + Contribution contribution = new Contribution("c1", uri); + Node node = NodeFactory.newInstance().createNode("CalculatorRMIServer.composite", contribution); + node.start(); + System.out.println("... Press Enter to Exit..."); + System.in.read(); + node.stop(); + System.out.println("Exited..."); + System.exit(0); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..3c0375924f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/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; + +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-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..bcfd8871b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,68 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..f7ac0b7287 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..b7dca792b2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..77b128ab8d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite new file mode 100644 index 0000000000..02614ad6e1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..27a1ee74e4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java new file mode 100644 index 0000000000..0e352db9bb --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java @@ -0,0 +1,63 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import java.rmi.Naming; + +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.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorRMIServerTestCase { + + private static Node node; + private static CalculatorService calculatorService; + + @BeforeClass + public static void setUp() throws Exception { + String uri = ContributionLocationHelper.getContributionLocation(CalculatorService.class); + Contribution contribution = new Contribution("c1", uri); + node = NodeFactory.newInstance().createNode("CalculatorRMIServer.composite", contribution); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testCalculator() throws Exception { + // Calculate + calculatorService = (CalculatorService)Naming.lookup("//localhost:8099/CalculatorRMIService"); + assertEquals(calculatorService.add(3, 2), 5.0, 0.0); + assertEquals(calculatorService.subtract(3, 2), 1.0, 0.0); + assertEquals(calculatorService.multiply(3, 2), 6.0, 0.0); + assertEquals(calculatorService.divide(3, 2), 1.5, 0.0); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/README b/tags/java/sca/2.0-M4-RC2/samples/calculator/README new file mode 100644 index 0000000000..56c22d9c89 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\features\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../features/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/build.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator/build.xml new file mode 100644 index 0000000000..4411cae659 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.png b/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.svg b/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.svg new file mode 100644 index 0000000000..0615925c50 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator/pom.xml new file mode 100644 index 0000000000..8c0a29be3b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-calculator + Apache Tuscany SCA Sample Calculator + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M4 + runtime + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + calculator.CalculatorClient + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..bb75bb2337 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.oasisopen.sca.annotation.Service; + +/** + * An implementation of the Add service + */ +@Service(AddService.class) +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..03fc56ceb3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,48 @@ +/* + * 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.Client; +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 { + + Node node = NodeFactory.newInstance().createNode(); + + node.start(); + + CalculatorService calculatorService = ((Client)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/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorService.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; + + +/** + * The Calculator service interface. + */ +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-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..fc53393d23 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,72 @@ +/* + * 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.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + + +/** + * An implementation of the Calculator service. + */ +@Service(CalculatorService.class) +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..b1250ed9f2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.oasisopen.sca.annotation.Service; + +/** + * An implementation of the Divide service. + */ +@Service(DivideService.class) +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..11f68c66e3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.oasisopen.sca.annotation.Service; + +/** + * An implementation of the Multiply service. + */ +@Service(MultiplyService.class) +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..30e59bf668 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.oasisopen.sca.annotation.Service; + +/** + * An implementation of the subtract service. + */ +@Service(SubtractService.class) +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/Calculator.composite b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..f67b212d99 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/Calculator.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..27a1ee74e4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/calculator/src/test/java/calculator/CalculatorTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..73c7d872b9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,63 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Client; +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.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase{ + private static Node node; + private static CalculatorService calculatorService; + + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + NodeFactory factory = NodeFactory.newInstance(); + String contribution = ContributionLocationHelper.getContributionLocation(CalculatorClient.class); + node = factory.createNode("Calculator.composite", new Contribution("calculator", contribution)).start(); + // node = factory.createNode().start(); + + calculatorService = ((Client)node).getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + node.stop(); + } + + @Test + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0, 0); + assertEquals(calculatorService.subtract(3, 2), 1.0, 0); + assertEquals(calculatorService.multiply(3, 2), 6.0, 0); + assertEquals(calculatorService.divide(3, 2), 1.5, 0); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/LICENSE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/META-INF/MANIFEST.MF b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..82a803e3a6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Export-Package: calculator.dosgi.operations;version="1.0.0" +Bundle-Version: 1.0.0 +Bundle-Name: calculator.dosgi.operations +Bundle-Activator: calculator.dosgi.operations.impl.OperationsActivator +Bundle-ManifestVersion: 2 +Import-Package: calculator.dosgi.operations;version="[1.0.0,1.0.0]", + org.oasisopen.sca.annotation;version="2.0.0", + org.osgi.framework, + org.osgi.service.component;resolution:=optional, + org.osgi.service.packageadmin +Bundle-SymbolicName: calculator.dosgi.operations +Bundle-Vendor: The Apache Software Foundation +Bundle-ActivationPolicy: lazy +Eclipse-LazyStart: true +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-DocURL: http://www.apache.org/ +Service-Component-Disabled: OSGI-INF/add-component.xml, + OSGI-INF/subtract-component.xml, + OSGI-INF/multiply-component.xml, + OSGI-INF/divide-component.xml +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/NOTICE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/add-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/add-component.xml new file mode 100644 index 0000000000..99845257ff --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/add-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml new file mode 100644 index 0000000000..f6b5f4690e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/divide-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/divide-component.xml new file mode 100644 index 0000000000..322d4daf2f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/divide-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/multiply-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/multiply-component.xml new file mode 100644 index 0000000000..b9ca777bd8 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/multiply-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType new file mode 100644 index 0000000000..72e2c339f1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType @@ -0,0 +1,47 @@ + + + + + + + + + 1 + ABC + + + + 1 + ABC + + + + 1 + ABC + + + + 1 + ABC + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite new file mode 100644 index 0000000000..253f7d0df1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/subtract-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/subtract-component.xml new file mode 100644 index 0000000000..1472f5a976 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/OSGI-INF/subtract-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/README b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/README new file mode 100644 index 0000000000..9e616c1f50 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/README @@ -0,0 +1,183 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +On Windows, run +java -jar ..\..\modules\osgi-3.4.0-v20080605-1900.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.4.0-v20080605-1900.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start +INFO: Equinox-based service discoverer is now configured. + +You can run "ss" command under the osgi> to see the status of the bundles. +osgi> ss + +Then you can install and start the calculator.dosgi bundle: + +osgi> install file:./target/sample-dosgi-calculator-operations.jar +Bundle id is 181 + +osgi> start 181 +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Starting file:./target/sample-dosgi-calculator-operations.jar [181] +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.AddService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.SubtractService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.MultiplyService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.DivideService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator get +Bundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi.operations +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi.operations +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.node.impl.NodeFactoryImpl configu +reNode +INFO: Loading contribution: bundleentry://181/ +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(AddService/AddService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/AddService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(SubtractService/SubtractService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/SubtractService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(MultiplyService/MultiplyService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/MultiplyService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(DivideService/DivideService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/DivideService + +osgi> + +To stop the bundle: + +osgi> stop 181 +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi.operations +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(AddService/AddService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/AddService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(SubtractService/SubtractService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/SubtractService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(MultiplyService/MultiplyService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/MultiplyService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(DivideService/DivideService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/DivideService +Jun 22, 2009 2:09:48 PM calculator.dosgi.operations.impl.OperationsActivator sto +p +INFO: Stopping file:./target/sample-dosgi-calculator-operations.jar [181] + +osgi> + +To exit the console, run: +osgi> exit + +Sample Overview +--------------- +The application consists of two OSGi bundles: + * The calculator bundle: It provides the calculator service. The service is implemented by a java class that + consumes other services to perform the “add”, “subtract”, “multiply” and “divide” operations. + * The operations bundle: It provides the add/subtract/multiply/divide services. + (See ../samples/dosgi-calculator-operations) + + +dosgi-calculator-operations/ + src/ + main/ + java/ + calculator/ + dosgi/ + operations/ + AddService.java - Interface for Add + SubtractService.java - Interface for Subtract + MultiplyService.java - Interface for Multiply + DivideService.java - Interface for Divide + impl/ + OperationsActivator.java - OSGi bundle activator + AddServiceImpl.java - Implementation for Add + SubtractServiceImpl.java - Implementation for Subtract + MultiplyServiceImpl.java - Implementation for Multiply + DivideServiceImpl.java - Implementation for Divide + resources/ + META-INF/ + sca-contribution.xml + OSGI-INF/ + sca/ + bundle.componentType - The component type for implementation.osgi of this bundle + bundle.composite - The composite file + test/ + java/ + src/ + calculator/ + dosgi/ + operations/ + test/ + OperationsOSGiNodeTestCase.java - The JUNIT test case that tests this bundle using a RMI client + + META-INF/ + MANIFEST.MF - The OSGi manifest for this bundle + pom.xml - the Maven build file + + + +Building And Running The Test Case Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd dosgi-calculator-operations +mvn + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/pom.xml new file mode 100644 index 0000000000..883eb22bbe --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/pom.xml @@ -0,0 +1,141 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + sample-dosgi-calculator-operations + Apache Tuscany SCA Distributed OSGi (RFC 119) Caculator Operations Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-M4 + pom + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-M4 + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-M4 + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + test + + + + + org.eclipse.equinox + ds + 1.1.0-v20090601 + test + + + + org.eclipse.equinox + util + 1.0.100-v20090520-1800 + test + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + org.apache.tuscany.maven.plugins + maven-osgi-junit-plugin + 1.0 + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + ${pom.version} + + + + + osgi-test + test + + test + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/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-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/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-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/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-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/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-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java new file mode 100644 index 0000000000..66b2977241 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.AddService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java new file mode 100644 index 0000000000..a3c21b2b96 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.DivideService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java new file mode 100644 index 0000000000..7922d2d392 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.MultiplyService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java new file mode 100644 index 0000000000..da2ce9063a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java @@ -0,0 +1,88 @@ +/* + * 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.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.operations.AddService; +import calculator.dosgi.operations.DivideService; +import calculator.dosgi.operations.MultiplyService; +import calculator.dosgi.operations.SubtractService; + +/** + * + */ +public class OperationsActivator implements BundleActivator { + private Logger logger = Logger.getLogger(OperationsActivator.class.getName()); + + public void start(BundleContext context) throws Exception { + logger.info("Starting " + context.getBundle()); + + Dictionary props = new Hashtable(); + + logger.info("Registering " + AddService.class.getName()); + props.put("sca.service", "AddComponent#service-name(Add)"); + context.registerService(AddService.class.getName(), new AddServiceImpl(), props); + + logger.info("Registering " + SubtractService.class.getName()); + props.put("sca.service", "SubtractComponent#service-name(Subtract)"); + context.registerService(SubtractService.class.getName(), new SubtractServiceImpl(), props); + + logger.info("Registering " + MultiplyService.class.getName()); + props.put("sca.service", "MultiplyComponent#service-name(Multiply)"); + context.registerService(MultiplyService.class.getName(), new MultiplyServiceImpl(), props); + + logger.info("Registering " + DivideService.class.getName()); + props.put("sca.service", "DivideComponent#service-name(Divide)"); + context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props); + + getBundle(context, AddService.class); + } + + public void stop(BundleContext context) throws Exception { + logger.info("Stopping " + context.getBundle()); + // Registered services will be automatically unregistered + } + + 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; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java new file mode 100644 index 0000000000..4bbe83b14f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.SubtractService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..16a33f4f65 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java new file mode 100644 index 0000000000..cd92989da1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java @@ -0,0 +1,105 @@ +/* + * 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.test; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +import org.osgi.framework.Bundle; + +/** + * + * Utility class to create OSGi bundles + * + * @version $Rev$ $Date$ + */ +public class OSGiTestUtils { + private static class InvocationHandlerImpl implements InvocationHandler { + private Object instance; + + public InvocationHandlerImpl(Object instance) { + super(); + this.instance = instance; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Method m = instance.getClass().getMethod(method.getName(), method.getParameterTypes()); + return m.invoke(instance, args); + } + + } + + /** + * Returns a string representation of the given bundle. + * + * @param b + * @param verbose + * @return + */ + public static String bundleStatus(Bundle bundle, boolean verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(bundle.getBundleId()).append(" ").append(bundle.getSymbolicName()); + int s = bundle.getState(); + if ((s & Bundle.UNINSTALLED) != 0) { + sb.append(" UNINSTALLED"); + } + if ((s & Bundle.INSTALLED) != 0) { + sb.append(" INSTALLED"); + } + if ((s & Bundle.RESOLVED) != 0) { + sb.append(" RESOLVED"); + } + if ((s & Bundle.STARTING) != 0) { + sb.append(" STARTING"); + } + if ((s & Bundle.STOPPING) != 0) { + sb.append(" STOPPING"); + } + if ((s & Bundle.ACTIVE) != 0) { + sb.append(" ACTIVE"); + } + + if (verbose) { + sb.append(" ").append(bundle.getLocation()); + sb.append(" ").append(bundle.getHeaders()); + } + return sb.toString(); + } + + /** + * A utility to cast the object to the given interface. If the class for the object + * is loaded by a different classloader, a proxy will be created. + * + * @param + * @param obj + * @param cls + * @return + */ + public static T cast(Object obj, Class cls) { + if (cls.isInstance(obj)) { + return cls.cast(obj); + } else { + return cls.cast(Proxy.newProxyInstance(cls.getClassLoader(), + new Class[] {cls}, + new InvocationHandlerImpl(obj))); + } + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java new file mode 100644 index 0000000000..02007c385c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java @@ -0,0 +1,43 @@ +/* + * 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.test; + +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + +/** + * + */ +public class OperationsNode { + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length == 0) { + args = new String[] {"-bundles"}; + } + try { + NodeLauncher.main(args); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java new file mode 100644 index 0000000000..49c5aab041 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.test; + +import static calculator.dosgi.operations.test.OSGiTestUtils.bundleStatus; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; + +import calculator.dosgi.operations.AddService; + +/** + * + */ +public class OperationsOSGiNodeTestCase { + private static EquinoxHost host; + private static BundleContext context; + private static Bundle operationsBundle; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + try { + host = new EquinoxHost(); + context = host.start(); + + for (Bundle b : context.getBundles()) { + if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName() + .startsWith("org.apache.tuscany.sca.")) { + try { + if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) { + // Start the non-fragment bundle + b.start(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(bundleStatus(b, false)); + } + if ("calculator.dosgi.operations".equals(b.getSymbolicName())) { + operationsBundle = b; + } + } + + if (operationsBundle != null) { + operationsBundle.start(); + System.out.println(bundleStatus(operationsBundle, false)); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testOSGi() throws Exception { + Registry registry = LocateRegistry.getRegistry(8085); + Object add = registry.lookup("AddService"); + AddService addService = OSGiTestUtils.cast(add, AddService.class); + double sum = addService.add(1.0, 2.0); + Assert.assertEquals(3.0, sum, 0.0); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (host != null) { + host.stop(); + context = null; + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/LICENSE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/META-INF/MANIFEST.MF b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..542b53b085 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/META-INF/MANIFEST.MF @@ -0,0 +1,20 @@ +Manifest-Version: 1.0 +Export-Package: calculator.dosgi;version="1.0.0", + calculator.dosgi.operations;version="1.0.0" +Bundle-Version: 1.0.0 +Bundle-Name: calculator.dosgi +Bundle-Activator: calculator.dosgi.impl.CalculatorActivator +Bundle-ManifestVersion: 2 +Import-Package: org.oasisopen.sca.annotation;version="2.0.0", + org.osgi.framework, + org.osgi.service.component;resolution:=optional, + org.osgi.service.packageadmin, + org.osgi.util.tracker +Bundle-SymbolicName: calculator.dosgi +Bundle-Vendor: The Apache Software Foundation +Bundle-ActivationPolicy: lazy +Eclipse-LazyStart: true +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-DocURL: http://www.apache.org/ +Service-Component-Disabled: OSGI-INF/calculator-component.xml +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/NOTICE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml new file mode 100644 index 0000000000..fd834e12ef --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/calculator-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/calculator-component.xml new file mode 100644 index 0000000000..5daaa59aae --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/calculator-component.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.componentType b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.componentType new file mode 100644 index 0000000000..769bcdd14d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.componentType @@ -0,0 +1,54 @@ + + + + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + 1 + ABC + + + + 1 + ABC + + + + 1 + ABC + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite new file mode 100644 index 0000000000..481fd67e09 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/README b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/README new file mode 100644 index 0000000000..374c0f0a8b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/README @@ -0,0 +1,155 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +On Windows, run +java -jar ..\..\modules\osgi-3.4.0-v20080605-1900.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.4.0-v20080605-1900.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start +INFO: Equinox-based service discoverer is now configured. + +You can run "ss" command under the osgi> to see the status of the bundles. +osgi> ss + +Then you can install and start the calculator.dosgi bundle: + +osgi> install file:./target/sample-dosgi-calculator.jar +Bundle id is 181 + +osgi> start 181 +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Starting file:./target/sample-dosgi-calculator.jar [181] +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Registering calculator.dosgi.CalculatorService +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator getBundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeFactoryImpl configu +reNode +INFO: Loading contribution: bundleentry://181/ +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = CalculatorComponent#serv +ice-binding(CalculatorService/CalculatorService) +2009-06-22 13:37:21.953::INFO: jetty-6.1.x +2009-06-22 13:37:21.953::INFO: Started SelectChannelConnector@0.0.0.0:8086 +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.http.jetty.JettyServer addServlet +Mapping +INFO: Added Servlet mapping: http://rfengt61p:8086/CalculatorService +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(addService/addService) Target = Endpoint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(subtractService/subtractService) Target = Endp +oint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(multiplyService/multiplyService) Target = Endp +oint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(divideService/divideService) Target = Endpoint +: + +osgi> + +You can point your browser to http://localhost:8086/CalculatorService?wsdl to see +the WSDL. + +You can also use the WebService Explorer from Eclipse WTP to test the Web Service. + +To stop the bundle: + +osgi> stop 181 +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = CalculatorComponent#s +ervice-binding(CalculatorService/CalculatorService) +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.http.jetty.JettyServer removeServ +letMapping +INFO: Removed Servlet mapping: /CalculatorService +Jun 22, 2009 1:39:09 PM calculator.dosgi.impl.CalculatorActivator stop +INFO: Stopping file:./target/sample-dosgi-calculator.jar [181] + +To exit the console, run: +osgi> exit + +Sample Overview +--------------- +The application consists of two OSGi bundles: + * The calculator bundle: It provides the calculator service. The service is implemented by a java class that + consumes other services to perform the “add”, “subtract”, “multiply” and “divide” operations. + * The operations bundle: It provides the add/subtract/multiply/divide services. + (See ../samples/dosgi-calculator-operations) + + +dosgi-calculator/ + src/ + main/ + java/ + calculator/ + dosgi/ + CalculatorService.java - The interface for Calculator service + impl/ + CalculatorActivator.java - OSGi bundle activator for Calculator bundle + CalculatorServiceDSImpl.java - OSGi declarative service based implementation + CalculatorServiceImpl.java - Basic OSGi implementation + operations/ + AddService.java - Interface for Add + SubtractService.java - Interface for Subtract + MultiplyService.java - Interface for Multiply + DivideService.java - Interface for Divide + rmi/ + OperationsRemote.java - RMI remote interface for operations + OperationsRMIServer_Stub.java - RMI stub + OperationsRMIServer.java - RMI server implementation of the operations + resources/ + META-INF/ + sca-contribution.xml + OSGI-INF/ + sca/ + bundle.componentType - The component type for implementation.osgi of this bundle + bundle.composite - The composite file + test/ + java/ + src/ + calculator/ + dosgi/ + test/ + CalculatorOSGiNodeTestCase.java - The JUNIT test case that tests this bundle against a RMI service + + META-INF/ + MANIFEST.MF - The OSGi manifest for this bundle + dosig-calculator.png - a pictorial representation of the sample + pom.xml - the Maven build file + + + +Building And Running The Test Case Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd dosgi-calculator +mvn + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/dosgi-calculator.png b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/dosgi-calculator.png new file mode 100644 index 0000000000..805baa54d2 Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/dosgi-calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/pom.xml new file mode 100644 index 0000000000..9865570638 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/pom.xml @@ -0,0 +1,146 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + sample-dosgi-calculator + Apache Tuscany SCA Distributed OSGi (RFC 119) Caculator Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-M4 + pom + + + org.apache.tuscany.sca + tuscany-feature-webservice + 2.0-M4 + pom + runtime + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-M4 + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-M4 + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + + + + junit + junit + 4.5 + test + + + + + org.eclipse.equinox + ds + 1.1.0-v20090601 + test + + + + org.eclipse.equinox + util + 1.0.100-v20090520-1800 + test + + + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + org.apache.tuscany.maven.plugins + maven-osgi-junit-plugin + 1.0 + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + ${pom.version} + + + + + osgi-test + test + + test + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java new file mode 100644 index 0000000000..cc562b7c2f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java new file mode 100644 index 0000000000..6b42645f69 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java @@ -0,0 +1,76 @@ +/* + * 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 props = new Hashtable(); + 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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java new file mode 100644 index 0000000000..5f9db16ca9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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 getService(Class 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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java new file mode 100644 index 0000000000..a9ea37585a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java @@ -0,0 +1,105 @@ +/* + * 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.*) (service.imported=*))"); + localFilter = + context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (!(service.imported=*)))"); + } 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 getService(Class cls) { + try { + // Wait for 10 seconds until the remote services are imported + remoteServices.waitForService(10000); + } catch (InterruptedException e) { + throw new IllegalStateException(cls.getSimpleName() + " is not available"); + } + 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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java new file mode 100644 index 0000000000..a4fc52694e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java new file mode 100644 index 0000000000..a813dfb6f3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java new file mode 100644 index 0000000000..955e386ad8 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/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-M4-RC2/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..b14b3516f6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java new file mode 100644 index 0000000000..565a314d85 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java @@ -0,0 +1,43 @@ +/* + * 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.test; + +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + +/** + * + */ +public class CalculatorNode { + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length == 0) { + args = new String[] {"-bundles"}; + } + try { + NodeLauncher.main(args); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java new file mode 100644 index 0000000000..4dd713ecef --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java @@ -0,0 +1,144 @@ +/* + * 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.test; + +import static calculator.dosgi.test.OSGiTestUtils.bundleStatus; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; + +import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + +import calculator.dosgi.CalculatorService; +import calculator.rmi.OperationsRMIServer; + +/** + * + */ +public class CalculatorOSGiNodeTestCase { + private static EquinoxHost host; + private static BundleContext context; + private static Bundle calculatorBundle; + private static OperationsRMIServer rmiServer; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + try { + rmiServer = new OperationsRMIServer(); + rmiServer.start(); + + host = new EquinoxHost(); + context = host.start(); + + for (Bundle b : context.getBundles()) { + System.out.println(b); + if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName() + .startsWith("org.apache.tuscany.sca.")) { + try { + if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) { + // Start the non-fragment bundle + b.start(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(bundleStatus(b, false)); + } + if ("calculator.dosgi".equals(b.getSymbolicName())) { + calculatorBundle = b; + } + } + + if (calculatorBundle != null) { + calculatorBundle.start(); + System.out.println(bundleStatus(calculatorBundle, false)); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testOSGi() { + ServiceReference ref = + calculatorBundle.getBundleContext().getServiceReference(CalculatorService.class.getName()); + Assert.assertNotNull(ref); + Object service = context.getService(ref); + Assert.assertNotNull(service); + CalculatorService calculator = OSGiTestUtils.cast(service, CalculatorService.class); + System.out.println("2.0 + 1.0 = " + calculator.add(2.0, 1.0)); + System.out.println("2.0 - 1.0 = " + calculator.subtract(2.0, 1.0)); + System.out.println("2.0 * 1.0 = " + calculator.multiply(2.0, 1.0)); + System.out.println("2.0 / 1.0 = " + calculator.divide(2.0, 1.0)); + } + + @Test + /** + * Test the Web service exposed by the Calculator + */ + public void testWS() throws Exception { + URL url = new URL("http://localhost:8086/CalculatorService?wsdl"); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader(is); + char[] content = new char[10240]; // 10k + int len = 0; + while (true) { + int size = reader.read(content, len, content.length - len); + if (size < 0) { + break; + } + len += size; + } + Assert.assertTrue(len > 0); + String str = new String(content, 0, len); + System.out.println(str); + Assert.assertTrue(str.indexOf(" + * @param obj + * @param cls + * @return + */ + public static T cast(Object obj, Class cls) { + if (cls.isInstance(obj)) { + return cls.cast(obj); + } else { + return cls.cast(Proxy.newProxyInstance(cls.getClassLoader(), + new Class[] {cls}, + new InvocationHandlerImpl(obj))); + } + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/LICENSE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..cea4e2ff79 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Export-Package: calculator.dosgi.operations;version="1.0.1" +Bundle-Version: 1.0.0 +Bundle-Name: calculator.dosgi.dynamic.operations +Bundle-Activator: calculator.dosgi.operations.impl.OperationsActivator +Bundle-ManifestVersion: 2 +Import-Package: calculator.dosgi.operations;version="[1.0.1,1.0.1]", + org.oasisopen.sca.annotation;version="2.0.0", + org.osgi.framework, + org.osgi.service.component;resolution:=optional, + org.osgi.service.packageadmin +Bundle-SymbolicName: calculator.dosgi.dynamic.operations +Bundle-Vendor: The Apache Software Foundation +Bundle-ActivationPolicy: lazy +Eclipse-LazyStart: true +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-DocURL: http://www.apache.org/ +Service-Component-Disabled: OSGI-INF/add-component.xml, + OSGI-INF/subtract-component.xml, + OSGI-INF/multiply-component.xml, + OSGI-INF/divide-component.xml +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 +SCA-Configuration: OSGI-INF/sca-config/*.xml diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/NOTICE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml new file mode 100644 index 0000000000..99845257ff --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml new file mode 100644 index 0000000000..f6b5f4690e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml new file mode 100644 index 0000000000..322d4daf2f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml new file mode 100644 index 0000000000..b9ca777bd8 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml new file mode 100644 index 0000000000..b00f05ad2d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml @@ -0,0 +1,29 @@ + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml new file mode 100644 index 0000000000..1472f5a976 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/README b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/README new file mode 100644 index 0000000000..9e616c1f50 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/README @@ -0,0 +1,183 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +On Windows, run +java -jar ..\..\modules\osgi-3.4.0-v20080605-1900.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.4.0-v20080605-1900.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start +INFO: Equinox-based service discoverer is now configured. + +You can run "ss" command under the osgi> to see the status of the bundles. +osgi> ss + +Then you can install and start the calculator.dosgi bundle: + +osgi> install file:./target/sample-dosgi-calculator-operations.jar +Bundle id is 181 + +osgi> start 181 +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Starting file:./target/sample-dosgi-calculator-operations.jar [181] +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.AddService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.SubtractService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.MultiplyService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator sta +rt +INFO: Registering calculator.dosgi.operations.DivideService +Jun 22, 2009 2:09:21 PM calculator.dosgi.operations.impl.OperationsActivator get +Bundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi.operations +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi.operations +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.node.impl.NodeFactoryImpl configu +reNode +INFO: Loading contribution: bundleentry://181/ +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(AddService/AddService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/AddService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(SubtractService/SubtractService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/SubtractService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(MultiplyService/MultiplyService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/MultiplyService +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = OperationsComponent#serv +ice-binding(DivideService/DivideService) +Jun 22, 2009 2:09:21 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerS +ervice +INFO: RMI service registered: rmi://localhost:8085/DivideService + +osgi> + +To stop the bundle: + +osgi> stop 181 +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi.operations +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(AddService/AddService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/AddService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(SubtractService/SubtractService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/SubtractService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(MultiplyService/MultiplyService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/MultiplyService +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = OperationsComponent#s +ervice-binding(DivideService/DivideService) +Jun 22, 2009 2:09:48 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregiste +rService +INFO: RMI service unregistered: rmi://localhost:8085/DivideService +Jun 22, 2009 2:09:48 PM calculator.dosgi.operations.impl.OperationsActivator sto +p +INFO: Stopping file:./target/sample-dosgi-calculator-operations.jar [181] + +osgi> + +To exit the console, run: +osgi> exit + +Sample Overview +--------------- +The application consists of two OSGi bundles: + * The calculator bundle: It provides the calculator service. The service is implemented by a java class that + consumes other services to perform the “add”, “subtract”, “multiply” and “divide” operations. + * The operations bundle: It provides the add/subtract/multiply/divide services. + (See ../samples/dosgi-calculator-operations) + + +dosgi-calculator-operations/ + src/ + main/ + java/ + calculator/ + dosgi/ + operations/ + AddService.java - Interface for Add + SubtractService.java - Interface for Subtract + MultiplyService.java - Interface for Multiply + DivideService.java - Interface for Divide + impl/ + OperationsActivator.java - OSGi bundle activator + AddServiceImpl.java - Implementation for Add + SubtractServiceImpl.java - Implementation for Subtract + MultiplyServiceImpl.java - Implementation for Multiply + DivideServiceImpl.java - Implementation for Divide + resources/ + META-INF/ + sca-contribution.xml + OSGI-INF/ + sca/ + bundle.componentType - The component type for implementation.osgi of this bundle + bundle.composite - The composite file + test/ + java/ + src/ + calculator/ + dosgi/ + operations/ + test/ + OperationsOSGiNodeTestCase.java - The JUNIT test case that tests this bundle using a RMI client + + META-INF/ + MANIFEST.MF - The OSGi manifest for this bundle + pom.xml - the Maven build file + + + +Building And Running The Test Case Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd dosgi-calculator-operations +mvn + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/pom.xml new file mode 100644 index 0000000000..71cd14113c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/pom.xml @@ -0,0 +1,141 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + sample-dosgi-dynamic-calculator-operations + Apache Tuscany SCA OSGi RemoteService Dynamic Caculator Operations Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-M4 + pom + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-M4 + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-M4 + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + test + + + + + org.eclipse.equinox + ds + 1.1.0-v20090601 + test + + + + org.eclipse.equinox + util + 1.0.100-v20090520-1800 + test + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + org.apache.tuscany.maven.plugins + maven-osgi-junit-plugin + 1.0 + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + ${pom.version} + + + + + osgi-test + test + + test + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/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-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/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-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/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-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/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-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java new file mode 100644 index 0000000000..66b2977241 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.AddService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java new file mode 100644 index 0000000000..a3c21b2b96 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.DivideService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java new file mode 100644 index 0000000000..7922d2d392 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.MultiplyService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java new file mode 100644 index 0000000000..f75cc6444e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java @@ -0,0 +1,94 @@ +/* + * 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.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.operations.AddService; +import calculator.dosgi.operations.DivideService; +import calculator.dosgi.operations.MultiplyService; +import calculator.dosgi.operations.SubtractService; + +/** + * + */ +public class OperationsActivator implements BundleActivator { + private Logger logger = Logger.getLogger(OperationsActivator.class.getName()); + + public void start(BundleContext context) throws Exception { + logger.info("Starting " + context.getBundle()); + + Dictionary props = new Hashtable(); + props.put("service.exported.configs", new String[] {"org.osgi.sca"}); + props.put("service.exported.interfaces", new String[] {"*"}); + + logger.info("Registering " + AddService.class.getName()); + props.put("sca.service", "AddComponent#service-name(Add)"); + props.put("org.osgi.sca.bindings", new String[] {"{http://sample}Add"}); + context.registerService(AddService.class.getName(), new AddServiceImpl(), props); + + logger.info("Registering " + SubtractService.class.getName()); + props.put("sca.service", "SubtractComponent#service-name(Subtract)"); + props.put("org.osgi.sca.bindings", new String[] {"{http://sample}Subtract"}); + context.registerService(SubtractService.class.getName(), new SubtractServiceImpl(), props); + + logger.info("Registering " + MultiplyService.class.getName()); + props.put("sca.service", "MultiplyComponent#service-name(Multiply)"); + props.put("org.osgi.sca.bindings", new String[] {"{http://sample}Multiply"}); + context.registerService(MultiplyService.class.getName(), new MultiplyServiceImpl(), props); + + logger.info("Registering " + DivideService.class.getName()); + props.put("sca.service", "DivideComponent#service-name(Divide)"); + props.put("org.osgi.sca.bindings", new String[] {"{http://sample}Divide"}); + context.registerService(DivideService.class.getName(), new DivideServiceImpl(), props); + + getBundle(context, AddService.class); + } + + public void stop(BundleContext context) throws Exception { + logger.info("Stopping " + context.getBundle()); + // Registered services will be automatically unregistered + } + + 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; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java new file mode 100644 index 0000000000..4bbe83b14f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.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.dosgi.operations.impl; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import calculator.dosgi.operations.SubtractService; + +/** + * 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/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java new file mode 100644 index 0000000000..cd92989da1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java @@ -0,0 +1,105 @@ +/* + * 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.test; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +import org.osgi.framework.Bundle; + +/** + * + * Utility class to create OSGi bundles + * + * @version $Rev$ $Date$ + */ +public class OSGiTestUtils { + private static class InvocationHandlerImpl implements InvocationHandler { + private Object instance; + + public InvocationHandlerImpl(Object instance) { + super(); + this.instance = instance; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Method m = instance.getClass().getMethod(method.getName(), method.getParameterTypes()); + return m.invoke(instance, args); + } + + } + + /** + * Returns a string representation of the given bundle. + * + * @param b + * @param verbose + * @return + */ + public static String bundleStatus(Bundle bundle, boolean verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(bundle.getBundleId()).append(" ").append(bundle.getSymbolicName()); + int s = bundle.getState(); + if ((s & Bundle.UNINSTALLED) != 0) { + sb.append(" UNINSTALLED"); + } + if ((s & Bundle.INSTALLED) != 0) { + sb.append(" INSTALLED"); + } + if ((s & Bundle.RESOLVED) != 0) { + sb.append(" RESOLVED"); + } + if ((s & Bundle.STARTING) != 0) { + sb.append(" STARTING"); + } + if ((s & Bundle.STOPPING) != 0) { + sb.append(" STOPPING"); + } + if ((s & Bundle.ACTIVE) != 0) { + sb.append(" ACTIVE"); + } + + if (verbose) { + sb.append(" ").append(bundle.getLocation()); + sb.append(" ").append(bundle.getHeaders()); + } + return sb.toString(); + } + + /** + * A utility to cast the object to the given interface. If the class for the object + * is loaded by a different classloader, a proxy will be created. + * + * @param + * @param obj + * @param cls + * @return + */ + public static T cast(Object obj, Class cls) { + if (cls.isInstance(obj)) { + return cls.cast(obj); + } else { + return cls.cast(Proxy.newProxyInstance(cls.getClassLoader(), + new Class[] {cls}, + new InvocationHandlerImpl(obj))); + } + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java new file mode 100644 index 0000000000..02007c385c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java @@ -0,0 +1,43 @@ +/* + * 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.test; + +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + +/** + * + */ +public class OperationsNode { + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length == 0) { + args = new String[] {"-bundles"}; + } + try { + NodeLauncher.main(args); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java new file mode 100644 index 0000000000..eee64bf86f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.test; + +import static calculator.dosgi.operations.test.OSGiTestUtils.bundleStatus; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; + +import calculator.dosgi.operations.AddService; + +/** + * + */ +public class OperationsOSGiNodeTestCase { + private static EquinoxHost host; + private static BundleContext context; + private static Bundle operationsBundle; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + try { + host = new EquinoxHost(); + context = host.start(); + + for (Bundle b : context.getBundles()) { + if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName() + .startsWith("org.apache.tuscany.sca.")) { + try { + if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) { + // Start the non-fragment bundle + b.start(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(bundleStatus(b, false)); + } + if ("calculator.dosgi.dynamic.operations".equals(b.getSymbolicName())) { + operationsBundle = b; + } + } + + if (operationsBundle != null) { + operationsBundle.start(); + System.out.println(bundleStatus(operationsBundle, false)); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testOSGi() throws Exception { + Registry registry = LocateRegistry.getRegistry(8085); + Object add = registry.lookup("AddService"); + AddService addService = OSGiTestUtils.cast(add, AddService.class); + double sum = addService.add(1.0, 2.0); + Assert.assertEquals(3.0, sum, 0.0); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (host != null) { + host.stop(); + context = null; + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/LICENSE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/META-INF/MANIFEST.MF b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..6ce24a4a32 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Export-Package: calculator.dosgi;version="1.0.1", + calculator.dosgi.operations;version="1.0.1" +Bundle-Version: 1.0.0 +Bundle-Name: calculator.dosgi.dynamic +Bundle-Activator: calculator.dosgi.impl.CalculatorActivator +Bundle-ManifestVersion: 2 +Import-Package: org.oasisopen.sca.annotation;version="2.0.0", + org.osgi.framework, + org.osgi.service.component;resolution:=optional, + org.osgi.service.packageadmin, + org.osgi.util.tracker +Bundle-SymbolicName: calculator.dosgi.dynamic +Bundle-Vendor: The Apache Software Foundation +Bundle-ActivationPolicy: lazy +Eclipse-LazyStart: true +Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt +Bundle-DocURL: http://www.apache.org/ +Service-Component-Disabled: OSGI-INF/calculator-component.xml +Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6 +SCA-Configuration: OSGI-INF/sca-config/calculator-config.xml +Remote-Service: OSGI-INF/remote-service/*.xml + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/NOTICE b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/NOTICE new file mode 100644 index 0000000000..51042eab05 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2009 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml new file mode 100644 index 0000000000..fd834e12ef --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml new file mode 100644 index 0000000000..5daaa59aae --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml new file mode 100644 index 0000000000..ac73ea98f0 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml @@ -0,0 +1,61 @@ + + + + + + + + + org.osgi.sca + + addService + + {http://sample}Add + + + + + org.osgi.sca + + subtractService + + {http://sample}Subtract + + + + + org.osgi.sca + + multiplyService + + {http://sample}Multiply + + + + + org.osgi.sca + + divideService + + {http://sample}Divide + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml new file mode 100644 index 0000000000..878ef9c18e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/README b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/README new file mode 100644 index 0000000000..374c0f0a8b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/README @@ -0,0 +1,155 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +On Windows, run +java -jar ..\..\modules\osgi-3.4.0-v20080605-1900.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.4.0-v20080605-1900.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start +INFO: Equinox-based service discoverer is now configured. + +You can run "ss" command under the osgi> to see the status of the bundles. +osgi> ss + +Then you can install and start the calculator.dosgi bundle: + +osgi> install file:./target/sample-dosgi-calculator.jar +Bundle id is 181 + +osgi> start 181 +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Starting file:./target/sample-dosgi-calculator.jar [181] +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Registering calculator.dosgi.CalculatorService +Jun 22, 2009 1:37:21 PM calculator.dosgi.impl.CalculatorActivator getBundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.node.impl.NodeFactoryImpl configu +reNode +INFO: Loading contribution: bundleentry://181/ +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpoint +INFO: EndpointRegistry: Add endpoint - Endpoint: URI = CalculatorComponent#serv +ice-binding(CalculatorService/CalculatorService) +2009-06-22 13:37:21.953::INFO: jetty-6.1.x +2009-06-22 13:37:21.953::INFO: Started SelectChannelConnector@0.0.0.0:8086 +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.http.jetty.JettyServer addServlet +Mapping +INFO: Added Servlet mapping: http://rfengt61p:8086/CalculatorService +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(addService/addService) Target = Endpoint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(subtractService/subtractService) Target = Endp +oint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(multiplyService/multiplyService) Target = Endp +oint: +Jun 22, 2009 1:37:21 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry addEndpointReference +INFO: EndpointRegistry: Add endpoint reference - Endpoint Reference: URI = Calc +ulatorComponent#reference-binding(divideService/divideService) Target = Endpoint +: + +osgi> + +You can point your browser to http://localhost:8086/CalculatorService?wsdl to see +the WSDL. + +You can also use the WebService Explorer from Eclipse WTP to test the Web Service. + +To stop the bundle: + +osgi> stop 181 +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.endpoint.tribes.ReplicatedEndpoin +tRegistry removeEndpoint +INFO: EndpointRegistry: Remove endpoint - Endpoint: URI = CalculatorComponent#s +ervice-binding(CalculatorService/CalculatorService) +Jun 22, 2009 1:39:09 PM org.apache.tuscany.sca.http.jetty.JettyServer removeServ +letMapping +INFO: Removed Servlet mapping: /CalculatorService +Jun 22, 2009 1:39:09 PM calculator.dosgi.impl.CalculatorActivator stop +INFO: Stopping file:./target/sample-dosgi-calculator.jar [181] + +To exit the console, run: +osgi> exit + +Sample Overview +--------------- +The application consists of two OSGi bundles: + * The calculator bundle: It provides the calculator service. The service is implemented by a java class that + consumes other services to perform the “add”, “subtract”, “multiply” and “divide” operations. + * The operations bundle: It provides the add/subtract/multiply/divide services. + (See ../samples/dosgi-calculator-operations) + + +dosgi-calculator/ + src/ + main/ + java/ + calculator/ + dosgi/ + CalculatorService.java - The interface for Calculator service + impl/ + CalculatorActivator.java - OSGi bundle activator for Calculator bundle + CalculatorServiceDSImpl.java - OSGi declarative service based implementation + CalculatorServiceImpl.java - Basic OSGi implementation + operations/ + AddService.java - Interface for Add + SubtractService.java - Interface for Subtract + MultiplyService.java - Interface for Multiply + DivideService.java - Interface for Divide + rmi/ + OperationsRemote.java - RMI remote interface for operations + OperationsRMIServer_Stub.java - RMI stub + OperationsRMIServer.java - RMI server implementation of the operations + resources/ + META-INF/ + sca-contribution.xml + OSGI-INF/ + sca/ + bundle.componentType - The component type for implementation.osgi of this bundle + bundle.composite - The composite file + test/ + java/ + src/ + calculator/ + dosgi/ + test/ + CalculatorOSGiNodeTestCase.java - The JUNIT test case that tests this bundle against a RMI service + + META-INF/ + MANIFEST.MF - The OSGi manifest for this bundle + dosig-calculator.png - a pictorial representation of the sample + pom.xml - the Maven build file + + + +Building And Running The Test Case Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd dosgi-calculator +mvn + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/dosgi-calculator.png b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/dosgi-calculator.png new file mode 100644 index 0000000000..805baa54d2 Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/dosgi-calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/pom.xml new file mode 100644 index 0000000000..53063357a2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/pom.xml @@ -0,0 +1,146 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + sample-dosgi-dynamic-calculator + Apache Tuscany SCA OSGi RemoteService Dynamic Caculator Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-M4 + pom + + + org.apache.tuscany.sca + tuscany-feature-webservice + 2.0-M4 + pom + runtime + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-M4 + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-M4 + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + + + + junit + junit + 4.5 + test + + + + + org.eclipse.equinox + ds + 1.1.0-v20090601 + test + + + + org.eclipse.equinox + util + 1.0.100-v20090520-1800 + test + + + + + + ${artifactId} + + + maven-eclipse-plugin + 2.5.1 + + + org.eclipse.pde.ManifestBuilder + org.eclipse.jdt.core.javabuilder + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + + org.eclipse.jdt.launching.JRE_CONTAINER + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + org.apache.tuscany.maven.plugins + maven-osgi-junit-plugin + 1.0 + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + ${pom.version} + + + + + osgi-test + test + + test + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java new file mode 100644 index 0000000000..cc562b7c2f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java new file mode 100644 index 0000000000..6228afcd53 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java @@ -0,0 +1,78 @@ +/* + * 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 props = new Hashtable(); + props.put("sca.service", "CalculatorComponent#service-name(Calculator)"); + props.put("calculator", "Calculator"); + props.put("service.exported.configs", new String[] {"org.osgi.sca"}); + props.put("org.osgi.sca.bindings", new String[] {"{http://sample}Calculator"}); + props.put("service.exported.interfaces", new String[] {"*"}); + 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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java new file mode 100644 index 0000000000..5f9db16ca9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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 getService(Class 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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java new file mode 100644 index 0000000000..a9ea37585a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java @@ -0,0 +1,105 @@ +/* + * 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.*) (service.imported=*))"); + localFilter = + context.createFilter("(&(" + OBJECTCLASS + "=calculator.dosgi.operations.*) (!(service.imported=*)))"); + } 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 getService(Class cls) { + try { + // Wait for 10 seconds until the remote services are imported + remoteServices.waitForService(10000); + } catch (InterruptedException e) { + throw new IllegalStateException(cls.getSimpleName() + " is not available"); + } + 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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java new file mode 100644 index 0000000000..a4fc52694e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java new file mode 100644 index 0000000000..a813dfb6f3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java new file mode 100644 index 0000000000..955e386ad8 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-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-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java new file mode 100644 index 0000000000..565a314d85 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java @@ -0,0 +1,43 @@ +/* + * 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.test; + +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + +/** + * + */ +public class CalculatorNode { + + /** + * @param args + */ + public static void main(String[] args) { + if (args.length == 0) { + args = new String[] {"-bundles"}; + } + try { + NodeLauncher.main(args); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java new file mode 100644 index 0000000000..4015c7bbc2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java @@ -0,0 +1,144 @@ +/* + * 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.test; + +import static calculator.dosgi.test.OSGiTestUtils.bundleStatus; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; + +import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + +import calculator.dosgi.CalculatorService; +import calculator.rmi.OperationsRMIServer; + +/** + * + */ +public class CalculatorOSGiNodeTestCase { + private static EquinoxHost host; + private static BundleContext context; + private static Bundle calculatorBundle; + private static OperationsRMIServer rmiServer; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + try { + rmiServer = new OperationsRMIServer(); + rmiServer.start(); + + host = new EquinoxHost(); + context = host.start(); + + for (Bundle b : context.getBundles()) { + System.out.println(b); + if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName() + .startsWith("org.apache.tuscany.sca.")) { + try { + if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) { + // Start the non-fragment bundle + b.start(); + } + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println(bundleStatus(b, false)); + } + if ("calculator.dosgi.dynamic".equals(b.getSymbolicName())) { + calculatorBundle = b; + } + } + + if (calculatorBundle != null) { + calculatorBundle.start(); + System.out.println(bundleStatus(calculatorBundle, false)); + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testOSGi() { + ServiceReference ref = + calculatorBundle.getBundleContext().getServiceReference(CalculatorService.class.getName()); + Assert.assertNotNull(ref); + Object service = context.getService(ref); + Assert.assertNotNull(service); + CalculatorService calculator = OSGiTestUtils.cast(service, CalculatorService.class); + System.out.println("2.0 + 1.0 = " + calculator.add(2.0, 1.0)); + System.out.println("2.0 - 1.0 = " + calculator.subtract(2.0, 1.0)); + System.out.println("2.0 * 1.0 = " + calculator.multiply(2.0, 1.0)); + System.out.println("2.0 / 1.0 = " + calculator.divide(2.0, 1.0)); + } + + @Test + /** + * Test the Web service exposed by the Calculator + */ + public void testWS() throws Exception { + URL url = new URL("http://localhost:8086/CalculatorService?wsdl"); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader(is); + char[] content = new char[10240]; // 10k + int len = 0; + while (true) { + int size = reader.read(content, len, content.length - len); + if (size < 0) { + break; + } + len += size; + } + Assert.assertTrue(len > 0); + String str = new String(content, 0, len); + System.out.println(str); + Assert.assertTrue(str.indexOf(" + * @param obj + * @param cls + * @return + */ + public static T cast(Object obj, Class cls) { + if (cls.isInstance(obj)) { + return cls.cast(obj); + } else { + return cls.cast(Proxy.newProxyInstance(cls.getClassLoader(), + new Class[] {cls}, + new InvocationHandlerImpl(obj))); + } + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/README b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/README new file mode 100644 index 0000000000..bf5f500ef3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/README @@ -0,0 +1,151 @@ +Hello World BPEL Sample +====================================== +This sample demonstrates an SCA service implemented by a BPEL process. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory, and do + +ant compile run + +OR if you don't have ant, on Windows do + +mkdir target\classes +mkdir target\wsdl2java-source +java -cp ..\..\lib\tuscany-sca-manifest.jar org.apache.tuscany.sdo.generate.XSD2JavaGenerator -targetDirectory target/wsdl2java-source -prefix HelloWorld -noContainment -noUnsettable src/main/resources/helloworld.wsdl +java -cp ..\..\lib\tuscany-sca-manifest.jar org.apache.tuscany.tools.wsdl2java.generate.WSDL2JavaGenerator -targetDirectory target/wsdl2java-source src/main/resources/helloworld.wsdl +unzip ..\..\lib\ode-dao-jpa-ojpa-derby-1.1.zip -d target\database +javac -d target\classes -cp target\classes;..\..\lib\tuscany-sca-manifest.jar -sourcepath src\main\java;target\wsdl2java-source -target 1.5 -g -source 1.5 src\main\java\helloworld\BPELClient.java +copy src\main\resources\* target\classes +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\classes;target\database helloworld.BPELClient + +and on *nix do + +mkdir target/classes +mkdir target/wsdl2java-source +java -cp ../../lib/tuscany-sca-manifest.jar org.apache.tuscany.sdo.generate.XSD2JavaGenerator -targetDirectory target/wsdl2java-source -prefix HelloWorld -noContainment -noUnsettable src/main/resources/helloworld.wsdl +java -cp ../../lib/tuscany-sca-manifest.jar org.apache.tuscany.tools.wsdl2java.generate.WSDL2JavaGenerator -targetDirectory target/wsdl2java-source src/main/resources/helloworld.wsdl +unzip ../../lib/ode-dao-jpa-ojpa-derby-1.1.zip -d target/database +javac -d target/classes -cp target/classes;../../lib/tuscany-sca-manifest.jar -sourcepath src/main/java;target/wsdl2java-source -target 1.5 -g -source 1.5 src/main/java/helloworld/BPELClient.java +cp src/main/resources/* target/classes +java -cp ../../lib/tuscany-sca-manifest.jar:target/classes:target/database helloworld.BPELClient + +The sample will start an embedded BPEL engine, deploy a process and invoke it. + +Sample Overview +--------------- +The sample provides a single component that is wired to a service with a +web service binding. + +helloworld-bpel/ + src/ + main/ + java/ + helloworld/ + BPELClient.java - client application for + BEPELHelloWorldComponent + + resources/ + deploy.xml - ODE deployment descriptor + helloworld.bpel - helloworld bpel process + helloworld.componentType - helloworld bpel service description + helloworld.composite - the SCA assembly for this sample + helloworld.wsdl - the service description that describes + the bpel process + log4j.properties - logging configuration + + test/ + java/ + helloworld/ + BPELHelloWorldTestCase.java - JUnit test case + helloworld-bpel.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- + +With the binary distribution the sample can be built and run using Ant as +follows + +cd helloworld-bpel +ant compile +ant run + + +You should see the following output from the run target. + +run: + [java] Starting BPELHelloWorldComponent + [java] >>> Deploying : D:\temp\SCA1.1-RC1\tuscany-sca-1.1-incubating\samples\helloworld-bpel\target\classes + [java] ::arg:::::: + [java] Hello + [java] ::message:: + [java] Hello + [java] Status: RESPONSE + [java] Response: + [java] Hello World + [java] Hello World + [java] Stopping BPELHelloWorldComponent + [java] Stopped !!! + +BUILD SUCCESSFUL +Total time: 36 seconds + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. When using Maven, a simple test is present that exercise +the same logic as the client to invoke the BPEl process. + +cd helloworld-bpel +mvn + +You should see the following output from the test phase. + +- + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.BPELHelloWorldTestCase +Starting BPELHelloWorldComponent +>>> Deploying : D:\dev\Opensource\Apache\Tuscany\source\java-sca-1.1\samples\helloworld-bpel\target\classes +::arg:::::: +Hello +::message:: +Hello +Status: RESPONSE +Response: +Hello World +Stopping BPELHelloWorldComponent +Stopped !!! +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 18.656 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +[INFO] [jar:jar] +[INFO] Building jar: D:\dev\Opensource\Apache\Tuscany\source\java-sca-1.1\samples\helloworld-bpel\target\sample-helloworld-bpel.jar +[INFO] [install:install] +[INFO] Installing D:\dev\Opensource\Apache\Tuscany\source\java-sca-1.1\samples\helloworld-bpel\target\sample-helloworld-bpel.jar to C:\Documents and Settings\lresend +e\.m2\repository\org\apache\tuscany\sca\sample-helloworld-bpel\1.1-incubating-SNAPSHOT\sample-helloworld-bpel-1.1-incubating-SNAPSHOT.jar +[INFO] ------------------------------------------------------------------------ +[INFO] BUILD SUCCESSFUL +[INFO] ------------------------------------------------------------------------ +[INFO] Total time: 53 seconds +[INFO] Finished at: Sun Jan 13 09:54:39 PST 2008 +[INFO] Final Memory: 24M/43M +[INFO] ------------------------------------------------------------------------ + + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/build.xml b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/build.xml new file mode 100644 index 0000000000..008953e63b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/build.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.png b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.png new file mode 100644 index 0000000000..5f53a3c5d1 Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.svg b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.svg new file mode 100644 index 0000000000..5a98f1a07c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/helloworld-bpel.svg @@ -0,0 +1,179 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldws + + HelloWorldServiceComponent + + HelloWorldWebService + + implementation.bpel helloworld.bpel + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/pom.xml new file mode 100644 index 0000000000..611c632bf2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/pom.xml @@ -0,0 +1,115 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-helloworld-bpel + Apache Tuscany SCA Sample HelloWorld BPEL + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-bpel-runtime + 2.0-M4 + runtime + + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + test-compile + + unpack + + + + + org.apache.ode + ode-dao-jpa-ojpa-derby + 1.3.2 + zip + true + ${project.build.directory}/test-classes/ + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/BPELClient.java b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/BPELClient.java new file mode 100644 index 0000000000..e2d69eddf6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/BPELClient.java @@ -0,0 +1,45 @@ +/* + * 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 helloworld; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +/** + * Simple BPEL sample application invoking a helloworld + * + * @version $Rev$ $Date$ + */ +public class BPELClient { + public static void main(String[] args) throws Exception { + + Node node = NodeFactory.newInstance().createNode(); + node.start(); + + Hello bpelService = node.getService(Hello.class, "BPELHelloWorldComponent"); + + String result = bpelService.hello("Hello"); + System.out.println(result); + + node.stop(); + + System.exit(0); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/Hello.java b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/Hello.java new file mode 100644 index 0000000000..dbd3854d7c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/java/helloworld/Hello.java @@ -0,0 +1,29 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Hello { + + String hello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..b95468acd8 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.bpel b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.bpel new file mode 100644 index 0000000000..19afe61fd3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.bpel @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + concat($myVar.TestPart/test:message/text(), ' World') + + + + + $tmpVar + $myVar.TestPart/test:message + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.composite b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.composite new file mode 100644 index 0000000000..603cc17af9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.wsdl b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.wsdl new file mode 100644 index 0000000000..46cf381577 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/helloworld.wsdl @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/log4j.properties b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/log4j.properties new file mode 100644 index 0000000000..8649a71550 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/main/resources/log4j.properties @@ -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. +# + +# Set root logger level to WARN and its only appender to CONSOLE +log4j.rootLogger=OFF, CONSOLE + +# log4j properties to work with commandline tools. +log4j.category.org.mortbay=OFF +log4j.category.org.hibernate.type=OFF +log4j.category.org.objectweb=OFF +log4j.category.org.apache.ode.sql=OFF +log4j.category.org.apache.ode.axis2=OFF +log4j.category.org.apache.ode.bpel.engine=OFF +log4j.category.org.apache.ode.daohib.bpel.CorrelatorDaoImpl=OFF +log4j.category.org.apache.ode.bpel.epr=OFF +log4j.category.org.apache.openjpa.kernel=OFF + +# Console appender +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%p - %C{1}.%M(%L) | %m%n \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/test/java/helloworld/BPELHelloWorldTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/test/java/helloworld/BPELHelloWorldTestCase.java new file mode 100644 index 0000000000..12e40d334b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/helloworld-bpel/src/test/java/helloworld/BPELHelloWorldTestCase.java @@ -0,0 +1,65 @@ +/* + * 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 helloworld; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests the BPEL service + * + * @version $Rev$ $Date$ + */ +public class BPELHelloWorldTestCase { + + private static Node node; + private static Hello bpelService; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUp() throws Exception { + + node = NodeFactory.newInstance().createNode(); + node.start(); + + bpelService = node.getService(Hello.class, "BPELHelloWorldComponent"); + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testInvoke() throws Exception { + String response = bpelService.hello("Hello"); + Assert.assertEquals("Hello World", response); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/README b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/README new file mode 100644 index 0000000000..28eccbdebb --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/README @@ -0,0 +1,96 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -jar ..\..\features\tuscany-sca-equinox-manifest.jar -composite Calculator.composite -config ..\..\features\configuration\ -ttl 0 target\sample-implementation-java-calculator.jar +and on *nix do + +java -jar ../../features/tuscany-sca-equinox-manifest.jar -composite Calculator.composite -config ../../features/configuration/ -ttl 0 target/sample-implementation-java-calculator.jar + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/build.xml b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/build.xml new file mode 100644 index 0000000000..050540a93a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/build.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.png b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.png differ diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.svg b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.svg new file mode 100644 index 0000000000..af34f07e04 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/pom.xml new file mode 100644 index 0000000000..590fa6f6ea --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + sample-implementation-java-calculator + Apache Tuscany SCA Sample Implementation Java Calculator + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-M4 + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-M4 + + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddService.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/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.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorClient.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..84c98d7f70 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,62 @@ +/* + * 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.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@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("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/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorService.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorService.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; + + +/** + * The Calculator service interface. + */ +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-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..17fad7de6b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,70 @@ +/* + * 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.oasisopen.sca.annotation.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideService.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/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.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyService.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/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.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractService.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/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.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/resources/Calculator.composite b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..9450558145 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/test/java/calculator/CalculatorTestCase.java b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..461c970373 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/implementation-java-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,73 @@ +/* + * 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.Node; +import org.apache.tuscany.sca.node.equinox.launcher.Contribution; +import org.apache.tuscany.sca.node.equinox.launcher.ContributionLocationHelper; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator composition. + */ +public class CalculatorTestCase { + + private static NodeLauncher launcher; + private static Node node; + private static String status = "Sample Success"; + + public static void main(String[] args) throws Exception { + setUpBeforeClass(); + tearDownAfterClass(); + } + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + launcher = NodeLauncher.newInstance(); + String location = ContributionLocationHelper.getContributionLocation(CalculatorClient.class); + node = launcher.createNode("Calculator.composite", new Contribution("test", location)); + + try { + node.start(); + } catch (Exception ex) { + status = ex.toString(); + System.out.println(status); + } + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + if (node != null) { + node.stop(); + node.destroy(); + } + if (launcher != null) { + launcher.destroy(); + } + } + + @Test + public void testSample() throws Exception { + Assert.assertEquals("Sample Success", status); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/logging.properties b/tags/java/sca/2.0-M4-RC2/samples/logging.properties new file mode 100644 index 0000000000..cf452e7812 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/logging.properties @@ -0,0 +1,25 @@ +# +# 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. +# + +handlers= java.util.logging.ConsoleHandler + +.level = INFO + +java.util.logging.ConsoleHandler.level = FINE +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + +org.apache.tuscany.sca.level = INFO diff --git a/tags/java/sca/2.0-M4-RC2/samples/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/pom.xml new file mode 100644 index 0000000000..6ada609ce9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../pom.xml + + tuscany-samples + pom + Apache Tuscany SCA Samples + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + default + + true + + + calculator + calculator-equinox + calculator-osgi + calculator-rmi-reference + calculator-rmi-service + + dosgi-calculator + dosgi-calculator-operations + + dosgi-dynamic-calculator + + dosgi-dynamic-calculator-operations + + helloworld-bpel + + implementation-java-calculator + binding-ws-calculator + + webapps/helloworld + webapps/helloworld-bpel + webapps/helloworld-jms + webapps/helloworld-js-client + webapps/helloworld-jsp + webapps/helloworld-stripes + webapps/helloworld-servlet + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/pom.xml new file mode 100644 index 0000000000..6c80b939e3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/pom.xml @@ -0,0 +1,130 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-bpel + war + Apache Tuscany SCA Sample Helloworld BPEL + + + 2.0-M4 + 6.1.18 + + + + + + org.apache.tuscany.sca + tuscany-sca-api + ${tuscany.version} + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + ${tuscany.version} + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-bpel-runtime + ${tuscany.version} + runtime + + + + + junit + junit + 3.8.2 + test + + + + + org.mortbay.jetty + jetty + ${jetty.version} + provided + + + org.mortbay.jetty + jetty-util + ${jetty.version} + provided + + + org.mortbay.jetty + jetty-management + ${jetty.version} + provided + + + + + ${artifactId} + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + compile + + unpack + + + + + org.apache.ode + ode-dao-jpa-ojpa-derby + 1.1.1 + zip + false + ${project.build.directory}/classes + **/* + + + + + + + + + org.mortbay.jetty + maven-jetty-plugin + ${jetty.version} + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..c1a50d9be5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/java/sample/HelloworldService.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloworldService { + + String hello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.bpel b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.bpel new file mode 100644 index 0000000000..f1e8895f76 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.bpel @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + concat('Hello ', $myVar.TestPart/test:message/text()) + + + + $tmpVar + $myVar.TestPart/test:message + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.wsdl b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.wsdl new file mode 100644 index 0000000000..46cf381577 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/resources/helloworld.wsdl @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..3ffe604ef7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..bf01a7b759 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + helloworld-bpel + + + tuscany.helloworld-bpel + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany.helloworld-bpel + /* + + + + hello.jsp + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/hello.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/hello.jsp new file mode 100644 index 0000000000..c52d7b1cb2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-bpel/src/main/webapp/hello.jsp @@ -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. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> + + + + + + +

helloworld-bpel

+ + Calling HelloworldService sayHello("world") returns: + +

+ + <%= service.hello("world") %> + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/README b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/README new file mode 100644 index 0000000000..88bbe9adcb --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/README @@ -0,0 +1,131 @@ +JMS HelloWorld Sample +===================== +This sample demonstrates a simple webapp containing a hello world style client +and service using the JMS binding for request-response style messaging. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/helloworld-jms.war ) +to you web application server. Alternatevly, the sample pom.xml is configured +with the Jetty plugin so you can run the it with Jetty by simply doing "mvn jetty:run". + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/helloworld-jms + +The port and hostname will of course vary depending on your local installation. + +Configuring the JMS resources +----------------------------- + +The sample requires JMS resources be manually configured in the server environment, these are: + +- a JMS connection factory named "ConnectionFactory" +- a JMS queue named "HelloWorldService" + +See the following for how to define these resources depending on the application server being used: + +Tuscany with embedded ActiveMQ broker +------------------------------------- + + +Apache Tomcat +------------- + +No configuration is necessary for Tomcat as the sample WAR includes everything pre-configured to run +an ActiveMQ embedded JMS broker and to configure the JMS resources in JNDI. + +The JNDI resources are configured in the META-INF/comtext.xml file, for more information on running +ActiveMQ in Tomcat see: http://activemq.apache.org/tomcat.html + + +Apache Geronimo +--------------- + +For Apache Geronimo 2.0.1 (2.0.2 fails to define JMS resources for me) + +Logon to the Geronimo Server Console (http://localhost:8080/console, uid system, pswd manager) + +In the Console Navigation on the left under Services click JMS Resources + +At the bottom of the JMS Resources panel click under Create a new JMS Resource Group click For ActiveMQ + +In Resource Group Name enter "MyRGN" and click next + +At JMS Resource Group click Add Connection Factory + +For JMS Factory Type choose javax.jms.ConnectionFactory and click Next + +In Connection Factory Name enter "ConnectionFactory" and click Next + +Click Add destination + +For JMS Destination Type choose javax.jms.Queue and click Next + +Enter "HelloWorldService" for both Message Destination Name and PhysicalName and click Next + +Click Deploy Now + +Thats it, you're done. + + +WebSphere +--------- + +To define the JMS resources in a new WebSphere Application Server 6.1 installation: + +1) First define a Service integration bus: + +Logon to the WebSphere Integrated Solutions Console (http://localhost:9060/ibm/console) + +On the Left hand menu expand Service integration, and click on Buses. + +In the Buses panel click on New + +Enter a name for the bus, eg MyBus, and click Next, and then click Finish and Save the changes. + +In the Buses panel click on MyBus + +Find the Topology secion and click on Bus members + +Click on Add, leave the defaults and click Next, Next, Next, Finish, and Save the changes. + +Restart WebSphere and when back up logon back on to the Integrated Solutions Console + +2) Now define the JMS rescources + +On the Left hand menu expand Resources, and JMS and click on Connection Facotories. + +In the Connection factories panel click New. + +Leave the Default messaging provider and click OK + +Enter "ConnectionFactory" in the Name and JNDI name and in the Bus name in the Connection pane choose MyBus and click OK + +On the Left hand menu in JMS click on Queues + +In the Queues panel click New, accept the defaults and click OK + +Enter "HelloWorldService" for the Name and JNDI name and in the Bus name in the Connection pane choose MyBus, +and then in the Queue name drop down list choose "Create SIB destination" + +In the Set queue attributes panel enter "HelloWorldService" for the Identifier and click Next, Next, and Finish + +That should take you back to the Queues panel where you can click OK to create the new JMS queue. + +Save the changes + +Restart WebSphere and you're done. + + + +Others... +--------- + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/pom.xml new file mode 100644 index 0000000000..09dddbd07d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/pom.xml @@ -0,0 +1,80 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-jms + war + Apache Tuscany SCA Sample JMS HelloWorld in a WebApp + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jms-runtime + 2.0-M4 + + + + org.apache.activemq + activemq-core + 5.1.0 + runtime + + + backport-util-concurrent + backport-util-concurrent + 3.1 + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldClient.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldClient.java new file mode 100644 index 0000000000..f209f11605 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldClient.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 sample; + +/** + * The HelloWorld client implementation + */ +public class HelloWorldClient implements HelloWorldService { + + HelloWorldService helloWorldRef; + + public String sayHello(String name) { + System.out.println("HelloWorldClient.sayHello " + name); + return helloWorldRef.sayHello(name); + } + + public void setHelloWorldRef(HelloWorldService helloWorldRef) { + System.out.println("HelloWorldClient.setHelloWorldService " + helloWorldRef); + this.helloWorldRef = helloWorldRef; + } +} \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldService.java new file mode 100644 index 0000000000..df2a852161 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldService.java @@ -0,0 +1,29 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the helloworld service + */ +@Remotable +public interface HelloWorldService { + public String sayHello(String name); +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..c09af51e23 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/java/sample/HelloWorldServiceImpl.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 sample; + +/** + * This class implements the HelloWorld service. + */ +public class HelloWorldServiceImpl implements HelloWorldService { + + public String sayHello(String name) { + System.out.println("HelloWorldServiceImpl.sayHello " + name); + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/META-INF/context.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000000..7575edfc29 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/META-INF/context.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/jetty-env.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/jetty-env.xml new file mode 100644 index 0000000000..a8cd27f6c6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/jetty-env.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + ConnectionFactory + + + vm://localhost?broker.persistent=false + + + + + + HelloWorldService + + + DEMO + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..5c52638661 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..86710435ae --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,66 @@ + + + + + + + Apache Tuscany JMS Web Service Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + hello.jsp + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/hello.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/hello.jsp new file mode 100644 index 0000000000..9ae037f2c2 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jms/src/main/webapp/hello.jsp @@ -0,0 +1,41 @@ +<%-- + * 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. +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> + + + + +HelloWorld JMS sample + + + +If this sample is working correctly you should see "Hello World" on the next line... +

+<%= service.sayHello("world") %> +

+If you do not see "Hello World" on the line above then there has been a problem. +

+The sample requires JMS resources be manually configured in the server environment, these are: +a JMS connection factory named "ConnectionFactory", and a destination queues named "HelloWorldService". +See the sample README file for more information. + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/pom.xml new file mode 100644 index 0000000000..32799fbf46 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-js-client + war + Apache Tuscany SCA Sample Helloworld Javascript Client + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-implementation-web-client + 2.0-M4 + runtime + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..123774b936 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..66cef71a25 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..c59c7a8f6d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..babeb7b203 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + Apache Tuscany Helloworld JSP Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + hello.html + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/hello.html b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/hello.html new file mode 100644 index 0000000000..12024cc4d3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-js-client/src/main/webapp/hello.html @@ -0,0 +1,51 @@ + + + + + Apache Tuscany Helloworld Javascript Client Sample + + + + + + + + + +

Apache Tuscany Helloworld Javascript Client Sample

+ + + + + +
+ + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/pom.xml new file mode 100644 index 0000000000..9917a2c880 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-jsf + Apache Tuscany SCA Sample Helloworld JSF + war + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-myfaces + 2.0-M4 + runtime + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloWorldController.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloWorldController.java new file mode 100644 index 0000000000..9c9f541997 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloWorldController.java @@ -0,0 +1,56 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.Reference; + +/** + * + */ +public class HelloWorldController { + + @Reference + protected HelloworldService service; + + private String name; + + public HelloWorldController() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * Method that is backed to a submit button of a form. + */ + public String send() { + if (service == null) { + name = "reference not injected!"; + } else { + name = service.sayHello(name); + } + return "success"; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..53ff7a5ca1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..23925d6c69 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,27 @@ +/* + * 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 sample; + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/faces-config.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..99cee9faeb --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,51 @@ + + + + + + + helloWorld + sample.HelloWorldController + request + + + + + /helloWorld.jsp + + success + /page2.jsp + + + + + + /page2.jsp + + back + /helloWorld.jsp + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..875d6aae9d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..fecbd7c79b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,191 @@ + + + + + MyProject web.xml + + + + org.apache.tuscany.sca.host.webapp.TuscanyContextListener + + + org.apache.myfaces.config.annotation.LifecycleProvider + org.apache.tuscany.sca.myfaces.TuscanyAnnotationLifecycleProvider + + + + + State saving method: "client" or "server" (= default) + See JSF Specification 2.5.3 + javax.faces.STATE_SAVING_METHOD + client + + + Only applicable if state saving method is "server" (= default). + Defines the amount (default = 20) of the latest views are stored in session. + org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION + 20 + + + Only applicable if state saving method is "server" (= default). + If true (default) the state will be serialized to a byte stream before it + is written to the session. + If false the state will not be serialized to a byte stream. + org.apache.myfaces.SERIALIZE_STATE_IN_SESSION + true + + + Only applicable if state saving method is "server" (= default) and if + org.apache.myfaces.SERIALIZE_STATE_IN_SESSION is true (= default) + If true (default) the serialized state will be compressed before it + is written to the session. If false the state will not be compressed. + org.apache.myfaces.COMPRESS_STATE_IN_SESSION + true + + + This parameter tells MyFaces if javascript code should be allowed in the + rendered HTML output. + If javascript is allowed, command_link anchors will have javascript code + that submits the corresponding form. + If javascript is not allowed, the state saving info and nested parameters + will be added as url parameters. + Default: "true" + org.apache.myfaces.ALLOW_JAVASCRIPT + true + + + org.apache.myfaces.DETECT_JAVASCRIPT + false + + + If true, rendered HTML code will be formatted, so that it is "human readable". + i.e. additional line separators and whitespace will be written, that do not + influence the HTML code. + Default: "true" + org.apache.myfaces.PRETTY_HTML + true + + + If true, a javascript function will be rendered that is able to restore the + former vertical scroll on every request. Convenient feature if you have pages + with long lists and you do not want the browser page to always jump to the top + if you trigger a link or button action that stays on the same page. + Default: "false" + org.apache.myfaces.AUTO_SCROLL + true + + + + Used for encrypting view state. Only relevant for client side + state saving. See MyFaces wiki/web site documentation for instructions + on how to configure an application for diffenent encryption strengths. + + org.apache.myfaces.SECRET + NzY1NDMyMTA= + + + + + Validate managed beans, navigation rules and ensure that forms are not nested. + + org.apache.myfaces.VALIDATE + true + + + + + Treat readonly same as if disabled attribute was set for select elements. + + org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS + true + + + + + Use the defined class as the class which will be called when a resource is added to the + ExtensionFilter handling. Using StreamingAddResource here helps with performance. If you want to add + custom components and want to use the ExtensionFilter, you need to provide your custom implementation here. + + org.apache.myfaces.ADD_RESOURCE_CLASS + org.apache.myfaces.renderkit.html.util.DefaultAddResource + + + + + Virtual path in the URL which triggers loading of resources for the MyFaces extended components + in the ExtensionFilter. + + org.apache.myfaces.RESOURCE_VIRTUAL_PATH + /faces/myFacesExtensionResource + + + + + Check if the extensions-filter has been properly configured. + + org.apache.myfaces.CHECK_EXTENSIONS_FILTER + true + + + + + Define partial state saving as true/false. + + javax.faces.PARTIAL_STATE_SAVING_METHOD + false + + + + + org.apache.myfaces.webapp.StartupServletContextListener + + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + + + Faces Servlet + *.jsf + + + + + index.jsp + index.html + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/helloWorld.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/helloWorld.jsp new file mode 100644 index 0000000000..189c142c99 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/helloWorld.jsp @@ -0,0 +1,40 @@ + + +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> + + + + Apache Tuscany Helloworld JSF sample + + +

Apache Tuscany Helloworld JSF sample

+ + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/index.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/index.jsp new file mode 100644 index 0000000000..5ca296e115 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/index.jsp @@ -0,0 +1,23 @@ + + +<%@ page session="false"%> +<% +response.sendRedirect("helloWorld.jsf"); +%> diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/page2.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/page2.jsp new file mode 100644 index 0000000000..89259021c7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsf/src/main/webapp/page2.jsp @@ -0,0 +1,38 @@ + + +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> + + + Apache Tuscany Helloworld JSF sample + + +

Apache Tuscany Helloworld JSF sample

+ + + +
+ + + +
+
+ + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/pom.xml new file mode 100644 index 0000000000..22d399f4cd --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-jsp + war + Apache Tuscany SCA Sample Helloworld JSP + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + 2.0-M4 + runtime + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..53ff7a5ca1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..a22c095f29 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..875d6aae9d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..fa1f7ad7b9 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + Apache Tuscany Helloworld JSP Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + hello.jsp + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/hello.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/hello.jsp new file mode 100644 index 0000000000..ffd01cca73 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-jsp/src/main/webapp/hello.jsp @@ -0,0 +1,37 @@ + + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> + + + + + + +

Apache Tuscany Helloworld JSP Sample

+ + Calling HelloworldService sayHello("world") returns: + +

+ + <%= service.sayHello("world") %> + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/README b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/README new file mode 100644 index 0000000000..00568d9bb0 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/README @@ -0,0 +1,37 @@ +Hello World REST Sample +======================= + +Sample Overview +--------------- +The service 'HelloWorldService' is exposed using the REST binding. + +helloworld-jsonrpc-webapp/ + src/ + main/ + java/ + helloworldjsonrpc/ + HelloWorldService.java - service interface + HelloWorldServiceImpl.java - service implementation + ClientTestServiceWebapp.java - Test class; uses java.net.HttpURLConnection to make 'GET', 'PUT', 'POST requests + resources/ + rest.composite - the SCA assembly for this sample + webapp + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + pom.xml - the Maven build file + +Build the sample using Maven. +A war 'helloworld-rest-webapp.war' will be created in the target directory. Deploy it in your web container. +You can access the service from the browser by making a simple GET request using the following URL: +http://:/helloworld-rest-webapp/HelloWorldService/helloworld/getname + +Use the test class 'ClientTestServiceWebapp' to test PUT, POST operations. + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/pom.xml new file mode 100644 index 0000000000..ce70092d3d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + helloworld-rest + war + HelloWorld RESTFul Web Application + + + + maven2-repository.dev.java.net + Java.net Repository for Maven + http://download.java.net/maven/2/ + default + + + maven-repository.dev.java.net + Java.net Maven 1 Repository (legacy) + http://download.java.net/maven/1 + legacy + + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-M4 + runtime + + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + 2.0-M4 + runtime + + + + org.apache.tuscany.sca + tuscany-binding-rest-runtime + 2.0-M4 + runtime + + + + javax.ws.rs + jsr311-api + 1.0 + compile + + + + com.sun.jersey + jersey-bundle + 1.0.3 + compile + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java new file mode 100644 index 0000000000..8b19af7a52 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientJavaTestService.java @@ -0,0 +1,29 @@ +package helloworldrest; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +/* + * To test, simply run the program + * Access the service by invoking the getName() method of HelloWorldService + */ + +public class ClientJavaTestService { + + /** + * @param args + */ + public static void main(String[] args) { + NodeFactory factory = NodeFactory.newInstance(); + Node node = factory.createNode("rest.composite", ClientJavaTestService.class.getClassLoader()).start(); + HelloWorldService helloService = node.getService(HelloWorldService.class, "HelloWorldRESTServiceComponent"); + + //HelloWorldService helloService = new HelloWorldServiceImpl(); + System.out.println("### Message from REST service " + helloService.getName()); + + node.stop(); + node.destroy(); + factory.destroy(); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java new file mode 100644 index 0000000000..fb83b26315 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/ClientTestServiceWebapp.java @@ -0,0 +1,108 @@ +package helloworldrest; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Formatter; + +/** + * + * To test, deploy the application as a webapp. + * Then, run this file to access the REST web service by making HTTP GET/POST requests + * + */ +public class ClientTestServiceWebapp { + + final static String UrlBase = "http://localhost:8080/helloworld-rest-webapp/HelloWorldService"; + + final static class HttpResponse { + Object content; + int code; + String message; + } + + static HttpResponse makeHttpGetRequest(String method, String url, String contentType) throws Exception { + HttpResponse response = new HttpResponse(); + URL urlAddress = new URL(url); + HttpURLConnection huc = (HttpURLConnection)urlAddress.openConnection(); + huc.setRequestMethod(method); + huc.setRequestProperty("Content-type", contentType); + huc.connect(); + InputStreamReader isr = new InputStreamReader(huc.getInputStream()); + + BufferedReader in = new BufferedReader(isr); + String uline = in.readLine(); + response.content = uline; + + // huc.disconnect(); + // System.out.println("#### huc disconnected ###"); + + return response; + } + + static HttpResponse makeHttpRequest(String method, String url, String contentType, InputStream is) throws Exception { + HttpResponse response = new HttpResponse(); + URL urlAddress = new URL(url); + HttpURLConnection huc = (HttpURLConnection)urlAddress.openConnection(); + huc.setRequestMethod(method); + if (null != is) { + huc.setDoOutput(true); + huc.setRequestProperty("Content-Type", contentType); + OutputStream os = huc.getOutputStream(); + byte[] buf = new byte[1024]; + int read; + while ((read = is.read(buf)) != -1) { + os.write(buf, 0, read); + } + } + InputStreamReader isr = new InputStreamReader(huc.getInputStream()); + BufferedReader in = new BufferedReader(isr); + String uline = in.readLine(); + response.content = uline; + return response; + } + + static HttpResponse makeHttpGetRequest(String method, String url, String contentType, String content) + throws Exception { + return makeHttpRequest(method, url, contentType, new ByteArrayInputStream(content.getBytes("UTF-8"))); + } + + static HttpResponse makeHttpRequest(String method, String url) throws Exception { + return makeHttpRequest(method, url, null, (InputStream)null); + } + + public static void main(String[] args) { + try { + + HttpResponse response; + + System.out.println("Getting the name *BEFORE* setting it:"); + response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain"); + System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString())); + + System.out.println("Setting the name:"); + String newText = "Morpheus"; + InputStream inputStream = new ByteArrayInputStream(newText.getBytes()); + response = makeHttpRequest("PUT", UrlBase + "/helloworld/setname", "text/plain", inputStream); + + System.out.println("Getting the name *AFTER* setting it:"); + response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain"); + System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString())); + + System.out.println("POST Operation:"); + response = makeHttpGetRequest("POST", UrlBase + "/helloworld/postoperation/prateek", "text/plain"); + //System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString())); + + System.out.println("Getting the name *AFTER* the POST operation:"); + response = makeHttpGetRequest("GET", UrlBase + "/helloworld/getname", "text/plain"); + System.out.println(new Formatter().format("---- Received String:\n%s", response.content.toString())); + } catch (Exception e) { + System.out.println("TEST FAILED! :-("); + e.printStackTrace(System.out); + } + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java new file mode 100644 index 0000000000..fb9d3e2f82 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldService.java @@ -0,0 +1,13 @@ +package helloworldrest; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloWorldService { + + public void setName(String name); + + public String getName(); + + public void postOperationTest(String name); +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..cacb88b5e3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/java/helloworldrest/HelloWorldServiceImpl.java @@ -0,0 +1,44 @@ +package helloworldrest; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +@Service(HelloWorldService.class) +@Scope("Composite") +@Path("/helloworld") +public class HelloWorldServiceImpl implements HelloWorldService { + + private String name = new String("original!"); + + @Path("/setname") + @PUT + @Consumes("text/plain") + public void setName(String name) { + this.name = name; + + } + + //http://:/helloworld-rest-webapp/HelloWorldService/helloworld/getname + @Path("/getname") + @GET + @Produces("text/plain") + public String getName() { + return this.name; + } + + @POST + @Path("/postoperation/{name}/") + @Consumes("text/plain") + public void postOperationTest(@PathParam("name") String name) { + this.name = name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/resources/rest.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/resources/rest.composite new file mode 100644 index 0000000000..7f76f5946d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/resources/rest.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/HelloWorldJSONRPC.html b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/HelloWorldJSONRPC.html new file mode 100644 index 0000000000..745164bf8d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/HelloWorldJSONRPC.html @@ -0,0 +1,75 @@ + + + + Tuscany JSON-RPC HelloWorld Example + + + + + + + + + + +

Tuscany JSON-RPC HelloWorld Sample

+ + + + + + + + + + + + + + + +
Non-Dojo Example
+ This example uses the JavaScript served from + SCADomain/scaDomain.js + to make JSON-RPC requests to the SCA service 'HelloWorldService' +
RequestResponse
+

+ Name please:     + + +

+ +
+
None Yet.
+
+ + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/META-INF/sca-contribution.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..9fc16372b3 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..3a670696e4 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + + + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/style.css b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/style.css new file mode 100644 index 0000000000..0f1cea3aaf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/src/main/webapp/style.css @@ -0,0 +1,22 @@ +/* + * 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. + */ +* { font-family: arial; } + +table, th, td { border: 2px solid blue; border-collapse: collapse; } +th { color: white; background-color: blue; } diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/target/classes/rest.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/target/classes/rest.composite new file mode 100644 index 0000000000..70b83fd986 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-rest/target/classes/rest.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/pom.xml new file mode 100644 index 0000000000..e979a251c7 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-servlet + war + Apache Tuscany SCA Sample Helloworld Servlet + + + + + org.apache.tuscany.sca + tuscany-implementation-web-runtime + 2.0-M4 + + + + javax.servlet + servlet-api + 2.5 + provided + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..2e43e09897 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..9e79276704 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,27 @@ +/* + * 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 sample; + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java new file mode 100644 index 0000000000..bb72c50f6a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/java/sample/HelloworldServlet.java @@ -0,0 +1,64 @@ +/* + * 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 sample; + +import java.io.IOException; +import java.io.Writer; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.oasisopen.sca.ComponentContext; +import org.oasisopen.sca.annotation.Reference; + +/** + */ +public class HelloworldServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + @Reference + protected HelloworldService service; + + @Override + public void init(ServletConfig servletConfig) throws ServletException { + if (service == null) { + System.out.println("HelloworldServlet reference injection failed, using ComponentContext"); + ComponentContext cc = (ComponentContext)servletConfig.getServletContext().getAttribute("org.oasisopen.sca.ComponentContext"); + service = cc.getService(HelloworldService.class, "service"); + } + } + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException { + + String name = request.getParameter("name"); + String greeting = service.sayHello(name); + + Writer out = response.getWriter(); + out.write("Apache Tuscany Helloworld Servlet Sample"); + out.write("

Apache Tuscany Helloworld Servlet Sample

"); + out.write("
Result: " + greeting); + out.write(""); + out.flush(); + out.close(); + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..875d6aae9d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..a91b3fc96b --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,44 @@ + + + + + Apache Tuscany Helloworld Servlet Sample + + org.apache.tuscany.sca.host.webapp.TuscanyContextListener + + + HelloworldServlet + sample.HelloworldServlet + + + + HelloworldServlet + /HelloworldServlet + + + + hello.html + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/hello.html b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/hello.html new file mode 100644 index 0000000000..c4484916aa --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-servlet/src/main/webapp/hello.html @@ -0,0 +1,46 @@ + + + + +Apache Tuscany Helloworld Servlet Sample + + + + +

Apache Tuscany Helloworld Servlet Sample

+ +
+ + + + + + + + +
Enter your name: + +
+ +
+
+ + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/pom.xml new file mode 100644 index 0000000000..0ae346e2cf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/pom.xml @@ -0,0 +1,72 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-stripes + war + Apache Tuscany SCA Sample Helloworld using Stripes + + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + + + org.apache.tuscany.sca + tuscany-stripes + 2.0-M4 + + + + + net.sourceforge.stripes + stripes + 1.5 + + + taglibs + standard + 1.1.2 + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/BaseActionBean.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/BaseActionBean.java new file mode 100644 index 0000000000..0ab02682ac --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/BaseActionBean.java @@ -0,0 +1,33 @@ +/* + * 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 mystripes.action; + +import net.sourceforge.stripes.action.ActionBean; +import net.sourceforge.stripes.action.ActionBeanContext; + +public class BaseActionBean implements ActionBean { + private ActionBeanContext context; + + public ActionBeanContext getContext() { + return context; + } + public void setContext(ActionBeanContext context) { + this.context = context; + } +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/HomeActionBean.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/HomeActionBean.java new file mode 100644 index 0000000000..0385c92369 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/mystripes/action/HomeActionBean.java @@ -0,0 +1,45 @@ +/* + * 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 mystripes.action; + +import net.sourceforge.stripes.action.DefaultHandler; +import net.sourceforge.stripes.action.ForwardResolution; +import net.sourceforge.stripes.action.Resolution; +import net.sourceforge.stripes.action.UrlBinding; + +import org.oasisopen.sca.annotation.Reference; + +import sample.HelloworldService; + +@UrlBinding("/Home.htm") +public class HomeActionBean extends BaseActionBean { + + @Reference + HelloworldService service; + + @DefaultHandler + public Resolution view() { + return new ForwardResolution("/WEB-INF/jsp/home.jsp"); + } + + public String getHello() { + return service.sayHello("world"); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..53ff7a5ca1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..a22c095f29 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/StripesResources.properties b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/StripesResources.properties new file mode 100644 index 0000000000..a23399569a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/StripesResources.properties @@ -0,0 +1,57 @@ + +# Resource strings used by the tag when there are no nested tags +stripes.errors.header=
Please fix the following errors:
    +stripes.errors.beforeError=
  1. +stripes.errors.afterError=
  2. +stripes.errors.footer=
+ +# Resource strings used by the tag when displaying errors for a +# specific field (e.g. ). If not supplied the +# values above will be used instead. +stripes.fieldErrors.header= +stripes.fieldErrors.beforeError= +stripes.fieldErrors.afterError=
+stripes.fieldErrors.footer= + +# Resource strings used by the stripes:messages tag +stripes.messages.header=
    +stripes.messages.beforeMessage=
  • +stripes.messages.afterMessage=
  • +stripes.messages.footer=
+ +# Validation error messages produced by Stripes' built-in converter classes. These +# are default error messages and can be overridden on per-field and per-form levels. +# Using the 'invalidNumber' error for a field 'age' of a form posting to +# '/user/Profile.action', the keys looked for (in order) would be: +# 1: /user/Profile.action.age.invalidNumber +# 2: /user/Profile.action.age.errorMessage +# 3: age.errorMessage +# 4: /user/Profile.action.invalidNumber +# 5: converter.number.invalidNumber +converter.number.invalidNumber=The value ({1}) entered in field {0} must be a valid number +converter.byte.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} +converter.short.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} +converter.integer.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} +converter.float.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} +converter.enum.notAnEnumeratedValue=The value "{1}" is not a valid value for field {0} +converter.date.invalidDate=The value ({1}) entered in field {0} must be a valid date +converter.email.invalidEmail=The value ({1}) entered is not a valid email address +converter.creditCard.invalidCreditCard=The value ({1}) entered is not a valid credit card number + +# Validation error messages produced by Stripes' annotation based validations. These +# are default error messages and can be overridden on per-field and per-form levels. +# Using the 'valueNotPresent' required field error for a field 'username' of a form +# posting to '/user/Register.action', the keys looked for (in order) would be: +# 1: /user/Register.action.username.valueNotPresent +# 2: /user/Register.action.username.errorMessage +# 3: username.errorMessage +# 4: /user/Register.action.valueNotPresent +# 5: validation.required.valueNotPresent +validation.required.valueNotPresent={0} is a required field +validation.minlength.valueTooShort={0} must be at least {2} characters long +validation.maxlength.valueTooLong={0} must be no more than {2} characters long +validation.minvalue.valueBelowMinimum=The minimum allowed value for {0} is {2} +validation.maxvalue.valueAboveMaximum=The maximum allowed value for {0} is {2} +validation.mask.valueDoesNotMatch={1} is not a valid {0} +validation.expression.valueFailedExpression=The value supplied ({1}) for field {0} is invalid +validation.file.postBodyTooBig=Total upload size of {3} KB exceeds the maximum size of {2} KB diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/log4j.properties b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/log4j.properties new file mode 100644 index 0000000000..77fa204a15 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/resources/log4j.properties @@ -0,0 +1,31 @@ +# log4j.properties + +# Set up a logger to the console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p %c %x - %m%n + +# Use this to only see log messages beyond a certain threshold in the console +#log4j.appender.stdout.Threshold=WARN + +# Set up a logger to a log file +log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.logfile.layout=org.apache.log4j.PatternLayout +log4j.appender.logfile.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p %c %x - %m%n +log4j.appender.logfile.File=${user.home}/stripesquick.log +log4j.appender.logfile.DatePattern='.'yyyy-MM-dd + +# Use this to only see log messages beyond a certain threshold in the log file +#log4j.appender.logfile.Threshold=WARN + +# Logger settings +log4j.rootLogger=INFO, stdout, logfile + +# Valid levels are TRACE, DEBUG, INFO, WARN, ERROR, FATAL +# Change to TRACE or DEBUG to see more log messages +log4j.logger.net.sourceforge.stripes=WARN +log4j.logger.org.stripesbook.quickstart=INFO +log4j.logger.org.mortbay.log=INFO +log4j.logger.org=WARN +log4j.logger.com=WARN +log4j.logger.net=WARN diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/home.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/home.jsp new file mode 100644 index 0000000000..0681c1f2bf --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/home.jsp @@ -0,0 +1,26 @@ + +<%@ include file="/WEB-INF/jsp/taglibs.jsp" %> + + + +

sayHello returns: ${actionBean.hello}

+

Congratulations, you've set up a Stripes SCA project!

+
+
diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/layout.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/layout.jsp new file mode 100644 index 0000000000..d0fb716b80 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/layout.jsp @@ -0,0 +1,39 @@ + +<%@ include file="/WEB-INF/jsp/taglibs.jsp" %> + + + + + + + ${title} + + + + + +
+ + +
+ + + +
\ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/taglibs.jsp b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/taglibs.jsp new file mode 100644 index 0000000000..f85602fcfa --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/jsp/taglibs.jsp @@ -0,0 +1,29 @@ + +<%-- Stripes TLD --%> +<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %> +<%@ taglib prefix="sdyn" uri="http://stripes.sourceforge.net/stripes-dynattr.tld" %> + +<%-- JSTL TLDs --%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> + +<%-- This is so that you can conveniently refer to the context path with ${contextPath} --%> + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..875d6aae9d --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..f01584cc2f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,61 @@ + + + + + Apache Tuscany Helloworld Stripes Sample + + + org.apache.tuscany.sca.host.webapp.TuscanyContextListener + + + + StripesFilter + net.sourceforge.stripes.controller.StripesFilter + + ActionResolver.Packages + mystripes.action + + + Extension.Packages + org.apache.tuscany.sca.stripes + + + + + DispatcherServlet + net.sourceforge.stripes.controller.DispatcherServlet + 1 + + + + StripesFilter + DispatcherServlet + REQUEST + FORWARD + + + + DispatcherServlet + *.htm + + + + index.html + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/index.html b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/index.html new file mode 100644 index 0000000000..c79d29e6a5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-stripes/src/main/webapp/index.html @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/pom.xml new file mode 100644 index 0000000000..af11fa2cba --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld-wicket + war + Apache Tuscany SCA Sample Helloworld using Wicket + + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + + + org.apache.tuscany.sca + tuscany-wicket + 2.0-M4 + + + javax.servlet + servlet-api + 2.5 + provided + + + + + org.apache.wicket + wicket + 1.4-rc2 + + + org.slf4j + slf4j-log4j12 + 1.4.2 + + + log4j + log4j + 1.2.14 + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..53ff7a5ca1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..a22c095f29 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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 sample; + + +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.html b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.html new file mode 100644 index 0000000000..61eb207e23 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.html @@ -0,0 +1,48 @@ + + + + + Wicket Examples - guice + + + +

+ This page uses Google Guice. + There is a service interface called IMyService, with an implementation POJO called MyService. + Guice is used to wire the implementation into the Page using an @Inject annotation. You can use this + annotation on the fields of any Component subclass. +

+

+ The value of the Label component below will be updated with the return value from one of the service's methods when you click the link. +

+
+
+ Value: Message goes here +
+ To update the label above, click here. +
+
+

+ The wicket-guice project will take care of proxying the injected beans so that your pages can be serialized safely. + To configure your application for Guice injection, see the javadoc for GuiceComponentInjector. +

+ + + \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.java new file mode 100644 index 0000000000..061f4c58ae --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/HomePage.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package sample.wicket; + +import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.Link; +import org.apache.wicket.model.AbstractReadOnlyModel; +import org.oasisopen.sca.annotation.Reference; + +/** + * Everybody's favorite example (Hello World), modified to use Guice. + * + * @author Alastair Maw + */ +public class HomePage extends WebPage +{ + @Reference + IMyService service; + + private String labelValue = ""; + + /** + * Constructor + */ + public HomePage() + { + add(new Link("link") + { + /** + * @see org.apache.wicket.markup.html.link.Link#onClick() + */ + @Override + public void onClick() + { + labelValue = service.getHelloWorldText(); + } + }); + add(new Label("message", new AbstractReadOnlyModel() + { + + @Override + public String getObject() + { + return labelValue; + } + + })); + } +} \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/IMyService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/IMyService.java new file mode 100644 index 0000000000..fdd91b0933 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/IMyService.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 sample.wicket; + + +/** + * Service interface for a simple "Hello World" app. + * + * @author Alastair Maw + */ +public interface IMyService +{ + /** + * Retrieves the text to say "Hello World". + * + * @return "Hello World" + */ + public String getHelloWorldText(); +} \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/MyService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/MyService.java new file mode 100644 index 0000000000..e7d864c5e6 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/MyService.java @@ -0,0 +1,38 @@ +/* + * 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 sample.wicket; + + +/** + * Implementation of IService. + * + * @author Alastair Maw + */ +public class MyService implements IMyService +{ + + /** + * @see org.apache.wicket.examples.guice.service.IMyService#getHelloWorldText() + */ + public String getHelloWorldText() + { + return "Hello World"; + } + +} \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/WicketApplication.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/WicketApplication.java new file mode 100644 index 0000000000..85f2c00dbc --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/java/sample/wicket/WicketApplication.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 sample.wicket; + +import org.apache.wicket.Page; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.tuscany.sca.wicket.TuscanyComponentInjector;; + +/** + * Application object for your web application. If you want to run this application without deploying, run the Start class. + * + * @see com.mycompany.Start#main(String[]) + */ +public class WicketApplication extends WebApplication +{ + + @Override + protected void init() + { + addComponentInstantiationListener(new TuscanyComponentInjector(this)); + } + + /** + * @see org.apache.wicket.Application#getHomePage() + */ + @Override + public Class< ? extends Page> getHomePage() + { + return HomePage.class; + } +} \ No newline at end of file diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/resources/log4j.properties b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/resources/log4j.properties new file mode 100644 index 0000000000..1e24577860 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/resources/log4j.properties @@ -0,0 +1,29 @@ +# +# 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. +# + +log4j.appender.Stdout=org.apache.log4j.ConsoleAppender +log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n + +log4j.rootLogger=INFO,Stdout + +log4j.logger.org.apache.wicket=INFO +log4j.logger.org.apache.wicket.protocol.http.HttpSessionStore=INFO +log4j.logger.org.apache.wicket.version=INFO +log4j.logger.org.apache.wicket.RequestCycle=INFO + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..a52d6b6cbe --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..3783b7bf82 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld-wicket/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,50 @@ + + + + + Apache Tuscany Helloworld Wicket Sample + + + org.apache.tuscany.sca.host.webapp.TuscanyContextListener + + + + + + wicket.tuscany + org.apache.wicket.protocol.http.WicketFilter + + applicationClassName + sample.wicket.WicketApplication + + + + + wicket.tuscany + /* + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/pom.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/pom.xml new file mode 100644 index 0000000000..618c941e5a --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-M4 + ../../pom.xml + + + helloworld + Apache Tuscany SCA Sample Helloworld + war + + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-M4 + compile + + + + org.apache.tuscany.sca + tuscany-host-webapp + 2.0-M4 + runtime + + + + + + ${artifactId} + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldService.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldService.java new file mode 100644 index 0000000000..53ff7a5ca1 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldService.java @@ -0,0 +1,25 @@ +/* + * 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 sample; + +public interface HelloworldService { + + String sayHello(String name); + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldServiceImpl.java b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldServiceImpl.java new file mode 100644 index 0000000000..8d220029a5 --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/java/sample/HelloworldServiceImpl.java @@ -0,0 +1,38 @@ +/* + * 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 sample; + +import org.oasisopen.sca.annotation.EagerInit; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Scope; + +@EagerInit +@Scope("COMPOSITE") +public class HelloworldServiceImpl implements HelloworldService { + + public String sayHello(String name) { + return "Hello " + name; + } + + @Init + public void init() { + System.out.println(sayHello("world")); + } + +} diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.composite b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..045aa4674f --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.xml b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..d7b237641c --- /dev/null +++ b/tags/java/sca/2.0-M4-RC2/samples/webapps/helloworld/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,37 @@ + + + + + Apache Tuscany Helloworld Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + -- cgit v1.2.3