From a40e527938d76ba71f211da7e327adb50384ba69 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:26:33 +0000 Subject: Moving 1.x tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835157 13f79535-47bb-0310-9956-ffa450edef68 --- sca-java-1.x/tags/0.91-incubating/samples/README | 261 ++++++++ .../samples/binding-echo-extension/README | 78 +++ .../samples/binding-echo-extension/build.xml | 51 ++ .../samples/binding-echo-extension/pom.xml | 78 +++ .../main/java/echo/DefaultEchoBindingFactory.java | 33 ++ .../src/main/java/echo/EchoBinding.java | 28 + .../src/main/java/echo/EchoBindingFactory.java | 33 ++ .../src/main/java/echo/impl/EchoBindingImpl.java | 77 +++ .../main/java/echo/impl/EchoBindingProcessor.java | 71 +++ .../main/java/echo/module/EchoModuleActivator.java | 69 +++ .../java/echo/provider/EchoBindingInvoker.java | 48 ++ .../echo/provider/EchoBindingProviderFactory.java | 55 ++ .../provider/EchoReferenceBindingProvider.java | 62 ++ .../echo/provider/EchoServiceBindingProvider.java | 74 +++ .../src/main/java/echo/server/EchoServer.java | 72 +++ .../src/main/java/echo/server/EchoService.java | 53 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/test/java/echo/Echo.java | 29 + .../src/test/java/echo/EchoComponentImpl.java | 44 ++ .../src/test/java/echo/EchoReferenceTestCase.java | 48 ++ .../src/test/java/echo/EchoServiceTestCase.java | 48 ++ .../src/test/resources/EchoBinding.composite | 40 ++ .../0.91-incubating/samples/binding-echo/README | 99 ++++ .../samples/binding-echo/binding-echo.png | Bin 0 -> 7846 bytes .../samples/binding-echo/binding-echo.svg | 174 ++++++ .../0.91-incubating/samples/binding-echo/build.xml | 75 +++ .../0.91-incubating/samples/binding-echo/pom.xml | 71 +++ .../binding-echo/src/main/java/echo/Echo.java | 29 + .../src/main/java/echo/EchoBindingClient.java | 51 ++ .../src/main/java/echo/EchoComponentImpl.java | 44 ++ .../src/main/resources/EchoBinding.composite | 40 ++ .../src/test/java/echo/EchoBindingTestCase.java | 57 ++ .../samples/calculator-rmi-reference/README | 138 +++++ .../samples/calculator-rmi-reference/build.xml | 72 +++ .../calculator-rmi-reference.png | Bin 0 -> 23615 bytes .../calculator-rmi-reference.svg | 412 +++++++++++++ .../samples/calculator-rmi-reference/pom.xml | 68 +++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/CalculatorClient.java | 44 ++ .../main/java/calculator/CalculatorService.java | 36 ++ .../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 | 39 ++ .../calculator/CalculatorRMIReferenceTestCase.java | 58 ++ .../java/calculator/CalculatorRMIServiceImpl.java | 52 ++ .../samples/calculator-rmi-service/README | 147 +++++ .../samples/calculator-rmi-service/build.xml | 72 +++ .../calculator-rmi-service.png | Bin 0 -> 20814 bytes .../calculator-rmi-service.svg | 330 +++++++++++ .../samples/calculator-rmi-service/pom.xml | 68 +++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/AddServiceImpl.java | 30 + .../src/main/java/calculator/CalculatorClient.java | 40 ++ .../src/main/java/calculator/CalculatorServer.java | 39 ++ .../main/java/calculator/CalculatorService.java | 33 ++ .../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 | 50 ++ .../calculator/CalculatorRMIServerTestCase.java | 51 ++ .../samples/calculator-script/README | 105 ++++ .../samples/calculator-script/build.xml | 72 +++ .../calculator-script/calculator-script.png | Bin 0 -> 23064 bytes .../calculator-script/calculator-script.svg | 334 +++++++++++ .../samples/calculator-script/pom.xml | 71 +++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/CalculatorClient.java | 43 ++ .../main/java/calculator/CalculatorService.java | 34 ++ .../java/calculator/CalculatorServiceImpl.java | 69 +++ .../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 | 47 ++ .../main/resources/calculator/AddServiceImpl.js | 22 + .../resources/calculator/DivideServiceImpl.groovy | 22 + .../resources/calculator/MultiplyServiceImpl.py | 20 + .../resources/calculator/SubtractServiceImpl.rb | 21 + .../test/java/calculator/CalculatorTestCase.java | 50 ++ .../samples/calculator-webapp/README | 118 ++++ .../samples/calculator-webapp/build.xml | 87 +++ .../samples/calculator-webapp/calculator-web.png | Bin 0 -> 22916 bytes .../samples/calculator-webapp/calculator-web.svg | 358 +++++++++++ .../samples/calculator-webapp/pom.xml | 65 ++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/AddServiceImpl.java | 30 + .../src/main/java/calculator/CalculatorClient.java | 47 ++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 69 +++ .../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 + .../src/main/resources/Calculator.composite | 47 ++ .../src/main/webapp/META-INF/sca-contribution.xml | 22 + .../src/main/webapp/WEB-INF/web.xml | 35 ++ .../calculator-webapp/src/main/webapp/calc.jsp | 50 ++ .../test/java/calculator/CalculatorTestCase.java | 50 ++ .../tags/0.91-incubating/samples/calculator/README | 97 +++ .../0.91-incubating/samples/calculator/build.xml | 72 +++ .../samples/calculator/calculator.png | Bin 0 -> 20552 bytes .../samples/calculator/calculator.svg | 329 +++++++++++ .../0.91-incubating/samples/calculator/pom.xml | 64 ++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/AddServiceImpl.java | 30 + .../src/main/java/calculator/CalculatorClient.java | 45 ++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 70 +++ .../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 + .../src/main/resources/Calculator.composite | 47 ++ .../test/java/calculator/CalculatorTestCase.java | 50 ++ .../0.91-incubating/samples/chat-webapp/README | 61 ++ .../0.91-incubating/samples/chat-webapp/pom.xml | 67 +++ .../src/main/java/sample/ChatService.java | 28 + .../src/main/java/sample/ChatServiceImpl.java | 36 ++ .../chat-webapp/src/main/resources/chat.composite | 37 ++ .../src/main/webapp/META-INF/sca-contribution.xml | 22 + .../chat-webapp/src/main/webapp/WEB-INF/web.xml | 42 ++ .../samples/chat-webapp/src/main/webapp/chat.html | 70 +++ .../samples/databinding-echo/README | 143 +++++ .../samples/databinding-echo/build.xml | 75 +++ .../samples/databinding-echo/databinding-echo.png | Bin 0 -> 23907 bytes .../samples/databinding-echo/databinding-echo.svg | 408 +++++++++++++ .../samples/databinding-echo/pom.xml | 83 +++ .../src/main/java/dbecho/ComponentAImpl.java | 85 +++ .../src/main/java/dbecho/ComponentBImpl.java | 59 ++ .../src/main/java/dbecho/Echo.java | 32 + .../main/java/dbecho/EchoDataBindingClient.java | 45 ++ .../src/main/java/dbecho/Interface1.java | 32 + .../src/main/java/dbecho/Interface2.java | 36 ++ .../src/main/resources/EchoDataBinding.composite | 58 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/main/resources/wsdl/echo.wsdl | 63 ++ .../test/java/dbecho/EchoDataBindingTestCase.java | 49 ++ .../samples/feed-aggregator/pom.xml | 79 +++ .../src/main/java/feed/AggregatorImpl.java | 76 +++ .../src/main/java/feed/SampleServer.java | 53 ++ .../feed-aggregator/src/main/java/feed/Sort.java | 38 ++ .../src/main/java/feed/SortImpl.java | 58 ++ .../src/main/resources/FeedAggregator.composite | 58 ++ .../0.91-incubating/samples/helloworld-dojo/README | 101 ++++ .../samples/helloworld-dojo/build-dojo.xml | 91 +++ .../samples/helloworld-dojo/build.xml | 107 ++++ .../samples/helloworld-dojo/helloworld-jsonrpc.png | Bin 0 -> 9947 bytes .../samples/helloworld-dojo/helloworld-jsonrpc.svg | 177 ++++++ .../samples/helloworld-dojo/pom.xml | 125 ++++ .../java/helloworldjsonrpc/HelloWorldService.java | 28 + .../helloworldjsonrpc/HelloWorldServiceImpl.java | 36 ++ .../src/main/resources/jsonrpc.composite | 36 ++ .../src/main/webapp/HelloWorldJSONRPC.html | 91 +++ .../src/main/webapp/META-INF/sca-contribution.xml | 26 + .../src/main/webapp/WEB-INF/web.xml | 45 ++ .../helloworld-dojo/src/main/webapp/style.css | 22 + .../samples/helloworld-jsonrpc/README | 90 +++ .../samples/helloworld-jsonrpc/build.xml | 95 +++ .../helloworld-jsonrpc/helloworld-jsonrpc.png | Bin 0 -> 9947 bytes .../helloworld-jsonrpc/helloworld-jsonrpc.svg | 177 ++++++ .../samples/helloworld-jsonrpc/pom.xml | 73 +++ .../java/helloworldjsonrpc/HelloWorldService.java | 28 + .../helloworldjsonrpc/HelloWorldServiceImpl.java | 36 ++ .../src/main/resources/jsonrpc.composite | 36 ++ .../src/main/webapp/HelloWorldJSONRPC.html | 75 +++ .../src/main/webapp/META-INF/sca-contribution.xml | 26 + .../src/main/webapp/WEB-INF/web.xml | 45 ++ .../helloworld-jsonrpc/src/main/webapp/style.css | 22 + .../samples/helloworld-ws-reference/README | 153 +++++ .../samples/helloworld-ws-reference/build.xml | 72 +++ .../helloworld-ws-reference.png | Bin 0 -> 7549 bytes .../helloworld-ws-reference.svg | 150 +++++ .../samples/helloworld-ws-reference/pom.xml | 79 +++ .../src/main/java/helloworld/HelloWorldClient.java | 38 ++ .../main/java/helloworld/HelloWorldService.java | 31 + .../helloworld/HelloWorldServiceComponent.java | 42 ++ .../main/resources/helloworldwsclient.composite | 34 ++ .../src/main/resources/logging.properties | 30 + .../src/main/resources/wsdl/helloworld.wsdl | 79 +++ .../java/helloworld/HelloWorldClientTestCase.java | 66 +++ .../test/java/helloworld/HelloWorldServerTest.java | 55 ++ .../samples/helloworld-ws-service/README | 132 +++++ .../samples/helloworld-ws-service/build.xml | 72 +++ .../helloworld-ws-service.png | Bin 0 -> 158 bytes .../helloworld-ws-service.svg | 149 +++++ .../samples/helloworld-ws-service/pom.xml | 79 +++ .../src/main/java/helloworld/HelloWorldImpl.java | 33 ++ .../src/main/java/helloworld/HelloWorldServer.java | 46 ++ .../main/java/helloworld/HelloWorldService.java | 33 ++ .../src/main/resources/helloworldws.composite | 33 ++ .../src/main/resources/wsdl/helloworld.wsdl | 79 +++ .../java/helloworld/HelloWorldServerTestCase.java | 51 ++ .../samples/implementation-composite/README | 116 ++++ .../samples/implementation-composite/build.xml | 72 +++ .../implementation-composite.png | Bin 0 -> 47415 bytes .../implementation-composite.svg | 658 +++++++++++++++++++++ .../samples/implementation-composite/pom.xml | 66 +++ .../src/main/java/composite/CompositeClient.java | 41 ++ .../src/main/java/composite/Source.java | 24 + .../src/main/java/composite/SourceCallback.java | 24 + .../src/main/java/composite/SourceImpl.java | 55 ++ .../src/main/java/composite/Target.java | 30 + .../src/main/java/composite/TargetImpl.java | 41 ++ .../src/main/resources/InnerComposite.composite | 41 ++ .../src/main/resources/InnerComposite2.composite | 33 ++ .../main/resources/META-INF/sca-contribution.xml | 25 + .../src/main/resources/OuterComposite.composite | 39 ++ .../src/test/java/composite/CompositeTestCase.java | 49 ++ .../samples/implementation-crud-extension/README | 87 +++ .../implementation-crud-extension/build.xml | 51 ++ .../samples/implementation-crud-extension/pom.xml | 77 +++ .../src/main/java/crud/CRUD.java | 54 ++ .../src/main/java/crud/CRUDImplementation.java | 48 ++ .../main/java/crud/CRUDImplementationFactory.java | 34 ++ .../crud/DefaultCRUDImplementationFactory.java | 49 ++ .../main/java/crud/backend/ResourceManager.java | 90 +++ .../java/crud/impl/CRUDImplementationImpl.java | 135 +++++ .../crud/impl/CRUDImplementationProcessor.java | 95 +++ .../main/java/crud/module/CRUDModuleActivator.java | 76 +++ .../crud/provider/CRUDImplementationProvider.java | 70 +++ .../CRUDImplementationProviderFactory.java | 45 ++ .../src/main/java/crud/provider/CRUDInvoker.java | 77 +++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/test/java/crud/CRUDTestCase.java | 64 ++ .../src/test/resources/crud.composite | 30 + .../samples/implementation-crud/README | 113 ++++ .../samples/implementation-crud/build.xml | 75 +++ .../implementation-crud/implementation-crud.png | Bin 0 -> 4227 bytes .../implementation-crud/implementation-crud.svg | 135 +++++ .../samples/implementation-crud/pom.xml | 64 ++ .../src/main/java/crud/client/CRUDClient.java | 53 ++ .../src/main/resources/crud.composite | 30 + .../src/test/java/crud/client/CRUDTestCase.java | 57 ++ sca-java-1.x/tags/0.91-incubating/samples/pom.xml | 67 +++ .../0.91-incubating/samples/simple-bigbank/README | 89 +++ .../samples/simple-bigbank/build.xml | 72 +++ .../0.91-incubating/samples/simple-bigbank/pom.xml | 71 +++ .../samples/simple-bigbank/simple-bigbank.png | Bin 0 -> 10202 bytes .../samples/simple-bigbank/simple-bigbank.svg | 200 +++++++ .../main/java/bigbank/account/AccountReport.java | 42 ++ .../main/java/bigbank/account/AccountService.java | 26 + .../java/bigbank/account/AccountServiceImpl.java | 61 ++ .../src/main/java/bigbank/accountdata/Account.java | 26 + .../bigbank/accountdata/AccountDataService.java | 28 + .../accountdata/AccountDataServiceImpl.java | 56 ++ .../java/bigbank/accountdata/CheckingAccount.java | 35 ++ .../java/bigbank/accountdata/SavingsAccount.java | 35 ++ .../java/bigbank/accountdata/StockAccount.java | 39 ++ .../main/java/bigbank/client/BigBankClient.java | 43 ++ .../src/main/resources/BigBank.composite | 33 ++ .../src/test/java/bigbank/BigBankTestCase.java | 48 ++ .../0.91-incubating/samples/simple-callback/README | 97 +++ .../samples/simple-callback/build.xml | 72 +++ .../samples/simple-callback/pom.xml | 65 ++ .../samples/simple-callback/simple-callback.png | Bin 0 -> 137 bytes .../samples/simple-callback/simple-callback.svg | 150 +++++ .../src/main/java/simplecallback/MyClient.java | 27 + .../src/main/java/simplecallback/MyClientImpl.java | 49 ++ .../src/main/java/simplecallback/MyService.java | 32 + .../java/simplecallback/MyServiceCallback.java | 27 + .../main/java/simplecallback/MyServiceImpl.java | 51 ++ .../java/simplecallback/SimpleCallbackClient.java | 38 ++ .../src/main/resources/simplecallback.composite | 34 ++ .../simplecallback/SimpleCallbackTestCase.java | 49 ++ .../0.91-incubating/samples/supplychain/README | 101 ++++ .../0.91-incubating/samples/supplychain/build.xml | 72 +++ .../0.91-incubating/samples/supplychain/pom.xml | 65 ++ .../src/main/java/supplychain/Customer.java | 33 ++ .../java/supplychain/CustomerComponentImpl.java | 44 ++ .../src/main/java/supplychain/Retailer.java | 28 + .../java/supplychain/RetailerComponentImpl.java | 39 ++ .../src/main/java/supplychain/Shipper.java | 28 + .../java/supplychain/ShipperComponentImpl.java | 39 ++ .../main/java/supplychain/SupplyChainClient.java | 40 ++ .../src/main/java/supplychain/Warehouse.java | 28 + .../java/supplychain/WarehouseComponentImpl.java | 39 ++ .../src/main/resources/supplychain.composite | 45 ++ .../supplychain/SupplyChainClientTestCase.java | 50 ++ .../samples/supplychain/supplychain.png | Bin 0 -> 3898 bytes .../samples/supplychain/supplychain.svg | 228 +++++++ 289 files changed, 18034 insertions(+) create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/DefaultEchoBindingFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBinding.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBindingFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/module/EchoModuleActivator.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoServer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/Echo.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoReferenceTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoServiceTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/resources/EchoBinding.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/Echo.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoBindingClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/resources/EchoBinding.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/AddService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/DivideService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/Calculator.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/AddServiceImpl.js create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/DivideServiceImpl.groovy create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/MultiplyServiceImpl.py create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/SubtractServiceImpl.rb create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/resources/Calculator.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/calc.jsp create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/resources/Calculator.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/resources/chat.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/chat.html create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentAImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentBImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Echo.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/EchoDataBindingClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface1.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface2.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/EchoDataBinding.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/wsdl/echo.wsdl create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/test/java/dbecho/EchoDataBindingTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/AggregatorImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SampleServer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/Sort.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SortImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/resources/FeedAggregator.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build-dojo.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/resources/jsonrpc.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/HelloWorldJSONRPC.html create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/style.css create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/resources/jsonrpc.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/HelloWorldJSONRPC.html create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/style.css create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldServiceComponent.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/logging.properties create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/wsdl/helloworld.wsdl create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldClientTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldServerTest.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldServer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/helloworldws.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/wsdl/helloworld.wsdl create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldServerTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/CompositeClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Source.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceCallback.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Target.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/TargetImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite2.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/OuterComposite.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/test/java/composite/CompositeTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUD.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/DefaultCRUDImplementationFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationProcessor.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/module/CRUDModuleActivator.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDInvoker.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/resources/crud.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/java/crud/client/CRUDClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/resources/crud.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/test/java/crud/client/CRUDTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountReport.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/Account.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/CheckingAccount.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/SavingsAccount.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/StockAccount.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/client/BigBankClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/resources/BigBank.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/test/java/bigbank/BigBankTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.svg create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClientImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyService.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceCallback.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/SimpleCallbackClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/resources/simplecallback.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/test/java/simplecallback/SimpleCallbackTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/README create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/build.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/pom.xml create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Customer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/CustomerComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Retailer.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/RetailerComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Shipper.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/ShipperComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/SupplyChainClient.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Warehouse.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/WarehouseComponentImpl.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/resources/supplychain.composite create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/test/java/supplychain/SupplyChainClientTestCase.java create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.png create mode 100644 sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.svg (limited to 'sca-java-1.x/tags/0.91-incubating/samples') diff --git a/sca-java-1.x/tags/0.91-incubating/samples/README b/sca-java-1.x/tags/0.91-incubating/samples/README new file mode 100644 index 0000000000..eac75adbce --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/README @@ -0,0 +1,261 @@ +The Apache Tuscany SCA Samples +============================== +The Apache Tuscany SCA samples are built as part of the main Maven build and +run, using the provided JUnit test cases, as tests in the Maven build. + +In the binary distribution of Apache Tuscany the samples can also +be run using the provided Ant build.xml files. These show the samples running +from a simple main() method without the need for a JUnit test case. + +In these notes text that appears in angled brackets like this means +that you need to make a choice and provide your own text at that point. + +These simple samples have been created with the intention of illustrating the +usage of the SCA API and annotations and certainly not to levels of SCA component +abstraction. In real life situations you should use SCA to assemble real and +usually bigger components, and when you do that you'll get all the benefits of +SCA, bindings, policies, integration in an SOA environment etc.. + +Sample Overview +--------------- +The samples generally show off different features of the SCA runtime +and the extensions that come packaged with it. This list is ordered in a rough +order of increasing complexity. + +calculator - A calculator built with java components and local + wires +calculator-script - The calculator but this time built using various + script languages +calculator-webapp - The calculator again but this time running inside a + web app +chat-webapp - A simple chat style web app demonsrating how to use + the AJAX binding +feed-aggregator - Demonstrates using the ATOM binding +helloworld-ws-reference - The client side of a hello world sample that uses a + web service binding +helloworld-ws-service - The server side of a hello world sample that uses a + web service binding +calculator-rmi-reference - The calculator configured to talk RMI to the + calculator-rmi-service sample +calculator-rmi-service - The calculator configured to accept RMI requests + from calculator-rmi-reference +helloworld-jsonrpc - An SCA application that exposes a service using + JSONRPC +helloworld-dojo - An SCA application that exposes a service using + JSONRPC and a client using the Dojo toolkit +simple-callback - An SCA application with two components demonstrating + the callback interface +implementation-composite - An SCA application that shows how composites are used to + implement components +supplychain - A more complicated sample showing how asynchronous + callbacks can be used +databinding-echo - An SCA application that shows how databindings + transform data +simple-bigbank - A banking application built with java components + and local wires + +There are two samples that demonstrate how to build extensions for the +Tuscany SCA runtime. These samples are slightly different from the samples +above in that the provided code is concerned with building the extension +and not with building an application that uses it. The application +that shows how the new extension can be used is provided in an associated +sample. + +implementation-crud-extension - Shows how to build new implementation type + extensions +implementation-crud - A sample application that exercises the new + implementation extensions +binding-echo-extension - Shows how to build new binding extensions +binding-echo - A sample application that exercises the new + binding extension + +Sample Layout +------------- +All sample directories are organized in the same way based on the default +project template provided by Maven. For example, take a look at the calculator +sample; + +calculator/ + src/ - Holds all of the source files for the sample + main/ - Groups together the files that implement the sample + java/ - Java source files + resources/ - Non java resource files such as composte files + test/ - Groups together files that provide sample tests + java - Java test sources files. Usually JUnit test cases + target/ - Holds the files generated when the sample is built + classes/ - For example, Java class files + test-classes/ - classes from src/test and other test files + +Getting Ready To Build +---------------------- +You will need to install the following software before you start. + +J2SE Development Kit (JDK) 5.0 +Apache Ant 1.7.0 - if you are going to use Ant +Apache Maven 2.0.6 - if you are going to use Maven + +Java and Ant and/or Maven binary directories must be present in your PATH so +that their executable programs are available in your environment. You may +find it useful to use a script to set up your environment, for example; + +For UNIX: + JAVA_HOME=/ + ANT_HOME=//apache-ant-1.7.0 + MAVEN_HOME=//maven-2.0.6 + export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$MAVEN_HOME/bin:$PATH + +For Windows: + set JAVA_HOME=C:\ + set ANT_HOME=C:\\apache-ant-1.7.0 + set MAVEN_HOME=C:\\maven-2.0.6 + set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%MAVEN_HOME%\bin;%PATH% + + +Building And Running The SCA Samples Using Ant +---------------------------------------------- +The build.xml files provided with the Apache Tuscany SCA samples are designed +to work with the binary distribution. They rely on the tuscany-sca-manifest.jar +to describe the class path and this jar is only provided as part of the +binary distribution. + +The binary distribution of SCA also includes precompiled versions of each sample. +If you look in the target directory of each sample you will see this jar file. To +run a sample based on all of the precompiled artifacts all you have to do is: + +cd +ant run + +Check each /README file as some samples require that two progams are +run to get the desired result, for example, the two samples that show how +to build extensions are run from their associated application samples. + +If you want to rebuild a sample, for example, if you have changed it, do the +following: + +cd +ant compile + +Once the sample is built you have the option of running the sample in whatever +way best suits you. Two alternatives are provided in the ant build files. + +The compile target builds the class files and then builds the jar so you can use +the same command as before: + +ant run + +This will use the generated jar to run the samples. The command line version of +this is: + +on Windows + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\ + +for example : java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient + +on *nix + +java -cp ../../lib/tuscany-sca-manifest.jar:target/ + +for example : java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + + +You can use the compiled classes directly using + +ant run-classes + +The command line version of this is: + +on Windows + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\classes + +for example : java -cp ..\..\lib\tuscany-sca-manifest.jar;target\classes calculator.CalculatorClient + +on *nix + +java -cp ../../lib/tuscany-sca-manifest.jar:target/classes + +for example : java -cp ../../lib/tuscany-sca-manifest.jar:target/classes calculator.CalculatorClient + +The class specified on the command of course depends on which sample you want to +run. In the examples we have used we are running the CalculatorClient from the calculator sample. + + +Building And Running The SCA Samples Using Maven +------------------------------------------------ + +The Maven build process will work from both source and binary distributions. +To build and test all of the Apache Tuscany SCA sources, including the samples, +do the following. + +cd sca +mvn + +This will take a little while to complete. Experience with Maven tells us that +sometimes there are problems downloading the dependencies that Apache Tuscany +SCA requires. If Maven reports that it cannot download required dependencies +try running the Maven build again. + +Once you have all of the source built you can build and run each sample +independently if required. + +cd +mvn + +When using Maven the samples are run within JUnit test cases and so you will +sometimes not see any test output. You will always see an indication of test +success or failure. + +Using The Samples In An IDE +--------------------------------------------- +The easiest way to use the samples in an IDE is to use Maven to generate all +of the IDE project files for you automatically. This works best if you +generate IDE projects for all of the Apache Tuscany modules. You can then +include the ones you are interested in working with in you IDE. + +To build IDE project files for all of the modules in Apache Tuscany SCA; + +cd sca + +If you are an Eclipse user do the following + +mvn -Peclipse eclipse:eclipse + +If you are an IDEA user do the following + +mvn idea:idea + +These commands generate project files for each module in Apache Tuscany SCA. +The modules you are interested in can now be included in your IDE, for example, +in Eclipse, if you create a new Java project and use the option to "create a +new project from existing source" you can specify an SCA module directory, +which includes the generated project files, and Eclipse will treat it like any +other Java project. + +Using The Samples In An IDE Without Maven +----------------------------------------- +We don't provide any IDE project files with our distributions so you will have to +import the sample files into your IDE manually. Here's an example of how it can be +done using Eclipse. + +In a new or existing workspace + Create a new java project to represent the sample you want to work on, e.g. + calculator + Import all of the sample code and resources into this project, e.g. + File, Import and then select tuscany-sca-0.90-incubating\samples\calculator from the filesystem + Configure the source path to include + src/main/java + src/main/resources + Configure the output folder to be + calculator/target + Configure the build path to include all of the jars provided in + lib + If you select calculator.CalculatorClient.java and run as "Java Application" you should see + 3 + 2=5.0 + 3 - 2=1.0 + 3 * 2=6.0 + 3 / 2=1.5 + +The details of how to do this for other development environments will +vary but the process will be similar. + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/README b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/README new file mode 100644 index 0000000000..d8ded49e21 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/README @@ -0,0 +1,78 @@ +Binding Echo Sample +=================== +This sample demonstrates how new bindings are constructed for Apache Tuscany +SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the echo binding that this sample provides +please see the binding-echo sample that provides the necessary client and +application code to bring up an application that uses this binding + +Sample Overview +--------------- +This sample contains a implementation of an SCA binding that simply echoes back +any messages that are sent to it. + +binding-echo-extension/ + src/ + main/ + java/ + echo/ - The binding interfaces + impl/ - The bindings model classes + module/ - The activator that loads the binding into the + SCA runtime + provider/ - The bindings runtime classes + server/ - A dummy server that the binding is plugged into + resources/ + META-INF/ + services/ + org.apache.sca.tuscany.sca.core.ModuleActivator - specifies the + module activation class to call + test/ + java/ + echo/ - test code + resources/ + EchoBinding.composite - the SCA assembly used by the unit test + build.xml - the Ant build file + pom.xml - the Maven build file + +Building The Sample Using Ant +----------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd binding-echo-extension +ant compile + +See the binding-echo sample to run a sample that uses this binding. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd binding-echo-extension +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running echo.EchoServiceTestCase +Returned message: foo +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.011 sec +Running echo.EchoReferenceTestCase +Returned message: foo +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/build.xml new file mode 100644 index 0000000000..17defccb6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/pom.xml new file mode 100644 index 0000000000..540a8f915c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/pom.xml @@ -0,0 +1,78 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-binding-echo-extension + Apache Tuscany Echo Binding Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/DefaultEchoBindingFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/DefaultEchoBindingFactory.java new file mode 100644 index 0000000000..b27b936302 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/DefaultEchoBindingFactory.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 echo; + +import echo.impl.EchoBindingImpl; + +/** + * A factory for the sample Echo binding model. + */ +public class DefaultEchoBindingFactory implements EchoBindingFactory { + + public EchoBinding createEchoBinding() { + return new EchoBindingImpl(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBinding.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBinding.java new file mode 100644 index 0000000000..446f720634 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBinding.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 echo; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * A model for the sample Echo binding. + */ +public interface EchoBinding extends Binding { +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBindingFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBindingFactory.java new file mode 100644 index 0000000000..0f6fee82be --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/EchoBindingFactory.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 echo; + +/** + * A factory for the sample Echo binding model. + */ +public interface EchoBindingFactory { + + /** + * Creates a new Echo binding. + * + * @return a new Echo binding + */ + EchoBinding createEchoBinding(); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingImpl.java new file mode 100644 index 0000000000..ef1629d519 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingImpl.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package echo.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +import echo.EchoBinding; + +/** + * Implementation of the Echo binding model. + */ +public class EchoBindingImpl implements EchoBinding { + + private String name; + private String uri; + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getPolicySets() { + // The sample binding does not support policies + return Collections.emptyList(); + } + + public List getRequiredIntents() { + // The sample binding does not support policies + return Collections.emptyList(); + } + + public List getExtensions() { + // The sample binding does not support extensions + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample binding is always resolved + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java new file mode 100644 index 0000000000..1d82cd860c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/impl/EchoBindingProcessor.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package echo.impl; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +import echo.EchoBinding; +import echo.EchoBindingFactory; + +/** + * A processor for elements. + */ +public class EchoBindingProcessor implements StAXArtifactProcessor { + + private QName BINDING_ECHO = new QName("http://echo", "binding.echo"); + + private final EchoBindingFactory factory; + + public EchoBindingProcessor(EchoBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_ECHO; + } + + public Class getModelType() { + return EchoBinding.class; + } + + public EchoBinding read(XMLStreamReader reader) throws ContributionReadException { + String uri = reader.getAttributeValue(null, "uri"); + EchoBinding echoBinding = factory.createEchoBinding(); + if (uri != null) { + echoBinding.setURI(uri.trim()); + } + return echoBinding; + } + + public void write(EchoBinding echoBinding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(EchoBinding echoBinding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/module/EchoModuleActivator.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/module/EchoModuleActivator.java new file mode 100644 index 0000000000..268b903e54 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/module/EchoModuleActivator.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package echo.module; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +import echo.DefaultEchoBindingFactory; +import echo.EchoBindingFactory; +import echo.impl.EchoBindingProcessor; +import echo.provider.EchoBindingProviderFactory; +import echo.server.EchoServer; + +/** + * A module activator for the sample Echo binding extension. + */ +public class EchoModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + // No extensionPoints being contributed here + return null; + } + + public void start(ExtensionPointRegistry registry) { + + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + MessageFactory messageFactory = factories.getFactory(MessageFactory.class); + + // Create the Echo model factory + EchoBindingFactory echoFactory = new DefaultEchoBindingFactory(); + + // Add the EchoProcessor extension + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + EchoBindingProcessor echoBindingProcessor = new EchoBindingProcessor(echoFactory); + processors.addArtifactProcessor(echoBindingProcessor); + + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + providerFactories.addProviderFactory(new EchoBindingProviderFactory(messageFactory)); + + // Start the Echo server + EchoServer.start(); + } + + public void stop(ExtensionPointRegistry registry) { + EchoServer.stop(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.java new file mode 100644 index 0000000000..e3d52fa703 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingInvoker.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 echo.provider; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Interceptor for the sample echo binding. + */ +public class EchoBindingInvoker implements Invoker { + + private Object echo(Object[] args) throws InvocationTargetException { + // echo back the result, a real binding would invoke some API for flowing the request + return args[0]; + } + + public Message invoke(Message msg) { + try { + Object resp = echo((Object[])msg.getBody()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + return msg; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java new file mode 100644 index 0000000000..623cb0e16e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoBindingProviderFactory.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package echo.provider; + +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +import echo.EchoBinding; + + +/** + * Implementation of the Echo binding model. + */ +public class EchoBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + + public EchoBindingProviderFactory(MessageFactory messageFactory) { + this.messageFactory = messageFactory; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, EchoBinding binding) { + return new EchoReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, EchoBinding binding) { + return new EchoServiceBindingProvider(component, service, binding, messageFactory); + } + + public Class getModelType() { + return EchoBinding.class; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.java new file mode 100644 index 0000000000..dd1a8f42f8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoReferenceBindingProvider.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 echo.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +import echo.EchoBinding; + +/** + * Implementation of the Echo binding provider. + */ +public class EchoReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public EchoReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + EchoBinding binding) { + this.reference = reference; + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + if (isCallback) { + throw new UnsupportedOperationException(); + } else { + return new EchoBindingInvoker(); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java new file mode 100644 index 0000000000..896e40df8d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/provider/EchoServiceBindingProvider.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package echo.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +import echo.EchoBinding; +import echo.server.EchoServer; +import echo.server.EchoService; + +/** + * Implementation of the Echo binding provider. + */ +public class EchoServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private EchoBinding binding; + private MessageFactory messageFactory; + + public EchoServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, EchoBinding binding, MessageFactory messageFactory) { + this.component = component; + this.service = service; + this.binding = binding; + this.messageFactory = messageFactory; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public void start() { + + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + InvocationChain chain = wire.getInvocationChains().get(0); + + // Register with the hosting server + String uri = component.getURI() + "/" + binding.getName(); + EchoServer.getServer().register(uri, new EchoService(chain.getHeadInvoker(), messageFactory)); + } + + public void stop() { + + // Unregister from the hosting server + String uri = component.getURI() + "/" + binding.getName(); + EchoServer.getServer().unregister(uri); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoServer.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoServer.java new file mode 100644 index 0000000000..e1c88c38f9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoServer.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 echo.server; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +/** + * A sample Echo server, showing how to integrate service bindings. + */ +public class EchoServer { + + public static EchoServer server; + + private Map services = new HashMap(); + + public static void start() { + server = new EchoServer(); + } + + public static void stop() { + server = null; + } + + public static EchoServer getServer() { + return server; + } + + /** + * Register a service under the given name. + * + * @param service + * @param name + */ + public void register(String uri, EchoService service) { + services.put(uri, service); + } + + public void unregister(String uri) { + services.remove(uri); + } + + /** + * Dispatch an incoming interaction to the corresponding service. + * + * @param uri + * @param input + * @return + */ + public String sendReceive(String uri, String input) throws InvocationTargetException { + return services.get(uri).sendReceive(input); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoService.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoService.java new file mode 100644 index 0000000000..79593b2b6c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/java/echo/server/EchoService.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 echo.server; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * The EchoService + */ +public class EchoService { + private Invoker invoker; + private MessageFactory messageFactory; + + public EchoService(Invoker invoker, MessageFactory messageFactory) { + super(); + this.invoker = invoker; + this.messageFactory = messageFactory; + } + + public String sendReceive(String input) throws InvocationTargetException { + + Message request = messageFactory.createMessage(); + request.setBody(new Object[] {input}); + // dispatch and get the response + Message response = invoker.invoke(request); + Object body = response.getBody(); + if (response.isFault()) { + throw new InvocationTargetException((Throwable)body); + } + return (String)body; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..13d0d6f570 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -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. +# Implementation class for the ExtensionActivator +echo.module.EchoModuleActivator diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/Echo.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/Echo.java new file mode 100644 index 0000000000..1d5e973f33 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/Echo.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package echo; + +/** + * Interface of our sample Echo service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoComponentImpl.java new file mode 100644 index 0000000000..ba68dfe908 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoComponentImpl.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 echo; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + + +/** + * A simple client component that uses a reference with an Echo binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + private Echo echoReference; + + @Constructor + public EchoComponentImpl(@Reference(name = "echoReference", required = true) Echo echoReference) { + this.echoReference = echoReference; + } + + public String echo(String msg) { + String result = echoReference.echo(msg); + System.out.println("Returned message: "+ result); + return result; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoReferenceTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoReferenceTestCase.java new file mode 100644 index 0000000000..dc6a37c11f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoReferenceTestCase.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 echo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev$ $Date$ + */ +public class EchoReferenceTestCase extends TestCase { + + private SCADomain scaDomain; + private Echo service; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + service = scaDomain.getService(Echo.class, "EchoComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testEchoBinding() { + String result = service.echo("foo"); + assertEquals(result, "foo"); + } + + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoServiceTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoServiceTestCase.java new file mode 100644 index 0000000000..fafc112d01 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/java/echo/EchoServiceTestCase.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 echo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo.server.EchoServer; + +/** + * @version $Rev$ $Date$ + */ +public class EchoServiceTestCase extends TestCase { + + private SCADomain scaDomain; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testEchoBinding() throws Exception { + String result = EchoServer.getServer().sendReceive("EchoComponent/EchoService", "foo"); + assertEquals(result, "foo"); + } + + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/resources/EchoBinding.composite b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/resources/EchoBinding.composite new file mode 100644 index 0000000000..d0d138533b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo-extension/src/test/resources/EchoBinding.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/README b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/README new file mode 100644 index 0000000000..0aea36a081 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/README @@ -0,0 +1,99 @@ +Binding Echo Sample Application +=============================== +This sample demonstrates how to use the new binding extension +binding-echo-extension. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens, open a command prompt, +navigate to this sample directory, and do + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;..\binding-echo-extension\target\sample-binding-echo-extension.jar;target\sample-binding-echo.jar echo.EchoBindingClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:../binding-echo-extension/target/sample-binding-echo-extension.jar:target/sample-binding-echo.jar echo.EchoBindingClient + +This looks like a long command. The three things we add to the classpath are + +tuscany-sca-manifest.jar - all of the standard Tuscany SCA runtime and + extension classes +sample-binding-echo-extension.jar - the new echo binding extension implementation +sample-binding-echo - the application that uses the echo binding + + +Sample Overview +--------------- +This sample contains an application (client and server code) that uses +an SCA binding that simply echoes back any messages that are sent to it. + +binding-echo/ + src/ + main/ + java/ + echo/ + Echo.java - interface definition for the sample + reference and service + EchoComponentImpl.java - sample component implementation with + echo binding reference + EchoBindingClient.java - sample client + resources/ + EchoBinding.composite - the SCA assembly for this sample + test/ + java/ + echo + EchoBindingTestCase.java - sample JUnit test case for the sample + client + binding-echo.png - pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows. + +cd binding-echo +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Returned message: foo + [java] Echo reference = foo + [java] Returned message: bar + [java] Echo service = bar + + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and +run using Maven as follows. + +cd binding-echo +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running echo.EchoBindingTestCase +Returned message: foo +Returned message: bar +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.811 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.png b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.png new file mode 100644 index 0000000000..a38d985363 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.svg b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.svg new file mode 100644 index 0000000000..5b5051bef5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/binding-echo.svg @@ -0,0 +1,174 @@ + + + + + + + + + + image/svg+xml + + + + + + + + EchoBinding + + + EchoComponent + + + + EchoSerivce EchoReference + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/build.xml new file mode 100644 index 0000000000..7689ef3a54 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/build.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/pom.xml new file mode 100644 index 0000000000..a8b660eaf8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-binding-echo + Apache Tuscany Echo Binding Sample Application + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + sample-binding-echo-extension + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/Echo.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/Echo.java new file mode 100644 index 0000000000..1d5e973f33 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/Echo.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package echo; + +/** + * Interface of our sample Echo service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoBindingClient.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoBindingClient.java new file mode 100644 index 0000000000..97ed202177 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoBindingClient.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package echo; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo.server.EchoServer; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + * @version $Rev$ $Date$ + */ +public class EchoBindingClient { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("EchoBinding.composite"); + + // Call the echo service component which will, in turn, call a reference + // with an echo binding. The echo binding will echo the given string. + Echo service = scaDomain.getService(Echo.class, "EchoComponent"); + String echoString = service.echo("foo"); + System.out.println("Echo reference = " + echoString ); + + // Call the echo server. This will dispatch the call to a service with an + // echo binding. The echo binding will pass the call to the echo component. + echoString = EchoServer.getServer().sendReceive("EchoComponent/EchoService", "bar"); + System.out.println("Echo service = " + echoString ); + + scaDomain.close(); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java new file mode 100644 index 0000000000..ba68dfe908 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/java/echo/EchoComponentImpl.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 echo; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + + +/** + * A simple client component that uses a reference with an Echo binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + private Echo echoReference; + + @Constructor + public EchoComponentImpl(@Reference(name = "echoReference", required = true) Echo echoReference) { + this.echoReference = echoReference; + } + + public String echo(String msg) { + String result = echoReference.echo(msg); + System.out.println("Returned message: "+ result); + return result; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/resources/EchoBinding.composite b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/resources/EchoBinding.composite new file mode 100644 index 0000000000..94612fb325 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/main/resources/EchoBinding.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java new file mode 100644 index 0000000000..9851379207 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.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 echo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo.Echo; +import echo.server.EchoServer; + +public class EchoBindingTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testReference() throws Exception { + // Call the echo service component which will, in turn, call a reference + // with an echo binding. The echo binding will echo the given string. + Echo service = scaDomain.getService(Echo.class, "EchoComponent"); + String echoString = service.echo("foo"); + assertEquals(echoString, "foo"); + } + + public void testService() throws Exception { + // Call the echo server. This will dispatch the call to a service with an + // echo binding. The echo binding will pass the call to the echo component. + String echoString = EchoServer.getServer().sendReceive("EchoComponent/EchoService", "bar"); + assertEquals(echoString, "bar"); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/README b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/README new file mode 100644 index 0000000000..837b5ce75f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/README @@ -0,0 +1,138 @@ +Calculator RMI Reference Sample +=============================== + +This sample illustrates the use of Tuscany RMI Binding to call reference +services that are hosted as Java RMI services. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, first +navigate to the calculator-rmi-service sample and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-service.jar calculator.CalculatorServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-service.jar calculator.CalculatorServer + +Now you have the server running you need to open another command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-reference.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-reference.jar calculator.CalculatorClient + +Sample Overview +--------------- +This sample extends the calculator sample by replacing the local wired +connections with RMI bindings. Instead of local add, subtract, multiply and +divide components, an RMI service implementation now provides the +add, subtract, multiply and divide interfaces and is hosted as an RMI server. +References specified in the .composite file include an RMI binding which targets +this RMI server. + +This sample adds a number of classes to the basic calculator sample: + +calculator-rmi-reference/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - as calculator sample + AddService.java - as calculator sample + SubtractService.java - as calculator sample + MultipleService.java - as calculator sample + DivideService.java - as calculator sample + CalculatorClient.java - as calculator sample + CalculatorServiceImpl.java - calls the RMI service + that provides the target for the + RMI bindings in the composite + resources/ + CalculatorRMIReference.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorRMIReferenceTestCase.java - JUnit test case + CalculatorRMIServiceImpl.java - test RMI service to call + calculator-rmi-reference.png - a pictorial representation of the + .composite file + build.xml - the Ant build file for the client + pom.xml - the Maven build file + +Note. As this test creates and uses local network connections you may need to +configure your firewall, if you are running one, to allow the test to run +successfully. + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant. + +The server provides an RMI server that the acts as a target for the SCA RMI +bindings. Start a new console and use the following commands. + +cd calculator-rmi-service +ant compile +ant run + +This will run up the server and display the following. + +run: + [java] Starting of the SCA Calculator Application exposed as RMI Services... + [java] ...Press Enter to Exit... + +The client is very similar to the calculator sample. It starts the SCA runtime +and calls each of the calculator operations. In doing this the RMI bindings +make calls out to the RMI server you started in the previous step. Start +a new console and use the following commands. + +cd calculator-rmi-reference +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +If you now return to the console window running the server and press enter the +server should stop. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-rmi-reference +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorRMIReferenceTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.308 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/build.xml new file mode 100644 index 0000000000..30817fe6f0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.png b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.png new file mode 100644 index 0000000000..8c76b77a9f Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.svg b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.svg new file mode 100644 index 0000000000..ba802e6717 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/calculator-rmi-reference.svg @@ -0,0 +1,412 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + CalculatorServiceRMIImpl + addService + subtractService + multiplyService + divideService + + + + + AddReference + SubtractReference + MultiplyReference + DivideReference + RMIRegistry + + + + + RMI RMI RMI RMI + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/pom.xml new file mode 100644 index 0000000000..eb3f35b0e4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-calculator-rmi-reference + Apache Tuscany Calculator Sample using an RMI Service Reference + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi + 0.91-incubating + runtime + + + junit + junit + 4.2 + test + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..ec57a6a533 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the add service + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..cd1076c3f1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorClient.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 org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * 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 { + SCADomain scaDomain = SCADomain.newInstance("CalculatorRMIReference.composite"); + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..08cba76467 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/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 java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * The Calculator service interface. + */ +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/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..f28f0ca179 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.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/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..835e4fda6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..30e4e6a56a --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite new file mode 100644 index 0000000000..20dce0ec28 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/main/resources/CalculatorRMIReference.composite @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java new file mode 100644 index 0000000000..0bddb0445f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIReferenceTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR 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.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorRMIReferenceTestCase extends TestCase { + + private SCADomain scaDomain; + private CalculatorService calculatorService; + + protected void setUp() throws Exception { + CalculatorRMIServiceImpl rmiCalculatorImpl = new CalculatorRMIServiceImpl(); + Registry rmiRegistry = LocateRegistry.createRegistry(8099); + rmiRegistry.bind("CalculatorRMIService", rmiCalculatorImpl); + + scaDomain = SCADomain.newInstance("CalculatorRMIReference.composite"); + calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + LocateRegistry.getRegistry(8099).unbind("CalculatorRMIService"); + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java new file mode 100644 index 0000000000..d8ded42cb2 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-reference/src/test/java/calculator/CalculatorRMIServiceImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.rmi.RemoteException; +import java.rmi.server.UnicastRemoteObject; + + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorRMIServiceImpl extends UnicastRemoteObject implements CalculatorService { + + private static final long serialVersionUID = -1543948944662001428L; + + public CalculatorRMIServiceImpl() throws RemoteException { + super(); + } + + public double add(double n1, double n2) throws RemoteException { + return n1 + n2; + } + + public double subtract(double n1, double n2) { + return n1 - n2; + } + + public double multiply(double n1, double n2) { + return n1 * n2; + } + + public double divide(double n1, double n2) { + return n1 / n2; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/README b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/README new file mode 100644 index 0000000000..454cdc0d37 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/README @@ -0,0 +1,147 @@ +Calculator RMI Service Sample +============================= + +This sample illustrates the use of Tuscany RMI Binding to expose component +services as Java RMI Services. It also demonstrates how a simple Java RMI +Client application invokes the SCA Application's services exposed as RMI +Services. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-service.jar calculator.CalculatorServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-service.jar calculator.CalculatorServer + +Now you have the server running you need to open another command prompt, navigate +to the calculator-rmi-reference sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-rmi-reference.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-rmi-reference.jar calculator.CalculatorClient + + +Sample Overview +--------------- +This sample extends the calculator sample by replacing the local service +binding with an RMI binding. SO a java client can call the service exposed +by the SCA application using an RMI client. + +This sample adds a number of classes to the basic calculator sample: + +calculator-rmi-service/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - as calculator sample + CalculatorServiceImpl.java + AddService.java - as calculator sample + AddServiceImpl.java + SubtractService.java - as calculator sample + SubtractServiceImpl.java + MultiplyService.java - as calculator sample + MultiplyServiceImpl.java + DivideService.java - as calculator sample + DivideServiceImpl.java + CalculatorClient.java - (Not currently used) Uses the + java naming service to + look up the Calculator RMI service. + It then calls add, subtract, multiple + and divide methods on the service + CalculatorServer.java - starts the SCA Runtime and deploys + the CalculatorRMIServer.composite. + In doing this the SCA RMI binding + acts to expose the CalculatorService + over RMI. + resources/ + CalculatorRMIServer.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorRMIServerTestCase.java - JUnit test case + calculator-rmi-service.png - a pictorial representation of the + .composite file + build.xml - the Ant build file for the server + pom.xml - the Maven build file + +Note. As this test creates and uses local network connections you may need to +configure your firewall, if you are running one, to allow the test to run +successfully. + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant. Two +build files are used to support client and server functions. + +The server starts the SCA runtime and loads the SCA calculator application +which exposes an RMI service. Start a new console and use the following +commands. + +cd calculator-rmi-service +ant compile +ant run + +This will run up the server and display the following. + +run: + [java] Starting of the SCA Calculator Application exposed as RMI Services... + [java] ...Press Enter to Exit... + +The client is very similar to the calculator sample + +It locates the RMI service that the SCA runtime is exposing and calls each of +the calculator operations. Start a new console and use the following commands. + +cd calculator-rmi-reference +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +If you now return to the console window running the server and press enter the +server should stop. + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-rmi-service +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorRMIServerTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.819 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/build.xml new file mode 100644 index 0000000000..f98f35e4b0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.png b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.png new file mode 100644 index 0000000000..574f5eb14b Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.svg b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.svg new file mode 100644 index 0000000000..9253110f98 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/calculator-rmi-service.svg @@ -0,0 +1,330 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService(RMI) + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/pom.xml new file mode 100644 index 0000000000..76310d0960 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-calculator-rmi-service + Apache Tuscany Calculator Sample exposing as RMI Service + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi + 0.91-incubating + runtime + + + junit + junit + 4.2 + test + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..ec57a6a533 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the add service + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e9c635e3c8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..2b99485b68 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import java.rmi.Naming; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + CalculatorService calculatorService = (CalculatorService)Naming.lookup("//localhost:8099/CalculatorRMIService"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.java new file mode 100644 index 0000000000..b698163c1b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServer.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 org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * A claculator service server. Starts up the SCA runtime which + * will start listening for RMI service requests. + */ +public class CalculatorServer { + public static void main(String[] args) throws Exception { + System.out.println("Starting of the SCA Calculator Application exposed as RMI Services..."); + SCADomain scaDomain = SCADomain.newInstance("CalculatorRMIServer.composite"); + System.out.println("... Press Enter to Exit..."); + System.in.read(); + scaDomain.close(); + System.out.println("Exited..."); + System.exit(0); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..978d2c6f42 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorService.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 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/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..f28f0ca179 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.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/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..835e4fda6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..8c33862f6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..c7fbc73c00 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..30e4e6a56a --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..1a7f145ad8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite new file mode 100644 index 0000000000..85e2dc4135 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/main/resources/CalculatorRMIServer.composite @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java new file mode 100644 index 0000000000..67300bd99e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-rmi-service/src/test/java/calculator/CalculatorRMIServerTestCase.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR 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; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorRMIServerTestCase extends TestCase { + + private SCADomain scaDomain; + private CalculatorService calculatorService; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("CalculatorRMIServer.composite"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + // Calculate + calculatorService = (CalculatorService)Naming.lookup("//localhost:8099/CalculatorRMIService"); + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/README b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/README new file mode 100644 index 0000000000..ab1dda13df --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/README @@ -0,0 +1,105 @@ +Calculator Script Sample +======================== +This sample implements a simple calculator using SCA components implemented +using Java, JavaScript, Ruby, Python and Groovy. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator-script.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator-script.jar calculator.CalculatorClient + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing +to the appropriate components in the composite across the local wires. Each +component is implemented using a different language. + +calculator-script/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + SubtractService.java - subtracts one number from another + MultiplyService.java - multiplies two numbers + DivideService.java - divides one number by another + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + calculator/ + AddServiceImpl.js - A JavaScript implementation of the + Add component + SubtractServiceImpl.rb - A Ruby implementation of the Subtract + component + MultiplyServiceImpl.py - A Python implementation of the + Multiple component + DivideServiceImpl.groovy- A Groovy implementation of the + Divide component + Calculator.composite - the SCA assembly for this sample + + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator-script.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator-script +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-script +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.918 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/build.xml new file mode 100644 index 0000000000..429d638ca5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.png b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.png new file mode 100644 index 0000000000..d3f8c491c3 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.svg b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.svg new file mode 100644 index 0000000000..16939f9310 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/calculator-script.svg @@ -0,0 +1,334 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent(Java) + + + CalculatorService + AddServiceComponent(Javascript) + + SubtractServiceComponent(Ruby) + + MultiplyServiceComponent(Python) + + DivideServiceComponent(Groovy) + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/pom.xml new file mode 100644 index 0000000000..dc7de68e4d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-calculator-script + Apache Tuscany Calculator Sample implemented using scripting languages + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-script + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/AddService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..243d1562dc --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorClient.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 org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * 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 { + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + 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)); + + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..c89043276e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..ba897fa301 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/DivideService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/SubtractService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/Calculator.composite b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..fce26f940f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/Calculator.composite @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/AddServiceImpl.js b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/AddServiceImpl.js new file mode 100644 index 0000000000..1d4d221364 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/DivideServiceImpl.groovy b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/DivideServiceImpl.groovy new file mode 100644 index 0000000000..c31c1e8fd6 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/MultiplyServiceImpl.py b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/MultiplyServiceImpl.py new file mode 100644 index 0000000000..d6f27ca7f5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/SubtractServiceImpl.rb b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/main/resources/calculator/SubtractServiceImpl.rb new file mode 100644 index 0000000000..132a1d13b0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/test/java/calculator/CalculatorTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..c174cf7ed9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-script/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 junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private SCADomain scaDomain; + private CalculatorService calculatorService; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("Calculator.composite"); + calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/README b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/README new file mode 100644 index 0000000000..c88b92b206 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/README @@ -0,0 +1,118 @@ +Calculator Sample +================= +This sample uses the same code as the calculator sample but deploys the +sample wrapped in a web app. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/sample-calculator-webapp.war) +to you web application server. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-calculator-webapp/calc.jsp + +The port and hostname will of course vary depending on your local installation. + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator-webapp/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - As calculator sample + CalculatorServiceImpl.java + AddService.java - As calculator sample + AddServiceImpl.java + SubtractService.java - As calculator sample + SubtractServiceImpl.java + MultiplyService.java - As calculator sample + MultiplyServiceImpl.java + DivideService.java - As calculator sample + DivideServiceImpl.java + CalculatorClient.java - As calculator sample + resources/ + Calculator.composite - As calculator sample + webapp + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + calc.jsp - the web application that makes use of the + SCA application + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + + calculator.png - a pictorial representation of the sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd calculator-webapp +ant package + +This should result in a war file (sample-calculator-webapp.war) in the target +directory. Copy this war file to your web app deployment directory in you +web app container. + +The process for getting the web app running will depend on which web app container +you are using. For example, if you are using Tomcat then it is simply a matter +of copying the WAR file to the webapps directory. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-calculator-webapp/calc.jsp + +The port and hostname will of course vary depending on your local installation. + +You should see the following output. + +Expression Result +2 + 3 5.0 +3 - 2 1.0 +3 * 2 6.0 +3 / 2 1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-webapp +mvn + + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.852 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +Again this should result in a war file (sample-calculator-webapp.war) in the target +directory. Follow the steps described in the previous section for running the web +app and for the expected results. + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/build.xml new file mode 100644 index 0000000000..e8022dd5d3 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/build.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.png b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.png new file mode 100644 index 0000000000..896ddc4093 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.svg b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.svg new file mode 100644 index 0000000000..00ed27556f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/calculator-web.svg @@ -0,0 +1,358 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + WebApp + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/pom.xml new file mode 100644 index 0000000000..3813f02d48 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-calculator-webapp + war + Apache Tuscany Calculator Sample WebApp + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-webapp + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..ec57a6a533 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e9c635e3c8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..4787b728f4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + * + * (not really necessary as this sample runs in a webapp) + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..ad87375529 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..bf3b0303ec --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..835e4fda6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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 interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..8c33862f6d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..c7fbc73c00 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..30e4e6a56a --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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 subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..1a7f145ad8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/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/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/resources/Calculator.composite b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..785984fd55 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/resources/Calculator.composite @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/META-INF/sca-contribution.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..048c4c125c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..dfed3b33e7 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + + + + Tuscany Calculator Web Service Sample + + + org.apache.tuscany.sca.webapp.TuscanyContextListener + + + + calc.jsp + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/calc.jsp b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/calc.jsp new file mode 100644 index 0000000000..375116e5de --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/main/webapp/calc.jsp @@ -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. +--%> + +<%@ page import="org.apache.tuscany.sca.host.embedded.SCADomain"%> +<%@ page import="calculator.CalculatorService" %> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<% + SCADomain scaDomain = (SCADomain) application.getAttribute("org.apache.tuscany.sca.SCADomain"); + CalculatorService calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); +%> + +Calculator sample + + + + + + + + + + + + + + + + + + +
ExpressionResult
2 + 3<%= calculatorService.add(2, 3) %>
3 - 2<%= calculatorService.subtract(3, 2) %>
3 * 2<%= calculatorService.multiply(3, 2) %>
3 / 2<%= calculatorService.divide(3, 2) %>
+ + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/test/java/calculator/CalculatorTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator-webapp/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..65b8646d4d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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 junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private SCADomain scaDomain; + private CalculatorService calculatorService; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("Calculator.composite"); + calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/README b/sca-java-1.x/tags/0.91-incubating/samples/calculator/README new file mode 100644 index 0000000000..ceb532faed --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator/build.xml new file mode 100644 index 0000000000..c4b755ef94 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.png b/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.svg b/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.svg new file mode 100644 index 0000000000..0615925c50 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/calculator/pom.xml new file mode 100644 index 0000000000..9b7a6c35a8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-calculator + Apache Tuscany Calculator Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..8b6fe066a6 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/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/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorClient.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..9d180bf52e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * 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 { + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..3d861f2018 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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.osoa.sca.annotations.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/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..f7ac0b7287 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/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/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..b7dca792b2 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/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/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractService.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..77b128ab8d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/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/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/resources/Calculator.composite b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..f8655c04fa --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/main/resources/Calculator.composite @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/test/java/calculator/CalculatorTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..8da7097149 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/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 junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private CalculatorService calculatorService; + private SCADomain scaDomain; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("Calculator.composite"); + calculatorService = scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/README b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/README new file mode 100644 index 0000000000..c52f12e3d4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/README @@ -0,0 +1,61 @@ +Chat WebApp Sample +================== +This sample demonstrates the SCA Ajax binding to implement the classic Ajax sample +of a chat application which allows multiple users to chat from their browsers. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/sample-chat-webapp.war) +to your web application server. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-chat-webapp + +The port and hostname will of course vary depending on your local installation. + +Sample Overview +--------------- +The sample provides an SCA component which has an SCA service using the SCA Ajax +binding and an SCA reference also using the Ajax binding. The component implementation +simply forwards every invocation of the service as an invocation on the reference. The +component reference is scoped by the composite so every active client of the composite +will receive every message sent to the component service, thus implementing the chat +application with very little code. + +chat-webapp/ + src/ + main/ + java/ + sample/ + ChatService.java - service interface + ChatServiceImpl.java - service implementation + resources/ + chat.composite - the SCA assembly for this sample + webapp + chat.html - the html UserInterface for this application + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + + pom.xml - the Maven build file + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd chat-webapp +mvn + +Again this should result in a war file (sample-chat-webapp.war) in the target +directory. Follow the steps described in the previous section for running the web +app and for the expected results. + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/pom.xml new file mode 100644 index 0000000000..41987963ab --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-chat-webapp + war + Apache Tuscany Chat Sample WebApp + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + + org.apache.tuscany.sca + tuscany-host-webapp + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-binding-ajax + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatService.java b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatService.java new file mode 100644 index 0000000000..1fb9d292cd --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatService.java @@ -0,0 +1,28 @@ +/** + * + * Copyright 2005 The Apache Software Foundation or its licensors, as applicable. + * + * 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. + */ +package sample; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Service +@Remotable +public interface ChatService { + + public void chat(String msg); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatServiceImpl.java new file mode 100644 index 0000000000..7d0bfb3307 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/java/sample/ChatServiceImpl.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 sample; + +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class ChatServiceImpl implements ChatService { + + ChatService chatters; + + public void chat(String msg) { + chatters.chat(msg); + } + + public void setChatters(ChatService chatters) { + this.chatters = chatters; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/resources/chat.composite b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/resources/chat.composite new file mode 100644 index 0000000000..3ee7716899 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/resources/chat.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/META-INF/sca-contribution.xml b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..b897ddef76 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..998d54bae5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + + + Tuscany Chat Sample + + + + org.apache.tuscany.sca.webapp.TuscanyContextListener + + + + TuscanyServlet + org.apache.tuscany.sca.webapp.TuscanyServlet + + + + TuscanyServlet + /SCA/* + + + + chat.html + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/chat.html b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/chat.html new file mode 100644 index 0000000000..ff3d71eb90 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/chat-webapp/src/main/webapp/chat.html @@ -0,0 +1,70 @@ + + + + Tuscany AJAX Chat Sample + + + + + + + + +

Tuscany AJAX Chat Sample

+ + A simple client to chat between multiple web browsers:

+ + Nickname: +

+ + Enter text: + + +

+
+ + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/README b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/README new file mode 100644 index 0000000000..67c1aa32d5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/README @@ -0,0 +1,143 @@ +DataBinding Echo Sample +======================= + +This sample demonstrates how databindings are used to convert data formats as +the data flows between components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens, open a command prompt, navigate +to this sample directory, and do + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;..\binding-echo-extension\target\sample-binding-echo-extension.jar;target\sample-databinding-echo.jar dbecho.EchoDataBindingClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:../binding-echo-extension/target/sample-binding-echo-extension.jar:target/sample-databinding-echo.jar dbecho.EchoDataBindingClient + + +Sample Overview +--------------- +If reference and service interfaces are the same in all but the formats of +data being passed to and returned from the operations of the interfaces, +then SCA will try to apply appropriate transformations to the data formats +to allow messages to pass. + +This sample shows this happening. ComponentA implements Interface1 which +defines; + + String call(String msg) + String call1(String msg) + +ComponentA defines a reference to ComponentB with Interface1. ComponentB +however implements Interface2 which defines; + + Node call(Node msg); + XMLStreamReader call1(XMLStreamReader msg); + +You can see from the test output below that SCA converts the call() msg from a +String to a DOM object (org.apache.xerces.dom.DeferredDocumentImpl). It +converts the call1() msg from a String to a XML stream reader +(com.ctc.wstx.sr.ValidatingStreamReader). + +databinding-echo/ + src/ + main/ + java/ + dbecho/ + ComponentAImpl.java - component implementation + ComponentBImpl.java - component implementation + Echo.java - service interface with data binding + EchoDataBindingClient.java - sample client code + Interface1.java - service interface with data binding + Interface2.java - service interface with data bindings + resources/ + META-INF/ + services/ + org.apache.tuscany.sca.core.ModuleActivator - specifies the module activation class to call + EchoDataBinding.composite - composite definition + wsdl/ + echo.wsdl - WSDL deinitions + test/ + java/ + dbecho/ + EchoDataBindingTestCase.java - junit test case + databinding-echo.png - pictorial representation of the sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +TODO - Needs more description of what else is going on in this test + properties, wsdl? + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows. + +cd databinding-echo +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] [Property] prefix: ABC + [java] [Property] prefix1: ABC + [java] [Property] bar: BAR + [java] ComponentA --> Received message: 123 [java.lang.String] + [java] ComponentB --> Received message: [#document: null] [org.apache.xerces.dom.DeferredDocumentImpl] + [java] ComponentB --> Returned message: [#document: null] [org.apache.xerces.dom.DeferredDocumentImpl] + [java] ComponentA --> Returned message: 123 [java.lang.String] + [java] [Property] prefix: ABC + [java] [Property] prefix1: ABC + [java] [Property] bar: BAR + [java] ComponentA --> Received message: 123 [java.lang.String] + [java] ComponentB --> Received message: com.ctc.wstx.sr.ValidatingStreamReader@4c444c44 [com.ctc.wstx.sr.ValidatingStreamReader] + [java] ComponentB --> Returned message: com.ctc.wstx.sr.ValidatingStreamReader@4c444c44 [com.ctc.wstx.sr.ValidatingStreamReader] + [java] ComponentA --> Returned message: 123 [java.lang.String] + [java] call response = 123 + [java] call1 response = 123 + + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd databinding-echo +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running dbecho.EchoDataBindingTestCase +[Property] prefix: ABC +[Property] prefix1: ABC +[Property] bar: BAR +ComponentA --> Received message: 123 [java.lang.String] +ComponentB --> Received message: [#document: null] [org.apache.xerces.dom.DeferredDocumentImpl] +ComponentB --> Returned message: [#document: null] [org.apache.xerces.dom.DeferredDocumentImpl] +ComponentA --> Returned message: 123 [java.lang.String] +[Property] prefix: ABC +[Property] prefix1: ABC +[Property] bar: BAR +ComponentA --> Received message: 123 [java.lang.String] +ComponentB --> Received message: com.ctc.wstx.sr.ValidatingStreamReader@74e274e2 [com.ctc.wstx.sr.ValidatingStreamReader] +ComponentB --> Returned message: com.ctc.wstx.sr.ValidatingStreamReader@74e274e2 [com.ctc.wstx.sr.ValidatingStreamReader] +ComponentA --> Returned message: 123 [java.lang.String] +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.653 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/build.xml new file mode 100644 index 0000000000..22fc41228b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/build.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.png b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.png new file mode 100644 index 0000000000..afbbfff285 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.svg b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.svg new file mode 100644 index 0000000000..87964abf86 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/databinding-echo.svg @@ -0,0 +1,408 @@ + + + + + + + + + + image/svg+xml + + + + + + + + EchoDataBinding + ComponentB + + + + + + ComponentA + + + prefixprefix1bar Interface1 Interface2 EchoReferencebinding.echo + + + messagePrefix complexProperty + @DataBinding("org.w3c.dom.Node")&@DataBinding("javax.xml.stream.XMLStreamReader") @DataBinding("java.lang.String") + + <db:databinding name="org.apache.axiom.om.OMElement" /> + Interface1 + Echo @DataBinding("org.w3c.dom.Node") + @DataBinding("java.lang.String") + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/pom.xml new file mode 100644 index 0000000000..1f19e28564 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + + sample-databinding-echo + Apache Tuscany Echo Data Binding Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + sca-api + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-core-databinding + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + sample-binding-echo-extension + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentAImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentAImpl.java new file mode 100644 index 0000000000..a0b39ad460 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentAImpl.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package dbecho; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * @version $Rev$ $Date$ + */ +@SuppressWarnings("unused") +public class ComponentAImpl implements Interface1 { + + private Interface1 componentBReference; + + @SuppressWarnings("unused") + private String prefix; + + private String prefix1; + + private String bar; + + @Constructor + public ComponentAImpl(@Reference(name = "componentBReference", required = true) + Interface1 componentBReference) { + this.componentBReference = componentBReference; + } + + public String call(String msg) { + String request = msg + " [" + msg.getClass().getName() + "]"; + System.out.println("ComponentA --> Received message: " + request); + Object ret = componentBReference.call(msg); + String response = ret + " [" + ret.getClass().getName() + "]"; + System.out.println("ComponentA --> Returned message: " + response); + return (String) ret; + } + + public String call1(String msg) { + String request = msg + " [" + msg.getClass().getName() + "]"; + System.out.println("ComponentA --> Received message: " + request); + Object ret = componentBReference.call1(msg); + String response = ret + " [" + ret.getClass().getName() + "]"; + System.out.println("ComponentA --> Returned message: " + response); + return (String) ret; + } + + @Property(name="prefix") + public void setPrefix(String prefix) { + System.out.println("[Property] prefix: " + prefix); + this.prefix = prefix; + } + + @Property(name="prefix1") + public void setPrefix1(String prefix1) { + System.out.println("[Property] prefix1: " + prefix1); + this.prefix1 = prefix1; + } + + /** + * @param bar the bar to set + */ + @Property(name="bar") + public void setBar(String bar) { + System.out.println("[Property] bar: " + bar); + this.bar = bar; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentBImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentBImpl.java new file mode 100644 index 0000000000..ff8968837d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/ComponentBImpl.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 dbecho; + +import javax.xml.stream.XMLStreamReader; + +import org.osoa.sca.annotations.AllowsPassByReference; +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; +import org.w3c.dom.Node; + +/** + * @version $Rev$ $Date$ + */ +@AllowsPassByReference +public class ComponentBImpl implements Interface2 { + + private Echo echoReference; + + @Constructor + public ComponentBImpl(@Reference(name = "echoReference", required = true) + Echo echoReference) { + this.echoReference = echoReference; + } + + public Node call(Node msg) { + String request = msg + " [" + msg.getClass().getName() + "]"; + System.out.println("ComponentB --> Received message: " + request); + Node ret = (Node) echoReference.echo(msg); + String response = ret + " [" + ret.getClass().getName() + "]"; + System.out.println("ComponentB --> Returned message: " + response); + return ret; + } + + public XMLStreamReader call1(XMLStreamReader msg) { + String request = msg + " [" + msg.getClass().getName() + "]"; + System.out.println("ComponentB --> Received message: " + request); +// XMLStreamReader ret = (XMLStreamReader) echoReference.echo(msg); + String response = request; + System.out.println("ComponentB --> Returned message: " + response); + return msg; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Echo.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Echo.java new file mode 100644 index 0000000000..25ecc90454 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Echo.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 dbecho; + +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.osoa.sca.annotations.Remotable; + +/** + * @version $Rev$ $Date$ + */ + +@DataBinding("org.w3c.dom.Node") +@Remotable +public interface Echo { + Object echo(Object msg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/EchoDataBindingClient.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/EchoDataBindingClient.java new file mode 100644 index 0000000000..9ec3819899 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/EchoDataBindingClient.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 dbecho; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + * @version $Rev$ $Date$ + */ +public class EchoDataBindingClient { + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("EchoDataBinding.composite"); + + Interface1 componentA = scaDomain.getService(Interface1.class, "ComponentA"); + String response = componentA.call("123"); + String response1= componentA.call1("123"); + + + System.out.println("call response = " + response ); + System.out.println("call1 response = " + response1 ); + + scaDomain.close(); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface1.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface1.java new file mode 100644 index 0000000000..70b450e358 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface1.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 dbecho; + +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.osoa.sca.annotations.Remotable; + +/** + * @version $Rev$ $Date$ + */ +@DataBinding("java.lang.String") +@Remotable +public interface Interface1 { + String call(String msg); + String call1(String msg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface2.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface2.java new file mode 100644 index 0000000000..b62f1f425d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/java/dbecho/Interface2.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 dbecho; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.osoa.sca.annotations.Remotable; +import org.w3c.dom.Node; + +/** + * @version $Rev$ $Date$ + */ +@DataBinding("org.w3c.dom.Node") +@Remotable +public interface Interface2 { + Node call(Node msg); + @DataBinding("javax.xml.stream.XMLStreamReader") + XMLStreamReader call1(XMLStreamReader msg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/EchoDataBinding.composite b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/EchoDataBinding.composite new file mode 100644 index 0000000000..2f042b8e34 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/EchoDataBinding.composite @@ -0,0 +1,58 @@ + + + + + + + + ABC + + + + + + + + + + + + + + + + + ABC + + + BAR + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..13d0d6f570 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -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. +# Implementation class for the ExtensionActivator +echo.module.EchoModuleActivator diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/wsdl/echo.wsdl b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/wsdl/echo.wsdl new file mode 100644 index 0000000000..ef2308aa73 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/main/resources/wsdl/echo.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/test/java/dbecho/EchoDataBindingTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/test/java/dbecho/EchoDataBindingTestCase.java new file mode 100644 index 0000000000..43434d8cee --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/databinding-echo/src/test/java/dbecho/EchoDataBindingTestCase.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 dbecho; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev$ $Date$ + */ +public class EchoDataBindingTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoDataBinding.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + protected Interface1 componentA; + + public void testTransform() { + componentA = scaDomain.getService(Interface1.class, "ComponentA"); + componentA.call("123"); + componentA.call1("123"); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/pom.xml new file mode 100644 index 0000000000..fcfec5d340 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../pom.xml + + sample-feed-aggregator + Apache Tuscany Atom+RSS Feed Aggregator Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-binding-feed + 0.91-incubating + compile + + + + org.apache.tuscany.sca + tuscany-http-tomcat + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/AggregatorImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/AggregatorImpl.java new file mode 100644 index 0000000000..6bb418067a --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/AggregatorImpl.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 feed; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.Feed; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; + +/** + * Implementation of an SCA component that aggregates several + * Atom and RSS feeds. + * + * @version $Rev$ $Date$ + */ +public class AggregatorImpl implements Feed { + + @Reference + public Feed feed1; + @Reference + public Feed feed2; + @Reference(required = false) + public Sort sort; + + @Property + public String feedTitle = "Aggregated Feed"; + @Property + public String feedDescription = "Anonymous Aggregated Feed"; + @Property + public String feedAuthor = "anonymous"; + + @SuppressWarnings("unchecked") + public SyndFeed get(String uri) { + + // Create a new Feed + SyndFeed feed = new SyndFeedImpl(); + feed.setTitle(feedTitle); + feed.setDescription(feedDescription); + feed.setAuthor(feedAuthor); + feed.setLink(uri); + + // Aggregate entries from feed1 and feed2 + List entries = new ArrayList(); + entries.addAll(feed1.get(null).getEntries()); + entries.addAll(feed2.get(null).getEntries()); + + // Sort entries by published date + if (sort != null) + feed.setEntries(sort.sort(entries)); + else + feed.setEntries(entries); + return feed; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SampleServer.java b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SampleServer.java new file mode 100644 index 0000000000..5e57487809 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SampleServer.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 feed; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class SampleServer { + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("FeedAggregator.composite"); + + try { + System.out.println("Sample Feed server started (press enter to shutdown)"); + System.out.println(); + System.out.println("To read the aggregated feeds, point your Web browser to the following addresses:"); + System.out.println("http://localhost:8083/atomAggregator"); + System.out.println("http://localhost:8083/rssAggregator"); + System.out.println("http://localhost:8083/atomAggregator?feedType=rss_2.0"); + System.out.println("http://localhost:8083/rssAggregator?feedType=atom_1.0"); + System.out.println(); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + // RssFeed feedService = scaDomain.getService(RssFeed.class, + // "RssAggregatorComponent"); + // SyndFeed syndFeed = feedService.get(); + // SyndFeedOutput output = new SyndFeedOutput(); + // output.output(syndFeed,new PrintWriter(System.out)); + + scaDomain.close(); + System.out.println("Sample Feed server stopped"); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/Sort.java b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/Sort.java new file mode 100644 index 0000000000..d08f2dcb72 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/Sort.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 feed; + +import java.util.List; + +import com.sun.syndication.feed.synd.SyndEntry; + +/** + * The Sort service business interface. + * + * @version $Rev$ $Date$ + */ +public interface Sort { + + /** + * Sort feed entries by published date. + * @param entries + * @return + */ + List sort(List entries); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SortImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SortImpl.java new file mode 100644 index 0000000000..d9987a0ff7 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/java/feed/SortImpl.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package feed; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.List; + +import org.osoa.sca.annotations.Property; + +import com.sun.syndication.feed.synd.SyndEntry; + +/** + * Implementation of a Feed Sort service component. + * + * @version $Rev$ $Date$ + */ +public class SortImpl implements Sort { + + @Property + public boolean newFirst = true; + + @SuppressWarnings("unchecked") + public List sort(List entries) { + SyndEntry[] entriesArray = new SyndEntry[entries.size()]; + entriesArray = (SyndEntry[])entries.toArray(entriesArray); + Arrays.sort(entriesArray, new Comparator() { + public int compare(final Object xObj, final Object yObj) { + Date xDate = ((SyndEntry)xObj).getPublishedDate(); + Date yDate = ((SyndEntry)yObj).getPublishedDate(); + if (xDate == null) + return -1; + if (newFirst) + return yDate.compareTo(xDate); + else + return xDate.compareTo(yDate); + } + }); + return Arrays.asList(entriesArray); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/resources/FeedAggregator.composite b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/resources/FeedAggregator.composite new file mode 100644 index 0000000000..f2a69eca43 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/feed-aggregator/src/main/resources/FeedAggregator.composite @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + Rss Sample + + + + true + + + + + + + + + + + Atom Sample + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/README b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/README new file mode 100644 index 0000000000..cc25b50192 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/README @@ -0,0 +1,101 @@ +Hello World Dojo RPC Sample +=========================== +This sample demostrates the SCA JSONRPC binding using a simple web app that +uses the RPC support of the Dojo Toolkit to an SCA service. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/sample-helloworld-dojo.war) +to you web application server. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-helloworld-dojo + +The port and hostname will of course vary depending on your local installation. + +See also the similar helloworld-jsonrpc sample which also uses the SCA JSONRPC binding +but uses SCA scaDomain.js script on the client instead of the Dojo Toolkit. + +Sample Overview +--------------- +The sample provides a single service with an operation that reflects +a greeting back to the caller. The service is exposed using the JSONRPC +binding. The web app provided shows how the Dojo Toolkit JSON-RPC support can be +used to invoke the SCA service. + +The web app provided shows how the service can be called by using the DOJO toolkit. + +helloworld-dojo/ + build-dojo.xml - This file is an Ant script used by the + sample build process to download the Dojo Toolkit + and get it included in the WAR file + for use by the sample. + src/ + main/ + java/ + helloworldjsonrpc/ + HelloWorldService.java - service interface + HelloWorldServiceImpl.java - service implementation + resources/ + jsonrpc.composite - the SCA assembly for this sample + webapp + dojo/ - the Dojo toolkit (this directory is created only + when you build the samples from the source distribution) + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + HelloWorldJSONRPC.html - the web application that calls the + SCA service via JSONRPC + style.css - style sheet + + helloworld-jsonrpc.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file that unpacks the + dojo installation + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd helloworld-dojo +ant package + +This should result in a war file (sample-helloworld-dojo.war) in the target +directory. Copy this war file to your web app deployment directory in your +web app container. + +The process for getting the web app running will depend on which web app container +you are using. For example, if you are using Tomcat then it is simply a matter +of copying the WAR file to the webapps directory. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-helloworld-dojo + +The port and hostname will of course vary depending on your local installation. + +You should see a web page that allows you to send messages, via JSONRPC, to the +application running in the Tuscany SCA Runtime + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd helloworld-dojo +mvn + +Again this should result in a war file (sample-helloworld-dojo.war) in the target +directory. Follow the steps described in the previous section for running the web +app and for the expected results. + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build-dojo.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build-dojo.xml new file mode 100644 index 0000000000..335a10817a --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build-dojo.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build.xml new file mode 100644 index 0000000000..5d3113f836 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/build.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.png b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.png new file mode 100644 index 0000000000..57f90aed01 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.svg b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.svg new file mode 100644 index 0000000000..5c5cb91157 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/helloworld-jsonrpc.svg @@ -0,0 +1,177 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldjsonrpc + + HelloWorldJSONServiceComponent + HelloWorldService + WebApp + DOJO + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/pom.xml new file mode 100644 index 0000000000..27ef5fe1d4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/pom.xml @@ -0,0 +1,125 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-helloworld-dojo + war + Apache Tuscany Dojo Sample WebApp + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-webapp + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-antrun-plugin + 1.1 + + + install-dojo + validate + + run + + + + + + + + + + + copy-dojo-files + generate-resources + + run + + + + + + + + + + + + clean-dojo-files + clean + + run + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldService.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldService.java new file mode 100644 index 0000000000..3d8ea24f04 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworldjsonrpc; + +/** + * This is the business interface of the HelloWorld service component. + */ +public interface HelloWorldService { + + String getGreetings(String name); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..35fd00fabd --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.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 helloworldjsonrpc; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service component. + */ +@Service(HelloWorldService.class) +public class HelloWorldServiceImpl implements HelloWorldService { + + /* + * @see org.apache.tuscany.samples.helloworld.HelloWorldServiceComponent#getGreetings() + */ + public String getGreetings(String name) { + return "jsonrpcHello " + name; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/resources/jsonrpc.composite b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/resources/jsonrpc.composite new file mode 100644 index 0000000000..6ceef2041f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/resources/jsonrpc.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/HelloWorldJSONRPC.html b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/HelloWorldJSONRPC.html new file mode 100644 index 0000000000..b6c8f868d3 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/HelloWorldJSONRPC.html @@ -0,0 +1,91 @@ + + + + Tuscany JSON-RPC HelloWorld Example + + + + + + + + + + + + + +

Tuscany Dojo JSON-RPC HelloWorld Sample

+ + + + + + + + + + + + + + + + + + +
Dojo Example
+

This example uses the Dojo Toolkit + to create a JavaScript object helloWorldService for the SCA service + 'HelloWorldService' using Dojo's RPC classes + and providing them with SCA/SCADomain/HelloWorldService?smd + for Simple Method Description (SMD) input.

+

It then creates a Dojo button that will envoke the getGreetings method of the HelloWorldService object.

+
RequestResponse
+
helloWorldService.getGreetings("Dojo").addCallback(contentCallBack);

+
+
None Yet.
+
+
Dojo Debug:
+
+ + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/META-INF/sca-contribution.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..1cc4ac12af --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..61b1057974 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,45 @@ + + + + + + + Tuscany sample HelloWorld JSON-RPC + + + org.apache.tuscany.sca.webapp.TuscanyContextListener + + + + TuscanyServlet + org.apache.tuscany.sca.webapp.TuscanyServlet + + + + TuscanyServlet + /SCA/* + + + + HelloWorldJSONRPC.html + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/style.css b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/style.css new file mode 100644 index 0000000000..1071583264 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-dojo/src/main/webapp/style.css @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +* { font-family: arial; } + +table, th, td { border: 2px solid blue; border-collapse: collapse; } +th { color: white; background-color: blue; } diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/README b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/README new file mode 100644 index 0000000000..93a2c703ac --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/README @@ -0,0 +1,90 @@ +Hello World JSONRPC Sample +========================== +This sample demostrates the JSONRPC binding using a simple web app that +talks JSONRPC to an SCA service. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/sample-helloworld-jsonrpc.war) +to you web application server. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-helloworld-jsonrpc + +The port and hostname will of course vary depending on your local installation. + +Sample Overview +--------------- +The sample provides a single service with an operation that reflects +a greeting back to the caller. The service is exposed using the JSONRPC +binding. The web app provided shows how the SCA-provided JSON client can be +used to invoke the SCA service. + +helloworld-jsonrpc/ + src/ + main/ + java/ + helloworldjsonrpc/ + HelloWorldService.java - service interface + HelloWorldServiceImpl.java - service implementation + resources/ + jsonrpc.composite - the SCA assembly for this sample + webapp + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + HelloWorldJSONRPC.html - the web application that calls the + SCA service via JSONRPC + style.css - style sheet + + helloworld-jsonrpc.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file that unpacks the + dojo installation + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd helloworld-jsonrpc +ant package + +This should result in a war file (sample-helloworld-jsonrpc.war) in the target +directory. Copy this war file to your web app deployment directory in your +web app container. + +The process for getting the web app running will depend on which web app container +you are using. For example, if you are using Tomcat then it is simply a matter +of copying the WAR file to the webapps directory. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-helloworld-jsonrpc + +The port and hostname will of course vary depending on your local installation. + +You should see a web page that allows you to send messages, via JSONRPC, to the +application running in the Tuscany SCA Runtime + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd helloworld-jsonrpc +mvn + +Again this should result in a war file (sample-helloworld-jsonrpc.war) in the target +directory. Follow the steps described in the previous section for running the web +app and for the expected results. + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/build.xml new file mode 100644 index 0000000000..b3bbbcfb44 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/build.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.png b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.png new file mode 100644 index 0000000000..57f90aed01 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.svg b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.svg new file mode 100644 index 0000000000..fe966d8c17 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/helloworld-jsonrpc.svg @@ -0,0 +1,177 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldjsonrpc + + HelloWorldJSONServiceComponent + HelloWorldService + WebApp + DOJO + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/pom.xml new file mode 100644 index 0000000000..58f89232e0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-helloworld-jsonrpc + war + Apache Tuscany JSON-RPC Sample WebApp + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-webapp + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldService.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldService.java new file mode 100644 index 0000000000..3d8ea24f04 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworldjsonrpc; + +/** + * This is the business interface of the HelloWorld service component. + */ +public interface HelloWorldService { + + String getGreetings(String name); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.java new file mode 100644 index 0000000000..35fd00fabd --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/java/helloworldjsonrpc/HelloWorldServiceImpl.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 helloworldjsonrpc; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service component. + */ +@Service(HelloWorldService.class) +public class HelloWorldServiceImpl implements HelloWorldService { + + /* + * @see org.apache.tuscany.samples.helloworld.HelloWorldServiceComponent#getGreetings() + */ + public String getGreetings(String name) { + return "jsonrpcHello " + name; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/resources/jsonrpc.composite b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/resources/jsonrpc.composite new file mode 100644 index 0000000000..6ceef2041f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/resources/jsonrpc.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/HelloWorldJSONRPC.html b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/HelloWorldJSONRPC.html new file mode 100644 index 0000000000..98853189db --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/HelloWorldJSONRPC.html @@ -0,0 +1,75 @@ + + + + Tuscany JSON-RPC HelloWorld Example + + + + + + + + + + +

Tuscany JSON-RPC HelloWorld Sample

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

+ Name please:     + + +

+ +
+
None Yet.
+
+ + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/META-INF/sca-contribution.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..be750ec461 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/WEB-INF/web.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..61b1057974 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,45 @@ + + + + + + + Tuscany sample HelloWorld JSON-RPC + + + org.apache.tuscany.sca.webapp.TuscanyContextListener + + + + TuscanyServlet + org.apache.tuscany.sca.webapp.TuscanyServlet + + + + TuscanyServlet + /SCA/* + + + + HelloWorldJSONRPC.html + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/style.css b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/style.css new file mode 100644 index 0000000000..1071583264 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-jsonrpc/src/main/webapp/style.css @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +* { font-family: arial; } + +table, th, td { border: 2px solid blue; border-collapse: collapse; } +th { color: white; background-color: blue; } diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/README b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/README new file mode 100644 index 0000000000..8ee8dd7ff5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/README @@ -0,0 +1,153 @@ +Hello World Web Service References Sample +========================================= +This sample demonstrates an SCA reference that uses a web service binding. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens you need to run the server first +so open a command prompt, navigate to the helloworld-ws-service sample directory +and do + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-helloworld-ws-service.jar helloworld.HelloWorldServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-helloworld-ws-service.jar helloworld.HelloWorldServer + + +Once the server is running open a command prompt, navigate to this sample +directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-helloworld-ws-reference.jar helloworld.HelloWorldClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-helloworld-ws-reference.jar helloworld.HelloWorldClient + + +Sample Overview +--------------- +The sample provides a single component that is wired to a reference with a +web service binding. The binding refers to WSDL that identifies the service +exposed by the helloworld-ws-service sample. + +helloworld-ws-reference/ + src/ + main/ + java/ + helloworld/ + HelloWorldService.java - interface description for + HelloWorldServiceComponent + HelloWorldServiceComponent.java - component implementation + HelloWorldClient.java - starts the SCA Runtime and + deploys the helloworldwsclient + .composite. It then calls the + HelloWorldServiceComponent + resources/ + wsdl + helloworld.wsdl - the service description that the + SCA reference uses to bind to + helloworldwsclient.composite - the SCA assembly for this sample + logging.properties - log4j configuration file + test/ + java/ + helloworld/ + HelloWorldClientTestCase.java - JUnit test case + HelloWorldServerTest.java - starts the Web service + helloworld-ws-reference.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant. Before +you do this start up the service that the reference will talk to. To do this +run up the helloworld-ws-service test. Take a look at the README in that sample +and you will see you need the following commands + +cd helloworld-ws-service +ant run + +Once done you can now compile and run this sample using the following commands; + +cd helloworld-ws-reference +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] log4j:WARN No appenders could be found for logger (org.apache.axiom. +om.util.StAXUtils). + [java] log4j:WARN Please initialize the log4j system properly. + [java] Injected helloWorldService + [java] Called getGreetings + [java] Hello World + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. When using Maven you don't need to run the helloworld- +ws-service sample first as Maven does this for you. + +cd helloworld-ws-reference +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.HelloWorldClientTestCase +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +10-May-2007 13:40:34 org.apache.catalina.core.StandardEngine start +INFO: Starting Servlet Engine: Apache Tomcat/6.0.10 +10-May-2007 13:40:35 org.apache.catalina.startup.ContextConfig defaultWebConfig +INFO: No default web.xml +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/j2ee_1_4.xsd +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/xml.xsd +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/jsp_2_0.xsd +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_2_ +0.xsd +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/web-app_2_4.xsd +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/j2ee_web_services_1_1.xs +d +10-May-2007 13:40:35 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/j2ee_web_services_client +_1_1.xsd +10-May-2007 13:40:35 org.apache.coyote.http11.Http11Protocol init +INFO: Initializing Coyote HTTP/1.1 on http-8085 +10-May-2007 13:40:35 org.apache.coyote.http11.Http11Protocol start +INFO: Starting Coyote HTTP/1.1 on http-8085 +Injected helloWorldService +Called getGreetings +10-May-2007 13:40:36 org.apache.coyote.http11.Http11Protocol destroy +INFO: Stopping Coyote HTTP/1.1 on http-8085 +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.349 sec + +Results : + + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/build.xml new file mode 100644 index 0000000000..71ee66b31e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.png b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.png new file mode 100644 index 0000000000..bd2bba41db Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.svg b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.svg new file mode 100644 index 0000000000..354ffbae8f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/helloworld-ws-reference.svg @@ -0,0 +1,150 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldwsclient + + HelloWorldServiceComponent + + + HelloWorldService + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/pom.xml new file mode 100644 index 0000000000..65aa51009c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-helloworld-ws-reference + Apache Tuscany HelloWorld Web Service Client Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + sample-helloworld-ws-service + 0.91-incubating + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..4559b282fe --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.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 helloworld; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * locate the HelloWorld service and invoke it. + */ +public class HelloWorldClient { + + public final static void main(String[] args) throws Exception { + SCADomain scaDomain = SCADomain.newInstance("helloworldwsclient.composite"); + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent"); + + String value = helloWorldService.getGreetings("World"); + System.out.println(value); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldService.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..433a98fd7f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldService.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 helloworld; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +/** + * The interface for the helloworld service + */ +@Remotable +@Service +public interface HelloWorldService { + public String getGreetings(String name); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldServiceComponent.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldServiceComponent.java new file mode 100644 index 0000000000..0dee19550b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldServiceComponent.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +/** + * The HelloWorld service implementation + */ +public class HelloWorldServiceComponent implements HelloWorldService { + + HelloWorldService helloWorldService; + + public String getGreetings(String name) { + System.out.println("Called getGreetings"); + return helloWorldService.getGreetings(name); + } + + public HelloWorldService getHelloWorldService() { + System.out.println("Got Injected helloWorldService"); + return helloWorldService; + } + + public void setHelloWorldService(HelloWorldService helloWorldService) { + System.out.println("Injected helloWorldService"); + this.helloWorldService = helloWorldService; + } +} \ No newline at end of file diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite new file mode 100644 index 0000000000..1f1310cbe9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/logging.properties b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/logging.properties new file mode 100644 index 0000000000..3dca310cdb --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/logging.properties @@ -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. +# +# $Rev$ $Date$ +# + +# Custom logging configuration for Tuscany samples +# By default, only INFO level logging is enabled and ALL messages get sent to the console +# For more messages from the runtime, uncomment specific settings at the end of this file +handlers = java.util.logging.ConsoleHandler +java.util.logging.ConsoleHandler.level = ALL +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter +.level=INFO + +# Uncomment the next setting to get all Tuscany messages (this will be a lot) +#org.apache.tuscany.level=FINEST diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/wsdl/helloworld.wsdl b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000000..1e468bc9ca --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/main/resources/wsdl/helloworld.wsdl @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldClientTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldClientTestCase.java new file mode 100644 index 0000000000..c4b7d03246 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldClientTestCase.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package helloworld; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.host.embedded.SCATestCaseRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test case for helloworld web service client + */ +public class HelloWorldClientTestCase { + + private HelloWorldService helloWorldService; + private SCADomain scaDomain; + + private SCATestCaseRunner server; + + @Before + public void startClient() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldwsclient.composite"); + helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent"); + + server = new SCATestCaseRunner(HelloWorldServerTest.class); + server.before(); + + } catch (Throwable e) { + e.printStackTrace(); + } + } + + @Test + public void testWSClient() throws Exception { + String msg = helloWorldService.getGreetings("Smith"); + Assert.assertEquals("Hello Smith", msg); + } + + @After + public void stopClient() throws Exception { + server.after(); + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldServerTest.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldServerTest.java new file mode 100644 index 0000000000..40caf1de4d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-reference/src/test/java/helloworld/HelloWorldServerTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Starts up the SCA runtime which starts listening for service requests + */ +public class HelloWorldServerTest { + + private SCADomain scaDomain; + + @Before + public void startServer() throws Exception { + try { + scaDomain = SCADomain.newInstance("helloworldws.composite"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/README b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/README new file mode 100644 index 0000000000..b82d5bd329 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/README @@ -0,0 +1,132 @@ +Hello World Web Service Service Sample +====================================== +This sample demonstrates an SCA service that uses a web service binding. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-helloworld-ws-service.jar helloworld.HelloWorldServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-helloworld-ws-service.jar helloworld.HelloWorldServer + +Now the server is started you can use the helloworld-ws-reference sample to +exercise it. + +Sample Overview +--------------- +The sample provides a single component that is wired to a service with a +web service binding. + +helloworld-ws-service/ + src/ + main/ + java/ + helloworld/ + HelloWorldService.java - interface description for + HelloWorldServiceComponent + HelloWorldImpl.java - component implementation + HelloWorldServer.java - starts the SCA Runtime and + deploys the helloworldws + .composite and then waits for the + service to be called via web services + resources/ + wsdl/ + helloworld.wsdl - the service description that describes + the exposed service + helloworldws.composite - the SCA assembly for this sample + test/ + java/ + helloworld/ + HelloWorldServerTestCase.java - JUnit test case + helloworld-ws-service.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant using the +following commands + +cd helloworld-ws-service +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] log4j:WARN No appenders could be found for logger (org.apache.axiom. +om.util.StAXUtils). + [java] log4j:WARN Please initialize the log4j system properly. + [java] HelloWorld server started (press enter to shutdown) + +As this point the SCA service is exposed as a web service by a web server +started automatically by the SCA runtime. To stop the server just press +enter. + +To exercise the service run up the helloworld-ws-reference sample. Take a look at +the README in that sample and you will see you need the following commands + +cd helloworld-ws-reference +ant run + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. When using Maven you don't need to run the helloworld- +ws-reference sample as Maven includes a simple ping test to make sure that the +service is available + +cd helloworld-ws-service +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.HelloWorldServerTestCase +log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAX +Utils). +log4j:WARN Please initialize the log4j system properly. +10-May-2007 13:48:42 org.apache.catalina.core.StandardEngine start +INFO: Starting Servlet Engine: Apache Tomcat/6.0.10 +10-May-2007 13:48:42 org.apache.catalina.startup.ContextConfig defaultWebConfig +INFO: No default web.xml +10-May-2007 13:48:42 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/jsp_2_0.xsd +10-May-2007 13:48:42 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_1_ +1.dtd +10-May-2007 13:48:42 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_1_ +2.dtd +10-May-2007 13:48:42 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/jsp/resources/web-jsptaglibrary_2_ +0.xsd +10-May-2007 13:48:42 org.apache.catalina.startup.DigesterFactory register +WARNING: Could not get url for /javax/servlet/resources/j2ee_web_services_1_1.xs +d +10-May-2007 13:48:43 org.apache.coyote.http11.Http11Protocol init +INFO: Initializing Coyote HTTP/1.1 on http-8085 +10-May-2007 13:48:43 org.apache.coyote.http11.Http11Protocol start +INFO: Starting Coyote HTTP/1.1 on http-8085 +10-May-2007 13:48:43 org.apache.coyote.http11.Http11Protocol destroy +INFO: Stopping Coyote HTTP/1.1 on http-8085 +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.857 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/build.xml new file mode 100644 index 0000000000..46678febc3 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.png b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.png new file mode 100644 index 0000000000..6f7d9dd450 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.svg b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.svg new file mode 100644 index 0000000000..3305faeed8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/helloworld-ws-service.svg @@ -0,0 +1,149 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldws + + HelloWorldServiceComponent + + HelloWorldWebService + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/pom.xml new file mode 100644 index 0000000000..975aed3cf9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/pom.xml @@ -0,0 +1,79 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-helloworld-ws-service + Apache Tuscany HelloWorld Web Service Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-http-tomcat + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..0de3c70303 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldImpl.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 helloworld; + +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String getGreetings(String name) { + return "Hello " + name; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldServer.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldServer.java new file mode 100644 index 0000000000..e03ed4dc25 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldServer.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This server program shows how to create an SCA runtime, and start it which + * activates the helloworld Web service endpoint. + */ +public class HelloWorldServer { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("helloworldws.composite"); + + try { + System.out.println("HelloWorld server started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + System.out.println("HelloWorld server stopped"); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldService.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..bd527ff8e2 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/java/helloworld/HelloWorldService.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 helloworld; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +@Remotable +@Service +public interface HelloWorldService { + + public String getGreetings(String name); +} + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/helloworldws.composite b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/helloworldws.composite new file mode 100644 index 0000000000..76ccf71fb8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/helloworldws.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/wsdl/helloworld.wsdl b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000000..454763410c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/main/resources/wsdl/helloworld.wsdl @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldServerTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldServerTestCase.java new file mode 100644 index 0000000000..449979d4c1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldServerTestCase.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import java.io.IOException; +import java.net.Socket; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that the helloworld server is available + */ +public class HelloWorldServerTestCase { + + private SCADomain scaDomain; + + @Before + public void startServer() throws Exception { + scaDomain = SCADomain.newInstance("helloworldws.composite"); + } + + @Test + public void testPing() throws IOException { + new Socket("127.0.0.1", 8085); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/README b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/README new file mode 100644 index 0000000000..27de00e8ef --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/README @@ -0,0 +1,116 @@ +Composite Implementation Sample +=============================== + +This sample shows how composites can be used to implement components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-implementation-composite.jar composite.CompositeClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-implementation-composite.jar composite.CompositeClient + + +Sample Overview +--------------- + +The sample is comprised of three composites. Take a look at the composite file +or the .svg/.png file which shows the composite file in pictorial form. The +OuterComposite defines three components two of which are implemented using +composites. The SourceComponent calls each TargetComponent in turn. There is a +callback which returns from each TargetComponent to the SourceComponent. + +implementation-composite/ + src/ + main/ + java/ + composite/ + Source.java - interface for the source component + SourceImpl.java - implementation for the source component + SourceCallback.java - source component callback interface + Target.java - interface for the target component + TargetImpl.java - implementation for the target component + CompositeClient.java - starts the SCA Runtime and + deploys the OuterComposite.composite. + This in turn pulls in the two inner + composites + resources/ + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + OuterComposite.composite - the top level SCA assembly for this sample + InnerComposite.composite - included by OuterComposite.composite + InnerComposite2.composite - included by OuterComposite.composite + test/ + java/ + composite/ + CompositeTestCase.java - JUnit test case + implementation-composite.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd implementation-composite +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Main thread Thread[main,5,main] + [java] Source: Client.main -> Source.clientMethod + [java] Source: Client.main => Source.clientMethod2 + [java] Sleeping ... + [java] Target: Client.main -> Source.clientMethod + [java] Work thread Thread[pool-1-thread-1,5,main] + [java] Result: Client.main -> Source.clientMethod -> Target.someMethod + [java] Target: Client.main => Source.clientMethod2 + [java] Work thread Thread[pool-1-thread-2,5,main] + [java] Result: Client.main => Source.clientMethod2 -> Target.someMethod + + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd implementation-composite +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running composite.CompositeTestCase +Main thread Thread[main,5,main] +Source: Client.main -> Source.clientMethod +Source: Client.main => Source.clientMethod2 +Sleeping ... +Target: Client.main => Source.clientMethod2 +Work thread Thread[pool-1-thread-2,5,main] +Result: Client.main => Source.clientMethod2 -> Target.someMethod +Target: Client.main -> Source.clientMethod +Work thread Thread[pool-1-thread-1,5,main] +Result: Client.main -> Source.clientMethod -> Target.someMethod +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.973 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/build.xml new file mode 100644 index 0000000000..7aa31aab8b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.png b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.png new file mode 100644 index 0000000000..4c6d71bc03 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.svg b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.svg new file mode 100644 index 0000000000..0e60354aab --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/implementation-composite.svg @@ -0,0 +1,658 @@ + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + OuterComposite + InnerComposite + + OuterComposite.composite + InnerComposite.composite + InnerComposite2.composite + SourceComponent + + TargetComponentRef TargetComponentRef2 + + TargetComponent + + TargetComponent2 + + + InnerSourceService + InnerSourceComponent + + + + + + TargetComponentRef TargetComponentRef2 + + promote promote + InnerTargetService + InnerTargetComponent + + TargetImpl Target + + Target + + SourceImpl + Source + SourceCallback + + + + + Target Source + InnerComposite2 promote promote + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/pom.xml new file mode 100644 index 0000000000..294adfc577 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-implementation-composite + Apache Tuscany Composite Implementation Sample + A sample showing local wiring of a component implemented by a nested composite + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/CompositeClient.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/CompositeClient.java new file mode 100644 index 0000000000..bf743e1797 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/CompositeClient.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 composite; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Simple client program that invokes the components that we wired together. + */ +public class CompositeClient { + + public static void main(String[] args) throws Exception { + SCADomain scaDomain = SCADomain.newInstance(); + + Source source = scaDomain.getService(Source.class, "SourceComponent"); + + System.out.println("Main thread " + Thread.currentThread()); + source.clientMethod("Client.main"); + System.out.println("Sleeping ..."); + Thread.sleep(1000); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Source.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Source.java new file mode 100644 index 0000000000..d0efcc1df1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Source.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package composite; + +public interface Source { + + void clientMethod(String arg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceCallback.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceCallback.java new file mode 100644 index 0000000000..baa95a8e39 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceCallback.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package composite; + +public interface SourceCallback { + + void receiveResult(String result); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceImpl.java new file mode 100644 index 0000000000..b9a0c7ff74 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/SourceImpl.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package composite; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + + +@Service(Source.class) +@Scope("COMPOSITE") +public class SourceImpl implements Source, SourceCallback { + + private Target targetReference; + private Target targetReference2; + + @Reference + public void setTargetReference(Target target) { + this.targetReference = target; + } + + @Reference + public void setTargetReference2(Target target) { + this.targetReference2 = target; + } + + public void clientMethod(String arg) { + System.out.println("Source: " + arg + " -> Source.clientMethod"); + targetReference.someMethod(arg + " -> Source.clientMethod"); + + System.out.println("Source: " + arg + " => Source.clientMethod2"); + targetReference2.someMethod(arg + " => Source.clientMethod2"); + } + + public void receiveResult(String result) { + System.out.println("Work thread " + Thread.currentThread()); + System.out.println("Result: " + result); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Target.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Target.java new file mode 100644 index 0000000000..9a8f68a7fa --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/Target.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 composite; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.OneWay; + + +@Callback(SourceCallback.class) +public interface Target { + + @OneWay + void someMethod(String arg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/TargetImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/TargetImpl.java new file mode 100644 index 0000000000..86686e9233 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/java/composite/TargetImpl.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 composite; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + + +@Service(Target.class) +@Scope("COMPOSITE") +public class TargetImpl implements Target { + + private SourceCallback sourceCallback; + + @Callback + public void setSourceCallback(SourceCallback sourceCallback) { + this.sourceCallback = sourceCallback; + } + + public void someMethod(String arg) { + System.out.println("Target: " + arg); + sourceCallback.receiveResult(arg + " -> Target.someMethod"); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite.composite b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite.composite new file mode 100644 index 0000000000..3376ac8ff5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite2.composite b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite2.composite new file mode 100644 index 0000000000..c9eff4fa9d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/InnerComposite2.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/META-INF/sca-contribution.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..71859a321e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/OuterComposite.composite b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/OuterComposite.composite new file mode 100644 index 0000000000..cb1c1e13d4 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/main/resources/OuterComposite.composite @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/test/java/composite/CompositeTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/test/java/composite/CompositeTestCase.java new file mode 100644 index 0000000000..d20f6d17d3 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-composite/src/test/java/composite/CompositeTestCase.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 composite; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class CompositeTestCase extends TestCase { + + private SCADomain scaDomain; + private Source source; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance(); + source = scaDomain.getService(Source.class, "SourceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void test() throws Exception { + try { + System.out.println("Main thread " + Thread.currentThread()); + source.clientMethod("Client.main"); + System.out.println("Sleeping ..."); + Thread.sleep(1000); + } catch (Throwable t) { + t.printStackTrace(); + } + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/README b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/README new file mode 100644 index 0000000000..973c13d00c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/README @@ -0,0 +1,87 @@ +Implementation CRUD Sample +========================== +This sample demonstrates how new implementation types are constructed for +Apache Tuscany SCA. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you want to try out the CRUD implementation type that this sample provides +please see the implementation-crud sample that provides the necessary client +code to bring up an application that uses this implementation extension. + +Sample Overview +--------------- +This sample contains a CRUD implementation type as an example of how to create +new implementation types. Components using this implementation type always +expose the same Create, Retrieve, Update and Delete interface. This sample +uses a singleton ResourceManager to perform the CRUD operations but of course +a real component would provide a real implementation. + +implementation-crud-extension/ + src/ + main/ + java/ + crud/ - implementation model interfaces + backend/ - fake component implementation + impl/ - implementations of the model interfaces + module/ - gets the implementation-crud module registered + with the SCA runtime + provider/ - runtime implementation + resources/ + META-INF/ + services/ + org.apache.sca.tuscany.sca.core.ModuleActivator - specifies the + module activation class to call + test/ + java/ + crud/ + CRUDTestCase.java - JUnit test case + resources/ + crud.composite - the SCA assembly used during unit testing + + build.xml - the Ant build file + pom.xml - the Maven build file + +Building The Sample Extension Using Ant +----------------------------------------- +With the binary distribution the sample extension can be built using Ant as +follows + +cd implementation-crud-extension +ant compile + +See the implementation-crud sample to run a sample that uses this +implementation extension. + +Building The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built +using Maven as follows. + +cd implementation-crud-extension +mvn + +Maven will also test that the sample extension built properly. You should see +the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running crud.CRUDTestCase +Starting CRUDServiceComponent +create(ABC) in tmp +retrieve(0) +update(0) +retrieve(0) +delete(0) +retrieve(0) +Stopping CRUDServiceComponent +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.212 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/build.xml new file mode 100644 index 0000000000..88d308e6fc --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/pom.xml new file mode 100644 index 0000000000..5299645ecb --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-implementation-crud-extension + Apache Tuscany CRUD Implementation Extension Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + test + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUD.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUD.java new file mode 100644 index 0000000000..b23d85887b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUD.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package crud; + +/** + * The service interface of the single CRUD service provided by CRUD components. + */ +public interface CRUD { + + /** + * Create a new resource. + * @param resource + * @return + */ + String create(Object resource); + + /** + * Retrieve a resource. + * @param id + * @return + */ + Object retrieve(String id); + + /** + * Update a resource. + * @param id + * @param resource + * @return + */ + Object update(String id, Object resource); + + /** + * Delete a resource. + * @param id + */ + void delete(String id); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.java new file mode 100644 index 0000000000..5cb2bd2b1c --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementation.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 crud; + +import org.apache.tuscany.sca.assembly.Implementation; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + * The sample CRUD implementation is not a full blown implementation, it only + * supports a subset of what a component implementation can support: - a single + * fixed service (as opposed to a list of services typed by different + * interfaces) - a directory attribute used to specify where a CRUD component is + * going to persist resources - no references or properties - no policy intents + * or policy sets + */ +public interface CRUDImplementation extends Implementation { + + /** + * Returns the directory used by CRUD implementations to persist resources. + * + * @return the directory used to persist resources + */ + public String getDirectory(); + + /** + * Sets the directory used by CRUD implementations to persist resources. + * + * @param directory the directory used to persist resources + */ + public void setDirectory(String directory); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.java new file mode 100644 index 0000000000..2a6f3bd955 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/CRUDImplementationFactory.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 crud; + +/** + * A factory for the sample CRUD implementation model. + */ +public interface CRUDImplementationFactory { + + /** + * Creates a new CRUD implementation. + * + * @return + */ + CRUDImplementation createCRUDImplementation(); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/DefaultCRUDImplementationFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/DefaultCRUDImplementationFactory.java new file mode 100644 index 0000000000..38aac604d9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/DefaultCRUDImplementationFactory.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 crud; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector; + +import crud.impl.CRUDImplementationImpl; + +/** + * A default factory for the CRUD implementation model. + */ +public class DefaultCRUDImplementationFactory implements CRUDImplementationFactory { + + private AssemblyFactory assemblyFactory; + private JavaInterfaceFactory javaFactory; + private JavaInterfaceIntrospector introspector; + + public DefaultCRUDImplementationFactory(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory, + JavaInterfaceIntrospector introspector) { + this.assemblyFactory = assemblyFactory; + this.javaFactory = javaFactory; + this.introspector = introspector; + } + + public CRUDImplementation createCRUDImplementation() { + return new CRUDImplementationImpl(assemblyFactory, javaFactory, introspector); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.java new file mode 100644 index 0000000000..cc0795a735 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/backend/ResourceManager.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 crud.backend; + +import java.util.HashMap; +import java.util.Map; + +/** + * A fake resource manager implementation used as a backend by the sample + * CRUD component implementation. + */ +public class ResourceManager { + private static int counter; + private static final Map store = new HashMap(); + private String directory; + + /** + * Constructs a new resource manager. + * + * @param directory the directory where to persist resources + */ + public ResourceManager(String directory) { + super(); + this.directory = directory; + } + + /** + * Creates a new resource. + * + * @param resource + * @return + */ + public String createResource(Object resource) { + System.out.println("create(" + resource + ") in " + directory); + String key = String.valueOf(counter++); + store.put(key, resource); + return key; + } + + /** + * Deletes a resource. + * + * @param id + */ + public void deleteResource(String id) { + System.out.println("delete(" + id + ")"); + store.remove(id); + } + + /** + * Retrieves a resource. + * + * @param id + * @return + */ + public Object retrieveResource(String id) { + System.out.println("retrieve(" + id + ")"); + return store.get(id); + } + + /** + * Updates a resource. + * + * @param id + * @param resource + * @return + */ + public Object updateResource(String id, Object resource) { + System.out.println("update(" + id + ")"); + return store.put(id, resource); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java new file mode 100644 index 0000000000..4dd3e336b7 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationImpl.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package crud.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +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.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +import crud.CRUD; +import crud.CRUDImplementation; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +public class CRUDImplementationImpl implements CRUDImplementation { + + private Service crudService; + private String directory; + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementationImpl(AssemblyFactory assemblyFactory, + JavaInterfaceFactory javaFactory, + JavaInterfaceIntrospector introspector) { + + // CRUD implementation always provide a single service exposing + // the CRUD interface, and have no references and properties + crudService = assemblyFactory.createService(); + crudService.setName("CRUD"); + JavaInterface javaInterface; + try { + javaInterface = introspector.introspect(CRUD.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + crudService.setInterfaceContract(interfaceContract); + } + + public String getDirectory() { + return directory; + } + + public void setDirectory(String directory) { + this.directory = directory; + } + + public ConstrainingType getConstrainingType() { + // The sample CRUD implementation does not support constrainingTypes + return null; + } + + public List getProperties() { + // The sample CRUD implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + // The sample CRUD implementation provides a single fixed CRUD service + return Collections.singletonList(crudService); + } + + public List getReferences() { + // The sample CRUD implementation does not support properties + return Collections.emptyList(); + } + + public String getURI() { + // The sample CRUD implementation does not have a URI + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The sample CRUD implementation does not support constrainingTypes + } + + public void setURI(String uri) { + // The sample CRUD implementation does not have a URI + } + + public List getPolicySets() { + // The sample CRUD implementation does not support policy sets + return Collections.emptyList(); + } + + public List getRequiredIntents() { + // The sample CRUD implementation does not support intents + return Collections.emptyList(); + } + + public List getExtensions() { + // The sample CRUD implementation does not support extensions + return Collections.emptyList(); + } + + public boolean isUnresolved() { + // The sample CRUD implementation is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The sample CRUD implementation is always resolved + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationProcessor.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationProcessor.java new file mode 100644 index 0000000000..cf57336cd1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/impl/CRUDImplementationProcessor.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package crud.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +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.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +import crud.CRUDImplementation; +import crud.CRUDImplementationFactory; + +/** + * Implements a STAX artifact processor for CRUD implementations. + * + * The artifact processor is responsible for processing + * elements in SCA assembly XML composite files and populating the CRUD + * implementation model, resolving its references to other artifacts in the SCA + * contribution, and optionally write the model back to SCA assembly XML. + */ +public class CRUDImplementationProcessor implements StAXArtifactProcessor { + private static final QName IMPLEMENTATION_CRUD = new QName("http://crud", "implementation.crud"); + + private CRUDImplementationFactory crudFactory; + + public CRUDImplementationProcessor(CRUDImplementationFactory crudFactory) { + this.crudFactory = crudFactory; + } + + public QName getArtifactType() { + // Returns the qname of the XML element processed by this processor + return IMPLEMENTATION_CRUD; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return CRUDImplementation.class; + } + + public CRUDImplementation read(XMLStreamReader reader) throws ContributionReadException { + assert IMPLEMENTATION_CRUD.equals(reader.getName()); + + // Read an element + try { + // Read the directory attribute. This is where the sample + // CRUD implementation will persist resources. + String directory = reader.getAttributeValue(null, "directory"); + + // Create an initialize the CRUD implementation model + CRUDImplementation implementation = crudFactory.createCRUDImplementation(); + implementation.setDirectory(directory); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_CRUD.equals(reader.getName())) { + break; + } + } + + return implementation; + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + public void resolve(CRUDImplementation impl, ModelResolver resolver) throws ContributionResolveException { + } + + public void write(CRUDImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException { + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/module/CRUDModuleActivator.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/module/CRUDModuleActivator.java new file mode 100644 index 0000000000..bd6a037ba7 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/module/CRUDModuleActivator.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 crud.module; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +import crud.CRUDImplementationFactory; +import crud.DefaultCRUDImplementationFactory; +import crud.impl.CRUDImplementationProcessor; +import crud.provider.CRUDImplementationProviderFactory; + +/** + * Implements a module activator for the CRUD implementation extension module. + * The module activator is responsible for contributing the CRUD implementation + * extensions and plugging them in the extension points defined by the Tuscany + * runtime. + */ +public class CRUDModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + // This module extension does not contribute any new extension point + return null; + } + + public void start(ExtensionPointRegistry registry) { + + // Create the CRUD implementation factory + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + JavaInterfaceIntrospectorExtensionPoint visitors = registry.getExtensionPoint(JavaInterfaceIntrospectorExtensionPoint.class); + JavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors); + CRUDImplementationFactory crudFactory = new DefaultCRUDImplementationFactory(assemblyFactory, javaFactory, introspector); + factories.addFactory(crudFactory); + + // Add the CRUD implementation extension to the StAXArtifactProcessor + // extension point + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + CRUDImplementationProcessor implementationArtifactProcessor = new CRUDImplementationProcessor(crudFactory); + processors.addArtifactProcessor(implementationArtifactProcessor); + + // Add the CRUD provider factory to the ProviderFactory extension point + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + providerFactories.addProviderFactory(new CRUDImplementationProviderFactory()); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.java new file mode 100644 index 0000000000..0f040a478f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProvider.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 crud.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +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; + +import crud.CRUDImplementation; +import crud.backend.ResourceManager; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + * The sample CRUD implementation is not a full blown implementation, it only + * supports a subset of what a component implementation can support: - a single + * fixed service (as opposed to a list of services typed by different + * interfaces) - a directory attribute used to specify where a CRUD component is + * going to persist resources - no references or properties - no policy intents + * or policy sets + */ +public class CRUDImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + private CRUDImplementation implementation; + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + this.component = component; + this.implementation = implementation; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + CRUDInvoker invoker = new CRUDInvoker(operation, new ResourceManager(implementation.getDirectory())); + return invoker; + } + + public Invoker createCallbackInvoker(Operation operation) { + CRUDInvoker invoker = new CRUDInvoker(operation, new ResourceManager(implementation.getDirectory())); + return invoker; + } + + public void start() { + System.out.println("Starting " + component.getName()); + } + + public void stop() { + System.out.println("Stopping " + component.getName()); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.java new file mode 100644 index 0000000000..08e041d7e0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDImplementationProviderFactory.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 crud.provider; + +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +import crud.CRUDImplementation; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +public class CRUDImplementationProviderFactory implements ImplementationProviderFactory { + + /** + * Constructs a new CRUD implementation. + */ + public CRUDImplementationProviderFactory() { + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, CRUDImplementation implementation) { + return new CRUDImplementationProvider(component, implementation); + } + + public Class getModelType() { + return CRUDImplementation.class; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDInvoker.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDInvoker.java new file mode 100644 index 0000000000..f09922e965 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/java/crud/provider/CRUDInvoker.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package crud.provider; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import crud.backend.ResourceManager; + +/** + * Implements a target invoker for CRUD component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. In this example we are simply delegating the + * CRUD operation invocations to the corresponding methods on our fake + * resource manager. + */ +public class CRUDInvoker implements Invoker { + private Operation operation; + private ResourceManager resourceManager; + + public CRUDInvoker(Operation operation, ResourceManager resourceManager) { + this.operation = operation; + this.resourceManager = resourceManager; + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = doTheWork(args); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + + public Object doTheWork(Object[] args) throws InvocationTargetException { + if (operation.getName().equals("create")) { + return resourceManager.createResource(args[0]); + + } else if (operation.getName().equals("retrieve")) { + return resourceManager.retrieveResource((String)args[0]); + + } else if (operation.getName().equals("update")) { + return resourceManager.updateResource((String)args[0], args[1]); + + } else if (operation.getName().equals("delete")) { + resourceManager.deleteResource((String)args[0]); + return null; + + } else { + return null; + } + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..d9ab99f258 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -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. +# Implementation class for the ExtensionActivator +crud.module.CRUDModuleActivator diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java new file mode 100644 index 0000000000..8b092818a9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/java/crud/CRUDTestCase.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package crud; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Tests the CRUD service + */ +public class CRUDTestCase extends TestCase { + + private SCADomain scaDomain; + private CRUD crudService; + + /** + * @throws java.lang.Exception + */ + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("crud.composite"); + crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + + } + + /** + * @throws java.lang.Exception + */ + protected void tearDown() throws Exception { + scaDomain.close(); + } + + + public void testCRUD() throws Exception { + String id = crudService.create("ABC"); + Object result = crudService.retrieve(id); + assertEquals("ABC", result); + crudService.update(id, "EFG"); + result = crudService.retrieve(id); + assertEquals("EFG", result); + crudService.delete(id); + result = crudService.retrieve(id); + assertNull(result); + } + + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/resources/crud.composite b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/resources/crud.composite new file mode 100644 index 0000000000..18745033bb --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud-extension/src/test/resources/crud.composite @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/README b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/README new file mode 100644 index 0000000000..50da631c04 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/README @@ -0,0 +1,113 @@ +Implementation CRUD Sample Client +================================= +This sample demonstrates how to use the new implementation extension, +implementation-crud-extension. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens, open a command prompt, +navigate to this sample directory, and do + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;..\implementation-crud-extension\target\sample-implementation-crud-extension.jar;target\sample-implementation-crud.jar crud.client.CRUDClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:../implementation-crud-extension/target/sample-implementation-crud-extension.jar:target/sample-implementation-crud.jar crud.client.CRUDClient + +This looks like a long command. The three things we add to the classpath are + +tuscany-sca-manifest.jar - all of the standard Tuscany SCA + runtime and extension classes +sample-implementation-crud-extension.jar - the new crud implementation + extension +sample-implementation-crud.jar - the application that uses the crud + implementation + +Sample Overview +--------------- +This sample contains a client application for a CRUD implementation type that +shows how to create new implementation types. See the README for the +mplementation-crud-extension sample for details of this implementation type. + +implementation-crud/ + src/ + main/ + java/ + crud/ + client/ + CRUDClient.java - sample client + resources/ + crud.composite - the SCA assembly used by this sample + + test/ + java/ + crud/ + client/ + CRUDTestCase.java - sample JUnit test case for the sample client + + implementation-crud.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd implementation-crud +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Starting CRUDServiceComponent + [java] create(ABC) in tmp + [java] retrieve(0) + [java] Result from create: ABC + [java] update(0) + [java] retrieve(0) + [java] Result from update: EFG + [java] delete(0) + [java] retrieve(0) + [java] Result from delete: null + [java] Stopping CRUDServiceComponent + + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and +run using Maven as follows. + +cd implementation-crud +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running crud.client.CRUDTestCase +Starting CRUDServiceComponent +create(ABC) in tmp +retrieve(0) +update(0) +retrieve(0) +delete(0) +retrieve(0) +Stopping CRUDServiceComponent +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.641 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/build.xml new file mode 100644 index 0000000000..10b26b5a94 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/build.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.png b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.png new file mode 100644 index 0000000000..a292037e7a Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.svg b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.svg new file mode 100644 index 0000000000..dbb37be208 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/implementation-crud.svg @@ -0,0 +1,135 @@ + + + + + + + + + + image/svg+xml + + + + + + + + crud + + CRUDServiceComponent + CRUD + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/pom.xml new file mode 100644 index 0000000000..a408b89ea1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-implementation-crud + Apache Tuscany CRUD Implementation Extension Sample Client + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + sample-implementation-crud-extension + 0.91-incubating + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/java/crud/client/CRUDClient.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/java/crud/client/CRUDClient.java new file mode 100644 index 0000000000..ff2da8985b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/java/crud/client/CRUDClient.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 crud.client; + +import crud.CRUD; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev$ $Date$ + */ +public class CRUDClient { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("crud.composite"); + CRUD crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + + String id = crudService.create("ABC"); + Object result = crudService.retrieve(id); + System.out.println("Result from create: " + result); + crudService.update(id, "EFG"); + result = crudService.retrieve(id); + System.out.println("Result from update: " + result); + crudService.delete(id); + result = crudService.retrieve(id); + if (result == null) { + System.out.println("Result from delete: null"); + } else { + System.out.println("Result from delete: should be null but was " + result); + } + + scaDomain.close(); + + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/resources/crud.composite b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/resources/crud.composite new file mode 100644 index 0000000000..18745033bb --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/main/resources/crud.composite @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/test/java/crud/client/CRUDTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/test/java/crud/client/CRUDTestCase.java new file mode 100644 index 0000000000..c3fe9d0f62 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/implementation-crud/src/test/java/crud/client/CRUDTestCase.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 crud.client; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import crud.CRUD; + +public class CRUDTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("crud.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void test() throws Exception { + CRUD crudService = scaDomain.getService(CRUD.class, "CRUDServiceComponent"); + + String id = crudService.create("ABC"); + Object result = crudService.retrieve(id); + assertEquals(result, "ABC"); + + crudService.update(id, "EFG"); + result = crudService.retrieve(id); + assertEquals(result, "EFG"); + + crudService.delete(id); + result = crudService.retrieve(id); + assertNull(result); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/pom.xml new file mode 100644 index 0000000000..adf5f54311 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/pom.xml @@ -0,0 +1,67 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../pom.xml + + tuscany-samples + pom + Apache Tuscany SCA Samples + + + + default + + true + + + binding-echo + binding-echo-extension + calculator + calculator-rmi-reference + calculator-rmi-service + calculator-script + calculator-webapp + chat-webapp + databinding-echo + feed-aggregator + helloworld-dojo + helloworld-jsonrpc + helloworld-ws-service + helloworld-ws-reference + implementation-composite + implementation-crud + implementation-crud-extension + + simple-bigbank + simple-callback + supplychain + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/README b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/README new file mode 100644 index 0000000000..92e4a379ac --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/README @@ -0,0 +1,89 @@ +Calculator Sample +================= +This sample implements a simple a version of the BigBank scenrio used in +various places in the SCA specification documents. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-simple-bigbank.jar bigbank.client.BigBankClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-simple-bigbank.jar bigbank.client.BigBankClient + + +Sample Overview +--------------- +The sample provides a composite with two java components wired together +with a default binding. A request to the AccountComponent results in a +request to the AccountDataComponent to get account data. The data returns +back via the AccountComponent to the client. + +calculator/ + src/ + main/ + java/ + bigbank/ + account/ - AccountComponent implementation + accountdata/ - AccountDataComponent implementation + client/ - starts the SCA Runtime and + deploys the BigBank.composite. + It then calls the deployed AccountService + resources/ + BigBank.composite - the SCA assembly for this sample + test/ + java/ + bigbank/ + BigBankTestCase.java - JUnit test case + simple-bigbank.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd simple-bigbank +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Account summary: currency: USD, [ID:Foo_CHA12345, balance:1500.0, ID +:Foo_SAA12345, balance:1500.0, ID:Foo_STA12345, symbol:IBM, quantity:100] + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd simple-bigbank +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running bigbank.BigBankTestCase +Account summary: currency: USD, [ID:Foo_CHA12345, balance:1500.0, ID:Foo_SAA1234 +5, balance:1500.0, ID:Foo_STA12345, symbol:IBM, quantity:100] +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.592 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/build.xml new file mode 100644 index 0000000000..a814014eae --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/pom.xml new file mode 100644 index 0000000000..a20fb4267e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-simple-bigbank + Apache Tuscany Simplified BigBank Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-core-databinding + 0.91-incubating + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.png b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.png new file mode 100644 index 0000000000..593c047f6a Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.svg b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.svg new file mode 100644 index 0000000000..c64f6de6b9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/simple-bigbank.svg @@ -0,0 +1,200 @@ + + + + + + + + + + image/svg+xml + + + + + + + + BigBank + + AccountServiceComponent + + + + + AccountDataServiceComponent + + + currency AccountService + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountReport.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountReport.java new file mode 100644 index 0000000000..3f207e2f79 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountReport.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bigbank.account; + +import java.util.List; + +/** + */ +public class AccountReport { + private List summaries; + private String currency; + + public AccountReport(String currency, List summaries) { + this.currency = currency; + this.summaries = summaries; + } + + public List getAccountSummaries() { return summaries; } + + public String getCurrency() { return currency; } + + public String toString() { + return "currency: "+ currency + ", " + summaries; + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountService.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountService.java new file mode 100644 index 0000000000..7c9082b944 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountService.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bigbank.account; + +/** + * Interface for a account service + */ +public interface AccountService { + public AccountReport getAccountReport(String customerID); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountServiceImpl.java new file mode 100644 index 0000000000..0d73a6c3c9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/account/AccountServiceImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bigbank.account; + +import java.util.ArrayList; +import java.util.List; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +import bigbank.accountdata.AccountDataService; +import bigbank.accountdata.CheckingAccount; +import bigbank.accountdata.SavingsAccount; +import bigbank.accountdata.StockAccount; + +/** + * Account service implementation + */ +@Service(AccountService.class) +public class AccountServiceImpl implements AccountService { + + @Reference + public AccountDataService accountDataService; + + @Property + public String currency; + + public AccountReport getAccountReport(String s) { + List summaries = new ArrayList(); + + CheckingAccount ca = accountDataService.getCheckingAccount(s); + summaries.add(ca.getSummary()); + + SavingsAccount sa = accountDataService.getSavingsAccount(s); + summaries.add(sa.getSummary()); + + StockAccount sk = accountDataService.getStockAccount(s); + summaries.add(sk.getSummary()); + + AccountReport report = new AccountReport(currency, summaries); + + return report; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/Account.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/Account.java new file mode 100644 index 0000000000..a5ae7b3955 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/Account.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package bigbank.accountdata; + +/** + * Interface for a account service + */ +public interface Account { + String getSummary(); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataService.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataService.java new file mode 100644 index 0000000000..c354de387b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataService.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 bigbank.accountdata; + +/** + * Interface for a account data service + */ +public interface AccountDataService { + public CheckingAccount getCheckingAccount(String customerID); + public SavingsAccount getSavingsAccount(String customerID); + public StockAccount getStockAccount(String customerID); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataServiceImpl.java new file mode 100644 index 0000000000..c8fc6277ca --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/AccountDataServiceImpl.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 bigbank.accountdata; + +import org.osoa.sca.annotations.Service; + +/** + * Account data service implementation + */ +@Service(AccountDataService.class) +public class AccountDataServiceImpl implements AccountDataService { + + public CheckingAccount getCheckingAccount(String customerID) { + + CheckingAccount checkingAccount = new CheckingAccount(); + checkingAccount.setAccountNumber(customerID+"_"+"CHA12345"); + checkingAccount.setBalance(1500.0f); + + return checkingAccount; + } + + public SavingsAccount getSavingsAccount(String customerID) { + + SavingsAccount savingsAccount = new SavingsAccount(); + savingsAccount.setAccountNumber(customerID+"_"+"SAA12345"); + savingsAccount.setBalance(1500.0f); + + return savingsAccount; + } + + public StockAccount getStockAccount(String customerID) { + + StockAccount stockAccount = new StockAccount(); + stockAccount.setAccountNumber(customerID+"_"+"STA12345"); + stockAccount.setSymbol("IBM"); + stockAccount.setQuantity(100); + + return stockAccount; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/CheckingAccount.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/CheckingAccount.java new file mode 100644 index 0000000000..11bdff757e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/CheckingAccount.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 bigbank.accountdata; + +/** + * An account service implementation for a checking account + */ +public class CheckingAccount implements Account { + private String accountNumber; + private double balance; + + public String getAccountNumber() { return accountNumber; } + public void setAccountNumber(String n) { this.accountNumber = n; } + + public double getBalance() { return balance; } + public void setBalance(double b) { this.balance = b; } + + public String getSummary() { return "ID:" + accountNumber + ", balance:" + balance; } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/SavingsAccount.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/SavingsAccount.java new file mode 100644 index 0000000000..b791024076 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/SavingsAccount.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 bigbank.accountdata; + +/** + * An account service implementation for a savings account + */ +public class SavingsAccount implements Account { + private String accountNumber; + private double balance; + + public String getAccountNumber() { return accountNumber; } + public void setAccountNumber(String n) { this.accountNumber = n; } + + public double getBalance() { return balance; } + public void setBalance(double b) { this.balance = b; } + + public String getSummary() { return "ID:" + accountNumber + ", balance:" + balance; } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/StockAccount.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/StockAccount.java new file mode 100644 index 0000000000..03df61772b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/accountdata/StockAccount.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 bigbank.accountdata; + +/** + * An account service implementation for a stock account + */ +public class StockAccount implements Account { + private String accountNumber; + private String symbol; + private int quantity; + + public String getAccountNumber() { return accountNumber; } + public void setAccountNumber(String n) { this.accountNumber = n; } + + public double getQuantity() { return quantity; } + public void setQuantity(int a) { this.quantity = a; } + + public String getSymbol() { return symbol; } + public void setSymbol(String s) { this.symbol = s; } + + public String getSummary() { return "ID:" + accountNumber + ", symbol:" + symbol + ", quantity:" + quantity; } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/client/BigBankClient.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/client/BigBankClient.java new file mode 100644 index 0000000000..edbf910d37 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/java/bigbank/client/BigBankClient.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 bigbank.client; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import bigbank.account.AccountService; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class BigBankClient { + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("BigBank.composite"); + + AccountService accountService = scaDomain.getService(AccountService.class, + "AccountServiceComponent"); + + System.out.println("Account summary: " + accountService.getAccountReport("Foo") ); + + scaDomain.close(); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/resources/BigBank.composite b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/resources/BigBank.composite new file mode 100644 index 0000000000..ebebce5af9 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/main/resources/BigBank.composite @@ -0,0 +1,33 @@ + + + + + + + + USD + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/test/java/bigbank/BigBankTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/test/java/bigbank/BigBankTestCase.java new file mode 100644 index 0000000000..42d780953d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-bigbank/src/test/java/bigbank/BigBankTestCase.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 bigbank; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import bigbank.account.AccountService; + +/** + * Tests out the big bank service + * + */ +public class BigBankTestCase extends TestCase { + + private SCADomain scaDomain; + AccountService accountService; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("BigBank.composite"); + accountService = scaDomain.getService(AccountService.class, "AccountServiceComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void test() throws Exception { + System.out.println("Account summary: " + accountService.getAccountReport("Foo") ); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/README b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/README new file mode 100644 index 0000000000..719376f254 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/README @@ -0,0 +1,97 @@ +Simple Callback Sample +====================== +This sample demonstrates asynchronous messaging using a callback. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-simple-callback.jar simplecallback.SimpleCallbackClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-simple-callback.jar simplecallback.SimpleCallbackClient + + +Sample Overview +--------------- +The sample provides a single composite with two components. MyClientComponent is +wired to MyServiceComponent. The interface of MyServiceComponent describes one +method as ONEWAY and with a callback semantic. When a message passes from +client to service the response is returned via the callback asynchronously. + +simple-callback/ + src/ + main/ + java/ + simplecallback/ + MyClient.java - client interface + MyClientImpl.java - implements the client and service callback + interfaces + MyService.java - service interface + MyServiceCallback.java - service callback interface, implemented by the + client + MyServiceImpl.java - implements the service interface + SimpleCallbackClient.java - starts the SCA Runtime and + deploys the simplecallback.composite. + It then calls MyClientComponent which in turn + calls MyServiceComponent + resources/ + simplecallback.composite - the SCA assembly for this sample + test/ + java/ + simplecallback/ + SimpleCallbackTestCase.java - JUnit test case + simple-callback.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd simple-callback +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Main thread Thread[main,5,main] + [java] Work thread Thread[pool-1-thread-1,5,main] + [java] Result: -> someMethod -> receiveResult + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd simple-callback +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running simplecallback.SimpleCallbackTestCase +Main thread Thread[main,5,main] +Sleeping ... +Work thread Thread[pool-1-thread-1,5,main] +Result: -> someMethod -> receiveResult +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.692 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/build.xml new file mode 100644 index 0000000000..47d1ea4bc1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/pom.xml new file mode 100644 index 0000000000..f26e1c1e95 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-simple-callback + Apache Tuscany Simple Callback Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.png b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.png new file mode 100644 index 0000000000..1b6353f5cf Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.svg b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.svg new file mode 100644 index 0000000000..484b65df9d --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/simple-callback.svg @@ -0,0 +1,150 @@ + + + + + + + + + + image/svg+xml + + + + + + + + simplecallback + MyServiceComponent + + + MyClientComponent + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClient.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClient.java new file mode 100644 index 0000000000..4cc00d6d0f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClient.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package simplecallback; + +/** + * The client interface + */ +public interface MyClient { + + void aClientMethod(); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClientImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClientImpl.java new file mode 100644 index 0000000000..3e2a1df5a5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyClientImpl.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 simplecallback; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +/** + * Demonstrates a component-to-component callback invocation + */ +@Service(MyClient.class) +@Scope("COMPOSITE") +public class MyClientImpl implements MyClient, MyServiceCallback { + + private MyService myService; + static String result; + + @Reference + public void setMyService(MyService myService) { + this.myService = myService; + } + + public void aClientMethod() { + myService.someMethod("-> someMethod"); + } + + public void receiveResult(String result) { + System.out.println("Work thread " + Thread.currentThread()); + System.out.println("Result: " + result); + MyClientImpl.result = result; + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyService.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyService.java new file mode 100644 index 0000000000..e78ad6f68f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyService.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 simplecallback; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.OneWay; + +/** + * This service that will be invoked in a non-blocking fashion + */ +@Callback(MyServiceCallback.class) +public interface MyService { + + @OneWay + void someMethod(String arg); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceCallback.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceCallback.java new file mode 100644 index 0000000000..b27eea44f5 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceCallback.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package simplecallback; + +/** + * The callback interface for {@link MyService}. + */ +public interface MyServiceCallback { + + void receiveResult(String result); +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceImpl.java new file mode 100644 index 0000000000..fc5e31d14e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/MyServiceImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package simplecallback; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +/** + * This class implements MyService and uses a callback. + */ +@Service(MyService.class) +@Scope("COMPOSITE") +public class MyServiceImpl implements MyService { + + private MyServiceCallback myServiceCallback; + + /** + * The setter used by the runtime to set the callback reference + * @param myServiceCallback + */ + @Callback + public void setMyServiceCallback(MyServiceCallback myServiceCallback) { + this.myServiceCallback = myServiceCallback; + } + + public void someMethod(String arg) { + // invoke the callback + try { + myServiceCallback.receiveResult(arg + " -> receiveResult"); + } catch(RuntimeException e) { + System.out.println("RuntimeException invoking receiveResult: " + e.toString()); + } + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/SimpleCallbackClient.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/SimpleCallbackClient.java new file mode 100644 index 0000000000..b8987fcd07 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/java/simplecallback/SimpleCallbackClient.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 simplecallback; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Demonstrates resolving the client service and initiating the callback sequence + */ +public class SimpleCallbackClient { + + public static void main(String[] args) throws Exception { + SCADomain scaDomain = SCADomain.newInstance("simplecallback.composite"); + MyClient myClient = scaDomain.getService(MyClient.class, "MyClientComponent"); + + System.out.println("Main thread " + Thread.currentThread()); + myClient.aClientMethod(); + Thread.sleep(500); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/resources/simplecallback.composite b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/resources/simplecallback.composite new file mode 100644 index 0000000000..33e6f60601 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/main/resources/simplecallback.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/test/java/simplecallback/SimpleCallbackTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/test/java/simplecallback/SimpleCallbackTestCase.java new file mode 100644 index 0000000000..cafa1bf2fb --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/simple-callback/src/test/java/simplecallback/SimpleCallbackTestCase.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 simplecallback; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * A testcase that demonstrates resolving the client service and initiating the callback sequence + */ +public class SimpleCallbackTestCase extends TestCase { + + private SCADomain scaDomain; + private MyClient myClient; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("simplecallback.composite"); + myClient = scaDomain.getService(MyClient.class, "MyClientComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void test() throws Exception { + System.out.println("Main thread " + Thread.currentThread()); + myClient.aClientMethod(); + System.out.println("Sleeping ..."); + Thread.sleep(300); + assertEquals("-> someMethod -> receiveResult", MyClientImpl.result); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/README b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/README new file mode 100644 index 0000000000..b376a172bd --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/README @@ -0,0 +1,101 @@ +SupplyChain Sample +================== + +This sample demonstrates SCA components using the asynchronous API. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-supplychain.jar supplychain.SupplyChainClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-supplychain.jar supplychain.SupplyChainClient + + +Sample Overview +--------------- + +The sample provides a Customer service with a purchaseGoods operation +and a notifyShipment operation annotated with the SCA @OneWay annotation. +The SupplyChainClient exercises this interface by calling the +purchaseGoods operation. This results in messages passing to +the Retailer, Warehouse, and Shipper components and the result returned +to the Customer service on a separate callback thread. + +calculator/ + src/ + main/ + java/ + supplychain/ + Customer.java - Defines the Java interface implemented + by the Customer component + CustomerComponentImpl.java - Implements the SCA Customer component + Retailer.java - Defines the Java interface implemented + by the Retailer component + RetailerComponentImpl.java - Implements the SCA RetailerComponent component + Shipper.java - Defines the Java interface implemented + by the Shipper component + ShipperComponentImpl.java - Implements the SCA ShipperComponent component + SupplyChainClient.java - SupplyChainClient.java loads SCA runtime + Warehouse.java - Defines the Java interface implemented + by the Warehouse component + WarehouseComponentImpl.java - Implements the SCA WarehouseComponent component + + resources/ + supplychain.composite - the SCA assembly for this sample + test/ + java/ + supplychain/ + SupplyChainClientTestCase.java - JUnit test case + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Main thread Thread[main,5,main] + [java] Main thread sleeping ... + [java] Work thread Thread[pool-1-thread-1,5,main] - Order, submitted, fulfilled, shipped + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd supplychain +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running supplychain.SupplyChainClientTestCase +Main thread Thread[main,5,main] +Sleeping ... +Work thread Thread[pool-1-thread-1,5,main] - Order, submitted, fulfilled, shipped +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.625 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/build.xml b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/build.xml new file mode 100644 index 0000000000..506180b8b1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/pom.xml b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/pom.xml new file mode 100644 index 0000000000..4c3583b943 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 0.91-incubating + ../../pom.xml + + sample-supplychain + Apache Tuscany Supply Chain Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Customer.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Customer.java new file mode 100644 index 0000000000..8088001898 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Customer.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 supplychain; + +import org.osoa.sca.annotations.OneWay; + +/** + * This is the business interface of the Customer service component. + */ +public interface Customer { + + public void purchaseGoods(); + + @OneWay + public void notifyShipment(String order); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/CustomerComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/CustomerComponentImpl.java new file mode 100644 index 0000000000..7a1e8553ec --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/CustomerComponentImpl.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 supplychain; + +import org.osoa.sca.annotations.Reference; + +/** + * This class implements the Customer service component. + */ +public class CustomerComponentImpl implements Customer { + + private Retailer retailer; + + @Reference + public void setRetailer(Retailer retailer) { + this.retailer = retailer; + } + + public void purchaseGoods() { + retailer.submitOrder("Order"); + } + + public void notifyShipment(String order) { + System.out.print("Work thread " + Thread.currentThread() + " - "); + System.out.println(order); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Retailer.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Retailer.java new file mode 100644 index 0000000000..1add63fb4e --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Retailer.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 supplychain; + +/** + * This is the business interface of the Retailer service component. + */ +public interface Retailer { + + public void submitOrder(String order); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/RetailerComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/RetailerComponentImpl.java new file mode 100644 index 0000000000..f622052cf8 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/RetailerComponentImpl.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 supplychain; + +import org.osoa.sca.annotations.Reference; + +/** + * This class implements the Customer service component. + */ +public class RetailerComponentImpl implements Retailer { + + private Warehouse warehouse; + + @Reference + public void setWarehouse(Warehouse warehouse) { + this.warehouse = warehouse; + } + + public void submitOrder(String order) { + warehouse.fulfillOrder(order + ", submitted"); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Shipper.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Shipper.java new file mode 100644 index 0000000000..d4d49a922b --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Shipper.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 supplychain; + +/** + * This is the business interface of the Shipper service component. + */ +public interface Shipper { + + public void processShipment(String order); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/ShipperComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/ShipperComponentImpl.java new file mode 100644 index 0000000000..4ae52a12a2 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/ShipperComponentImpl.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 supplychain; + +import org.osoa.sca.annotations.Reference; + +/** + * This class implements the Warehouse service component. + */ +public class ShipperComponentImpl implements Shipper { + + private Customer customer; + + @Reference + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public void processShipment(String order) { + customer.notifyShipment(order + ", shipped"); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/SupplyChainClient.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/SupplyChainClient.java new file mode 100644 index 0000000000..7072f582d1 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/SupplyChainClient.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 supplychain; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * locate a Customer service component and invoke it. + */ +public class SupplyChainClient { + + public static final void main(String[] args) throws Exception { + SCADomain scaDomain = SCADomain.newInstance("supplychain.composite"); + Customer customer = scaDomain.getService(Customer.class, "CustomerComponent"); + + System.out.println("Main thread " + Thread.currentThread()); + customer.purchaseGoods(); + System.out.println("Main thread sleeping ..."); + Thread.sleep(1000); + + scaDomain.close(); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Warehouse.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Warehouse.java new file mode 100644 index 0000000000..0be499f569 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/Warehouse.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 supplychain; + +/** + * This is the business interface of the Warehouse service component. + */ +public interface Warehouse { + + public void fulfillOrder(String order); + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/WarehouseComponentImpl.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/WarehouseComponentImpl.java new file mode 100644 index 0000000000..b5e256a1e0 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/java/supplychain/WarehouseComponentImpl.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 supplychain; + +import org.osoa.sca.annotations.Reference; + +/** + * This class implements the Warehouse service component. + */ +public class WarehouseComponentImpl implements Warehouse { + + private Shipper shipper; + + @Reference + public void setShipper(Shipper shipper) { + this.shipper = shipper; + } + + public void fulfillOrder(String order) { + shipper.processShipment(order + ", fulfilled"); + } + +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/resources/supplychain.composite b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/resources/supplychain.composite new file mode 100644 index 0000000000..301efcaf1f --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/main/resources/supplychain.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/test/java/supplychain/SupplyChainClientTestCase.java b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/test/java/supplychain/SupplyChainClientTestCase.java new file mode 100644 index 0000000000..d7421e9889 --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/src/test/java/supplychain/SupplyChainClientTestCase.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 supplychain; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * locate a the Customer service component and invoke it. + */ +public class SupplyChainClientTestCase extends TestCase { + + private SCADomain scaDomain; + private Customer customer; + + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("supplychain.composite"); + customer = scaDomain.getService(Customer.class, "CustomerComponent"); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void test() throws Exception { + + System.out.println("Main thread " + Thread.currentThread()); + customer.purchaseGoods(); + System.out.println("Sleeping ..."); + Thread.sleep(1000); + } +} diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.png b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.png new file mode 100644 index 0000000000..51a384e827 Binary files /dev/null and b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.png differ diff --git a/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.svg b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.svg new file mode 100644 index 0000000000..f72e77acab --- /dev/null +++ b/sca-java-1.x/tags/0.91-incubating/samples/supplychain/supplychain.svg @@ -0,0 +1,228 @@ + + + + + + + + + + image/svg+xml + + + + + + + + supplychain + + CustomerComponent + + + RetailerComponent + + + WharehouseComponent + + + ShipperComponent + + + + + + + -- cgit v1.2.3