From 4f6a51d428d96dbb476d8412143748e841993372 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 20 Sep 2010 12:32:50 +0000 Subject: Copy trunk samples to sanbox to experiment with renames and moves git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@998905 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/sca-features/binding-comet/deploy.sh | 20 ++ sandbox/samples/sca-features/binding-comet/pom.xml | 56 ++++ .../apache/tuscany/sca/sample/comet/Helper.java | 34 +++ .../tuscany/sca/sample/comet/HumidityService.java | 31 ++ .../sca/sample/comet/PrecipitationService.java | 31 ++ .../sca/sample/comet/PrecipitationServiceImpl.java | 39 +++ .../comet/TemperatureHumidityServiceImpl.java | 48 ++++ .../sca/sample/comet/TemperatureService.java | 34 +++ .../tuscany/sca/sample/comet/model/Location.java | 43 +++ .../tuscany/sca/sample/comet/model/Response.java | 45 +++ .../src/main/webapp/META-INF/MANIFEST.MF | 2 + .../src/main/webapp/WEB-INF/appengine-web.xml | 24 ++ .../src/main/webapp/WEB-INF/web.composite | 45 +++ .../binding-comet/src/main/webapp/WEB-INF/web.xml | 34 +++ .../binding-comet/src/main/webapp/index.html | 157 +++++++++++ .../samples/sca-features/binding-jsonrpc/README | 1 + .../contribution-calculator-webapp/build-dojo.xml | 64 +++++ .../contribution-calculator-webapp/pom.xml | 126 +++++++++ .../src/main/java/calculator/AddBean.java | 90 ++++++ .../src/main/java/calculator/AddService.java | 32 +++ .../src/main/java/calculator/AddServiceImpl.java | 44 +++ .../main/java/calculator/CalculatorService.java | 37 +++ .../java/calculator/CalculatorServiceImpl.java | 86 ++++++ .../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/webapp/WEB-INF/web.composite | 53 ++++ .../src/main/webapp/WEB-INF/web.xml | 41 +++ .../src/main/webapp/calculate.html | 62 ++++ .../test/java/calculator/CalculatorTestCase.java | 50 ++++ .../binding-jsonrpc/contribution-calculator/README | 26 ++ .../contribution-calculator/build.xml | 57 ++++ .../contribution-calculator/pom.xml | 58 ++++ .../src/main/java/calculator/AddBean.java | 88 ++++++ .../src/main/java/calculator/AddService.java | 32 +++ .../src/main/java/calculator/AddServiceImpl.java | 43 +++ .../src/main/java/calculator/CalculatorClient.java | 52 ++++ .../main/java/calculator/CalculatorService.java | 37 +++ .../java/calculator/CalculatorServiceImpl.java | 86 ++++++ .../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 | 53 ++++ .../src/main/resources/CalculatorClient.composite | 30 ++ .../main/resources/META-INF/sca-contribution.xml | 24 ++ .../test/java/calculator/CalculatorTestCase.java | 50 ++++ .../samples/sca-features/binding-jsonrpc/pom.xml | 43 +++ sandbox/samples/sca-features/binding-rmi/README | 1 + .../contribution-calculator-reference/README | 34 +++ .../contribution-calculator-reference/build.xml | 59 ++++ .../contribution-calculator-reference/pom.xml | 74 +++++ .../src/main/java/calculator/AddService.java | 28 ++ .../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 ++++ .../contribution-calculator-service/README | 28 ++ .../contribution-calculator-service/build.xml | 59 ++++ .../contribution-calculator-service/pom.xml | 74 +++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 30 ++ .../src/main/java/calculator/CalculatorClient.java | 40 +++ .../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 +++++ sandbox/samples/sca-features/binding-rmi/pom.xml | 44 +++ sandbox/samples/sca-features/binding-sca/README | 1 + .../binding-sca/contribution-calculator/README | 26 ++ .../binding-sca/contribution-calculator/build.xml | 57 ++++ .../binding-sca/contribution-calculator/pom.xml | 58 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 38 +++ .../src/main/java/calculator/CalculatorClient.java | 52 ++++ .../main/java/calculator/CalculatorService.java | 37 +++ .../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 ++++ .../src/main/resources/CalculatorClient.composite | 30 ++ .../main/resources/META-INF/sca-contribution.xml | 24 ++ .../test/java/calculator/CalculatorTestCase.java | 50 ++++ sandbox/samples/sca-features/binding-sca/pom.xml | 43 +++ sandbox/samples/sca-features/binding-ws/README | 1 + .../binding-ws/contribution-calculator/README | 25 ++ .../binding-ws/contribution-calculator/build.xml | 55 ++++ .../contribution-calculator/calculator.odg | Bin 0 -> 12477 bytes .../contribution-calculator/calculator.png | Bin 0 -> 41196 bytes .../binding-ws/contribution-calculator/pom.xml | 54 ++++ .../src/main/java/calculator/AddService.java | 31 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 +++ .../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 ++++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../test/java/calculator/CalculatorTestCase.java | 50 ++++ sandbox/samples/sca-features/binding-ws/pom.xml | 43 +++ .../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 | 196 +++++++++++++ .../dosgi-dynamic-calculator-operations/pom.xml | 148 ++++++++++ .../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 +++++++ .../dynamic/dosgi-dynamic-calculator/LICENSE | 205 ++++++++++++++ .../dosgi-dynamic-calculator/META-INF/MANIFEST.MF | 23 ++ .../dynamic/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 +++ .../dynamic/dosgi-dynamic-calculator/README | 145 ++++++++++ .../dosgi-dynamic-calculator/dosgi-calculator.png | Bin 0 -> 85103 bytes .../dynamic/dosgi-dynamic-calculator/pom.xml | 153 ++++++++++ .../java/calculator/dosgi/CalculatorService.java | 36 +++ .../calculator/dosgi/impl/CalculatorActivator.java | 78 ++++++ .../dosgi/impl/CalculatorServiceDSImpl.java | 114 ++++++++ .../dosgi/impl/CalculatorServiceImpl.java | 99 +++++++ .../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-features/distributed-osgi/dynamic/pom.xml | 44 +++ .../dosgi-calculator-operations/LICENSE | 205 ++++++++++++++ .../META-INF/MANIFEST.MF | 22 ++ .../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 | 54 ++++ .../OSGI-INF/sca/bundle.composite | 43 +++ .../OSGI-INF/subtract-component.xml | 25 ++ .../dosgi-calculator-operations/README | 185 ++++++++++++ .../dosgi-calculator-operations/pom.xml | 148 ++++++++++ .../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 +++++++ .../implementation.osgi/dosgi-calculator/LICENSE | 205 ++++++++++++++ .../dosgi-calculator/META-INF/MANIFEST.MF | 20 ++ .../implementation.osgi/dosgi-calculator/NOTICE | 6 + .../OSGI-INF/blueprint/calculator-module.xml | 43 +++ .../OSGI-INF/calculator-component.xml | 36 +++ .../OSGI-INF/sca/bundle.componentType | 64 +++++ .../dosgi-calculator/OSGI-INF/sca/bundle.composite | 45 +++ .../implementation.osgi/dosgi-calculator/README | 143 ++++++++++ .../dosgi-calculator/dosgi-calculator.png | Bin 0 -> 85103 bytes .../implementation.osgi/dosgi-calculator/pom.xml | 153 ++++++++++ .../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 | 152 ++++++++++ .../java/calculator/dosgi/test/OSGiTestUtils.java | 105 +++++++ .../distributed-osgi/implementation.osgi/pom.xml | 44 +++ .../samples/sca-features/distributed-osgi/pom.xml | 44 +++ .../sca-features/implementation-extension/README | 8 + .../sca-features/implementation-extension/pom.xml | 79 ++++++ .../src/main/java/sample/api/Java.java | 34 +++ .../src/main/java/sample/api/WSDL.java | 34 +++ .../src/main/java/sample/api/WSDLReference.java | 28 ++ .../src/main/java/sample/impl/EmbedUtil.java | 311 +++++++++++++++++++++ .../src/main/java/sample/impl/ImplUtil.java | 148 ++++++++++ .../java/sample/impl/SampleImplementation.java | 41 +++ .../sample/impl/SampleImplementationProcessor.java | 174 ++++++++++++ .../main/java/sample/impl/SampleJavaInvoker.java | 52 ++++ .../src/main/java/sample/impl/SampleProvider.java | 91 ++++++ .../java/sample/impl/SampleProviderFactory.java | 48 ++++ .../main/java/sample/impl/SampleWSDLInvoker.java | 56 ++++ .../src/main/java/sample/impl/SampleWSDLProxy.java | 57 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 20 ++ ...any.sca.contribution.processor.ValidationSchema | 18 ++ ...cany.sca.provider.ImplementationProviderFactory | 20 ++ .../src/main/resources/sample/impl/sample.xsd | 38 +++ .../src/test/java/sample/Client.java | 35 +++ .../src/test/java/sample/ClientTest.java | 65 +++++ .../src/test/java/sample/Hello.java | 33 +++ .../src/test/java/sample/JelloTest.java | 40 +++ .../src/test/java/sample/Upper.java | 33 +++ .../src/test/java/sample/UpperTest.java | 37 +++ .../src/test/java/sample/WelloTest.java | 59 ++++ .../src/test/java/sample/Xutil.java | 225 +++++++++++++++ .../src/test/java/sample/impl/EmbedTestCase.java | 151 ++++++++++ .../test/java/sample/impl/ReadWriteTestCase.java | 84 ++++++ .../src/test/java/sample/impl/RunTestCase.java | 75 +++++ .../src/test/java/sample/impl/RunWSTestCase.java | 120 ++++++++ .../src/test/java/sample/impl/TestUtil.java | 31 ++ .../src/test/resources/Hello.wsdl | 62 ++++ .../src/test/resources/Upper.wsdl | 62 ++++ .../src/test/resources/test.composite | 60 ++++ .../sca-features/implementation-java/README | 1 + .../contribution-calculator/README | 25 ++ .../contribution-calculator/build.xml | 56 ++++ .../contribution-calculator/pom.xml | 58 ++++ .../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 | 37 +++ .../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 | 49 ++++ .../src/main/resources/CalculatorClient.composite | 30 ++ .../main/resources/META-INF/sca-contribution.xml | 24 ++ .../test/java/calculator/CalculatorTestCase.java | 49 ++++ .../sca-features/implementation-java/pom.xml | 43 +++ .../sca-features/implementation-script/README | 1 + .../contribution-calculator/README | 26 ++ .../contribution-calculator/build.xml | 57 ++++ .../contribution-calculator/pom.xml | 58 ++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/CalculatorClient.java | 52 ++++ .../main/java/calculator/CalculatorService.java | 37 +++ .../java/calculator/CalculatorServiceImpl.java | 72 +++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../src/main/resources/Calculator.composite | 50 ++++ .../src/main/resources/CalculatorClient.composite | 30 ++ .../main/resources/META-INF/sca-contribution.xml | 24 ++ .../calculator/AddServiceImpl.componentType | 30 ++ .../main/resources/calculator/AddServiceImpl.js | 22 ++ .../calculator/DivideServiceImpl.componentType | 30 ++ .../resources/calculator/DivideServiceImpl.groovy | 22 ++ .../calculator/MultiplyServiceImpl.componentType | 30 ++ .../resources/calculator/MultiplyServiceImpl.py | 20 ++ .../calculator/SubtractServiceImpl.componentType | 30 ++ .../resources/calculator/SubtractServiceImpl.rb | 21 ++ .../sca-features/implementation-script/pom.xml | 43 +++ sandbox/samples/sca-features/pom.xml | 54 ++++ .../sca-client/calculator-scaclient/README | 13 + .../sca-client/calculator-scaclient/pom.xml | 69 +++++ .../main/java/calculator/CalculatorService.java | 38 +++ .../src/main/java/sample/CalculatorSCAClient.java | 53 ++++ sandbox/samples/sca-features/sca-client/pom.xml | 45 +++ 307 files changed, 15727 insertions(+) create mode 100755 sandbox/samples/sca-features/binding-comet/deploy.sh create mode 100644 sandbox/samples/sca-features/binding-comet/pom.xml create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/Helper.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Location.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Response.java create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/webapp/META-INF/MANIFEST.MF create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/appengine-web.xml create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.composite create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/samples/sca-features/binding-comet/src/main/webapp/index.html create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/README create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/build-dojo.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/pom.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddBean.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.composite create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/calculate.html create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/README create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/build.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddBean.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/CalculatorClient.composite create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sandbox/samples/sca-features/binding-jsonrpc/pom.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/README create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/README create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/build.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/pom.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/resources/CalculatorRMIReference.composite create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/README create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/build.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/pom.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/CalculatorRMIServer.composite create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/test/java/calculator/CalculatorRMIServerTestCase.java create mode 100644 sandbox/samples/sca-features/binding-rmi/pom.xml create mode 100644 sandbox/samples/sca-features/binding-sca/README create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/README create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/build.xml create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/CalculatorClient.composite create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/binding-sca/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sandbox/samples/sca-features/binding-sca/pom.xml create mode 100644 sandbox/samples/sca-features/binding-ws/README create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/README create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/build.xml create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.odg create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.png create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/binding-ws/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sandbox/samples/sca-features/binding-ws/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/LICENSE create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/NOTICE create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/README create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/LICENSE create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/META-INF/MANIFEST.MF create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/NOTICE create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/README create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/dosgi-calculator.png create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/OSGiTestUtils.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/dynamic/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/LICENSE create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/META-INF/MANIFEST.MF create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/NOTICE create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/add-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/divide-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/multiply-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/subtract-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/README create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/LICENSE create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/META-INF/MANIFEST.MF create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/NOTICE create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/calculator-component.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.componentType create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.composite create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/README create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/dosgi-calculator.png create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/OSGiTestUtils.java create mode 100644 sandbox/samples/sca-features/distributed-osgi/implementation.osgi/pom.xml create mode 100644 sandbox/samples/sca-features/distributed-osgi/pom.xml create mode 100644 sandbox/samples/sca-features/implementation-extension/README create mode 100644 sandbox/samples/sca-features/implementation-extension/pom.xml create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/Java.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDL.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDLReference.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/EmbedUtil.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/ImplUtil.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementation.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleJavaInvoker.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProvider.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProviderFactory.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLInvoker.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLProxy.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sandbox/samples/sca-features/implementation-extension/src/main/resources/sample/impl/sample.xsd create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Client.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/ClientTest.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Hello.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/JelloTest.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Upper.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/UpperTest.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/WelloTest.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Xutil.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunTestCase.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/TestUtil.java create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/resources/Hello.wsdl create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/resources/Upper.wsdl create mode 100644 sandbox/samples/sca-features/implementation-extension/src/test/resources/test.composite create mode 100644 sandbox/samples/sca-features/implementation-java/README create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/README create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/build.xml create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/CalculatorClient.composite create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/implementation-java/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sandbox/samples/sca-features/implementation-java/pom.xml create mode 100644 sandbox/samples/sca-features/implementation-script/README create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/README create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/build.xml create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/pom.xml create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/CalculatorClient.composite create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.componentType create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.js create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.componentType create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.groovy create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.componentType create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.py create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.componentType create mode 100644 sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.rb create mode 100644 sandbox/samples/sca-features/implementation-script/pom.xml create mode 100644 sandbox/samples/sca-features/pom.xml create mode 100644 sandbox/samples/sca-features/sca-client/calculator-scaclient/README create mode 100644 sandbox/samples/sca-features/sca-client/calculator-scaclient/pom.xml create mode 100644 sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/sample/CalculatorSCAClient.java create mode 100644 sandbox/samples/sca-features/sca-client/pom.xml (limited to 'sandbox/samples/sca-features') diff --git a/sandbox/samples/sca-features/binding-comet/deploy.sh b/sandbox/samples/sca-features/binding-comet/deploy.sh new file mode 100755 index 0000000000..eb53bd5c76 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/deploy.sh @@ -0,0 +1,20 @@ +# 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 + +#!/bin/bash + +mvn clean install +appcfg.sh update target/comet-webapp \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-comet/pom.xml b/sandbox/samples/sca-features/binding-comet/pom.xml new file mode 100644 index 0000000000..5f28205da4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + org.apache.tuscany.sca + sample-binding-comet + war + 1.0 + Apache Tuscany SCA Sample binding.comet + + + + org.apache.tuscany.sca.shades + tuscany-base-nodep + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-comet-runtime + 2.0-SNAPSHOT + jar + + + javax + javaee-web-api + 6.0 + provided + + + + + diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/Helper.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/Helper.java new file mode 100644 index 0000000000..eecc6044ea --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/Helper.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 org.apache.tuscany.sca.sample.comet; + +import java.util.Date; +import java.util.Random; + +public final class Helper { + + public static int randomInt(final int max) { + return (new Random(new Date().getTime()).nextInt(100)); + } + + private Helper() { + } + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.java new file mode 100644 index 0000000000..00cbe73e82 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/HumidityService.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 org.apache.tuscany.sca.sample.comet; + +import org.apache.tuscany.sca.sample.comet.model.Location; +import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HumidityService { + + Response getHumidity(Location location); + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.java new file mode 100644 index 0000000000..afbdcbc8d7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationService.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 org.apache.tuscany.sca.sample.comet; + +import org.apache.tuscany.sca.sample.comet.model.Location; +import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface PrecipitationService { + + Response getPrecipitation(Location location); + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.java new file mode 100644 index 0000000000..4278ef975b --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/PrecipitationServiceImpl.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 org.apache.tuscany.sca.sample.comet; + +import java.util.Date; + +import org.apache.tuscany.sca.sample.comet.model.Location; +import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Service; + +@Service(PrecipitationService.class) +public class PrecipitationServiceImpl implements PrecipitationService { + + @Override + public Response getPrecipitation(final Location location) { + final Response response = new Response(); + response.setDate(new Date()); + response.setData(Helper.randomInt(100) + "%"); + return response; + } + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.java new file mode 100644 index 0000000000..55f935fa9f --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureHumidityServiceImpl.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 org.apache.tuscany.sca.sample.comet; + +import java.util.Date; + +import org.apache.tuscany.sca.sample.comet.model.Location; +import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Service; + +@Service({TemperatureService.class, HumidityService.class}) +public class TemperatureHumidityServiceImpl implements TemperatureService, HumidityService { + + @Override + public Response getHumidity(final Location location) { + final Response response = new Response(); + response.setDate(new Date()); + response.setData(Helper.randomInt(90) + "%"); + return response; + } + + @Override + public Response getTemperature(final Location location, final int scale) { + final Response response = new Response(); + response.setDate(new Date()); + final String data = "" + Helper.randomInt(scale == TemperatureService.CELSIUS ? 40 : 150); + response.setData(data); + return response; + } + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.java new file mode 100644 index 0000000000..092988213b --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/TemperatureService.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 org.apache.tuscany.sca.sample.comet; + +import org.apache.tuscany.sca.sample.comet.model.Location; +import org.apache.tuscany.sca.sample.comet.model.Response; +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface TemperatureService { + + public static final int CELSIUS = 1; + public static final int FAHRENHEIT = 2; + + Response getTemperature(Location location, int scale); + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Location.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Location.java new file mode 100644 index 0000000000..ff2da3a360 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Location.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 org.apache.tuscany.sca.sample.comet.model; + +public class Location { + + private String city; + private String country; + + public String getCity() { + return this.city; + } + + public void setCity(final String city) { + this.city = city; + } + + public String getCountry() { + return this.country; + } + + public void setCountry(final String country) { + this.country = country; + } + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Response.java b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Response.java new file mode 100644 index 0000000000..aaa23f0b8a --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/java/org/apache/tuscany/sca/sample/comet/model/Response.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 org.apache.tuscany.sca.sample.comet.model; + +import java.util.Date; + +public class Response { + + private Date date; + private String data; + + public Date getDate() { + return this.date; + } + + public void setDate(final Date date) { + this.date = date; + } + + public String getData() { + return this.data; + } + + public void setData(final String data) { + this.data = data; + } + +} diff --git a/sandbox/samples/sca-features/binding-comet/src/main/webapp/META-INF/MANIFEST.MF b/sandbox/samples/sca-features/binding-comet/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..58630c02ef --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/appengine-web.xml b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/appengine-web.xml new file mode 100644 index 0000000000..8696f76c50 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/appengine-web.xml @@ -0,0 +1,24 @@ + + + + tuscany-comet + 1 + true + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.composite b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..05b2ddd0d7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.xml b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..25b06c457a --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + Apache Tuscany Stock Comet Sample + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + true + + + tuscany + /* + + + index.html + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-comet/src/main/webapp/index.html b/sandbox/samples/sca-features/binding-comet/src/main/webapp/index.html new file mode 100644 index 0000000000..0387e67adb --- /dev/null +++ b/sandbox/samples/sca-features/binding-comet/src/main/webapp/index.html @@ -0,0 +1,157 @@ + + + + Apache Tuscany Comet Sample + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/README b/sandbox/samples/sca-features/binding-jsonrpc/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/build-dojo.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/build-dojo.xml new file mode 100644 index 0000000000..36714c67fc --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/build-dojo.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/pom.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/pom.xml new file mode 100644 index 0000000000..586937b5e5 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/pom.xml @@ -0,0 +1,126 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-jsonrpc-calculator-webapp + Apache Tuscany SCA Sample Contribution binding-jsonrpc Calculator WebApp + war + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webapp + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-json + 2.0-SNAPSHOT + + + + org.dojotoolkit + dojo + 1.3.0 + zip + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + org.apache.maven.plugins + maven-antrun-plugin + + + copy-dojo-files + generate-resources + + run + + + + + + + + + + + + clean-dojo-files + clean + + run + + + + + + + + + + + + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddBean.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddBean.java new file mode 100644 index 0000000000..71724ee7ae --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddBean.java @@ -0,0 +1,90 @@ +/* + * 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; + +public class AddBean { + private static final String DEFAULT_S = "default string"; + private static final Boolean DEFAULT_B = false; + + protected double n1; + protected double n2; + protected double n3; + + protected Boolean b; + protected String s; + protected int x; + protected Integer y; + + public double getN1() { + return n1; + } + + public void setN1(double n1) { + this.n1 = n1; + } + + public double getN2() { + return n2; + } + + public void setN2(double n2) { + this.n2 = n2; + } + + public double getN3() { + return n3; + } + + public void setN3(double n3) { + this.n3 = n3; + } + + public Boolean getB() { + return b; + } + + public void setB(Boolean b) { + this.b = b; + } + + public String getS() { + return s; + } + + public void setS(String s) { + this.s = s; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public Integer getY() { + return y; + } + + public void setY(Integer y) { + this.y = y; + } +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..03e844d09c --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddService.java @@ -0,0 +1,32 @@ +/* + * 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); + AddBean addComplexParam(AddBean aBean); + +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e16b352021 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,44 @@ +/* + * 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; + } + + public AddBean addComplexParam(AddBean aBean) { + aBean.setN3(aBean.getN1() + aBean.getN2()); + System.out.println("Adding " + aBean.getN1() + " to " + aBean.getN1() + " gives " + aBean.getN3()); + return aBean; + } + +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..78eea39c71 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorService.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; + +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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..d32cc73815 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,86 @@ +/* + * 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) { + AddBean aBean = new AddBean(); + // So data to test different types + aBean.setB(true); + aBean.setS("Fred"); + aBean.setX(27); + aBean.setY(58); + + // the numbers to be added + aBean.setN1(n1); + aBean.setN2(n2); + + aBean = addService.addComplexParam(aBean); + + return aBean.getN3(); + //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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..ef6a8b375b --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..ddd7b9cc6e --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..cc0de498d3 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..56ee372fc4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..22e95f7f54 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.composite b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..dc0df8756c --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..b7e216baf7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + Apache Tuscany Contribution binding-jsonrpc Calculator WebApp Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + calculate.html + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/calculate.html b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/calculate.html new file mode 100644 index 0000000000..6d22806e8f --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/main/webapp/calculate.html @@ -0,0 +1,62 @@ + + + + + Apache Tuscany binding-jsonrpc Calculator WebApp with DOJO Sample + + + + + + + + + +

Apache Tuscany binding-jsonrpc Calculator WebApp with DOJO Sample

+ + 1 + 1 = + + +
+ + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/test/java/calculator/CalculatorTestCase.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..1952eb4a6e --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator-webapp/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,50 @@ +/* + * 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.junit.Test; + +/** + * A unit test of the basic Java implementation classes in this contribution + * without using SCA + */ +public class CalculatorTestCase { + + @Test + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); + } +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/README b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/README new file mode 100644 index 0000000000..1e5bc9c584 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/README @@ -0,0 +1,26 @@ +Calculator Sample Contribution +============================== + +This sample contribution implements a simple calculator using SCA components. + +The README in the /samples directory provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + +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. + +Amongst the other output created by the launcher/contribution combination, you should see the following output ... + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/build.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/build.xml new file mode 100644 index 0000000000..7d0ce122dd --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/build.xml @@ -0,0 +1,57 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/pom.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/pom.xml new file mode 100644 index 0000000000..7e08ce52be --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-jsonrpc-calculator + Apache Tuscany SCA Sample Contribution binding-jsonrpc Calculator + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddBean.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddBean.java new file mode 100644 index 0000000000..bb39e961b4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddBean.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; + +public class AddBean { + + protected double n1; + protected double n2; + protected double n3; + + protected Boolean b; + protected String s; + protected int x; + protected Integer y; + + public double getN1() { + return n1; + } + + public void setN1(double n1) { + this.n1 = n1; + } + + public double getN2() { + return n2; + } + + public void setN2(double n2) { + this.n2 = n2; + } + + public double getN3() { + return n3; + } + + public void setN3(double n3) { + this.n3 = n3; + } + + public Boolean getB() { + return b; + } + + public void setB(Boolean b) { + this.b = b; + } + + public String getS() { + return s; + } + + public void setS(String s) { + this.s = s; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public Integer getY() { + return y; + } + + public void setY(Integer y) { + this.y = y; + } +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..03e844d09c --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddService.java @@ -0,0 +1,32 @@ +/* + * 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); + AddBean addComplexParam(AddBean aBean); + +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..8eabfa6773 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/AddServiceImpl.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; + +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; + } + + public AddBean addComplexParam(AddBean aBean) { + aBean.setN3(aBean.getN1() + aBean.getN2()); + return aBean; + } + +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorClient.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..1df1f31c48 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..78eea39c71 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorService.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; + +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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..d32cc73815 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,86 @@ +/* + * 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) { + AddBean aBean = new AddBean(); + // So data to test different types + aBean.setB(true); + aBean.setS("Fred"); + aBean.setX(27); + aBean.setY(58); + + // the numbers to be added + aBean.setN1(n1); + aBean.setN2(n2); + + aBean = addService.addComplexParam(aBean); + + return aBean.getN3(); + //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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..ef6a8b375b --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..ddd7b9cc6e --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..cc0de498d3 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..56ee372fc4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..22e95f7f54 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-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/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/Calculator.composite b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..5f1add2431 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/CalculatorClient.composite b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/CalculatorClient.composite new file mode 100644 index 0000000000..dfd32761be --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/CalculatorClient.composite @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..70aab0e051 --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..1952eb4a6e --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,50 @@ +/* + * 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.junit.Test; + +/** + * A unit test of the basic Java implementation classes in this contribution + * without using SCA + */ +public class CalculatorTestCase { + + @Test + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); + } +} diff --git a/sandbox/samples/sca-features/binding-jsonrpc/pom.xml b/sandbox/samples/sca-features/binding-jsonrpc/pom.xml new file mode 100644 index 0000000000..52d05e075b --- /dev/null +++ b/sandbox/samples/sca-features/binding-jsonrpc/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-binding-jsonrpc + pom + Apache Tuscany SCA Sample binding.jsonrpc + + + + default + + true + + + contribution-calculator + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/README b/sandbox/samples/sca-features/binding-rmi/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/README b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/README new file mode 100644 index 0000000000..2f169419ba --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/README @@ -0,0 +1,34 @@ +Calculator RMI Reference Sample Contribution +============================================ + +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 provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + +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. +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. + +Amongst the other output created by the launcher/contribution combination, you should see the following output ... + + + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/build.xml b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/build.xml new file mode 100644 index 0000000000..fe28a46b7c --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/build.xml @@ -0,0 +1,59 @@ + + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/pom.xml b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/pom.xml new file mode 100644 index 0000000000..c10d764ff1 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-rmi-calculator-reference + Apache Tuscany SCA Sample Contribution binding-rmi Calculator Reference + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + test + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-SNAPSHOT + runtime + + + junit + junit + 4.8.1 + test + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..0f7dec116f --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..bcfd8871b6 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/resources/CalculatorRMIReference.composite b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/resources/CalculatorRMIReference.composite new file mode 100644 index 0000000000..7455dc7d38 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/main/resources/CalculatorRMIReference.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java new file mode 100644 index 0000000000..39d4b2fd28 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java new file mode 100644 index 0000000000..d8ded42cb2 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/README b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/README new file mode 100644 index 0000000000..cb25027f14 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/README @@ -0,0 +1,28 @@ +Calculator RMI Service Sample Contribution +========================================== + +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 provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + + +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. + +Amongst the other output created by the launcher/contribution combination, you should see the following output ... + + + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/build.xml b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/build.xml new file mode 100644 index 0000000000..888a1c88b7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/build.xml @@ -0,0 +1,59 @@ + + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/pom.xml b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/pom.xml new file mode 100644 index 0000000000..5cd39e96bb --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-rmi-calculator-service + Apache Tuscany SCA Sample Contribution binding-rmi Calculator Service + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + test + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-SNAPSHOT + runtime + + + junit + junit + 4.8.1 + test + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..8b6fe066a6 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorClient.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..2b99485b68 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..3c0375924f --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..bcfd8871b6 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..f7ac0b7287 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..b7dca792b2 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..77b128ab8d --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/CalculatorRMIServer.composite b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/CalculatorRMIServer.composite new file mode 100644 index 0000000000..8b37d407f0 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/CalculatorRMIServer.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..8d6012e5c4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/test/java/calculator/CalculatorRMIServerTestCase.java b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-service/src/test/java/calculator/CalculatorRMIServerTestCase.java new file mode 100644 index 0000000000..0e352db9bb --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/contribution-calculator-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/sandbox/samples/sca-features/binding-rmi/pom.xml b/sandbox/samples/sca-features/binding-rmi/pom.xml new file mode 100644 index 0000000000..073687983d --- /dev/null +++ b/sandbox/samples/sca-features/binding-rmi/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-binding-rmi + pom + Apache Tuscany SCA Sample binding.rmi + + + + default + + true + + + contribution-calculator-reference + contribution-calculator-service + + + + diff --git a/sandbox/samples/sca-features/binding-sca/README b/sandbox/samples/sca-features/binding-sca/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/README b/sandbox/samples/sca-features/binding-sca/contribution-calculator/README new file mode 100644 index 0000000000..4777c5ad88 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/README @@ -0,0 +1,26 @@ +Calculator Sample Contribution +============================== + +This sample contribution implements a simple calculator using SCA components. + +The README in the /samples directory provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + +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. + +Amongst the other output created by the launcher/contribution combination, you should see the following output ... + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/build.xml b/sandbox/samples/sca-features/binding-sca/contribution-calculator/build.xml new file mode 100644 index 0000000000..593e1ba7a4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/build.xml @@ -0,0 +1,57 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/pom.xml b/sandbox/samples/sca-features/binding-sca/contribution-calculator/pom.xml new file mode 100644 index 0000000000..c877155853 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-sca-calculator + Apache Tuscany SCA Sample Contribution binding-sca Calculator + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..bb75bb2337 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorClient.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..afd5ea48fc --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..ce1cdaae5a --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorService.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; + +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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..fc53393d23 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..b1250ed9f2 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..11f68c66e3 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..30e59bf668 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-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/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/Calculator.composite b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..05bea57944 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/CalculatorClient.composite b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/CalculatorClient.composite new file mode 100644 index 0000000000..dfd32761be --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/CalculatorClient.composite @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..3e64787ce4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..9d3024f451 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,50 @@ +/* + * 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.junit.Test; + +/** + * A unit test of the basic Java implementation classes in this contribution + * without using SCA + */ +public class CalculatorTestCase { + + @Test + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); + } +} diff --git a/sandbox/samples/sca-features/binding-sca/pom.xml b/sandbox/samples/sca-features/binding-sca/pom.xml new file mode 100644 index 0000000000..e3cc9d6e43 --- /dev/null +++ b/sandbox/samples/sca-features/binding-sca/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-binding-sca + pom + Apache Tuscany SCA Sample binding.sca + + + + default + + true + + + contribution-calculator + + + + diff --git a/sandbox/samples/sca-features/binding-ws/README b/sandbox/samples/sca-features/binding-ws/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/README b/sandbox/samples/sca-features/binding-ws/contribution-calculator/README new file mode 100644 index 0000000000..a1f34e0e8a --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/README @@ -0,0 +1,25 @@ +Calculator Contribution Sample +============================== + +This directory contains code which implements a simple calculator SCA contribution. + +The contribution can be run as a tuscany application using one of the tuscany launchers +as described in the README in the root directory of the samples. + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The launcher 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. + +You should see the following output (depending on the launcher you use, this output +may be surrounded by other output). + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + + diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/build.xml b/sandbox/samples/sca-features/binding-ws/contribution-calculator/build.xml new file mode 100644 index 0000000000..69661f7b5e --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/build.xml @@ -0,0 +1,55 @@ + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.odg b/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.odg new file mode 100644 index 0000000000..c2646f7d5e Binary files /dev/null and b/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.odg differ diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.png b/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.png new file mode 100644 index 0000000000..476306e5f0 Binary files /dev/null and b/sandbox/samples/sca-features/binding-ws/contribution-calculator/calculator.png differ diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/pom.xml b/sandbox/samples/sca-features/binding-ws/contribution-calculator/pom.xml new file mode 100644 index 0000000000..a177a043d5 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-binding-ws-calculator + Apache Tuscany SCA Sample Contribution binding-ws Calculator + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + + + diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..138213b5fc --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..caf4d358df --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..ad87375529 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..d3fa7a8f41 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..ef6a8b375b --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..cd91935f08 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..c85357fcd8 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..56ee372fc4 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..1b669084d9 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-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/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/Calculator.composite b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..3688ebcb85 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..3a7548cd47 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..1952eb4a6e --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java @@ -0,0 +1,50 @@ +/* + * 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.junit.Test; + +/** + * A unit test of the basic Java implementation classes in this contribution + * without using SCA + */ +public class CalculatorTestCase { + + @Test + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); + } +} diff --git a/sandbox/samples/sca-features/binding-ws/pom.xml b/sandbox/samples/sca-features/binding-ws/pom.xml new file mode 100644 index 0000000000..bfac74c8c0 --- /dev/null +++ b/sandbox/samples/sca-features/binding-ws/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-binding-ws + pom + Apache Tuscany SCA Sample binding.ws + + + + default + + true + + + contribution-calculator + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/LICENSE b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..cea4e2ff79 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/NOTICE b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/NOTICE new file mode 100644 index 0000000000..9ddba06a32 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2010 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml new file mode 100644 index 0000000000..99845257ff --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/add-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml new file mode 100644 index 0000000000..f6b5f4690e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/blueprint/operations-module.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml new file mode 100644 index 0000000000..322d4daf2f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/divide-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml new file mode 100644 index 0000000000..b9ca777bd8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/multiply-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml new file mode 100644 index 0000000000..1965b571a9 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/sca-config/operations-config.xml @@ -0,0 +1,29 @@ + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml new file mode 100644 index 0000000000..1472f5a976 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/OSGI-INF/subtract-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/README b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/README new file mode 100644 index 0000000000..77a4cbae9e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/README @@ -0,0 +1,196 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the /samples directory provides +general instructions about building and running samples. (where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive). Take a look there first (noting at you read it that this sample +is not a new style sample). + +On Windows, run +java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.5.0-v20090520.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +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-dynamic-calculator-operations.jar +Bundle id is 198 + +osgi> start 198 +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Starting calculator.dosgi.dynamic.operations_1.0.0 [198] +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.AddService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: urn:osgi.service.d3cadb93-e9b9-4486-87eb-07ece11888f6 domai +n: tuscany.apache.org +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/AddService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@8144744)Endpoint: URI = osgi.service.d3cadb93-e9b9-4486- +87eb-07ece11888f6#service-binding(AddService/Add) +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.SubtractService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: urn:osgi.service.b6259ccc-6ae4-41f0-b61b-c5a8c7f42b35 domai +n: tuscany.apache.org +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/SubtractService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@30229114)Endpoint: URI = osgi.service.b6259ccc-6ae4-41f0 +-b61b-c5a8c7f42b35#service-binding(SubtractService/Subtract) +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.MultiplyService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: urn:osgi.service.8469c64c-9a28-47b3-bc4a-c5fa8d471057 domai +n: tuscany.apache.org +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/MultiplyService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@3312704)Endpoint: URI = osgi.service.8469c64c-9a28-47b3- +bc4a-c5fa8d471057#service-binding(MultiplyService/Multiply) +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.DivideService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98 domai +n: tuscany.apache.org +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/DivideService +Nov 4, 2009 5:16:51 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@8010288)Endpoint: URI = osgi.service.b43555f0-9509-444e- +b22a-06d347ab7e98#service-binding(DivideService/Divide) +Nov 4, 2009 5:16:51 PM calculator.dosgi.operations.impl.OperationsActivator getB +undle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi.dynamic.operations + +osgi> + +To stop the bundle: + +osgi> stop 198 +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98 +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@8010288)Endpoint: URI = osgi.service.b43555f0-9509-44 +4e-b22a-06d347ab7e98#service-binding(DivideService/Divide) +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/DivideService +Nov 4, 2009 5:18:43 PM calculator.dosgi.operations.impl.OperationsActivator stop + +INFO: Stopping calculator.dosgi.dynamic.operations_1.0.0 [198] +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.d3cadb93-e9b9-4486-87eb-07ece11888f6 +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@8144744)Endpoint: URI = osgi.service.d3cadb93-e9b9-44 +86-87eb-07ece11888f6#service-binding(AddService/Add) +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/AddService +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.b6259ccc-6ae4-41f0-b61b-c5a8c7f42b35 +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@30229114)Endpoint: URI = osgi.service.b6259ccc-6ae4-4 +1f0-b61b-c5a8c7f42b35#service-binding(SubtractService/Subtract) +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/SubtractService +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.8469c64c-9a28-47b3-bc4a-c5fa8d471057 +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@3312704)Endpoint: URI = osgi.service.8469c64c-9a28-47 +b3-bc4a-c5fa8d471057#service-binding(MultiplyService/Multiply) +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/MultiplyService +Nov 4, 2009 5:18:43 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.b43555f0-9509-444e-b22a-06d347ab7e98 + +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-dynamic-calculator-operations) + + +dosgi-dynamic-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-config/ + operations-config.xml - The SCA configuration file for OSGi remote services + 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-dynamic-calculator-operations +mvn + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/pom.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/pom.xml new file mode 100644 index 0000000000..926208b388 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + sample-dosgi-dynamic-calculator-operations + Apache Tuscany SCA OSGi Remote Services Dynamic Caculator Operations Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-SNAPSHOT + pom + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-SNAPSHOT + 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.8.1 + 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 + + + + + osgi.configuration.area + ${project.build.directory}/equinox + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java new file mode 100644 index 0000000000..66b2977241 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java new file mode 100644 index 0000000000..a3c21b2b96 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java new file mode 100644 index 0000000000..7922d2d392 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java new file mode 100644 index 0000000000..f75cc6444e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java new file mode 100644 index 0000000000..4bbe83b14f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java new file mode 100644 index 0000000000..cd92989da1 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java new file mode 100644 index 0000000000..02007c385c --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java new file mode 100644 index 0000000000..eee64bf86f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/LICENSE b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/META-INF/MANIFEST.MF b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..6ce24a4a32 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/NOTICE b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/NOTICE new file mode 100644 index 0000000000..9ddba06a32 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2010 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml new file mode 100644 index 0000000000..fd834e12ef --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/blueprint/calculator-module.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml new file mode 100644 index 0000000000..5daaa59aae --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/calculator-component.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml new file mode 100644 index 0000000000..ded82797b5 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + {http://sample}Add + + + + + + + + + + + {http://sample}Subtract + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml new file mode 100644 index 0000000000..f10b577e87 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/OSGI-INF/sca-config/calculator-config.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/README b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/README new file mode 100644 index 0000000000..e8d311298e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/README @@ -0,0 +1,145 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the /samples directory provides +general instructions about building and running samples. (where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive). Take a look there first (noting at you read it that this sample +is not a new style sample). + +On Windows, run +java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.5.0-v20090520.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-dynamic-calculator.jar +Bundle id is 198 + +osgi> start 198 +Nov 4, 2009 5:20:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Starting calculator.dosgi.dynamic_1.0.0 [198] +Nov 4, 2009 5:20:21 PM calculator.dosgi.impl.CalculatorActivator start +INFO: Registering calculator.dosgi.CalculatorService +Nov 4, 2009 5:20:21 PM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: urn:osgi.service.d5a06834-ae15-42b3-9287-71fe6537c869 domai +n: tuscany.apache.org +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +Nov 4, 2009 5:20:24 PM org.mortbay.log.Slf4jLog info +INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mort +bay.log.Slf4jLog +Nov 4, 2009 5:20:25 PM org.apache.tuscany.sca.http.jetty.JettyLogger info +INFO: jetty-6.1.x +Nov 4, 2009 5:20:25 PM org.apache.tuscany.sca.http.jetty.JettyLogger info +INFO: Started SelectChannelConnector@0.0.0.0:8086 +Nov 4, 2009 5:20:25 PM org.apache.tuscany.sca.http.jetty.JettyServer addServletM +apping +INFO: Added Servlet mapping: http://rfengt61p:8086/CalculatorService +Nov 4, 2009 5:20:25 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@23394516)Endpoint: URI = osgi.service.d5a06834-ae15-42b3 +-9287-71fe6537c869#service-binding(CalculatorService/Calculator) +Nov 4, 2009 5:20:25 PM calculator.dosgi.impl.CalculatorActivator getBundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi.dynamic + +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 198 +Nov 4, 2009 5:21:16 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.d5a06834-ae15-42b3-9287-71fe6537c869 +Nov 4, 2009 5:21:16 PM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@23394516)Endpoint: URI = osgi.service.d5a06834-ae15-4 +2b3-9287-71fe6537c869#service-binding(CalculatorService/Calculator) +Nov 4, 2009 5:21:16 PM org.apache.tuscany.sca.http.jetty.JettyServer removeServl +etMapping +INFO: Removed Servlet mapping: /CalculatorService +Nov 4, 2009 5:21:16 PM calculator.dosgi.impl.CalculatorActivator stop +INFO: Stopping calculator.dosgi.dynamic_1.0.0 [198] +Nov 4, 2009 5:21:16 PM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: urn:osgi.service.d5a06834-ae15-42b3-9287-71fe6537c869 + +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-dynamic-calculator-operations) + + +dosgi-dynamic-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-config/ + calculator-config.xml - The SCA configuration file for OSGi remote services + remote-service/ + calculator-service-descriptions.xml - The OSGi remote service endpoint descriptions + 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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/dosgi-calculator.png b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/dosgi-calculator.png new file mode 100644 index 0000000000..805baa54d2 Binary files /dev/null and b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/dosgi-calculator.png differ diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/pom.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/pom.xml new file mode 100644 index 0000000000..0394373342 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/pom.xml @@ -0,0 +1,153 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + sample-dosgi-dynamic-calculator + Apache Tuscany SCA OSGi Remote Services Dynamic Caculator Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-SNAPSHOT + pom + + + org.apache.tuscany.sca + tuscany-feature-webservice + 2.0-SNAPSHOT + pom + runtime + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-SNAPSHOT + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + + + + junit + junit + 4.8.1 + 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 + + + + + osgi.configuration.area + ${project.build.directory}/equinox + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/CalculatorService.java new file mode 100644 index 0000000000..cc562b7c2f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java new file mode 100644 index 0000000000..6228afcd53 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java new file mode 100644 index 0000000000..5f9db16ca9 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java new file mode 100644 index 0000000000..aa09b27139 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java @@ -0,0 +1,99 @@ +/* + * 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 java.util.HashMap; +import java.util.Map; + +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 Map, ServiceTracker> remoteServices = new HashMap, ServiceTracker>(); + + public CalculatorServiceImpl() { + super(); + } + + public CalculatorServiceImpl(BundleContext context) { + super(); + for (Class cls : new Class[] {AddService.class, SubtractService.class, MultiplyService.class, + DivideService.class}) { + Filter remoteFilter = null; + try { + remoteFilter = + context.createFilter("(&(" + OBJECTCLASS + "=" + cls.getName() + ") (service.imported=*))"); + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + } + ServiceTracker tracker = new ServiceTracker(context, remoteFilter, null); + this.remoteServices.put(cls, tracker); + tracker.open(); + } + } + + private T getService(Class cls) { + ServiceTracker tracker = remoteServices.get(cls); + try { + // Wait for 10 seconds until the remote services are imported + tracker.waitForService(10000); + } catch (InterruptedException e) { + throw new IllegalStateException(cls.getSimpleName() + " is not available"); + } + Object[] remoteObjects = tracker.getServices(); + if (remoteObjects != null) { + for (Object s : remoteObjects) { + if (cls.isInstance(s)) { + System.out.println("Remote 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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java new file mode 100644 index 0000000000..a4fc52694e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java new file mode 100644 index 0000000000..a813dfb6f3 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/main/java/calculator/rmi/OperationsRemote.java new file mode 100644 index 0000000000..955e386ad8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java new file mode 100644 index 0000000000..565a314d85 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/sandbox/samples/sca-features/distributed-osgi/dynamic/dosgi-dynamic-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java new file mode 100644 index 0000000000..4015c7bbc2 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/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/sandbox/samples/sca-features/distributed-osgi/dynamic/pom.xml b/sandbox/samples/sca-features/distributed-osgi/dynamic/pom.xml new file mode 100644 index 0000000000..c3021a3cc5 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/dynamic/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-samples-distributed-osgi-dynamic + pom + Apache Tuscany SCA Distributed OSGI Dynamically Configured Samples + + + + default + + true + + + dosgi-dynamic-calculator + dosgi-dynamic-calculator-operations + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/LICENSE b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/META-INF/MANIFEST.MF b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..82a803e3a6 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/NOTICE b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/NOTICE new file mode 100644 index 0000000000..9ddba06a32 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2010 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/add-component.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/add-component.xml new file mode 100644 index 0000000000..99845257ff --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/add-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml new file mode 100644 index 0000000000..f6b5f4690e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/blueprint/operations-module.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/divide-component.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/divide-component.xml new file mode 100644 index 0000000000..322d4daf2f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/divide-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/multiply-component.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/multiply-component.xml new file mode 100644 index 0000000000..b9ca777bd8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/multiply-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType new file mode 100644 index 0000000000..fced5b7840 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.componentType @@ -0,0 +1,54 @@ + + + + + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + + + 1 + ABC + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite new file mode 100644 index 0000000000..c7250912b0 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/sca/bundle.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/subtract-component.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/subtract-component.xml new file mode 100644 index 0000000000..1472f5a976 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/OSGI-INF/subtract-component.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/README b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/README new file mode 100644 index 0000000000..57126842a4 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/README @@ -0,0 +1,185 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the /samples directory provides +general instructions about building and running samples. (where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive). Take a look there first (noting at you read it that this sample +is not a new style sample). + +On Windows, run +java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.5.0-v20090520.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 198 + +osgi> start 198 +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Starting calculator.dosgi.operations_1.0.0 [198] +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.AddService +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.SubtractService +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.MultiplyService +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator star +t +INFO: Registering calculator.dosgi.operations.DivideService +Nov 4, 2009 9:51:56 AM calculator.dosgi.operations.impl.OperationsActivator getB +undle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi.operations +Nov 4, 2009 9:51:56 AM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi.operations domain: tuscany.apache.org +Nov 4, 2009 9:51:56 AM org.apache.tuscany.sca.node.impl.NodeFactoryImpl loadCont +ributions +INFO: Loading contribution: bundleentry://198.fwk8152936/ +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/AddService +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@27845948)Endpoint: URI = OperationsComponent#service-bin +ding(AddService/AddService) +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/SubtractService +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@10576215)Endpoint: URI = OperationsComponent#service-bin +ding(SubtractService/SubtractService) +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/MultiplyService +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@31713234)Endpoint: URI = OperationsComponent#service-bin +ding(MultiplyService/MultiplyService) +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost registerSe +rvice +INFO: RMI service registered: rmi://localhost:8085/DivideService +Nov 4, 2009 9:52:00 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@10202447)Endpoint: URI = OperationsComponent#service-bin +ding(DivideService/DivideService) + +osgi> + +To stop the bundle: + +osgi> stop 198 +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi.operations +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@27845948)Endpoint: URI = OperationsComponent#service- +binding(AddService/AddService) +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/AddService +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@10576215)Endpoint: URI = OperationsComponent#service- +binding(SubtractService/SubtractService) +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/SubtractService +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@31713234)Endpoint: URI = OperationsComponent#service- +binding(MultiplyService/MultiplyService) +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/MultiplyService +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@10202447)Endpoint: URI = OperationsComponent#service- +binding(DivideService/DivideService) +Nov 4, 2009 9:53:19 AM org.apache.tuscany.sca.host.rmi.DefaultRMIHost unregister +Service +INFO: RMI service unregistered: rmi://localhost:8085/DivideService +Nov 4, 2009 9:53:19 AM calculator.dosgi.operations.impl.OperationsActivator stop + +INFO: Stopping calculator.dosgi.operations_1.0.0 [198] + +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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/pom.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/pom.xml new file mode 100644 index 0000000000..cf7faab1e8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/pom.xml @@ -0,0 +1,148 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + sample-dosgi-calculator-operations + Apache Tuscany SCA OSGi Remote Services Caculator Operations Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-SNAPSHOT + pom + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-SNAPSHOT + 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.8.1 + 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 + + + + + osgi.configuration.area + ${project.build.directory}/equinox + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/AddServiceImpl.java new file mode 100644 index 0000000000..66b2977241 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/DivideServiceImpl.java new file mode 100644 index 0000000000..a3c21b2b96 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/MultiplyServiceImpl.java new file mode 100644 index 0000000000..7922d2d392 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/OperationsActivator.java new file mode 100644 index 0000000000..da2ce9063a --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/java/calculator/dosgi/operations/impl/SubtractServiceImpl.java new file mode 100644 index 0000000000..4bbe83b14f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d24999ab3e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OSGiTestUtils.java new file mode 100644 index 0000000000..cd92989da1 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsNode.java new file mode 100644 index 0000000000..02007c385c --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/OperationsOSGiNodeTestCase.java new file mode 100644 index 0000000000..49c5aab041 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/LICENSE b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/META-INF/MANIFEST.MF b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..542b53b085 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/NOTICE b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/NOTICE new file mode 100644 index 0000000000..9ddba06a32 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2010 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml new file mode 100644 index 0000000000..fd834e12ef --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/blueprint/calculator-module.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/calculator-component.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/calculator-component.xml new file mode 100644 index 0000000000..5daaa59aae --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/calculator-component.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.componentType b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.componentType new file mode 100644 index 0000000000..1dff21ab6b --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.componentType @@ -0,0 +1,64 @@ + + + + + + + + + + 1 + ABC + + + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + + + 1 + ABC + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.composite b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.composite new file mode 100644 index 0000000000..c64e999fc6 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/OSGI-INF/sca/bundle.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/README b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/README new file mode 100644 index 0000000000..e2cf7cd522 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/README @@ -0,0 +1,143 @@ +Distributed OSGi Calculator Sample +================================== +This sample implements a distributed calculator using Distributed OSGi (RFC 119) over SCA. + +The README in the /samples directory provides +general instructions about building and running samples. (where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive). Take a look there first (noting at you read it that this sample +is not a new style sample). + + +On Windows, run +java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.5.0-v20090520.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +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 198 + +osgi> start 198 +Nov 4, 2009 9:40:00 AM calculator.dosgi.impl.CalculatorActivator start +INFO: Starting calculator.dosgi_1.0.0 [198] +Nov 4, 2009 9:40:01 AM calculator.dosgi.impl.CalculatorActivator start +INFO: Registering calculator.dosgi.CalculatorService +Nov 4, 2009 9:40:01 AM calculator.dosgi.impl.CalculatorActivator getBundle +INFO: calculator.dosgi.operations.AddService is loaded by bundle: calculator.dos +gi +Nov 4, 2009 9:40:01 AM org.apache.tuscany.sca.node.impl.NodeImpl start +INFO: Starting node: calculator.dosgi domain: tuscany.apache.org +Nov 4, 2009 9:40:01 AM org.apache.tuscany.sca.node.impl.NodeFactoryImpl loadCont +ributions +INFO: Loading contribution: bundleentry://198.fwk15020296/ +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +Nov 4, 2009 9:40:47 AM org.mortbay.log.Slf4jLog info +INFO: Logging to org.slf4j.impl.JDK14LoggerAdapter(org.mortbay.log) via org.mort +bay.log.Slf4jLog +Nov 4, 2009 9:40:48 AM org.apache.tuscany.sca.http.jetty.JettyLogger info +INFO: jetty-6.1.x +Nov 4, 2009 9:40:48 AM org.apache.tuscany.sca.http.jetty.JettyLogger info +INFO: Started SelectChannelConnector@0.0.0.0:8086 +Nov 4, 2009 9:40:48 AM org.apache.tuscany.sca.http.jetty.JettyServer addServletM +apping +INFO: Added Servlet mapping: http://rfengt61p:8086/CalculatorService +Nov 4, 2009 9:40:48 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl addEndpoint +INFO: Add endpoint - (@1277930)Endpoint: URI = CalculatorComponent#service-bind +ing(CalculatorService/CalculatorService) +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 198 +Nov 4, 2009 9:41:22 AM org.apache.tuscany.sca.node.impl.NodeImpl stop +INFO: Stopping node: calculator.dosgi +Nov 4, 2009 9:41:22 AM org.apache.tuscany.sca.core.assembly.impl.EndpointRegistr +yImpl endpointRemoved +INFO: Remove endpoint - (@1277930)Endpoint: URI = CalculatorComponent#service-b +inding(CalculatorService/CalculatorService) +Nov 4, 2009 9:41:22 AM org.apache.tuscany.sca.http.jetty.JettyServer removeServl +etMapping +INFO: Removed Servlet mapping: /CalculatorService +Nov 4, 2009 9:41:22 AM calculator.dosgi.impl.CalculatorActivator stop +INFO: Stopping calculator.dosgi_1.0.0 [198] + +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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/dosgi-calculator.png b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/dosgi-calculator.png new file mode 100644 index 0000000000..805baa54d2 Binary files /dev/null and b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/dosgi-calculator.png differ diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/pom.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/pom.xml new file mode 100644 index 0000000000..2e06ff7e05 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/pom.xml @@ -0,0 +1,153 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + sample-dosgi-calculator + Apache Tuscany SCA OSGi Remote Services Calculator Sample + + + + org.apache.tuscany.sca + tuscany-feature-ejava + 2.0-SNAPSHOT + pom + + + org.apache.tuscany.sca + tuscany-feature-webservice + 2.0-SNAPSHOT + pom + runtime + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-node-impl-osgi + 2.0-SNAPSHOT + runtime + + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + + + + junit + junit + 4.8.1 + 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 + + + + + osgi.configuration.area + ${project.build.directory}/equinox + + + + + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/CalculatorService.java new file mode 100644 index 0000000000..cc562b7c2f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java new file mode 100644 index 0000000000..6b42645f69 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceDSImpl.java new file mode 100644 index 0000000000..5f9db16ca9 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java new file mode 100644 index 0000000000..a9ea37585a --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/AddService.java new file mode 100644 index 0000000000..971500782f --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/DivideService.java new file mode 100644 index 0000000000..49b8a1c0bf --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/MultiplyService.java new file mode 100644 index 0000000000..f4e59d12ea --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/dosgi/operations/SubtractService.java new file mode 100644 index 0000000000..bfb9b820f7 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java new file mode 100644 index 0000000000..a4fc52694e --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer_Stub.java new file mode 100644 index 0000000000..a813dfb6f3 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/java/calculator/rmi/OperationsRemote.java new file mode 100644 index 0000000000..955e386ad8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..b48c048000 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorNode.java new file mode 100644 index 0000000000..565a314d85 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java new file mode 100644 index 0000000000..2f37da0707 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java @@ -0,0 +1,152 @@ +/* + * 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); + // debug to print out exported packages + // handy if you want to find aplit packages + //Object exports = b.getHeaders().get(Constants.EXPORT_PACKAGE); + //if (exports != null){ + // System.out.println(exports.toString()); + //} + 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)); + } else { + 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/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/pom.xml b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/pom.xml new file mode 100644 index 0000000000..56d975dea8 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/implementation.osgi/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-samples-distributed-osgi-static + pom + Apache Tuscany SCA Distributed OSGI Statically Configured Samples + + + + default + + true + + + dosgi-calculator + dosgi-calculator-operations + + + + diff --git a/sandbox/samples/sca-features/distributed-osgi/pom.xml b/sandbox/samples/sca-features/distributed-osgi/pom.xml new file mode 100644 index 0000000000..52fc787d75 --- /dev/null +++ b/sandbox/samples/sca-features/distributed-osgi/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-samples-distributed-osgi + pom + Apache Tuscany SCA Distributed OSGI Samples + + + + default + + true + + + implementation.osgi + dynamic + + + + diff --git a/sandbox/samples/sca-features/implementation-extension/README b/sandbox/samples/sca-features/implementation-extension/README new file mode 100644 index 0000000000..3c3ef5e3d5 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/README @@ -0,0 +1,8 @@ +Sample Implementation Extension +=============================== +This sample demonstrates how to develop a new component implementation type +for Apache Tuscany SCA. + +The README in the samples directory (the directory above this) provides +instructions about building and running the samples. Take a look there. + diff --git a/sandbox/samples/sca-features/implementation-extension/pom.xml b/sandbox/samples/sca-features/implementation-extension/pom.xml new file mode 100644 index 0000000000..47aff7e941 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-implementation-extension + Apache Tuscany SCA Sample Implementation Extension + jar + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-web20 + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-webapp + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/Java.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/Java.java new file mode 100644 index 0000000000..6c9240005f --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/Java.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 sample.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target( {TYPE, FIELD}) +@Retention(RUNTIME) +public @interface Java { + + Class value(); +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDL.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDL.java new file mode 100644 index 0000000000..655770ec32 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDL.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 sample.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target( {TYPE, FIELD}) +@Retention(RUNTIME) +public @interface WSDL { + + String value(); +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDLReference.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDLReference.java new file mode 100644 index 0000000000..cad8478a2a --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/api/WSDLReference.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.api; + +import org.w3c.dom.Element; + +public interface WSDLReference { + + Element call(String op, Element e); + +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/EmbedUtil.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/EmbedUtil.java new file mode 100644 index 0000000000..0ccbcc9e36 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/EmbedUtil.java @@ -0,0 +1,311 @@ +/* + * 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.impl; + +import java.net.URI; +import java.net.URL; +import java.util.Arrays; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +/** + * A few utility functions to help embed a Tuscany runtime, and a simple DSL + * to help assemble and run SCDL. + */ +public class EmbedUtil { + + /** + * A runtime embedder context, which conveniently initializes a Node factory + * and gets the various registries, factories and extension points we need. + */ + static class Context { + final NodeFactory nf; + final ExtensionPointRegistry epr; + final FactoryExtensionPoint fep; + final ContributionFactory cf; + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wif; + final URLArtifactProcessorExtensionPoint apep; + final ExtensibleURLArtifactProcessor aproc; + final ModelResolverExtensionPoint mrep; + final ProviderFactoryExtensionPoint pfep; + + Context(final NodeFactory nf) { + this.nf = nf; + epr = nf.getExtensionPointRegistry(); + fep = epr.getExtensionPoint(FactoryExtensionPoint.class); + cf = fep.getFactory(ContributionFactory.class); + af = fep.getFactory(AssemblyFactory.class); + jif = fep.getFactory(JavaInterfaceFactory.class); + wif = fep.getFactory(WSDLFactory.class); + apep = epr.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + aproc = new ExtensibleURLArtifactProcessor(apep); + mrep = epr.getExtensionPoint(ModelResolverExtensionPoint.class); + pfep = epr.getExtensionPoint(ProviderFactoryExtensionPoint.class); + } + } + + static Context embedContext(NodeFactory nf) { + return new Context(nf); + } + + /** + * A mini DSL to help build and assemble contributions and SCDL composites. + */ + interface Builder { + T build(Context ec); + } + + static T build(final Builder builder, final Context ec) { + return builder.build(ec); + } + + /** + * Return a contribution builder. + */ + static Builder contrib(final String uri, final String loc, final Builder... artifacts) { + return new Builder() { + public Contribution build(final Context ec) { + final Contribution c = ec.cf.createContribution(); + c.setURI(uri); + c.setLocation(loc); + c.setModelResolver(new ExtensibleModelResolver(c, ec.mrep, ec.fep)); + for(Builder a: artifacts) + c.getArtifacts().add(a.build(ec)); + return c; + } + }; + } + + /** + * Return an artifact builder. + */ + static Builder artifact(final String uri, final Object model) { + return new Builder() { + public Artifact build(final Context ec) { + final Artifact a = ec.cf.createArtifact(); + a.setURI(uri); + a.setModel(model); + return a; + } + }; + } + + /** + * Return a composite builder. + */ + static Builder composite(final String ns, final String name, final Builder... components) { + return new Builder() { + public Composite build(final Context ec) { + final Composite compos = ec.af.createComposite(); + compos.setName(new QName(ns, name)); + for(final Builder c: components) + compos.getComponents().add(c.build(ec)); + return compos; + } + }; + } + + /** + * Return a component builder. + */ + static Builder component(final String name, final Builder impl, final Builder... references) { + return new Builder() { + public Component build(final Context ec) { + final Component c = ec.af.createComponent(); + c.setName(name); + c.setImplementation(impl.build(ec)); + for(Builder r: references) + c.getReferences().add(r.build(ec)); + return c; + } + }; + } + + /** + * Return an implementation builder. + */ + static Builder implementation(final Class clazz, final Builder... contracts) { + return new Builder() { + public SampleImplementation build(final Context ec) { + final SampleImplementation impl = ImplUtil.implementation(clazz.getName()); + impl.clazz = clazz; + impl.setUnresolved(false); + for(final Builder b: contracts) { + Contract c = b.build(ec); + if(c instanceof Service) + impl.getServices().add((Service)c); + else + impl.getReferences().add((Reference)c); + } + return impl; + } + }; + } + + /** + * Return a reference builder. + */ + static Builder reference(final String name, final Class c) { + return new Builder() { + public Reference build(final Context ec) { + try { + return ImplUtil.reference(name, c, ec.jif, ec.af); + } catch(InvalidInterfaceException e) { + throw new RuntimeException(e); + } + } + }; + } + + static Builder reference(final String name, final WSDLInterface c) { + return new Builder() { + public Reference build(final Context ec) { + return ImplUtil.reference(name, c, ec.wif, ec.af); + } + }; + } + + static Builder reference(final String name, final String target) { + return new Builder() { + public ComponentReference build(final Context ec) { + final ComponentReference r = ec.af.createComponentReference(); + r.setName(name); + final ComponentService s = ec.af.createComponentService(); + s.setUnresolved(true); + s.setName(target); + r.getTargets().add(s); + return r; + } + }; + } + + /** + * Return a service builder. + */ + static Builder service(final Class c) { + return new Builder() { + public Service build(final Context ec) { + try { + return ImplUtil.service(c, ec.jif, ec.af); + } catch(InvalidInterfaceException e) { + throw new RuntimeException(e); + } + } + }; + } + + static Builder service(final WSDLInterface c) { + return new Builder() { + public Service build(final Context ec) { + return ImplUtil.service(c, ec.wif, ec.af); + } + }; + } + + /** + * Return a WSDLInterface builder which loads a WSDL into a contribution. + */ + static Builder wsdli(final String uri, final String ns, final String name, final Contribution c) { + return new Builder() { + public WSDLInterface build(final Context ec) { + try { + final ProcessorContext ctx = new ProcessorContext(); + final WSDLDefinition wd = ec.aproc.read(null, new URI(uri), new URL(new URL(c.getLocation()), uri), ctx, WSDLDefinition.class); + c.getModelResolver().addModel(wd, ctx); + c.getModelResolver().resolveModel(WSDLDefinition.class, wd, ctx); + final WSDLObject pt = wd.getWSDLObject(PortType.class, new QName(ns, name)); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + final WSDLInterface nwi = ec.wif.createWSDLInterface(pt.getElement(), wd, c.getModelResolver(), null); + nwi.setWsdlDefinition(wd); + nwi.resetDataBinding(DOMDataBinding.NAME); + return nwi; + } catch(Exception e) { + throw new RuntimeException(e); + } + } + }; + } + + /** + * Return the extension point registry used by our nodes. + */ + static ExtensionPointRegistry extensionPoints(final Context ec) { + return ec.epr; + } + + /** + * Return the provider factory extension point used by our nodes. + */ + static ProviderFactoryExtensionPoint providerFactories(final Context ec) { + return ec.pfep; + } + + /** + * Add a deployable composite to a contribution. + */ + static Contribution deploy(final Contribution contrib, final Composite... comps) { + for(Composite c: comps) + contrib.getDeployables().add(c); + return contrib; + } + + /** + * Configure a node with a list of contributions. + */ + static Node node(final NodeFactory nf, final Contribution... contributions) { + return nf.createNode(Arrays.asList(contributions)); + } + +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/ImplUtil.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/ImplUtil.java new file mode 100644 index 0000000000..abd4cd7ab0 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/ImplUtil.java @@ -0,0 +1,148 @@ +/* + * 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.impl; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * Utility functions to help develop a component implementation extension. + */ +class ImplUtil { + + /** + * Return a Sample implementation with the given name. + */ + static SampleImplementation implementation(String name) { + final SampleImplementation impl = new SampleImplementation(name); + impl.setUnresolved(true); + return impl; + } + + /** + * Return the Java class configured on an annotation. + */ + static Class clazz(final Annotation a) { + return ((Java)a).value(); + } + + /** + * Return the WSDL QName configured on an annotation. + */ + static QName qname(final Annotation a) { + final String uri = ((WSDL)a).value(); + final int h = uri.indexOf('#'); + return new QName(uri.substring(0, h), uri.substring(h + 1)); + } + + /** + * Convert a Java class to an interface contract. + */ + static JavaInterfaceContract contract(final Class c, final JavaInterfaceFactory jif) throws InvalidInterfaceException { + final JavaInterfaceContract ic = jif.createJavaInterfaceContract(); + ic.setInterface(jif.createJavaInterface(c)); + return ic; + } + + /** + * Convert a WSDL interface to an interface contract. + */ + static WSDLInterfaceContract contract(final WSDLInterface wi, final WSDLFactory wf) { + final WSDLInterfaceContract ic = wf.createWSDLInterfaceContract(); + ic.setInterface(wi); + return ic; + } + + /** + * Convert a Java class to a service. + */ + static Service service(final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + Service s = af.createService(); + s.setName(c.getSimpleName()); + s.setInterfaceContract(contract(c, jif)); + return s; + } + + /** + * Convert a WSDL interface to a service. + */ + static Service service(final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + Service s = af.createService(); + s.setName(wi.getName().getLocalPart()); + s.setInterfaceContract(contract(wi, wf)); + return s; + } + + /** + * Convert a name and Java class to a reference. + */ + static Reference reference(final String name, final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(c, jif)); + return r; + } + + /** + * Convert a name and WSDL interface to a reference. + */ + static Reference reference(final String name, final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(wi, wf)); + return r; + } + + /** + * Convert a WSDL qname to a WSDL interface. + */ + static WSDLInterface interfaze(final QName name, final WSDLFactory wif) { + final WSDLInterface wir = wif.createWSDLInterface(); + wir.setUnresolved(true); + wir.setName(name); + return wir; + } + + /** + * Convert a WSDL qname to a WSDL definition. + */ + static WSDLDefinition definition(final QName name, final WSDLFactory wif) { + final WSDLDefinition wdr = wif.createWSDLDefinition(); + wdr.setUnresolved(true); + wdr.setNamespace(name.getNamespaceURI()); + wdr.setNameOfPortTypeToResolve(name); + return wdr; + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementation.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementation.java new file mode 100644 index 0000000000..41ce71a732 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementation.java @@ -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. + */ +package sample.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * Model representing a Sample implementation in an SCA assembly. + * + * @version $Rev$ $Date$ + */ +public class SampleImplementation extends ImplementationImpl { + static final QName QN = new QName(SCA11_TUSCANY_NS, "implementation.sample"); + + final String name; + Class clazz; + + SampleImplementation(final String name) { + super(QN); + this.name = name; + } + +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java new file mode 100644 index 0000000000..6017030d35 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java @@ -0,0 +1,174 @@ +/* + * 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.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static sample.impl.SampleImplementation.QN; +import static sample.impl.ImplUtil.clazz; +import static sample.impl.ImplUtil.definition; +import static sample.impl.ImplUtil.implementation; +import static sample.impl.ImplUtil.interfaze; +import static sample.impl.ImplUtil.qname; +import static sample.impl.ImplUtil.reference; +import static sample.impl.ImplUtil.service; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * StAX artifact processor for Sample implementations. + * + * @version $Rev$ $Date$ + */ +public class SampleImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wf; + + public SampleImplementationProcessor(final ExtensionPointRegistry ep) { + final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class); + this.af = fep.getFactory(AssemblyFactory.class); + this.jif = fep.getFactory(JavaInterfaceFactory.class); + this.wf = fep.getFactory(WSDLFactory.class); + } + + public QName getArtifactType() { + return QN; + } + + public Class getModelType() { + return SampleImplementation.class; + } + + public SampleImplementation read(final XMLStreamReader r, final ProcessorContext ctx) throws ContributionReadException, XMLStreamException { + // Read the component implementation element + final SampleImplementation impl = implementation(r.getAttributeValue(null, "class")); + while(r.hasNext() && !(r.next() == END_ELEMENT && QN.equals(r.getName()))) + ; + return impl; + } + + public void resolve(final SampleImplementation impl, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + try { + // Resolve and introspect the implementation class + impl.clazz = resolve(impl.name, res, ctx); + + for(final Annotation a: impl.clazz.getAnnotations()) { + if(a instanceof Java) + impl.getServices().add(service(clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getServices().add(service(resolve(qname(a), res, ctx, wf), wf, af)); + } + + for(Field f: impl.clazz.getDeclaredFields()) { + for(final Annotation a: f.getAnnotations()) { + if(a instanceof Java) + impl.getReferences().add(reference(f.getName(), clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getReferences().add(reference(f.getName(), resolve(qname(a), res, ctx, wf), wf, af)); + } + } + + impl.setUnresolved(false); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + public void write(final SampleImplementation impl, final XMLStreamWriter w, final ProcessorContext ctx) throws ContributionWriteException, XMLStreamException { + writeStart(w, QN.getNamespaceURI(), QN.getLocalPart(), new XAttr("class", impl.name)); + writeEnd(w); + } + + /** + * Resolve a Java class. + */ + static Class resolve(final String name, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + final ClassReference cr = res.resolveModel(ClassReference.class, new ClassReference(name), ctx); + if(cr.getJavaClass() != null) + return cr.getJavaClass(); + throw new ContributionResolveException(new ClassNotFoundException(name)); + } + + /** + * Resolve a WSDL interface. + */ + static WSDLInterface resolve(final QName name, final ModelResolver res, final ProcessorContext ctx, final WSDLFactory wif) throws ContributionResolveException { + final WSDLInterface wi = res.resolveModel(WSDLInterface.class, interfaze(name, wif), ctx); + if(!wi.isUnresolved()) + return domBound(wi); + + final WSDLDefinition wd = res.resolveModel(WSDLDefinition.class, definition(wi.getName(), wif), ctx); + if(wd.isUnresolved()) + throw new ContributionResolveException("Couldn't find " + name.getNamespaceURI()); + + WSDLObject pt = wd.getWSDLObject(PortType.class, name); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + try { + final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, res, ctx.getMonitor()); + nwi.setWsdlDefinition(wd); + res.addModel(nwi, ctx); + return domBound(nwi); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + /** + * Return a WSDL interface configured to use a DOM databinding. + */ + static WSDLInterface domBound(WSDLInterface wi) throws ContributionResolveException { + try { + final WSDLInterface domwi = (WSDLInterface)wi.clone(); + domwi.resetDataBinding(DOMDataBinding.NAME); + return domwi; + } catch(CloneNotSupportedException e) { + throw new ContributionResolveException(e); + } + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleJavaInvoker.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleJavaInvoker.java new file mode 100644 index 0000000000..244251c4c9 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleJavaInvoker.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 sample.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for Sample components that implement a Java interface. + * + * @version $Rev$ $Date$ + */ +class SampleJavaInvoker implements Invoker { + final Object instance; + final Method method; + + SampleJavaInvoker(final JavaOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.instance = instance; + this.method = clazz.getMethod(op.getJavaMethod().getName(), op.getJavaMethod().getParameterTypes()); + } + + public Message invoke(final Message msg) { + try { + // Call the method that implements the operation + msg.setBody(method.invoke(instance, (Object[])msg.getBody())); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProvider.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProvider.java new file mode 100644 index 0000000000..5d946b037b --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProvider.java @@ -0,0 +1,91 @@ +/* + * 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.impl; + +import java.lang.reflect.Field; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation provider for Sample component implementations. + * + * @version $Rev$ $Date$ + */ +class SampleProvider implements ImplementationProvider { + final RuntimeComponent comp; + final SampleImplementation impl; + final ProxyFactory pxf; + Object instance; + + SampleProvider(final RuntimeComponent comp, final SampleImplementation impl, ProxyFactory pf) { + this.comp = comp; + this.impl = impl; + this.pxf = pf; + } + + public void start() { + // Construct implementation instance and inject reference proxies + try { + instance = impl.clazz.newInstance(); + + for(ComponentReference r: comp.getReferences()) { + final Field f = impl.clazz.getDeclaredField(r.getName()); + f.setAccessible(true); + // Inject a Java or WSDLReference proxy + final Interface i = r.getInterfaceContract().getInterface(); + if(i instanceof JavaInterface) + f.set(instance, pxf.createProxy(comp.getComponentContext().getServiceReference(f.getType(), r.getName()))); + else + f.set(instance, new SampleWSDLProxy(r.getEndpointReferences().get(0), i)); + } + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + public void stop() { + instance = null; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(final RuntimeComponentService s, final Operation op) { + try { + // Creating an invoker for a Java or WSDL-typed implementation + if(op instanceof JavaOperation) + return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance); + return new SampleWSDLInvoker((WSDLOperation)op, impl.clazz, instance); + } catch(Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProviderFactory.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProviderFactory.java new file mode 100644 index 0000000000..4ad24d33ff --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleProviderFactory.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 sample.impl; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory for Sample implementation providers. + * + * @version $Rev$ $Date$ + */ +public class SampleProviderFactory implements ImplementationProviderFactory { + final ProxyFactory pxf; + + public SampleProviderFactory(final ExtensionPointRegistry ep) { + pxf = ExtensibleProxyFactory.getInstance(ep); + } + + public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final SampleImplementation impl) { + return new SampleProvider(comp, impl, pxf); + } + + public Class getModelType() { + return SampleImplementation.class; + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLInvoker.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLInvoker.java new file mode 100644 index 0000000000..6c5317274f --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLInvoker.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.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.w3c.dom.Element; + +/** + * Invoker for Sample components that implement a WSDL interface using a generic + * call method. + * + * @version $Rev$ $Date$ + */ +class SampleWSDLInvoker implements Invoker { + final String name; + final Object instance; + final Method method; + + SampleWSDLInvoker(final WSDLOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.name = op.getName(); + this.instance = instance; + this.method = clazz.getMethod("call", String.class, Element.class); + } + + public Message invoke(final Message msg) { + try { + // Invoke the generic call method + msg.setBody(method.invoke(instance, name, ((Object[])msg.getBody())[0])); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLProxy.java b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLProxy.java new file mode 100644 index 0000000000..a6882a0103 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/java/sample/impl/SampleWSDLProxy.java @@ -0,0 +1,57 @@ +/* + * 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.impl; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.w3c.dom.Element; + +import sample.api.WSDLReference; + +/** + * Proxy used to call operations on WSDL references. + */ +class SampleWSDLProxy implements WSDLReference { + final RuntimeEndpointReference repr; + final Map ops; + + SampleWSDLProxy(EndpointReference epr, Interface wi) { + repr = (RuntimeEndpointReference)epr; + ops = new HashMap(); + for(Operation o: wi.getOperations()) + ops.put(o.getName(), o); + } + + @Override + public Element call(String op, Element e) { + try { + // Invoke the named operation on the endpoint reference + return (Element)repr.invoke(ops.get(op), new Object[] {e}); + } catch(InvocationTargetException ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..908ac95a2e --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# 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. + +# Implementation class for the artifact processor extension +sample.impl.SampleImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.sample,model=sample.impl.SampleImplementation + diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..85aff44074 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,18 @@ +# 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. +# +sample/impl/sample.xsd diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..32a7efcaf9 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -0,0 +1,20 @@ +# 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. + +# Implementation provider for Sample components +sample.impl.SampleProviderFactory;model=sample.impl.SampleImplementation + diff --git a/sandbox/samples/sca-features/implementation-extension/src/main/resources/sample/impl/sample.xsd b/sandbox/samples/sca-features/implementation-extension/src/main/resources/sample/impl/sample.xsd new file mode 100644 index 0000000000..c057aef1c1 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/main/resources/sample/impl/sample.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Client.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Client.java new file mode 100644 index 0000000000..1b7e11c786 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Client.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; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Client { + + String jello(String s); + + String wello(String s); +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/ClientTest.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/ClientTest.java new file mode 100644 index 0000000000..92291c98a1 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/ClientTest.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 sample; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.elems; +import static sample.Xutil.print; +import static sample.Xutil.select; +import static sample.Xutil.text; +import static sample.Xutil.xdom; +import static sample.Xutil.xfilter; +import static sample.Xutil.xreduce; + +import org.w3c.dom.Element; + +import sample.api.Java; +import sample.api.WSDL; +import sample.api.WSDLReference; + +/** + * Sample component implementation that uses a mix of Java and WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Client.class) +public class ClientTest { + + @Java(Hello.class) + Hello jello; + + @WSDL("http://sample/hello#Hello") + WSDLReference wello; + + public String jello(String s) { + out.println("ClientTest.jello(" + s + ")"); + return jello.hello(s); + } + + public String wello(String s) { + out.println("ClientTest.wello(" + s + ")"); + final Element hreq = xdom("http://sample/hello", "hello", elem("name", text(s))); + + final Element hres = wello.call("hello", hreq); + + return xreduce(print, "", xfilter(select("result"), elems(hres))); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Hello.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Hello.java new file mode 100644 index 0000000000..247fc8aa78 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Hello.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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Hello { + + String hello(String s); +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/JelloTest.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/JelloTest.java new file mode 100644 index 0000000000..5c999a6c80 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/JelloTest.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 sample; + +import static java.lang.System.out; +import sample.api.Java; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Hello.class) +public class JelloTest { + + @Java(Upper.class) + Upper upper; + + public String hello(String s) { + out.println("JelloTest.hello(" + s + ")"); + return upper.upper("Hello " + s); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Upper.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Upper.java new file mode 100644 index 0000000000..9c772b3487 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Upper.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 sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Upper { + + String upper(String s); +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/UpperTest.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/UpperTest.java new file mode 100644 index 0000000000..5399e4410d --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/UpperTest.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; + +import static java.lang.System.out; +import sample.api.Java; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Upper.class) +public class UpperTest { + + public String upper(String s) { + out.println("UpperTest.upper(" + s + ")"); + return s.toUpperCase(); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/WelloTest.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/WelloTest.java new file mode 100644 index 0000000000..1bb9fc11ce --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/WelloTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.elems; +import static sample.Xutil.print; +import static sample.Xutil.select; +import static sample.Xutil.text; +import static sample.Xutil.xdom; +import static sample.Xutil.xfilter; +import static sample.Xutil.xml; +import static sample.Xutil.xreduce; + +import org.w3c.dom.Element; + +import sample.api.WSDL; +import sample.api.WSDLReference; + +/** + * Sample component implementation that uses WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +@WSDL("http://sample/hello#Hello") +public class WelloTest { + + @WSDL("http://sample/upper#Upper") + WSDLReference upper; + + public Element call(String op, Element e) { + out.println("WelloTest." + op + "(" + xml(e) + ")"); + final String name = xreduce(print, "", xfilter(select("name"), elems(e))); + + final Element ureq = xdom("http://sample/upper", "upper", elem("s", text("Hello " + name))); + final Element ures = upper.call("upper", ureq); + + final String s = xreduce(print, "", xfilter(select("result"), elems(ures))); + return xdom("http://sample/hello", "helloResponse", elem("result", text(s))); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Xutil.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Xutil.java new file mode 100644 index 0000000000..ce89f9dd8c --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/Xutil.java @@ -0,0 +1,225 @@ +/* + * 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.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Just for fun, a little bit of magic code and utility functions to help work with XML DOM. + */ +class Xutil { + interface NodeBuilder { + Node build(Document doc); + } + + /** + * Convert a name and a list of children to a document element. + */ + static Element xdom(String ns, String name, final NodeBuilder... nodes) { + return (Element)elem(ns, name, nodes).build(db.newDocument()); + } + + /** + * Convert a name and children to an element. + */ + static NodeBuilder elem(final String uri, final String n, final NodeBuilder... nodes) { + return new NodeBuilder() { + public Node build(Document doc) { + final Element e = doc.createElementNS(uri, n); + for(final NodeBuilder n: nodes) + e.appendChild(n.build(doc)); + return e; + } + }; + } + + static NodeBuilder elem(final String n, final NodeBuilder... nodes) { + return elem(null, n, nodes); + } + + /** + * Convert a string to a text element. + */ + static NodeBuilder text(final String t) { + return new NodeBuilder() { + public Node build(final Document doc) { + return doc.createTextNode(t); + } + }; + } + + private final static DocumentBuilder db = db(); + + private static DocumentBuilder db() { + try { + return DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch(ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * Convert an element to XML. + */ + static TransformerFactory trf = TransformerFactory.newInstance(); + + static String xml(final Node node) { + try { + final StreamResult r = new StreamResult(new StringWriter()); + trf.newTransformer().transform(new DOMSource(node), r); + return r.getWriter().toString(); + } catch(TransformerException e) { + throw new RuntimeException(e); + } + } + + /** + * Evaluate an xpath expression. + */ + private static XPathFactory xpf = XPathFactory.newInstance(); + + static String xpath(final String expr, final Node node) { + final XPath xp = xpf.newXPath(); + try { + return (String)xp.evaluate(expr, node, XPathConstants.STRING); + } catch(XPathExpressionException e) { + throw new RuntimeException(e); + } + } + + /** + * A pure Java FP-style alternative to xpath for DOM. + */ + interface Mapper { + T map(final Element e); + } + + static Mapper identity = new Mapper() { + public Element map(Element e) { + return e; + }; + }; + + interface Reducer { + T reduce(final T accum, final Element e); + } + + static Reducer print = new Reducer() { + public String reduce(String accum, Element e) { + return accum + e.getTextContent(); + } + }; + + /** + * Apply a mapper to a list of elements. + */ + static List xmap(final Mapper f, final Iterable l) { + final List v = new ArrayList(); + for(Element e: l) + v.add(f.map(e)); + return v; + } + + /** + * Apply a filter to a list of elements. + */ + static List xfilter(final Mapper f, final Iterable l) { + final List v = new ArrayList(); + for(Element e: l) + if(f.map(e)) + v.add(e); + return v; + } + + /** + * Perform a reduction over a list of elements. + */ + static T xreduce(final Reducer f, final T initial, final Iterable l) { + T accum = initial; + for(Element e: l) + accum = f.reduce(accum, e); + return accum; + } + + /** + * Return a filter that selects elements by name. + */ + static Mapper select(final String name) { + return new Mapper() { + public Boolean map(Element e) { + return name.equals(e.getLocalName()); + } + }; + } + + /** + * Return the child elements of a node. + */ + static Iterable elems(final Node parent) { + final List l = new ArrayList(); + for (Node n: children(parent)) + if (n instanceof Element) + l.add((Element)n); + return l; + } + + /** + * An iterable over the children of a node. + */ + private static Iterable children(Node parent) { + final NodeList l = parent.getChildNodes(); + final int n = l.getLength(); + return new Iterable() { + public Iterator iterator() { + return new Iterator() { + int i = 0; + public boolean hasNext() { + return i < n; + } + public Node next() { + return l.item(i++); + } + public void remove() { + } + }; + } + }; + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java new file mode 100644 index 0000000000..406dbabee0 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java @@ -0,0 +1,151 @@ +/* + * 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.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.EmbedUtil.build; +import static sample.impl.EmbedUtil.component; +import static sample.impl.EmbedUtil.composite; +import static sample.impl.EmbedUtil.contrib; +import static sample.impl.EmbedUtil.deploy; +import static sample.impl.EmbedUtil.embedContext; +import static sample.impl.EmbedUtil.extensionPoints; +import static sample.impl.EmbedUtil.implementation; +import static sample.impl.EmbedUtil.node; +import static sample.impl.EmbedUtil.providerFactories; +import static sample.impl.EmbedUtil.reference; +import static sample.impl.EmbedUtil.service; +import static sample.impl.EmbedUtil.wsdli; +import static sample.impl.TestUtil.here; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sample.Client; +import sample.ClientTest; +import sample.Hello; +import sample.JelloTest; +import sample.Upper; +import sample.UpperTest; +import sample.WelloTest; + +/** + * Test how to assemble a contribution, a SCDL composite and run it on an embedded + * Tuscany runtime node. Also shows how pass in a ProviderFactory instead of having + * it loaded and constructed by the runtime node. + * + * @version $Rev$ $Date$ + */ +public class EmbedTestCase { + static NodeFactory nf; + static EmbedUtil.Context ec; + static Node node; + + @SuppressWarnings("unchecked") + @BeforeClass + public static void setUp() throws Exception { + nf = NodeFactory.newInstance(); + ec = embedContext(nf); + + // Load the test WSDL definitions (could also construct the WSDL + // and XSD models in code but that'd be quite painful, so just + // load them from XML for now) + final Contribution contrib = build(contrib("test", here()), ec); + WSDLInterface Hello_wsdl = build(wsdli("Hello.wsdl", "http://sample/hello", "Hello", contrib), ec); + WSDLInterface Upper_wsdl = build(wsdli("Upper.wsdl", "http://sample/upper", "Upper", contrib), ec); + + // Assemble a test composite model (see EmbedUtil + // for the little DSL used here, much more concise + // than using the assembly model interfaces) + final Composite comp = + build(composite("http://sample", "test", + component("client-test", + implementation(ClientTest.class, + service(Client.class), + reference("jello", Hello.class), + reference("wello", Hello_wsdl)), + reference("jello", "jello-test"), + reference("wello", "wello-test")), + component("wello-test", + implementation(WelloTest.class, + service(Hello_wsdl), + reference("upper", Upper_wsdl)), + reference("upper", "upper-test")), + component("jello-test", + implementation(JelloTest.class, + service(Hello.class), + reference("upper", Upper.class)), + reference("upper", "upper-test")), + component("upper-test", + implementation(UpperTest.class, + service(Upper.class)))), ec); + + // Register a test instance of our sample implementation ProviderFactory + providerFactories(ec).addProviderFactory(testProviderFactory()); + + // Run with it + node = node(nf, deploy(contrib, comp)); + node.start(); + } + + static ProviderFactory testProviderFactory() { + // This shows how to get called when a provider is created + return new SampleProviderFactory(extensionPoints(ec)) { + public ImplementationProvider createImplementationProvider(RuntimeComponent comp, SampleImplementation impl) { + out.println("Creating a provider for component " + comp.getName()); + return super.createImplementationProvider(comp, impl); + }}; + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void jello() { + out.println("RunTestCase.jello"); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); + } + + @Test + public void wello() { + out.println("RunTestCase.wello"); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); + } + + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java new file mode 100644 index 0000000000..8a4768cd9e --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/ReadWriteTestCase.java @@ -0,0 +1,84 @@ +/* + * 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.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static sample.impl.TestUtil.here; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Test read/write Sample SCDL implementation elements. + * + * @version $Rev$ $Date$ + */ +public class ReadWriteTestCase { + static XMLInputFactory xif; + static XMLOutputFactory xof; + static StAXArtifactProcessor xproc; + static ProcessorContext ctx; + + @BeforeClass + public static void setUp() throws Exception { + final DefaultExtensionPointRegistry ep = new DefaultExtensionPointRegistry(); + final Contribution contrib = new DefaultContributionFactory().createContribution(); + contrib.setLocation(here()); + ctx = new ProcessorContext(contrib, null); + xif = XMLInputFactory.newInstance(); + xof = XMLOutputFactory.newInstance(); + final StAXArtifactProcessorExtensionPoint xpep = new DefaultStAXArtifactProcessorExtensionPoint(ep); + xproc = new ExtensibleStAXArtifactProcessor(xpep, xif, xof); + } + + @Test + public void testRead() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + assertNotNull(c); + assertEquals("sample.ClientTest", ((SampleImplementation)c.getComponents().get(0).getImplementation()).name); + } + + @Test + public void testReadWrite() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + xproc.write(c, xof.createXMLStreamWriter(bos), ctx); + assertTrue(bos.toString().contains("class=\"sample.WelloTest\"")); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunTestCase.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunTestCase.java new file mode 100644 index 0000000000..29bf02d26b --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunTestCase.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.TestUtil.here; + +import org.apache.tuscany.sca.node.Contribution; +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; + +import sample.Client; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class RunTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode(new Contribution("test", here())); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void jello() { + out.println("RunTestCase.jello"); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); + } + + @Test + public void wello() { + out.println("RunTestCase.wello"); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); + } + + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java new file mode 100644 index 0000000000..61133d0fbf --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java @@ -0,0 +1,120 @@ +/* + * 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.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertTrue; +import static sample.impl.TestUtil.here; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.http.jetty.JettyServer; +import org.apache.tuscany.sca.node.Contribution; +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; + +/** + * Test a component that provides and consumes SOAP Web services. + * + * @version $Rev$ $Date$ + */ +public class RunWSTestCase { + static Node node; + static JettyServer jetty; + + @BeforeClass + public static void setUp() throws Exception { + // Start test composite on a Tuscany node + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode(new Contribution("test", here())); + node.start(); + + // Mock up a test Web service on http://localhost:8086/wsupper + jetty = new JettyServer((ExtensionPointRegistry)nf.getExtensionPointRegistry()); + jetty.start(); + jetty.addServletMapping("http://localhost:8086/wsupper", new HttpServlet() { + private static final long serialVersionUID = 1L; + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + assertTrue(read(req.getInputStream()).contains("Hello SOAP")); + final String soapresp = + "" + + "" + + "HELLO SOAP" + + ""; + + write(soapresp, resp.getOutputStream()); + } + }); + } + + @AfterClass + public static void tearDown() throws Exception { + jetty.stop(); + node.stop(); + } + + @Test + public void wsello() throws Exception { + out.println("RunWSTestCase.wsello"); + // Send a SOAP request to the Web service provided by SCA component wsello-test + // on http://localhost:8085/wsello + final Socket s = new Socket("localhost", 8085); + final String soapreq = + "POST /wsello HTTP/1.0\r\n" + + "Content-Type: text/xml; charset=UTF-8\r\n" + + "Content-length: 231\r\n\r\n" + + "" + + "" + + "SOAP" + + ""; + write(soapreq, s.getOutputStream()); + assertTrue(read(s.getInputStream()).contains("HELLO SOAP")); + } + + static void write(final String s, final OutputStream o) throws IOException { + final OutputStreamWriter w = new OutputStreamWriter(o); + w.write(s); + w.flush(); + } + + static String read(final InputStream i) throws IOException { + return read(new BufferedReader(new InputStreamReader(i))); + } + + static String read(final BufferedReader r) throws IOException { + final String s = r.readLine(); + return s == null? "" : s + read(r); + } +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/TestUtil.java b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/TestUtil.java new file mode 100644 index 0000000000..6dcfb33912 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/java/sample/impl/TestUtil.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.impl; + +/** + * A hack to determine the test contribution location. + */ +public class TestUtil { + + static String here() { + return TestUtil.class.getProtectionDomain().getCodeSource().getLocation().toString(); + } + +} diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/resources/Hello.wsdl b/sandbox/samples/sca-features/implementation-extension/src/test/resources/Hello.wsdl new file mode 100644 index 0000000000..360cea5ff3 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/resources/Hello.wsdl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/resources/Upper.wsdl b/sandbox/samples/sca-features/implementation-extension/src/test/resources/Upper.wsdl new file mode 100644 index 0000000000..8a148bb5e8 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/resources/Upper.wsdl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-extension/src/test/resources/test.composite b/sandbox/samples/sca-features/implementation-extension/src/test/resources/test.composite new file mode 100644 index 0000000000..43a75f50a7 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-extension/src/test/resources/test.composite @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-java/README b/sandbox/samples/sca-features/implementation-java/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/README b/sandbox/samples/sca-features/implementation-java/contribution-calculator/README new file mode 100644 index 0000000000..9e1ff828ee --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/README @@ -0,0 +1,25 @@ +Calculator Sample Contribution +============================== + +This sample implements a simple calculator using SCA components. + +The README in the /samples directory provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + +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. + +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 diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/build.xml b/sandbox/samples/sca-features/implementation-java/contribution-calculator/build.xml new file mode 100644 index 0000000000..8ec250d009 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/build.xml @@ -0,0 +1,56 @@ + + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/pom.xml b/sandbox/samples/sca-features/implementation-java/contribution-calculator/pom.xml new file mode 100644 index 0000000000..c3e4ba4208 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-implementation-java-calculator + Apache Tuscany SCA Sample Contribution Implementation Java Calculator + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + + diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..5a1e7a638a --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddServiceImpl.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..caf4d358df --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorClient.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..2b791a8e1f --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..78eea39c71 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorService.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; + +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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..d3fa7a8f41 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..ef6a8b375b --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..cd91935f08 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..c85357fcd8 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..56ee372fc4 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..1b669084d9 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-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/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/Calculator.composite b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..370e1cf315 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/CalculatorClient.composite b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/CalculatorClient.composite new file mode 100644 index 0000000000..dfd32761be --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/CalculatorClient.composite @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..70aab0e051 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..c1cd131f40 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/contribution-calculator/src/test/java/calculator/CalculatorTestCase.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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * This shows how to test the Calculator composition. + */ +public class CalculatorTestCase { + + @Test + public void testCalculator() throws Exception { + AddService add = new AddServiceImpl(); + SubtractService subtract = new SubtractServiceImpl(); + MultiplyService multiply = new MultiplyServiceImpl(); + DivideService divide = new DivideServiceImpl(); + + CalculatorServiceImpl calculator = new CalculatorServiceImpl(); + + calculator.setAddService(add); + calculator.setSubtractService(subtract); + calculator.setMultiplyService(multiply); + calculator.setDivideService(divide); + + assertEquals(calculator.add(3, 2), 5.0, 0); + assertEquals(calculator.subtract(3, 2), 1.0, 0); + assertEquals(calculator.multiply(3, 2), 6.0, 0); + assertEquals(calculator.divide(3, 2), 1.5, 0); + } +} diff --git a/sandbox/samples/sca-features/implementation-java/pom.xml b/sandbox/samples/sca-features/implementation-java/pom.xml new file mode 100644 index 0000000000..96fece7481 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-java/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-implementation-java + pom + Apache Tuscany SCA Sample implementation.java + + + + default + + true + + + contribution-calculator + + + + diff --git a/sandbox/samples/sca-features/implementation-script/README b/sandbox/samples/sca-features/implementation-script/README new file mode 100644 index 0000000000..18ba62d494 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/README @@ -0,0 +1 @@ +Please look at the README files in the subdirectories of this directory for descriptions of the sample contributions. diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/README b/sandbox/samples/sca-features/implementation-script/contribution-calculator/README new file mode 100644 index 0000000000..1e5bc9c584 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/README @@ -0,0 +1,26 @@ +Calculator Sample Contribution +============================== + +This sample contribution implements a simple calculator using SCA components. + +The README in the /samples directory provides +general instructions about building and running samples. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) Take a look there for instructions on how to launch +this sample contribution. + +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. + +Amongst the other output created by the launcher/contribution combination, you should see the following output ... + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/build.xml b/sandbox/samples/sca-features/implementation-script/contribution-calculator/build.xml new file mode 100644 index 0000000000..91285fdbca --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/build.xml @@ -0,0 +1,57 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/pom.xml b/sandbox/samples/sca-features/implementation-script/contribution-calculator/pom.xml new file mode 100644 index 0000000000..61c864a4f0 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-contribution-implementation-script-calculator + Apache Tuscany SCA Sample Contribution implementation-script Calculator + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/AddService.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..5a1e7a638a --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorClient.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..1df1f31c48 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..78eea39c71 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorService.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; + +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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..8e4b082d14 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/DivideService.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..ef6a8b375b --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/SubtractService.java b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..56ee372fc4 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-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/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/Calculator.composite b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..d441aa0aea --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/CalculatorClient.composite b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/CalculatorClient.composite new file mode 100644 index 0000000000..dfd32761be --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/CalculatorClient.composite @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..70aab0e051 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.componentType b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.componentType new file mode 100644 index 0000000000..5f6d88454c --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.componentType @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.js b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.js new file mode 100644 index 0000000000..6f11106ddd --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/AddServiceImpl.js @@ -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. + */ + +function add(n1, n2) { + return n1 + n2; +} \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.componentType b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.componentType new file mode 100644 index 0000000000..f4bb4e3471 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.componentType @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.groovy b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.groovy new file mode 100644 index 0000000000..c31c1e8fd6 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/DivideServiceImpl.groovy @@ -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. + */ + +def divide(n1, n2) { + return n1 / n2 +} \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.componentType b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.componentType new file mode 100644 index 0000000000..35dc5721b2 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.componentType @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.py b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.py new file mode 100644 index 0000000000..cce0b5b3ec --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/MultiplyServiceImpl.py @@ -0,0 +1,20 @@ +# 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. +# + +def multiply(n1, n2): + return n1 * n2 \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.componentType b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.componentType new file mode 100644 index 0000000000..ee768f73f2 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.componentType @@ -0,0 +1,30 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.rb b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.rb new file mode 100644 index 0000000000..132a1d13b0 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/contribution-calculator/src/main/resources/calculator/SubtractServiceImpl.rb @@ -0,0 +1,21 @@ +# 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. +# + +def subtract(n1, n2) + return n1 - n2 +end \ No newline at end of file diff --git a/sandbox/samples/sca-features/implementation-script/pom.xml b/sandbox/samples/sca-features/implementation-script/pom.xml new file mode 100644 index 0000000000..cf719a7918 --- /dev/null +++ b/sandbox/samples/sca-features/implementation-script/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-implementation-script + pom + Apache Tuscany SCA Sample implementation.script + + + + default + + true + + + contribution-calculator + + + + diff --git a/sandbox/samples/sca-features/pom.xml b/sandbox/samples/sca-features/pom.xml new file mode 100644 index 0000000000..8c74eece33 --- /dev/null +++ b/sandbox/samples/sca-features/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + org.apache.tuscany.sca + tuscany-samples-sca-features + 2.0-SNAPSHOT + pom + Apache Tuscany SCA Feature Samples + + + + default + + true + + + binding-rmi + binding-sca + binding-ws + binding-comet + binding-jsonrpc + implementation-extension + implementation-java + implementation-script + distributed-osgi + sca-client + + + + diff --git a/sandbox/samples/sca-features/sca-client/calculator-scaclient/README b/sandbox/samples/sca-features/sca-client/calculator-scaclient/README new file mode 100644 index 0000000000..97058ca4c9 --- /dev/null +++ b/sandbox/samples/sca-features/sca-client/calculator-scaclient/README @@ -0,0 +1,13 @@ +To run an application that uses the SCA client API to send messages to the +Calculator service running in the domain do the following + +First start one of the Calculator based contributions. For example, + +cd samples/binding-sca/contribution-calculator +follow the instructions in the README there + +Then run the the SCA client by doing the following: + +cd samples/calculator-scaclient +mvn exec:java + diff --git a/sandbox/samples/sca-features/sca-client/calculator-scaclient/pom.xml b/sandbox/samples/sca-features/sca-client/calculator-scaclient/pom.xml new file mode 100644 index 0000000000..6197b12e50 --- /dev/null +++ b/sandbox/samples/sca-features/sca-client/calculator-scaclient/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + + sample-calculator-scaclient + Apache Tuscany SCA Sample Calculator SCAClient + + + + + org.apache.tuscany.sca.shades + tuscany-base + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + org.codehaus.mojo + exec-maven-plugin + 1.1.1 + + + + java + + + + + sample.CalculatorSCAClient + + + + + diff --git a/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/calculator/CalculatorService.java b/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/calculator/CalculatorService.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 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/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/sample/CalculatorSCAClient.java b/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/sample/CalculatorSCAClient.java new file mode 100644 index 0000000000..edbf528517 --- /dev/null +++ b/sandbox/samples/sca-features/sca-client/calculator-scaclient/src/main/java/sample/CalculatorSCAClient.java @@ -0,0 +1,53 @@ +/* + * 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.net.URI; + +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.client.SCAClientFactory; + +import calculator.CalculatorService; + +public class CalculatorSCAClient { + + public static void main(String[] args) throws NoSuchDomainException, NoSuchServiceException { + + String domainURI = "default"; + String name = "world"; + + if (args.length == 2) { + domainURI= args[0]; + name = args[1]; + } else if (args.length == 1) { + domainURI= args[0]; + } + + System.out.println("using domain uri: " + domainURI); + System.out.println("using name: " + name); + + SCAClientFactory factory = SCAClientFactory.newInstance(URI.create(domainURI)); + CalculatorService calculator = factory.getService(CalculatorService.class, "CalculatorServiceComponent"); + + System.out.println("Calling CalculatorService.add(2, 3)"); + System.out.println(calculator.add(3, 2)); + } + +} diff --git a/sandbox/samples/sca-features/sca-client/pom.xml b/sandbox/samples/sca-features/sca-client/pom.xml new file mode 100644 index 0000000000..8a65e9f16d --- /dev/null +++ b/sandbox/samples/sca-features/sca-client/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + org.apache.tuscany.sca + 2.0-SNAPSHOT + tuscany-samples-sca-client + pom + Apache Tuscany SCA SCAClient Samples + + + + default + + true + + + calculator-scaclient + + + + -- cgit v1.2.3