From ddce09144c53a0edd85f5929605cd3d3191d4ea4 Mon Sep 17 00:00:00 2001 From: antelder Date: Thu, 10 Feb 2011 08:36:51 +0000 Subject: Copy trunk to beta2 release branch. (I've not yet changed the version so that would need to be done first before the branch is used) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1069272 13f79535-47bb-0310-9956-ffa450edef68 --- .../contribution-add/pom.xml | 74 +++++ .../src/main/java/calculator/AddService.java | 31 ++ .../src/main/java/calculator/AddServiceImpl.java | 30 ++ .../src/main/resources/Add.composite | 30 ++ .../main/resources/META-INF/sca-contribution.xml | 23 ++ .../src/test/java/calculator/AddTestCase.java | 56 ++++ .../contribution-calculator/pom.xml | 74 +++++ .../src/main/java/calculator/AddService.java | 31 ++ .../main/java/calculator/CalculatorService.java | 39 +++ .../java/calculator/CalculatorServiceImpl.java | 68 +++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../src/main/resources/Calculator.composite | 31 ++ .../src/test/java/calculator/AddServiceImpl.java | 30 ++ .../test/java/calculator/CalculatorTestCase.java | 59 ++++ .../samples/domain/distributed-calculator/pom.xml | 44 +++ .../2.0-Beta2/unreleased/samples/domain/pom.xml | 42 +++ .../samples/implementation-sample-async/pom.xml | 70 +++++ .../src/main/java/sample/api/Java.java | 34 +++ .../src/main/java/sample/api/WSDL.java | 34 +++ .../src/main/java/sample/api/WSDLReference.java | 29 ++ .../src/main/java/sample/impl/EmbedUtil.java | 311 +++++++++++++++++++ .../src/main/java/sample/impl/ImplUtil.java | 148 +++++++++ .../java/sample/impl/SampleImplementation.java | 41 +++ .../sample/impl/SampleImplementationProcessor.java | 174 +++++++++++ .../main/java/sample/impl/SampleJavaInvoker.java | 52 ++++ .../src/main/java/sample/impl/SampleProvider.java | 91 ++++++ .../java/sample/impl/SampleProviderFactory.java | 48 +++ .../main/java/sample/impl/SampleWSDLInvoker.java | 56 ++++ .../src/main/java/sample/impl/SampleWSDLProxy.java | 62 ++++ .../src/main/java/sampleasync/impl/ImplUtil.java | 148 +++++++++ .../impl/SampleAsyncImplementation.java | 41 +++ .../impl/SampleAsyncImplementationProcessor.java | 174 +++++++++++ .../java/sampleasync/impl/SampleAsyncProvider.java | 107 +++++++ .../impl/SampleAsyncProviderFactory.java | 50 ++++ .../impl/SampleAsyncResponseInvoker.java | 66 ++++ .../java/sampleasync/impl/SampleJavaInvoker.java | 63 ++++ .../java/sampleasync/impl/SampleWSDLInvoker.java | 88 ++++++ .../java/sampleasync/impl/SampleWSDLProxy.java | 98 ++++++ ...ca.contribution.processor.StAXArtifactProcessor | 21 ++ ...any.sca.contribution.processor.ValidationSchema | 19 ++ ...cany.sca.provider.ImplementationProviderFactory | 21 ++ .../src/main/resources/sample/impl/sample.xsd | 38 +++ .../resources/sampleasync/impl/definitions.xml | 30 ++ .../resources/sampleasync/impl/sampleasync.xsd | 38 +++ .../src/test/java/sample/Client.java | 35 +++ .../src/test/java/sample/ClientTest.java | 65 ++++ .../src/test/java/sample/Hello.java | 33 ++ .../src/test/java/sample/JelloTest.java | 40 +++ .../src/test/java/sample/Upper.java | 33 ++ .../src/test/java/sample/UpperTest.java | 37 +++ .../src/test/java/sample/WelloTest.java | 59 ++++ .../src/test/java/sample/Xutil.java | 225 ++++++++++++++ .../src/test/java/sample/impl/EmbedTestCase.java | 153 ++++++++++ .../test/java/sample/impl/ReadWriteTestCase.java | 86 ++++++ .../src/test/java/sample/impl/RunTestCase.java | 77 +++++ .../src/test/java/sample/impl/RunWSTestCase.java | 122 ++++++++ .../src/test/java/sample/impl/TestUtil.java | 31 ++ .../src/test/java/sampleasync/Upper.java | 33 ++ .../test/java/sampleasync/UpperAsyncReference.java | 47 +++ .../test/java/sampleasync/UpperAsyncService.java | 36 +++ .../impl/SampleGenericAsyncTestCase.java | 63 ++++ .../impl/SampleNativeAsyncTestCase.java | 63 ++++ .../impl/UpperJavaAsyncReferenceImpl.java | 70 +++++ .../impl/UpperJavaAsyncServiceImpl.java | 39 +++ .../impl/UpperSampleAsyncReferenceImpl.java | 74 +++++ .../impl/UpperSampleAsyncServiceImpl.java | 45 +++ .../src/test/resources/Hello.wsdl | 62 ++++ .../src/test/resources/Upper.wsdl | 63 ++++ .../src/test/resources/test.composite.off | 61 ++++ .../src/test/resources/testgenericasync.composite | 45 +++ .../src/test/resources/testnativeasync.composite | 35 +++ .../unreleased/samples/jsonp-webapp/pom.xml | 53 ++++ .../src/main/java/sample/Location.java | 33 ++ .../src/main/java/sample/ShareService.java | 14 + .../src/main/java/sample/ShareServiceImpl.java | 23 ++ .../src/main/webapp/META-INF/MANIFEST.MF | 2 + .../src/main/webapp/WEB-INF/web.composite | 33 ++ .../jsonp-webapp/src/main/webapp/WEB-INF/web.xml | 34 +++ .../jsonp-webapp/src/main/webapp/index.html | 104 +++++++ .../samples/launcher-embedded-jse-spec/README | 20 ++ .../samples/launcher-embedded-jse-spec/build.xml | 118 ++++++++ .../samples/launcher-embedded-jse-spec/pom.xml | 83 +++++ .../main/java/calculator/CalculatorService.java | 38 +++ .../launcher/JSELauncherBindingWSCalculator.java | 75 +++++ .../java/launcher/SampleLauncherException.java | 42 +++ .../src/test/java/launcher/LauncherTestCase.java | 33 ++ .../branches/2.0-Beta2/unreleased/samples/pom.xml | 90 ++++++ .../2.0-Beta2/unreleased/samples/reporting/README | 6 + .../2.0-Beta2/unreleased/samples/reporting/pom.xml | 94 ++++++ .../main/java/calculator/CalculatorService.java | 38 +++ .../main/java/reporting/JSELauncheCalculator.java | 333 +++++++++++++++++++++ .../src/main/java/reporting/JSELauncherAdd.java | 144 +++++++++ .../reporting/src/main/resources/node-add.xml | 34 +++ .../src/main/resources/node-calculator.xml | 34 +++ .../reporting/JSELauncherReportingTestCase.java | 320 ++++++++++++++++++++ 97 files changed, 6428 insertions(+) create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/Add.composite create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/test/java/calculator/AddTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/AddService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/DivideService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/MultiplyService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/SubtractService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/resources/Calculator.composite create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/AddServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/Java.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDL.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDLReference.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/EmbedUtil.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/ImplUtil.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementation.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementationProcessor.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleJavaInvoker.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProvider.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProviderFactory.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLInvoker.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLProxy.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/ImplUtil.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementation.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementationProcessor.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProviderFactory.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleJavaInvoker.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sample/impl/sample.xsd create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/definitions.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/sampleasync.xsd create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Client.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/ClientTest.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Hello.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/JelloTest.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Upper.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/UpperTest.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/WelloTest.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Xutil.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/EmbedTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/ReadWriteTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunWSTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/TestUtil.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Hello.wsdl create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Upper.wsdl create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/test.composite.off create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testgenericasync.composite create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testnativeasync.composite create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/Location.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareServiceImpl.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/META-INF/MANIFEST.MF create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.composite create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/index.html create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/README create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/build.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/JSELauncherBindingWSCalculator.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/SampleLauncherException.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/test/java/launcher/LauncherTestCase.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/README create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/pom.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/calculator/CalculatorService.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncheCalculator.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncherAdd.java create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-add.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-calculator.xml create mode 100644 sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/test/java/reporting/JSELauncherReportingTestCase.java (limited to 'sca-java-2.x/branches/2.0-Beta2/unreleased/samples') diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/pom.xml new file mode 100644 index 0000000000..a81b2497e4 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sample-domain-distributed-calculator + 2.0-SNAPSHOT + ../pom.xml + + sample-domain-distributed-calculator-contribution-add + Apache Tuscany SCA Sample Domain Distributed Calculator Contribution Add + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + test + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-SNAPSHOT + runtime + + + junit + junit + 4.8.1 + test + + + + + ${project.artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..c7e6383559 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddService.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the add service + */ +@Remotable +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e9c635e3c8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/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-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/Add.composite b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/Add.composite new file mode 100644 index 0000000000..a452c24141 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/Add.composite @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/META-INF/sca-contribution.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..37e304ac4d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/test/java/calculator/AddTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/test/java/calculator/AddTestCase.java new file mode 100644 index 0000000000..b7baf9b64b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-add/src/test/java/calculator/AddTestCase.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 calculator; + +import static org.junit.Assert.assertEquals; + +import java.rmi.Naming; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This shows how to test the Calculator service component. + */ +public class AddTestCase { + + private static Node node; + private static AddService addService; + + @BeforeClass + public static void setUp() throws Exception { + addService = new AddServiceImpl(); + } + + @AfterClass + public static void tearDown() throws Exception { + + } + + @Test + public void testCalculator() throws Exception { + // Calculate + assertEquals(addService.add(3, 2), 5.0, 0.0); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/pom.xml new file mode 100644 index 0000000000..daa747bcf2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/pom.xml @@ -0,0 +1,74 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sample-domain-distributed-calculator + 2.0-SNAPSHOT + ../pom.xml + + sample-domain-distributed-calculator-contribution-calculator + Apache Tuscany SCA Sample Domain Distributed Calculator Contribution Calculator + + + + org.apache.tuscany.sca + tuscany-node-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-node-impl + 2.0-SNAPSHOT + test + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + org.apache.tuscany.sca + tuscany-binding-rmi-runtime + 2.0-SNAPSHOT + runtime + + + junit + junit + 4.8.1 + test + + + + + ${project.artifactId} + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/AddService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..c7e6383559 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/AddService.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The interface for the add service + */ +@Remotable +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..0bac3da45c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * The Calculator service interface. + */ +@Remotable +public interface CalculatorService extends Remote { + + double add(double n1, double n2) throws RemoteException; + + double subtract(double n1, double n2) throws RemoteException; + + double multiply(double n1, double n2) throws RemoteException; + + double divide(double n1, double n2) throws RemoteException; +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..389ecb5f82 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + // @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + // @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + // @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/DivideService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..835e4fda6d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/MultiplyService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..db568cc762 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/SubtractService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..30e4e6a56a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/resources/Calculator.composite b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..32b748d5ab --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/main/resources/Calculator.composite @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/AddServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..e9c635e3c8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/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-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..6cccf83fbb --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/contribution-calculator/src/test/java/calculator/CalculatorTestCase.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 calculator; + +import static org.junit.Assert.assertEquals; + +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase { + + private static Node node; + private static CalculatorService calculatorService; + + @BeforeClass + public static void setUp() throws Exception { + calculatorService = new CalculatorServiceImpl(); + ((CalculatorServiceImpl)calculatorService).setAddService(new AddServiceImpl()); + } + + @AfterClass + public static void tearDown() throws Exception { + + } + + @Test + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0, 0.0); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/pom.xml new file mode 100644 index 0000000000..3cb2db8c64 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/distributed-calculator/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sample-domain + 2.0-SNAPSHOT + ../pom.xml + + tuscany-sample-domain-distributed-calculator + pom + Apache Tuscany SCA Sample Domain Distributed Calculator + + + + default + + true + + + contribution-calculator + contribution-add + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/pom.xml new file mode 100644 index 0000000000..1e50881ff2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/domain/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + + tuscany-sample-domain + pom + Apache Tuscany SCA Sample Domain + + + + default + + true + + + distributed-calculator + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/pom.xml new file mode 100644 index 0000000000..cf996d32a8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/pom.xml @@ -0,0 +1,70 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../pom.xml + + sample-implementation-async-extension + Apache Tuscany SCA Sample Implementation Extension With Async + jar + + + + org.apache.tuscany.sca + tuscany-base-runtime-pom + 2.0-SNAPSHOT + pom + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-runtime-axis2 + 2.0-SNAPSHOT + + + + org.mortbay.jetty + jetty + 6.1.19 + + + + junit + junit + 4.8.1 + test + + + + + + ${project.artifactId} + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/Java.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/Java.java new file mode 100644 index 0000000000..6c9240005f --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/Java.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target( {TYPE, FIELD}) +@Retention(RUNTIME) +public @interface Java { + + Class value(); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDL.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDL.java new file mode 100644 index 0000000000..655770ec32 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDL.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target( {TYPE, FIELD}) +@Retention(RUNTIME) +public @interface WSDL { + + String value(); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDLReference.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDLReference.java new file mode 100644 index 0000000000..185383d3b3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/api/WSDLReference.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.api; + +import org.w3c.dom.Element; + +public interface WSDLReference { + + Element call(String op, Element e); + void callAsync(String op, Element e); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/EmbedUtil.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/EmbedUtil.java new file mode 100644 index 0000000000..0ccbcc9e36 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/EmbedUtil.java @@ -0,0 +1,311 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import java.net.URI; +import java.net.URL; +import java.util.Arrays; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +/** + * A few utility functions to help embed a Tuscany runtime, and a simple DSL + * to help assemble and run SCDL. + */ +public class EmbedUtil { + + /** + * A runtime embedder context, which conveniently initializes a Node factory + * and gets the various registries, factories and extension points we need. + */ + static class Context { + final NodeFactory nf; + final ExtensionPointRegistry epr; + final FactoryExtensionPoint fep; + final ContributionFactory cf; + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wif; + final URLArtifactProcessorExtensionPoint apep; + final ExtensibleURLArtifactProcessor aproc; + final ModelResolverExtensionPoint mrep; + final ProviderFactoryExtensionPoint pfep; + + Context(final NodeFactory nf) { + this.nf = nf; + epr = nf.getExtensionPointRegistry(); + fep = epr.getExtensionPoint(FactoryExtensionPoint.class); + cf = fep.getFactory(ContributionFactory.class); + af = fep.getFactory(AssemblyFactory.class); + jif = fep.getFactory(JavaInterfaceFactory.class); + wif = fep.getFactory(WSDLFactory.class); + apep = epr.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); + aproc = new ExtensibleURLArtifactProcessor(apep); + mrep = epr.getExtensionPoint(ModelResolverExtensionPoint.class); + pfep = epr.getExtensionPoint(ProviderFactoryExtensionPoint.class); + } + } + + static Context embedContext(NodeFactory nf) { + return new Context(nf); + } + + /** + * A mini DSL to help build and assemble contributions and SCDL composites. + */ + interface Builder { + T build(Context ec); + } + + static T build(final Builder builder, final Context ec) { + return builder.build(ec); + } + + /** + * Return a contribution builder. + */ + static Builder contrib(final String uri, final String loc, final Builder... artifacts) { + return new Builder() { + public Contribution build(final Context ec) { + final Contribution c = ec.cf.createContribution(); + c.setURI(uri); + c.setLocation(loc); + c.setModelResolver(new ExtensibleModelResolver(c, ec.mrep, ec.fep)); + for(Builder a: artifacts) + c.getArtifacts().add(a.build(ec)); + return c; + } + }; + } + + /** + * Return an artifact builder. + */ + static Builder artifact(final String uri, final Object model) { + return new Builder() { + public Artifact build(final Context ec) { + final Artifact a = ec.cf.createArtifact(); + a.setURI(uri); + a.setModel(model); + return a; + } + }; + } + + /** + * Return a composite builder. + */ + static Builder composite(final String ns, final String name, final Builder... components) { + return new Builder() { + public Composite build(final Context ec) { + final Composite compos = ec.af.createComposite(); + compos.setName(new QName(ns, name)); + for(final Builder c: components) + compos.getComponents().add(c.build(ec)); + return compos; + } + }; + } + + /** + * Return a component builder. + */ + static Builder component(final String name, final Builder impl, final Builder... references) { + return new Builder() { + public Component build(final Context ec) { + final Component c = ec.af.createComponent(); + c.setName(name); + c.setImplementation(impl.build(ec)); + for(Builder r: references) + c.getReferences().add(r.build(ec)); + return c; + } + }; + } + + /** + * Return an implementation builder. + */ + static Builder implementation(final Class clazz, final Builder... contracts) { + return new Builder() { + public SampleImplementation build(final Context ec) { + final SampleImplementation impl = ImplUtil.implementation(clazz.getName()); + impl.clazz = clazz; + impl.setUnresolved(false); + for(final Builder b: contracts) { + Contract c = b.build(ec); + if(c instanceof Service) + impl.getServices().add((Service)c); + else + impl.getReferences().add((Reference)c); + } + return impl; + } + }; + } + + /** + * Return a reference builder. + */ + static Builder reference(final String name, final Class c) { + return new Builder() { + public Reference build(final Context ec) { + try { + return ImplUtil.reference(name, c, ec.jif, ec.af); + } catch(InvalidInterfaceException e) { + throw new RuntimeException(e); + } + } + }; + } + + static Builder reference(final String name, final WSDLInterface c) { + return new Builder() { + public Reference build(final Context ec) { + return ImplUtil.reference(name, c, ec.wif, ec.af); + } + }; + } + + static Builder reference(final String name, final String target) { + return new Builder() { + public ComponentReference build(final Context ec) { + final ComponentReference r = ec.af.createComponentReference(); + r.setName(name); + final ComponentService s = ec.af.createComponentService(); + s.setUnresolved(true); + s.setName(target); + r.getTargets().add(s); + return r; + } + }; + } + + /** + * Return a service builder. + */ + static Builder service(final Class c) { + return new Builder() { + public Service build(final Context ec) { + try { + return ImplUtil.service(c, ec.jif, ec.af); + } catch(InvalidInterfaceException e) { + throw new RuntimeException(e); + } + } + }; + } + + static Builder service(final WSDLInterface c) { + return new Builder() { + public Service build(final Context ec) { + return ImplUtil.service(c, ec.wif, ec.af); + } + }; + } + + /** + * Return a WSDLInterface builder which loads a WSDL into a contribution. + */ + static Builder wsdli(final String uri, final String ns, final String name, final Contribution c) { + return new Builder() { + public WSDLInterface build(final Context ec) { + try { + final ProcessorContext ctx = new ProcessorContext(); + final WSDLDefinition wd = ec.aproc.read(null, new URI(uri), new URL(new URL(c.getLocation()), uri), ctx, WSDLDefinition.class); + c.getModelResolver().addModel(wd, ctx); + c.getModelResolver().resolveModel(WSDLDefinition.class, wd, ctx); + final WSDLObject pt = wd.getWSDLObject(PortType.class, new QName(ns, name)); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + final WSDLInterface nwi = ec.wif.createWSDLInterface(pt.getElement(), wd, c.getModelResolver(), null); + nwi.setWsdlDefinition(wd); + nwi.resetDataBinding(DOMDataBinding.NAME); + return nwi; + } catch(Exception e) { + throw new RuntimeException(e); + } + } + }; + } + + /** + * Return the extension point registry used by our nodes. + */ + static ExtensionPointRegistry extensionPoints(final Context ec) { + return ec.epr; + } + + /** + * Return the provider factory extension point used by our nodes. + */ + static ProviderFactoryExtensionPoint providerFactories(final Context ec) { + return ec.pfep; + } + + /** + * Add a deployable composite to a contribution. + */ + static Contribution deploy(final Contribution contrib, final Composite... comps) { + for(Composite c: comps) + contrib.getDeployables().add(c); + return contrib; + } + + /** + * Configure a node with a list of contributions. + */ + static Node node(final NodeFactory nf, final Contribution... contributions) { + return nf.createNode(Arrays.asList(contributions)); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/ImplUtil.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/ImplUtil.java new file mode 100644 index 0000000000..abd4cd7ab0 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/ImplUtil.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * Utility functions to help develop a component implementation extension. + */ +class ImplUtil { + + /** + * Return a Sample implementation with the given name. + */ + static SampleImplementation implementation(String name) { + final SampleImplementation impl = new SampleImplementation(name); + impl.setUnresolved(true); + return impl; + } + + /** + * Return the Java class configured on an annotation. + */ + static Class clazz(final Annotation a) { + return ((Java)a).value(); + } + + /** + * Return the WSDL QName configured on an annotation. + */ + static QName qname(final Annotation a) { + final String uri = ((WSDL)a).value(); + final int h = uri.indexOf('#'); + return new QName(uri.substring(0, h), uri.substring(h + 1)); + } + + /** + * Convert a Java class to an interface contract. + */ + static JavaInterfaceContract contract(final Class c, final JavaInterfaceFactory jif) throws InvalidInterfaceException { + final JavaInterfaceContract ic = jif.createJavaInterfaceContract(); + ic.setInterface(jif.createJavaInterface(c)); + return ic; + } + + /** + * Convert a WSDL interface to an interface contract. + */ + static WSDLInterfaceContract contract(final WSDLInterface wi, final WSDLFactory wf) { + final WSDLInterfaceContract ic = wf.createWSDLInterfaceContract(); + ic.setInterface(wi); + return ic; + } + + /** + * Convert a Java class to a service. + */ + static Service service(final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + Service s = af.createService(); + s.setName(c.getSimpleName()); + s.setInterfaceContract(contract(c, jif)); + return s; + } + + /** + * Convert a WSDL interface to a service. + */ + static Service service(final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + Service s = af.createService(); + s.setName(wi.getName().getLocalPart()); + s.setInterfaceContract(contract(wi, wf)); + return s; + } + + /** + * Convert a name and Java class to a reference. + */ + static Reference reference(final String name, final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(c, jif)); + return r; + } + + /** + * Convert a name and WSDL interface to a reference. + */ + static Reference reference(final String name, final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(wi, wf)); + return r; + } + + /** + * Convert a WSDL qname to a WSDL interface. + */ + static WSDLInterface interfaze(final QName name, final WSDLFactory wif) { + final WSDLInterface wir = wif.createWSDLInterface(); + wir.setUnresolved(true); + wir.setName(name); + return wir; + } + + /** + * Convert a WSDL qname to a WSDL definition. + */ + static WSDLDefinition definition(final QName name, final WSDLFactory wif) { + final WSDLDefinition wdr = wif.createWSDLDefinition(); + wdr.setUnresolved(true); + wdr.setNamespace(name.getNamespaceURI()); + wdr.setNameOfPortTypeToResolve(name); + return wdr; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementation.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementation.java new file mode 100644 index 0000000000..41ce71a732 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementation.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package sample.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * Model representing a Sample implementation in an SCA assembly. + * + * @version $Rev$ $Date$ + */ +public class SampleImplementation extends ImplementationImpl { + static final QName QN = new QName(SCA11_TUSCANY_NS, "implementation.sample"); + + final String name; + Class clazz; + + SampleImplementation(final String name) { + super(QN); + this.name = name; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementationProcessor.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementationProcessor.java new file mode 100644 index 0000000000..6017030d35 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleImplementationProcessor.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package sample.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static sample.impl.SampleImplementation.QN; +import static sample.impl.ImplUtil.clazz; +import static sample.impl.ImplUtil.definition; +import static sample.impl.ImplUtil.implementation; +import static sample.impl.ImplUtil.interfaze; +import static sample.impl.ImplUtil.qname; +import static sample.impl.ImplUtil.reference; +import static sample.impl.ImplUtil.service; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * StAX artifact processor for Sample implementations. + * + * @version $Rev$ $Date$ + */ +public class SampleImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wf; + + public SampleImplementationProcessor(final ExtensionPointRegistry ep) { + final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class); + this.af = fep.getFactory(AssemblyFactory.class); + this.jif = fep.getFactory(JavaInterfaceFactory.class); + this.wf = fep.getFactory(WSDLFactory.class); + } + + public QName getArtifactType() { + return QN; + } + + public Class getModelType() { + return SampleImplementation.class; + } + + public SampleImplementation read(final XMLStreamReader r, final ProcessorContext ctx) throws ContributionReadException, XMLStreamException { + // Read the component implementation element + final SampleImplementation impl = implementation(r.getAttributeValue(null, "class")); + while(r.hasNext() && !(r.next() == END_ELEMENT && QN.equals(r.getName()))) + ; + return impl; + } + + public void resolve(final SampleImplementation impl, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + try { + // Resolve and introspect the implementation class + impl.clazz = resolve(impl.name, res, ctx); + + for(final Annotation a: impl.clazz.getAnnotations()) { + if(a instanceof Java) + impl.getServices().add(service(clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getServices().add(service(resolve(qname(a), res, ctx, wf), wf, af)); + } + + for(Field f: impl.clazz.getDeclaredFields()) { + for(final Annotation a: f.getAnnotations()) { + if(a instanceof Java) + impl.getReferences().add(reference(f.getName(), clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getReferences().add(reference(f.getName(), resolve(qname(a), res, ctx, wf), wf, af)); + } + } + + impl.setUnresolved(false); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + public void write(final SampleImplementation impl, final XMLStreamWriter w, final ProcessorContext ctx) throws ContributionWriteException, XMLStreamException { + writeStart(w, QN.getNamespaceURI(), QN.getLocalPart(), new XAttr("class", impl.name)); + writeEnd(w); + } + + /** + * Resolve a Java class. + */ + static Class resolve(final String name, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + final ClassReference cr = res.resolveModel(ClassReference.class, new ClassReference(name), ctx); + if(cr.getJavaClass() != null) + return cr.getJavaClass(); + throw new ContributionResolveException(new ClassNotFoundException(name)); + } + + /** + * Resolve a WSDL interface. + */ + static WSDLInterface resolve(final QName name, final ModelResolver res, final ProcessorContext ctx, final WSDLFactory wif) throws ContributionResolveException { + final WSDLInterface wi = res.resolveModel(WSDLInterface.class, interfaze(name, wif), ctx); + if(!wi.isUnresolved()) + return domBound(wi); + + final WSDLDefinition wd = res.resolveModel(WSDLDefinition.class, definition(wi.getName(), wif), ctx); + if(wd.isUnresolved()) + throw new ContributionResolveException("Couldn't find " + name.getNamespaceURI()); + + WSDLObject pt = wd.getWSDLObject(PortType.class, name); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + try { + final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, res, ctx.getMonitor()); + nwi.setWsdlDefinition(wd); + res.addModel(nwi, ctx); + return domBound(nwi); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + /** + * Return a WSDL interface configured to use a DOM databinding. + */ + static WSDLInterface domBound(WSDLInterface wi) throws ContributionResolveException { + try { + final WSDLInterface domwi = (WSDLInterface)wi.clone(); + domwi.resetDataBinding(DOMDataBinding.NAME); + return domwi; + } catch(CloneNotSupportedException e) { + throw new ContributionResolveException(e); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleJavaInvoker.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleJavaInvoker.java new file mode 100644 index 0000000000..244251c4c9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleJavaInvoker.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for Sample components that implement a Java interface. + * + * @version $Rev$ $Date$ + */ +class SampleJavaInvoker implements Invoker { + final Object instance; + final Method method; + + SampleJavaInvoker(final JavaOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.instance = instance; + this.method = clazz.getMethod(op.getJavaMethod().getName(), op.getJavaMethod().getParameterTypes()); + } + + public Message invoke(final Message msg) { + try { + // Call the method that implements the operation + msg.setBody(method.invoke(instance, (Object[])msg.getBody())); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProvider.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProvider.java new file mode 100644 index 0000000000..5d946b037b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProvider.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import java.lang.reflect.Field; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation provider for Sample component implementations. + * + * @version $Rev$ $Date$ + */ +class SampleProvider implements ImplementationProvider { + final RuntimeComponent comp; + final SampleImplementation impl; + final ProxyFactory pxf; + Object instance; + + SampleProvider(final RuntimeComponent comp, final SampleImplementation impl, ProxyFactory pf) { + this.comp = comp; + this.impl = impl; + this.pxf = pf; + } + + public void start() { + // Construct implementation instance and inject reference proxies + try { + instance = impl.clazz.newInstance(); + + for(ComponentReference r: comp.getReferences()) { + final Field f = impl.clazz.getDeclaredField(r.getName()); + f.setAccessible(true); + // Inject a Java or WSDLReference proxy + final Interface i = r.getInterfaceContract().getInterface(); + if(i instanceof JavaInterface) + f.set(instance, pxf.createProxy(comp.getComponentContext().getServiceReference(f.getType(), r.getName()))); + else + f.set(instance, new SampleWSDLProxy(r.getEndpointReferences().get(0), i)); + } + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + public void stop() { + instance = null; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(final RuntimeComponentService s, final Operation op) { + try { + // Creating an invoker for a Java or WSDL-typed implementation + if(op instanceof JavaOperation) + return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance); + return new SampleWSDLInvoker((WSDLOperation)op, impl.clazz, instance); + } catch(Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProviderFactory.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProviderFactory.java new file mode 100644 index 0000000000..4ad24d33ff --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleProviderFactory.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory for Sample implementation providers. + * + * @version $Rev$ $Date$ + */ +public class SampleProviderFactory implements ImplementationProviderFactory { + final ProxyFactory pxf; + + public SampleProviderFactory(final ExtensionPointRegistry ep) { + pxf = ExtensibleProxyFactory.getInstance(ep); + } + + public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final SampleImplementation impl) { + return new SampleProvider(comp, impl, pxf); + } + + public Class getModelType() { + return SampleImplementation.class; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLInvoker.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLInvoker.java new file mode 100644 index 0000000000..6c5317274f --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLInvoker.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.w3c.dom.Element; + +/** + * Invoker for Sample components that implement a WSDL interface using a generic + * call method. + * + * @version $Rev$ $Date$ + */ +class SampleWSDLInvoker implements Invoker { + final String name; + final Object instance; + final Method method; + + SampleWSDLInvoker(final WSDLOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.name = op.getName(); + this.instance = instance; + this.method = clazz.getMethod("call", String.class, Element.class); + } + + public Message invoke(final Message msg) { + try { + // Invoke the generic call method + msg.setBody(method.invoke(instance, name, ((Object[])msg.getBody())[0])); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLProxy.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLProxy.java new file mode 100644 index 0000000000..0d000ae071 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sample/impl/SampleWSDLProxy.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 sample.impl; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.w3c.dom.Element; + +import sample.api.WSDLReference; + +/** + * Proxy used to call operations on WSDL references. + */ +class SampleWSDLProxy implements WSDLReference { + final RuntimeEndpointReference repr; + final Map ops; + + SampleWSDLProxy(EndpointReference epr, Interface wi) { + repr = (RuntimeEndpointReference)epr; + ops = new HashMap(); + for(Operation o: wi.getOperations()) + ops.put(o.getName(), o); + } + + @Override + public Element call(String op, Element e) { + try { + // Invoke the named operation on the endpoint reference + return (Element)repr.invoke(ops.get(op), new Object[] {e}); + } catch(InvocationTargetException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void callAsync(String op, Element e) { + return; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/ImplUtil.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/ImplUtil.java new file mode 100644 index 0000000000..c30c784d64 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/ImplUtil.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * Utility functions to help develop a component implementation extension. + */ +class ImplUtil { + + /** + * Return a Sample implementation with the given name. + */ + static SampleAsyncImplementation implementation(String name) { + final SampleAsyncImplementation impl = new SampleAsyncImplementation(name); + impl.setUnresolved(true); + return impl; + } + + /** + * Return the Java class configured on an annotation. + */ + static Class clazz(final Annotation a) { + return ((Java)a).value(); + } + + /** + * Return the WSDL QName configured on an annotation. + */ + static QName qname(final Annotation a) { + final String uri = ((WSDL)a).value(); + final int h = uri.indexOf('#'); + return new QName(uri.substring(0, h), uri.substring(h + 1)); + } + + /** + * Convert a Java class to an interface contract. + */ + static JavaInterfaceContract contract(final Class c, final JavaInterfaceFactory jif) throws InvalidInterfaceException { + final JavaInterfaceContract ic = jif.createJavaInterfaceContract(); + ic.setInterface(jif.createJavaInterface(c)); + return ic; + } + + /** + * Convert a WSDL interface to an interface contract. + */ + static WSDLInterfaceContract contract(final WSDLInterface wi, final WSDLFactory wf) { + final WSDLInterfaceContract ic = wf.createWSDLInterfaceContract(); + ic.setInterface(wi); + return ic; + } + + /** + * Convert a Java class to a service. + */ + static Service service(final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + Service s = af.createService(); + s.setName(c.getSimpleName()); + s.setInterfaceContract(contract(c, jif)); + return s; + } + + /** + * Convert a WSDL interface to a service. + */ + static Service service(final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + Service s = af.createService(); + s.setName(wi.getName().getLocalPart()); + s.setInterfaceContract(contract(wi, wf)); + return s; + } + + /** + * Convert a name and Java class to a reference. + */ + static Reference reference(final String name, final Class c, final JavaInterfaceFactory jif, final AssemblyFactory af) throws InvalidInterfaceException { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(c, jif)); + return r; + } + + /** + * Convert a name and WSDL interface to a reference. + */ + static Reference reference(final String name, final WSDLInterface wi, final WSDLFactory wf, final AssemblyFactory af) { + final Reference r = af.createReference(); + r.setName(name); + r.setInterfaceContract(contract(wi, wf)); + return r; + } + + /** + * Convert a WSDL qname to a WSDL interface. + */ + static WSDLInterface interfaze(final QName name, final WSDLFactory wif) { + final WSDLInterface wir = wif.createWSDLInterface(); + wir.setUnresolved(true); + wir.setName(name); + return wir; + } + + /** + * Convert a WSDL qname to a WSDL definition. + */ + static WSDLDefinition definition(final QName name, final WSDLFactory wif) { + final WSDLDefinition wdr = wif.createWSDLDefinition(); + wdr.setUnresolved(true); + wdr.setNamespace(name.getNamespaceURI()); + wdr.setNameOfPortTypeToResolve(name); + return wdr; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementation.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementation.java new file mode 100644 index 0000000000..e0abd72b84 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementation.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 sampleasync.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; + +/** + * Model representing a Sample implementation in an SCA assembly. + * + * @version $Rev$ $Date$ + */ +public class SampleAsyncImplementation extends ImplementationImpl { + static final QName QN = new QName(SCA11_TUSCANY_NS, "implementation.sampleasync"); + + final String name; + Class clazz; + + SampleAsyncImplementation(final String name) { + super(QN); + this.name = name; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementationProcessor.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementationProcessor.java new file mode 100644 index 0000000000..03fe3da178 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncImplementationProcessor.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package sampleasync.impl; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static sampleasync.impl.SampleAsyncImplementation.QN; +import static sampleasync.impl.ImplUtil.clazz; +import static sampleasync.impl.ImplUtil.definition; +import static sampleasync.impl.ImplUtil.implementation; +import static sampleasync.impl.ImplUtil.interfaze; +import static sampleasync.impl.ImplUtil.qname; +import static sampleasync.impl.ImplUtil.reference; +import static sampleasync.impl.ImplUtil.service; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; + +import sample.api.Java; +import sample.api.WSDL; + +/** + * StAX artifact processor for Sample implementations. + * + * @version $Rev$ $Date$ + */ +public class SampleAsyncImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + final AssemblyFactory af; + final JavaInterfaceFactory jif; + final WSDLFactory wf; + + public SampleAsyncImplementationProcessor(final ExtensionPointRegistry ep) { + final FactoryExtensionPoint fep = ep.getExtensionPoint(FactoryExtensionPoint.class); + this.af = fep.getFactory(AssemblyFactory.class); + this.jif = fep.getFactory(JavaInterfaceFactory.class); + this.wf = fep.getFactory(WSDLFactory.class); + } + + public QName getArtifactType() { + return QN; + } + + public Class getModelType() { + return SampleAsyncImplementation.class; + } + + public SampleAsyncImplementation read(final XMLStreamReader r, final ProcessorContext ctx) throws ContributionReadException, XMLStreamException { + // Read the component implementation element + final SampleAsyncImplementation impl = implementation(r.getAttributeValue(null, "class")); + while(r.hasNext() && !(r.next() == END_ELEMENT && QN.equals(r.getName()))) + ; + return impl; + } + + public void resolve(final SampleAsyncImplementation impl, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + try { + // Resolve and introspect the implementation class + impl.clazz = resolve(impl.name, res, ctx); + + for(final Annotation a: impl.clazz.getAnnotations()) { + if(a instanceof Java) + impl.getServices().add(service(clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getServices().add(service(resolve(qname(a), res, ctx, wf), wf, af)); + } + + for(Field f: impl.clazz.getDeclaredFields()) { + for(final Annotation a: f.getAnnotations()) { + if(a instanceof Java) + impl.getReferences().add(reference(f.getName(), clazz(a), jif, af)); + else if(a instanceof WSDL) + impl.getReferences().add(reference(f.getName(), resolve(qname(a), res, ctx, wf), wf, af)); + } + } + + impl.setUnresolved(false); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + public void write(final SampleAsyncImplementation impl, final XMLStreamWriter w, final ProcessorContext ctx) throws ContributionWriteException, XMLStreamException { + writeStart(w, QN.getNamespaceURI(), QN.getLocalPart(), new XAttr("class", impl.name)); + writeEnd(w); + } + + /** + * Resolve a Java class. + */ + static Class resolve(final String name, final ModelResolver res, final ProcessorContext ctx) throws ContributionResolveException { + final ClassReference cr = res.resolveModel(ClassReference.class, new ClassReference(name), ctx); + if(cr.getJavaClass() != null) + return cr.getJavaClass(); + throw new ContributionResolveException(new ClassNotFoundException(name)); + } + + /** + * Resolve a WSDL interface. + */ + static WSDLInterface resolve(final QName name, final ModelResolver res, final ProcessorContext ctx, final WSDLFactory wif) throws ContributionResolveException { + final WSDLInterface wi = res.resolveModel(WSDLInterface.class, interfaze(name, wif), ctx); + if(!wi.isUnresolved()) + return domBound(wi); + + final WSDLDefinition wd = res.resolveModel(WSDLDefinition.class, definition(wi.getName(), wif), ctx); + if(wd.isUnresolved()) + throw new ContributionResolveException("Couldn't find " + name.getNamespaceURI()); + + WSDLObject pt = wd.getWSDLObject(PortType.class, name); + if(pt == null) + throw new ContributionResolveException("Couldn't find " + name); + try { + final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, res, ctx.getMonitor()); + nwi.setWsdlDefinition(wd); + res.addModel(nwi, ctx); + return domBound(nwi); + } catch(InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + } + + /** + * Return a WSDL interface configured to use a DOM databinding. + */ + static WSDLInterface domBound(WSDLInterface wi) throws ContributionResolveException { + try { + final WSDLInterface domwi = (WSDLInterface)wi.clone(); + domwi.resetDataBinding(DOMDataBinding.NAME); + return domwi; + } catch(CloneNotSupportedException e) { + throw new ContributionResolveException(e); + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java new file mode 100644 index 0000000000..10eb78f6c8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProvider.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.InvokerAsyncRequest; +import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; +import org.apache.tuscany.sca.provider.ImplementationAsyncProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation provider for Sample component implementations. + * + * @version $Rev$ $Date$ + */ +class SampleAsyncProvider implements ImplementationAsyncProvider { + final RuntimeComponent comp; + final SampleAsyncImplementation impl; + final ProxyFactory pxf; + final ExtensionPointRegistry ep; + Object instance; + Map asyncMessageMap = new HashMap(); + + SampleAsyncProvider(final RuntimeComponent comp, final SampleAsyncImplementation impl, ProxyFactory pf, ExtensionPointRegistry ep) { + this.comp = comp; + this.impl = impl; + this.pxf = pf; + this.ep = ep; + } + + public void start() { + // Construct implementation instance and inject reference proxies + try { + instance = impl.clazz.newInstance(); + + for(ComponentReference r: comp.getReferences()) { + final Field f = impl.clazz.getDeclaredField(r.getName()); + f.setAccessible(true); + // Inject a Java or WSDLReference proxy + final Interface i = r.getInterfaceContract().getInterface(); + if(i instanceof JavaInterface) + f.set(instance, pxf.createProxy(comp.getComponentContext().getServiceReference(f.getType(), r.getName()))); + else + f.set(instance, new SampleWSDLProxy(asyncMessageMap, r.getEndpointReferences().get(0), i, ep)); + } + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + public void stop() { + instance = null; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public Invoker createInvoker(final RuntimeComponentService s, final Operation op) { + return (Invoker)createAsyncInvoker(s, op); + } + + public InvokerAsyncRequest createAsyncInvoker(final RuntimeComponentService s, final Operation op) { + try { + // Creating an invoker for a Java or WSDL-typed implementation + if(op instanceof JavaOperation) + return new SampleJavaInvoker((JavaOperation)op, impl.clazz, instance); + return new SampleWSDLInvoker((WSDLOperation)op, impl.clazz, instance); + } catch(Exception e) { + throw new RuntimeException(e); + } + } + + public InvokerAsyncResponse createAsyncResponseInvoker(Operation operation) { + return new SampleAsyncResponseInvoker(asyncMessageMap, operation, impl.clazz, instance); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProviderFactory.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProviderFactory.java new file mode 100644 index 0000000000..2170313eec --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncProviderFactory.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 sampleasync.impl; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory for Sample implementation providers. + * + * @version $Rev$ $Date$ + */ +public class SampleAsyncProviderFactory implements ImplementationProviderFactory { + final ProxyFactory pxf; + final ExtensionPointRegistry ep; + + public SampleAsyncProviderFactory(final ExtensionPointRegistry ep) { + this.ep = ep; + pxf = ExtensibleProxyFactory.getInstance(ep); + } + + public ImplementationProvider createImplementationProvider(final RuntimeComponent comp, final SampleAsyncImplementation impl) { + return new SampleAsyncProvider(comp, impl, pxf, ep); + } + + public Class getModelType() { + return SampleAsyncImplementation.class; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.java new file mode 100644 index 0000000000..2a7ad3f5bc --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleAsyncResponseInvoker.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 sampleasync.impl; + +import java.lang.reflect.Method; +import java.util.Map; + +import org.apache.tuscany.sca.core.invocation.Constants; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; +import org.apache.tuscany.sca.invocation.Message; +import org.w3c.dom.Element; + +/** + * Invoker for Sample components that implement a WSDL interface using a generic + * call method. + * + * @version $Rev$ $Date$ + */ +class SampleAsyncResponseInvoker implements InvokerAsyncResponse { + final String name; + final Object instance; + final Operation op; + Map asyncMessageMap; + + SampleAsyncResponseInvoker(Map asyncMessageMap, final Operation op, final Class clazz, final Object instance) { + this.asyncMessageMap = asyncMessageMap; + this.name = op.getName(); + this.instance = instance; + this.op = op; + } + + public void invokeAsyncResponse(final Message msg) { + try { + String messageID = (String) msg.getHeaders().get(Constants.MESSAGE_ID); + String forwardOpName = (String)asyncMessageMap.get(messageID); + + // process the async response + //Object response = ((Object[])msg.getBody())[0]; + Object response = msg.getBody(); + + Method method = instance.getClass().getMethod(forwardOpName + "Callback", Element.class); + method.invoke(instance, response); + } catch(Exception e) { + e.printStackTrace(); + // TODO - need to throw this to somewhere? + } + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleJavaInvoker.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleJavaInvoker.java new file mode 100644 index 0000000000..063fe166eb --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleJavaInvoker.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.InvokerAsyncRequest; +import org.apache.tuscany.sca.invocation.InvokerAsyncResponse; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Invoker for Sample components that implement a Java interface. + * + * @version $Rev$ $Date$ + */ +class SampleJavaInvoker implements Invoker, InvokerAsyncRequest { + final Object instance; + final Method method; + + SampleJavaInvoker(final JavaOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.instance = instance; + this.method = clazz.getMethod(op.getJavaMethod().getName(), op.getJavaMethod().getParameterTypes()); + } + + public Message invoke(final Message msg) { + return processRequest(msg); + } + + public void invokeAsyncRequest(Message msg) { + processRequest(msg); + // TODO - need to do something about exceptions + } + + public Message processRequest(Message msg) { + try { + // Call the method that implements the operation + msg.setBody(method.invoke(instance, (Object[])msg.getBody())); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java new file mode 100644 index 0000000000..26412ab281 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLInvoker.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.w3c.dom.Element; + +/** + * Invoker for Sample components that implement a WSDL interface using a generic + * call method. + * + * @version $Rev$ $Date$ + */ +class SampleWSDLInvoker extends InterceptorAsyncImpl { + final String name; + final Object instance; + final Method method; + + SampleWSDLInvoker(final WSDLOperation op, final Class clazz, final Object instance) throws SecurityException, NoSuchMethodException { + this.name = op.getName(); + this.instance = instance; + this.method = clazz.getMethod("call", String.class, Element.class); + } + + public Invoker getNext() { + // Can't get next for an implementation invoker + return null; + } + + public Message invoke(final Message msg) { + return processRequest(msg); + } + + public void invokeAsyncRequest(Message msg) { + Message responseMsg = processRequest(msg); + + // in this sample programming model we make the async + // response from the implementation provider. The + // component implementation itself doesn't get a chance to + // do async responses. + + // At this point we could serialize the ??? and pick it up again + // later to send the async response + + ((RuntimeEndpoint)msg.getTo()).invokeAsyncResponse(responseMsg); + } + + public Message processRequest(Message msg) { + try { + //AsyncHeader asyncHeader = (String) message.getHeaders().get("ASYNC-HEADER"); + // Invoke the generic call method + Object response = method.invoke(instance, name, ((Object[])msg.getBody())[0]); + msg.setBody(response); + } catch(Exception e) { + e.printStackTrace(); + msg.setFaultBody(e.getCause()); + } + return msg; + } + + public Message processResponse(Message msg) { + return msg; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java new file mode 100644 index 0000000000..a02132ac9e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/java/sampleasync/impl/SampleWSDLProxy.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.invocation.Constants; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; +import org.w3c.dom.Element; + +import sample.api.WSDLReference; + +/** + * Proxy used to call operations on WSDL references. + */ +class SampleWSDLProxy implements WSDLReference { + final RuntimeEndpointReference repr; + final Map ops; + final ExtensionPointRegistry ep; + final MessageFactory mf; + Map asyncMessageMap; + + SampleWSDLProxy(Map asyncMessageMap, EndpointReference epr, Interface wi, ExtensionPointRegistry ep) { + this.asyncMessageMap = asyncMessageMap; + this.ep = ep; + mf = ep.getExtensionPoint(MessageFactory.class); + + repr = (RuntimeEndpointReference)epr; + ops = new HashMap(); + for(Operation o: wi.getOperations()) + ops.put(o.getName(), o); + } + + @Override + public Element call(String op, Element e) { + try { + // Invoke the named operation on the endpoint reference + return (Element)repr.invoke(ops.get(op), new Object[] {e}); + } catch(InvocationTargetException ex) { + throw new RuntimeException(ex); + } + } + + @Override + public void callAsync(String op, Element e) { + // Asynchronously invoke the named operation on the endpoint reference + Message message = mf.createMessage(); + message.setBody(new Object[]{e}); + + // We could MESSAGE_ID here if required. If not the infrastructure + // will generate a UUID + String messageID = "myuniqueid"; + message.getHeaders().put(Constants.MESSAGE_ID, messageID); + + // save the message id ready for when we process the response + asyncMessageMap.put(messageID, op); + + // We could add implementation specific headers here if required + //message.getHeaders().put(Constants.???, ???); + + try { + repr.invokeAsync(ops.get(op), message); + } catch (Throwable ex) { + ex.printStackTrace(); + } + + // if we don't provide a message id we can get the one the + // infrastructure generates + //String messageID = (String) message.getHeaders().get(Constants.MESSAGE_ID); + //asyncMessageMap.put(messageID, op); + + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..00d0306d92 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -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. + +# Implementation class for the artifact processor extension +sample.impl.SampleImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.sample,model=sample.impl.SampleImplementation +sampleasync.impl.SampleAsyncImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#implementation.sampleasync,model=sampleasync.impl.SampleAsyncImplementation + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..42e61c9d89 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +sample/impl/sample.xsd +sampleasync/impl/sampleasync.xsd diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..4eeecb7ba2 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -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. + +# Implementation provider for Sample components +sample.impl.SampleProviderFactory;model=sample.impl.SampleImplementation +sampleasync.impl.SampleAsyncProviderFactory;model=sampleasync.impl.SampleAsyncImplementation + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sample/impl/sample.xsd b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sample/impl/sample.xsd new file mode 100644 index 0000000000..c057aef1c1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sample/impl/sample.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/definitions.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/definitions.xml new file mode 100644 index 0000000000..96a1a6f574 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/definitions.xml @@ -0,0 +1,30 @@ + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/sampleasync.xsd b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/sampleasync.xsd new file mode 100644 index 0000000000..ff70fd6020 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/main/resources/sampleasync/impl/sampleasync.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Client.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Client.java new file mode 100644 index 0000000000..1b7e11c786 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Client.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Client { + + String jello(String s); + + String wello(String s); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/ClientTest.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/ClientTest.java new file mode 100644 index 0000000000..92291c98a1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/ClientTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.elems; +import static sample.Xutil.print; +import static sample.Xutil.select; +import static sample.Xutil.text; +import static sample.Xutil.xdom; +import static sample.Xutil.xfilter; +import static sample.Xutil.xreduce; + +import org.w3c.dom.Element; + +import sample.api.Java; +import sample.api.WSDL; +import sample.api.WSDLReference; + +/** + * Sample component implementation that uses a mix of Java and WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Client.class) +public class ClientTest { + + @Java(Hello.class) + Hello jello; + + @WSDL("http://sample/hello#Hello") + WSDLReference wello; + + public String jello(String s) { + out.println("ClientTest.jello(" + s + ")"); + return jello.hello(s); + } + + public String wello(String s) { + out.println("ClientTest.wello(" + s + ")"); + final Element hreq = xdom("http://sample/hello", "hello", elem("name", text(s))); + + final Element hres = wello.call("hello", hreq); + + return xreduce(print, "", xfilter(select("result"), elems(hres))); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Hello.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Hello.java new file mode 100644 index 0000000000..247fc8aa78 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Hello.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Hello { + + String hello(String s); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/JelloTest.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/JelloTest.java new file mode 100644 index 0000000000..5c999a6c80 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/JelloTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import static java.lang.System.out; +import sample.api.Java; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Hello.class) +public class JelloTest { + + @Java(Upper.class) + Upper upper; + + public String hello(String s) { + out.println("JelloTest.hello(" + s + ")"); + return upper.upper("Hello " + s); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Upper.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Upper.java new file mode 100644 index 0000000000..9c772b3487 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Upper.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Upper { + + String upper(String s); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/UpperTest.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/UpperTest.java new file mode 100644 index 0000000000..5399e4410d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/UpperTest.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import static java.lang.System.out; +import sample.api.Java; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Upper.class) +public class UpperTest { + + public String upper(String s) { + out.println("UpperTest.upper(" + s + ")"); + return s.toUpperCase(); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/WelloTest.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/WelloTest.java new file mode 100644 index 0000000000..1bb9fc11ce --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/WelloTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.elems; +import static sample.Xutil.print; +import static sample.Xutil.select; +import static sample.Xutil.text; +import static sample.Xutil.xdom; +import static sample.Xutil.xfilter; +import static sample.Xutil.xml; +import static sample.Xutil.xreduce; + +import org.w3c.dom.Element; + +import sample.api.WSDL; +import sample.api.WSDLReference; + +/** + * Sample component implementation that uses WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +@WSDL("http://sample/hello#Hello") +public class WelloTest { + + @WSDL("http://sample/upper#Upper") + WSDLReference upper; + + public Element call(String op, Element e) { + out.println("WelloTest." + op + "(" + xml(e) + ")"); + final String name = xreduce(print, "", xfilter(select("name"), elems(e))); + + final Element ureq = xdom("http://sample/upper", "upper", elem("s", text("Hello " + name))); + final Element ures = upper.call("upper", ureq); + + final String s = xreduce(print, "", xfilter(select("result"), elems(ures))); + return xdom("http://sample/hello", "helloResponse", elem("result", text(s))); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Xutil.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Xutil.java new file mode 100644 index 0000000000..264ce7fc85 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/Xutil.java @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample; + +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Just for fun, a little bit of magic code and utility functions to help work with XML DOM. + */ +public class Xutil { + public interface NodeBuilder { + Node build(Document doc); + } + + /** + * Convert a name and a list of children to a document element. + */ + public static Element xdom(String ns, String name, final NodeBuilder... nodes) { + return (Element)elem(ns, name, nodes).build(db.newDocument()); + } + + /** + * Convert a name and children to an element. + */ + public static NodeBuilder elem(final String uri, final String n, final NodeBuilder... nodes) { + return new NodeBuilder() { + public Node build(Document doc) { + final Element e = doc.createElementNS(uri, n); + for(final NodeBuilder n: nodes) + e.appendChild(n.build(doc)); + return e; + } + }; + } + + public static NodeBuilder elem(final String n, final NodeBuilder... nodes) { + return elem(null, n, nodes); + } + + /** + * Convert a string to a text element. + */ + public static NodeBuilder text(final String t) { + return new NodeBuilder() { + public Node build(final Document doc) { + return doc.createTextNode(t); + } + }; + } + + private final static DocumentBuilder db = db(); + + private static DocumentBuilder db() { + try { + return DocumentBuilderFactory.newInstance().newDocumentBuilder(); + } catch(ParserConfigurationException e) { + throw new RuntimeException(e); + } + } + + /** + * Convert an element to XML. + */ + static TransformerFactory trf = TransformerFactory.newInstance(); + + public static String xml(final Node node) { + try { + final StreamResult r = new StreamResult(new StringWriter()); + trf.newTransformer().transform(new DOMSource(node), r); + return r.getWriter().toString(); + } catch(TransformerException e) { + throw new RuntimeException(e); + } + } + + /** + * Evaluate an xpath expression. + */ + private static XPathFactory xpf = XPathFactory.newInstance(); + + public static String xpath(final String expr, final Node node) { + final XPath xp = xpf.newXPath(); + try { + return (String)xp.evaluate(expr, node, XPathConstants.STRING); + } catch(XPathExpressionException e) { + throw new RuntimeException(e); + } + } + + /** + * A pure Java FP-style alternative to xpath for DOM. + */ + interface Mapper { + T map(final Element e); + } + + static Mapper identity = new Mapper() { + public Element map(Element e) { + return e; + }; + }; + + interface Reducer { + T reduce(final T accum, final Element e); + } + + public static Reducer print = new Reducer() { + public String reduce(String accum, Element e) { + return accum + e.getTextContent(); + } + }; + + /** + * Apply a mapper to a list of elements. + */ + public static List xmap(final Mapper f, final Iterable l) { + final List v = new ArrayList(); + for(Element e: l) + v.add(f.map(e)); + return v; + } + + /** + * Apply a filter to a list of elements. + */ + public static List xfilter(final Mapper f, final Iterable l) { + final List v = new ArrayList(); + for(Element e: l) + if(f.map(e)) + v.add(e); + return v; + } + + /** + * Perform a reduction over a list of elements. + */ + public static T xreduce(final Reducer f, final T initial, final Iterable l) { + T accum = initial; + for(Element e: l) + accum = f.reduce(accum, e); + return accum; + } + + /** + * Return a filter that selects elements by name. + */ + public static Mapper select(final String name) { + return new Mapper() { + public Boolean map(Element e) { + return name.equals(e.getLocalName()); + } + }; + } + + /** + * Return the child elements of a node. + */ + public static Iterable elems(final Node parent) { + final List l = new ArrayList(); + for (Node n: children(parent)) + if (n instanceof Element) + l.add((Element)n); + return l; + } + + /** + * An iterable over the children of a node. + */ + private static Iterable children(Node parent) { + final NodeList l = parent.getChildNodes(); + final int n = l.getLength(); + return new Iterable() { + public Iterator iterator() { + return new Iterator() { + int i = 0; + public boolean hasNext() { + return i < n; + } + public Node next() { + return l.item(i++); + } + public void remove() { + } + }; + } + }; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/EmbedTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/EmbedTestCase.java new file mode 100644 index 0000000000..292aa9c8f7 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/EmbedTestCase.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.EmbedUtil.build; +import static sample.impl.EmbedUtil.component; +import static sample.impl.EmbedUtil.composite; +import static sample.impl.EmbedUtil.contrib; +import static sample.impl.EmbedUtil.deploy; +import static sample.impl.EmbedUtil.embedContext; +import static sample.impl.EmbedUtil.extensionPoints; +import static sample.impl.EmbedUtil.implementation; +import static sample.impl.EmbedUtil.node; +import static sample.impl.EmbedUtil.providerFactories; +import static sample.impl.EmbedUtil.reference; +import static sample.impl.EmbedUtil.service; +import static sample.impl.EmbedUtil.wsdli; +import static sample.impl.TestUtil.here; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import sample.Client; +import sample.ClientTest; +import sample.Hello; +import sample.JelloTest; +import sample.Upper; +import sample.UpperTest; +import sample.WelloTest; + +/** + * Test how to assemble a contribution, a SCDL composite and run it on an embedded + * Tuscany runtime node. Also shows how pass in a ProviderFactory instead of having + * it loaded and constructed by the runtime node. + * + * @version $Rev$ $Date$ + */ +@Ignore +public class EmbedTestCase { + static NodeFactory nf; + static EmbedUtil.Context ec; + static Node node; + + @SuppressWarnings("unchecked") + @BeforeClass + public static void setUp() throws Exception { + nf = NodeFactory.newInstance(); + ec = embedContext(nf); + + // Load the test WSDL definitions (could also construct the WSDL + // and XSD models in code but that'd be quite painful, so just + // load them from XML for now) + final Contribution contrib = build(contrib("test", here()), ec); + WSDLInterface Hello_wsdl = build(wsdli("Hello.wsdl", "http://sample/hello", "Hello", contrib), ec); + WSDLInterface Upper_wsdl = build(wsdli("Upper.wsdl", "http://sample/upper", "Upper", contrib), ec); + + // Assemble a test composite model (see EmbedUtil + // for the little DSL used here, much more concise + // than using the assembly model interfaces) + final Composite comp = + build(composite("http://sample", "test", + component("client-test", + implementation(ClientTest.class, + service(Client.class), + reference("jello", Hello.class), + reference("wello", Hello_wsdl)), + reference("jello", "jello-test"), + reference("wello", "wello-test")), + component("wello-test", + implementation(WelloTest.class, + service(Hello_wsdl), + reference("upper", Upper_wsdl)), + reference("upper", "upper-test")), + component("jello-test", + implementation(JelloTest.class, + service(Hello.class), + reference("upper", Upper.class)), + reference("upper", "upper-test")), + component("upper-test", + implementation(UpperTest.class, + service(Upper.class)))), ec); + + // Register a test instance of our sample implementation ProviderFactory + providerFactories(ec).addProviderFactory(testProviderFactory()); + + // Run with it + node = node(nf, deploy(contrib, comp)); + node.start(); + } + + static ProviderFactory testProviderFactory() { + // This shows how to get called when a provider is created + return new SampleProviderFactory(extensionPoints(ec)) { + public ImplementationProvider createImplementationProvider(RuntimeComponent comp, SampleImplementation impl) { + out.println("Creating a provider for component " + comp.getName()); + return super.createImplementationProvider(comp, impl); + }}; + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void jello() { + out.println("RunTestCase.jello"); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); + } + + @Test + public void wello() { + out.println("RunTestCase.wello"); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); + } + + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/ReadWriteTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/ReadWriteTestCase.java new file mode 100644 index 0000000000..115ceff069 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/ReadWriteTestCase.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static sample.impl.TestUtil.here; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test read/write Sample SCDL implementation elements. + * + * @version $Rev$ $Date$ + */ +@Ignore +public class ReadWriteTestCase { + static XMLInputFactory xif; + static XMLOutputFactory xof; + static StAXArtifactProcessor xproc; + static ProcessorContext ctx; + + @BeforeClass + public static void setUp() throws Exception { + final DefaultExtensionPointRegistry ep = new DefaultExtensionPointRegistry(); + final Contribution contrib = new DefaultContributionFactory().createContribution(); + contrib.setLocation(here()); + ctx = new ProcessorContext(contrib, null); + xif = XMLInputFactory.newInstance(); + xof = XMLOutputFactory.newInstance(); + final StAXArtifactProcessorExtensionPoint xpep = new DefaultStAXArtifactProcessorExtensionPoint(ep); + xproc = new ExtensibleStAXArtifactProcessor(xpep, xif, xof); + } + + @Test + public void testRead() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + assertNotNull(c); + assertEquals("sample.ClientTest", ((SampleImplementation)c.getComponents().get(0).getImplementation()).name); + } + + @Test + public void testReadWrite() throws Exception { + final InputStream is = getClass().getClassLoader().getResourceAsStream("test.composite"); + final Composite c = (Composite)xproc.read(xif.createXMLStreamReader(is), ctx); + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + xproc.write(c, xof.createXMLStreamWriter(bos), ctx); + assertTrue(bos.toString().contains("class=\"sample.WelloTest\"")); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunTestCase.java new file mode 100644 index 0000000000..38cc558c14 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunTestCase.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 sample.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertEquals; +import static sample.impl.TestUtil.here; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import sample.Client; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +@Ignore +public class RunTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode(new Contribution("test", here())); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void jello() { + out.println("RunTestCase.jello"); + final String r = client().jello("Java"); + out.println(r); + assertEquals("HELLO JAVA", r); + } + + @Test + public void wello() { + out.println("RunTestCase.wello"); + final String r = client().wello("WSDL"); + out.println(r); + assertEquals("HELLO WSDL", r); + } + + static Client client() { + return node.getService(Client.class, "client-test/Client"); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunWSTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunWSTestCase.java new file mode 100644 index 0000000000..9eef998655 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/RunWSTestCase.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +import static java.lang.System.out; +import static org.junit.Assert.assertTrue; +import static sample.impl.TestUtil.here; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.Socket; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.http.jetty.JettyServer; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test a component that provides and consumes SOAP Web services. + * + * @version $Rev$ $Date$ + */ +@Ignore +public class RunWSTestCase { + static Node node; + static JettyServer jetty; + + @BeforeClass + public static void setUp() throws Exception { + // Start test composite on a Tuscany node + final NodeFactory nf = NodeFactory.newInstance(); + node = nf.createNode(new Contribution("test", here())); + node.start(); + + // Mock up a test Web service on http://localhost:8086/wsupper + jetty = new JettyServer((ExtensionPointRegistry)nf.getExtensionPointRegistry()); + jetty.start(); + jetty.addServletMapping("http://localhost:8086/wsupper", new HttpServlet() { + private static final long serialVersionUID = 1L; + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + assertTrue(read(req.getInputStream()).contains("Hello SOAP")); + final String soapresp = + "" + + "" + + "HELLO SOAP" + + ""; + + write(soapresp, resp.getOutputStream()); + } + }); + } + + @AfterClass + public static void tearDown() throws Exception { + jetty.stop(); + node.stop(); + } + + @Test + public void wsello() throws Exception { + out.println("RunWSTestCase.wsello"); + // Send a SOAP request to the Web service provided by SCA component wsello-test + // on http://localhost:8085/wsello + final Socket s = new Socket("localhost", 8085); + final String soapreq = + "POST /wsello HTTP/1.0\r\n" + + "Content-Type: text/xml; charset=UTF-8\r\n" + + "Content-length: 231\r\n\r\n" + + "" + + "" + + "SOAP" + + ""; + write(soapreq, s.getOutputStream()); + assertTrue(read(s.getInputStream()).contains("HELLO SOAP")); + } + + static void write(final String s, final OutputStream o) throws IOException { + final OutputStreamWriter w = new OutputStreamWriter(o); + w.write(s); + w.flush(); + } + + static String read(final InputStream i) throws IOException { + return read(new BufferedReader(new InputStreamReader(i))); + } + + static String read(final BufferedReader r) throws IOException { + final String s = r.readLine(); + return s == null? "" : s + read(r); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/TestUtil.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/TestUtil.java new file mode 100644 index 0000000000..6dcfb33912 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sample/impl/TestUtil.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sample.impl; + +/** + * A hack to determine the test contribution location. + */ +public class TestUtil { + + static String here() { + return TestUtil.class.getProtectionDomain().getCodeSource().getLocation().toString(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java new file mode 100644 index 0000000000..0c29cea1dc --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Upper { + + String upper(String s); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java new file mode 100644 index 0000000000..ad2e62f85d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.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 sampleasync; + +import java.util.concurrent.Future; + +import javax.xml.ws.AsyncHandler; +import javax.xml.ws.Response; + +import org.oasisopen.sca.annotation.AsyncInvocation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +@AsyncInvocation +public interface UpperAsyncReference { + + // Sync + String upper(String s); + + // Aysnc Poll + public Response upperAsync(String s); + + // Async Callback + public Future upperAsync(String s, AsyncHandler handler); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java new file mode 100644 index 0000000000..cb4a1c0b42 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.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 sampleasync; + +import org.oasisopen.sca.ResponseDispatch; +import org.oasisopen.sca.annotation.AsyncInvocation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +@AsyncInvocation +public interface UpperAsyncService { + + void upperAsync(String s,ResponseDispatch response); +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java new file mode 100644 index 0000000000..36fdb76424 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleGenericAsyncTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sampleasync.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleGenericAsyncTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleGenericAsyncTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + node = nf.createNode(new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testReference() { + System.out.println("SampleAsyncReferenceTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java new file mode 100644 index 0000000000..bc35a637d1 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleNativeAsyncTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sampleasync.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleNativeAsyncTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleNativeAsyncTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + node = nf.createNode(new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testReference() { + System.out.println("SampleNaiveAsyncTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleNativeAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java new file mode 100644 index 0000000000..9cf7ff9883 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.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 sampleasync.impl; + +import static java.lang.System.out; + +import java.util.concurrent.ExecutionException; + +import javax.xml.ws.Response; + +import org.oasisopen.sca.annotation.Reference; + +import sampleasync.Upper; +import sampleasync.UpperAsyncReference; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +public class UpperJavaAsyncReferenceImpl implements Upper { + + @Reference + UpperAsyncReference upper; + + public String upper(String s) { + out.println("UpperAsyncReferenceImpl.upper(" + s + ")"); + + // async poll + Response response = upper.upperAsync(s); + + while (!response.isDone()){ + System.out.println("Waiting for poll"); + try { + Thread.sleep(500); + } catch (Exception ex) { + // do nothing + } + } + + String result = null; + + try { + result = response.get(); + System.out.println("Async client poll patern: result = " + result); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java new file mode 100644 index 0000000000..fb9ad065ad --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.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 sampleasync.impl; + +import static java.lang.System.out; + +import org.oasisopen.sca.ResponseDispatch; + +import sampleasync.UpperAsyncService; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +public class UpperJavaAsyncServiceImpl implements UpperAsyncService { + + public void upperAsync(String s,ResponseDispatch response) { + out.println("UpperJavaAsyncServiceImpl.upperAsync(" + s + ")"); + response.sendResponse(s.toUpperCase()); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java new file mode 100644 index 0000000000..101c6a4399 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.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 sampleasync.impl; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.text; +import static sample.Xutil.xdom; + +import org.w3c.dom.Element; + +import sample.api.Java; +import sample.api.WSDL; +import sample.api.WSDLReference; +import sampleasync.Upper; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Upper.class) +public class UpperSampleAsyncReferenceImpl { + + @WSDL("http://sample/upper#Upper") + WSDLReference upper; + Element response; + + public String upper(String s) { + out.println("UpperSampleAsyncReferenceImpl.upper(" + s + ")"); + + // TODO - I'm passing in the non-wrapped version of the parameter + // here which doesn't seem right. If I pass in the wrapped + // version then the databinding won't unwrap on the reference + // side as it thinks the target Java interface is bare? + final Element ureq = xdom("http://sample/upper", "s", text(s)); + upper.callAsync("upper", ureq); + + try { + Thread.sleep(500); + } catch (Exception ex) { + // do nothing + } + + return response.getTextContent(); + } + + /** + * In this implementation the convention is that the + * async callback arrives at an operation named + * operationName + Callback + */ + public void upperCallback(Element response) { + out.println("UpperSampleAsyncReferenceImpl.upperCallback(" + response.getTextContent() + ")"); + this.response = response; + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java new file mode 100644 index 0000000000..41a85e44a0 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.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 sampleasync.impl; + +import static java.lang.System.out; +import static sample.Xutil.elem; +import static sample.Xutil.text; +import static sample.Xutil.xdom; + +import org.w3c.dom.Element; + +import sample.api.WSDL; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@WSDL("http://sample/upper#Upper") +public class UpperSampleAsyncServiceImpl { + + public Element call(String op, Element e) { + String input = e.getTextContent(); + out.println("UpperSampleAsyncServiceImpl.upper(" + input + ")"); + String output = input.toUpperCase(); + return xdom("http://sample/upper", "upperResponse", elem("result", text(output))); + } +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Hello.wsdl b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Hello.wsdl new file mode 100644 index 0000000000..360cea5ff3 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Hello.wsdl @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Upper.wsdl b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Upper.wsdl new file mode 100644 index 0000000000..dc236073ca --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/Upper.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/test.composite.off b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/test.composite.off new file mode 100644 index 0000000000..1f5b98c00b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/test.composite.off @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testgenericasync.composite b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testgenericasync.composite new file mode 100644 index 0000000000..c289a1ab32 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testgenericasync.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testnativeasync.composite b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testnativeasync.composite new file mode 100644 index 0000000000..f9c077e272 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/implementation-sample-async/src/test/resources/testnativeasync.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/pom.xml new file mode 100644 index 0000000000..fb4bd349fb --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../pom.xml + + + org.apache.tuscany.sca + sample-jsonp-webapp + war + 1.0 + jsonp-webapp + + + + org.apache.tuscany.sca + tuscany-base-runtime-nodep + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-jsonp-runtime + 2.0-SNAPSHOT + jar + + + + + jsonp-webapp + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/Location.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/Location.java new file mode 100644 index 0000000000..1a47edf73c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/Location.java @@ -0,0 +1,33 @@ +package sample; + +public class Location { + + private String city; + private String country; + private int altitude; + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public int getAltitude() { + return altitude; + } + + public void setAltitude(int altitude) { + this.altitude = altitude; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareService.java new file mode 100644 index 0000000000..3c79c6c2e9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareService.java @@ -0,0 +1,14 @@ +package sample; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface ShareService { + + String shareName(String firstName, String lastName); + + int shareAge(int age); + + Location shareLocation(Location location); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareServiceImpl.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareServiceImpl.java new file mode 100644 index 0000000000..13bae36eb9 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/java/sample/ShareServiceImpl.java @@ -0,0 +1,23 @@ +package sample; + +import org.oasisopen.sca.annotation.Service; + +@Service(ShareService.class) +public class ShareServiceImpl implements ShareService { + + @Override + public String shareName(String firstName, String lastName) { + return firstName + " " + lastName; + } + + @Override + public int shareAge(int age) { + return age; + } + + @Override + public Location shareLocation(Location location) { + return location; + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..58630c02ef --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.composite b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.composite new file mode 100644 index 0000000000..515c2dba09 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..0deec29fcc --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + + Apache Tuscany JSONP Sample + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + true + + + tuscany + /* + + + index.html + + \ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/index.html b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/index.html new file mode 100644 index 0000000000..2a754e494e --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/jsonp-webapp/src/main/webapp/index.html @@ -0,0 +1,104 @@ + + + + Apache Tuscany Comet Sample + + + + + +

Apache Tuscany JSONP Sample

+

Share Personal Information Webapp

+ +
+ + + + + + + + +
First Name +
Last Name +
+ + +
+ +
+ + + + + +
Age +
+ + +
+ +
+ + + + + + + + + + + +
City +
Country +
Altitude +
+ +
+ + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/README b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/README new file mode 100644 index 0000000000..7108333efa --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/README @@ -0,0 +1,20 @@ +JSE Sample Launcher +=================== + +This directory contains a sample java launcher for the +tuscany sample contributions. + +The README file in the /samples directory provides +general instructions about building and running sample contributions using the +tuscany sample launchers ( where distribution-unpack-dir is the directory in which you +unpacked the tuscany binary distribution archive) + +To use this sample JSE launcher with ant excute the command + +ant run- + +where run- is one of the targets in the build.xml file + +To use this sample launcher to run all of the contributions as junit test cases, +execute the command "mvn" in the launcher directory. + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/build.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/build.xml new file mode 100644 index 0000000000..64bad00b76 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/build.xml @@ -0,0 +1,118 @@ + + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + Please use 'ant run-name-of-sample-contribution-to-run' for example, try one of + 'ant run-contribution-binding-sca-calculator' + 'ant run-contribution-binding-ws-calculator' + 'ant run-contribution-binding-rmi-calculator' + 'ant run-contribution-implementation-java-calculator' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/pom.xml new file mode 100644 index 0000000000..fc003d991c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../pom.xml + + sample-launcher-embedded-jse-spec + Apache Tuscany SCA Sample Launcher Embedded JSE Spec + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-ejava + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-domain-node + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${project.artifactId} + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/calculator/CalculatorService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/JSELauncherBindingWSCalculator.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/JSELauncherBindingWSCalculator.java new file mode 100644 index 0000000000..2f48e273bd --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/JSELauncherBindingWSCalculator.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node2.Node; +import org.apache.tuscany.sca.node2.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherBindingWSCalculator { + + public static void main(String[] args) throws Exception { + JSELauncherBindingWSCalculator launcher = new JSELauncherBindingWSCalculator(); + launcher.launchBindingWSCalculator(); + } + + /* + * Using the Tuscany Node API to load a contribution. + * Using the Tuscany Node API to get a local service proxy + */ + public void launchBindingWSCalculator(){ + NodeFactory nodeFactory = NodeFactory.newInstance(); + Node node = nodeFactory.createNode("MyDomain"); + + try { + node.installContribution("../../../samples/contribution-binding-ws-calculator/target/sample-contribution-binding-ws-calculator.jar"); + } catch(Exception ex){ + System.out.println("Exception on installContribution"); + ex.printStackTrace(); + } + + //node.start(); + + CalculatorService calculator = null; + + try { + calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + } catch(Exception ex){ + System.out.println("Exception on getService"); + ex.printStackTrace(); + } + + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + node.stop(); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/SampleLauncherException.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/SampleLauncherException.java new file mode 100644 index 0000000000..f2ed3d421d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/main/java/launcher/SampleLauncherException.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 launcher; + +/** + * This exception signals problems in the management of SCA component execution. + */ +public class SampleLauncherException extends RuntimeException { + /** + * Constructs a SampleLauncherException with no detail message. + */ + public SampleLauncherException() { + super(); + } + + /** + * Constructs a SampleLauncherException with the specified detail + * message. + * + * @param message the detail message + */ + public SampleLauncherException(String message) { + super(message); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/test/java/launcher/LauncherTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/test/java/launcher/LauncherTestCase.java new file mode 100644 index 0000000000..04521d326b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/launcher-embedded-jse-spec/src/test/java/launcher/LauncherTestCase.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 launcher; + +import org.junit.Test; + +/** + * Test sample contributions. + */ +public class LauncherTestCase { + + @Test + public void testContributionBindingWSCalculator() throws Exception { + JSELauncherBindingWSCalculator.main(null); + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/pom.xml new file mode 100644 index 0000000000..1459d66152 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/pom.xml @@ -0,0 +1,90 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../pom.xml + + tuscany-contrib-samples + pom + Apache Tuscany SCA Contributed Samples + + + comet-webapp + + + + + eclipse + + org.apache.tuscany.maven.plugins:maven-bundle-plugin:eclipse + + + + + + + + junit + junit + 4.8.1 + test + + + + + + + + maven-jar-plugin + + + ${basedir}/META-INF/MANIFEST.MF + + + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/README b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/README new file mode 100644 index 0000000000..b33446cde8 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/README @@ -0,0 +1,6 @@ +Reporting Sample +================ + +A simple sample to motivate the implementation of some mechanisms for +retiriving information about an active domain and it's nodes. + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/pom.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/pom.xml new file mode 100644 index 0000000000..1c82f4be5a --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-reporting + Apache Tuscany SCA Sample Reporting + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-ejava + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-script-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-json + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${project.artifactId} + + + + + + diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/calculator/CalculatorService.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncheCalculator.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncheCalculator.java new file mode 100644 index 0000000000..25729ea1ea --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncheCalculator.java @@ -0,0 +1,333 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package reporting; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.StringWriter; +import java.net.URI; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.impl.NodeFactoryImpl; +import org.apache.tuscany.sca.node.impl.NodeImpl; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.sun.jmx.remote.util.Service; +import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter; + +import calculator.CalculatorService; + +/** + * This client program shows how to extract useful(?) information from the Tuscany SCA runtime + */ +public class JSELauncheCalculator { + + private static NodeFactory nodeFactory; + private static Node node1; + private static Node node2; + private static CalculatorService calculator; + + + public static void main(String[] args) throws Exception { + JSELauncheCalculator launcher = new JSELauncheCalculator(); + launcher.setUp(); + + launcher.callCalulator(); + launcher.listExtensions(); + launcher.listNodes(); + launcher.listNodeConfigurations(); + launcher.listContributions(); + launcher.listDomainComposite(); + launcher.listDomainDefinitions(); + launcher.listEndpoints(); + launcher.listWires(); + + launcher.tearDown(); + } + + @BeforeClass + public static void setUp() throws Exception { + try { +/* new + org.apache.tuscany.sca.node2.NodeFactory nodeFactoryNew = org.apache.tuscany.sca.node2.NodeFactory.newInstance(); + + org.apache.tuscany.sca.node2.Node node2New = nodeFactoryNew.createNode(); + node2New.installContribution("../domain/distributed-calculator/contribution-calculator/target/classes"); + + calculator = node2New.getService(CalculatorService.class, "CalculatorServiceComponent"); +*/ + +/* old */ + // TUSCANY-3675 - push hazelcast config into factory as adding it to URI doesn't work + Properties properties = new Properties(); + properties.setProperty("bind", "192.168.0.2"); + nodeFactory = NodeFactory.newInstance(properties); + + // TUSCANY-3675 - push hazelcast config into factory as adding it to URI doesn't work + //node2 = nodeFactory.createNode(new Contribution("c1", "../domain/distributed-calculator/contribution-calculator/target/classes")); + //node2 = nodeFactory.createNode(URI.create("tuscany:default?listen=127.0.0.1:14820"), "../domain/distributed-calculator/contribution-calculator/target/classes"); + //node2 = nodeFactory.createNode(URI.create("tuscany:default"), "../domain/distributed-calculator/contribution-calculator/target/classes"); + node2 = nodeFactory.createNode(new File("./target/classes/node-calculator.xml").toURL()); + + node2.start(); + + calculator = node2.getService(CalculatorService.class, "CalculatorServiceComponent"); + + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node2.stop(); + } + + @Test + public void callCalulator(){ + printTestName("callCalulator"); + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + } + + @Test + public void listExtensions(){ + printTestName("listExtensions"); + // TODO + } + + @Test + public void listNodes(){ + printTestName("listNodes"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Object nodeKey : nodes.keySet()){ + System.out.println(nodeKey); + } + } + + @Test + public void listNodeConfigurations(){ + printTestName("listNodeConfigurations"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + printXML(((NodeImpl)node).getConfiguration()); + } + } + + @Test + public void listContributions(){ + printTestName("listContributions"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + NodeConfiguration nodeConfiguration = ((NodeImpl)node).getConfiguration(); + for (org.apache.tuscany.sca.contribution.Contribution contribution : ((NodeImpl)node).getContributions()){ + System.out.println("Contribution: " + contribution.getURI() + " location " + contribution.getLocation()); + for (Artifact artifact : contribution.getArtifacts()){ + System.out.println(" Artifact: " + artifact.getURI() + " location " + artifact.getLocation()); + } + } + } + } + + @Test + public void listDomainComposite(){ + printTestName("listDomainComposite"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + printXML(((NodeImpl)node).getDomainComposite()); + } + } + + @Test + public void listDomainDefinitions(){ + printTestName("listDomainDefinitions"); + Deployer deployer = ((NodeFactoryImpl)nodeFactory).getDeployer(); + Definitions systemDefinitions = deployer.getSystemDefinitions(); + printXML(systemDefinitions); + } + + @Test + public void listEndpoints(){ + printTestName("listEndpoints"); + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + Node firstNode = nodes.values().iterator().next(); + NodeConfiguration firstNodeConfig = ((NodeImpl)firstNode).getConfiguration(); + + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry); + // TODO - I don't understand where the scheme gets set/used + EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("vm:" + firstNodeConfig.getDomainRegistryURI(), firstNodeConfig.getDomainURI()); + + for (Endpoint endpoint : endpointRegistry.getEndpoints()){ + System.out.println(endpoint); + printEndpointXML(endpoint); + } + } + + @Test + public void listWires(){ + printTestName("listWires"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + listComponentWires(((NodeImpl)node).getDomainComposite()); + } + } + + // utils + + private void listComponentWires(Composite composite){ + for(Component component : composite.getComponents()){ + if (component.getImplementation() instanceof Composite){ + listComponentWires((Composite)component.getImplementation()); + } + System.out.println(" Component: " + component.getName()); + + for(ComponentService service : component.getServices()){ + System.out.println(" Service: " + service.getName()); + for(Endpoint endpoint : service.getEndpoints()){ + System.out.println(" Endpoint: " + endpoint); + System.out.println(" Binding: " + endpoint.getBinding().getType()); + printInvocationChains(((RuntimeEndpointImpl)endpoint).getInvocationChains()); + } + } + for(ComponentReference reference : component.getReferences()){ + System.out.println(" Reference: " + reference.getName()); + for(EndpointReference endpointReference : reference.getEndpointReferences()){ + System.out.println(" EndpointReference: " + endpointReference); + Binding binding = endpointReference.getBinding(); + if (binding != null){ + System.out.println(" Binding: " + binding.getType()); + printInvocationChains(((RuntimeEndpointReferenceImpl)endpointReference).getInvocationChains()); + } + } + } + } + } + + private void printInvocationChains(List chains){ + for(InvocationChain chain : chains){ + System.out.println(" Operation: " + chain.getTargetOperation().getName()); + Invoker invoker = chain.getHeadInvoker(); + while(invoker != null){ + System.out.println(" Invoker: " + invoker.getClass().getName()); + if (invoker instanceof Interceptor){ + invoker = ((Interceptor)invoker).getNext(); + } else { + invoker = null; + } + } + } + } + + private void printTestName(String name){ + System.out.println("====================================================================="); + System.out.println(name); + System.out.println("====================================================================="); + } + + private void printXML(Object model){ + try { + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint xmlProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessors, inputFactory, null); + + ProcessorContext context = new ProcessorContext(registry); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class); + XMLStreamWriter writer = new IndentingXMLStreamWriter(outputFactory.createXMLStreamWriter(bos)); + + xmlProcessor.write(model, writer, context); + writer.flush(); + + System.out.println(bos.toString()); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + + // TODO - we don't have a processor registered for RuntimeEndpointImpl? + private void printEndpointXML(Endpoint model){ + try { + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint xmlProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor xmlProcessor = xmlProcessors.getProcessor(Endpoint.class); + + ProcessorContext context = new ProcessorContext(registry); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class); + XMLStreamWriter writer = new IndentingXMLStreamWriter(outputFactory.createXMLStreamWriter(bos)); + + xmlProcessor.write(model, writer, context); + writer.flush(); + + System.out.println(bos.toString()); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncherAdd.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncherAdd.java new file mode 100644 index 0000000000..5351ed263b --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/java/reporting/JSELauncherAdd.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package reporting; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.StringWriter; +import java.net.URI; +import java.net.URL; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.impl.NodeFactoryImpl; +import org.apache.tuscany.sca.node.impl.NodeImpl; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.RuntimeProperties; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.sun.jmx.remote.util.Service; +import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter; + +import calculator.CalculatorService; + +/** + * This client program shows how to extract useful(?) information from the Tuscany SCA runtime + */ +public class JSELauncherAdd { + + private static NodeFactory nodeFactory; + private static Node node1; + private static Node node2; + private static CalculatorService calculator; + + + public static void main(String[] args) throws Exception { + JSELauncherAdd launcher = new JSELauncherAdd (); + launcher.setUp(); + + launcher.waitForInput(); + + launcher.tearDown(); + } + + @BeforeClass + public static void setUp() throws Exception { + try { +/* new + org.apache.tuscany.sca.node2.NodeFactory nodeFactoryNew = org.apache.tuscany.sca.node2.NodeFactory.newInstance(); + org.apache.tuscany.sca.node2.Node node1New = nodeFactoryNew.createNode(); + node1New.installContribution("../domain/distributed-calculator/contribution-add/target/classes"); + +*/ + +/* old */ + // TUSCANY-3675 - push hazelcast config into factory as adding it to URI doesn't work + Properties properties = new Properties(); + properties.setProperty("bind", "192.168.0.2"); + nodeFactory = NodeFactory.newInstance(properties); + + // TUSCANY-3675 - push hazelcast config into factory as adding it to URI doesn't work + //node1 = nodeFactory.createNode(new Contribution("c1", "../domain/distributed-calculator/contribution-add/target/classes")); + //node1 = nodeFactory.createNode(URI.create("tuscany:default?listen=127.0.0.1:14820"), "../domain/distributed-calculator/contribution-add/target/classes"); + //node1 = nodeFactory.createNode(URI.create("tuscany:default"), "../domain/distributed-calculator/contribution-add/target/classes"); + node1 = nodeFactory.createNode(new File("./target/classes/node-add.xml").toURL()); + + node1.start(); + + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node1.stop(); + } + + @Test + @Ignore + public void waitForInput(){ + System.out.println("Press key to end"); + try { + System.in.read(); + } catch(Exception ex){ + // do nothing + } + } + +} diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-add.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-add.xml new file mode 100644 index 0000000000..7a4a6d5695 --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-add.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-calculator.xml b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-calculator.xml new file mode 100644 index 0000000000..31098b129d --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/main/resources/node-calculator.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/test/java/reporting/JSELauncherReportingTestCase.java b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/test/java/reporting/JSELauncherReportingTestCase.java new file mode 100644 index 0000000000..b4cc8fa3ee --- /dev/null +++ b/sca-java-2.x/branches/2.0-Beta2/unreleased/samples/reporting/src/test/java/reporting/JSELauncherReportingTestCase.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package reporting; + +import java.io.ByteArrayOutputStream; +import java.io.StringWriter; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.contribution.Artifact; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointImpl; +import org.apache.tuscany.sca.core.assembly.impl.RuntimeEndpointReferenceImpl; +import org.apache.tuscany.sca.definitions.Definitions; +import org.apache.tuscany.sca.deployment.Deployer; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; +import org.apache.tuscany.sca.node.configuration.NodeConfiguration; +import org.apache.tuscany.sca.node.impl.NodeFactoryImpl; +import org.apache.tuscany.sca.node.impl.NodeImpl; +import org.apache.tuscany.sca.runtime.DomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.sun.jmx.remote.util.Service; +import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter; + +import calculator.CalculatorService; + +/** + * This client program shows how to extract useful(?) information from the Tuscany SCA runtime + */ +public class JSELauncherReportingTestCase { + + private static NodeFactory nodeFactory; + private static Node node1; + private static Node node2; + private static CalculatorService calculator; + + + public static void main(String[] args) throws Exception { + JSELauncherReportingTestCase launcher = new JSELauncherReportingTestCase(); + launcher.setUp(); + + launcher.callCalulator(); +/* + launcher.listNodes(); + launcher.listNodeConfigurations(); + launcher.listContributions(); + launcher.listDomainDefinitions(); + launcher.listEndpoints(); +*/ + launcher.listWires(); + launcher.tearDown(); + } + + @BeforeClass + public static void setUp() throws Exception { + try { +/* new + org.apache.tuscany.sca.node2.NodeFactory nodeFactoryNew = org.apache.tuscany.sca.node2.NodeFactory.newInstance(); + org.apache.tuscany.sca.node2.Node node1New = nodeFactoryNew.createNode(); + node1New.installContribution("../domain/distributed-calculator/contribution-add/target/classes"); + + org.apache.tuscany.sca.node2.Node node2New = nodeFactoryNew.createNode(); + node2New.installContribution("../domain/distributed-calculator/contribution-calculator/target/classes"); + + calculator = node2New.getService(CalculatorService.class, "CalculatorServiceComponent"); +*/ + +/* old */ + nodeFactory = NodeFactory.newInstance(); + node1 = nodeFactory.createNode(new Contribution("c1", "../domain/distributed-calculator/contribution-add/target/classes")); + node1.start(); + + node2 = nodeFactory.createNode(new Contribution("c1", "../domain/distributed-calculator/contribution-calculator/target/classes")); + node2.start(); + + calculator = node2.getService(CalculatorService.class, "CalculatorServiceComponent"); + + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + @AfterClass + public static void tearDown() throws Exception { + node1.stop(); + node2.stop(); + } + + @Test + public void callCalulator(){ + printTestName("callCalulator"); + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + } + + @Test + public void listNodes(){ + printTestName("listNodes"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Object nodeKey : nodes.keySet()){ + System.out.println(nodeKey); + } + } + + @Test + public void listNodeConfigurations(){ + printTestName("listNodeConfigurations"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + printXML(((NodeImpl)node).getConfiguration()); + } + } + + @Test + public void listContributions(){ + printTestName("listContributions"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + NodeConfiguration nodeConfiguration = ((NodeImpl)node).getConfiguration(); + for (org.apache.tuscany.sca.contribution.Contribution contribution : ((NodeImpl)node).getContributions()){ + System.out.println("Contribution: " + contribution.getURI() + " location " + contribution.getLocation()); + for (Artifact artifact : contribution.getArtifacts()){ + System.out.println(" Artifact: " + artifact.getURI() + " location " + artifact.getLocation()); + } + } + } + } + + @Test + public void listDomainComposite(){ + printTestName("listDomainComposite"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + printXML(((NodeImpl)node).getDomainComposite()); + } + } + + @Test + public void listDomainDefinitions(){ + printTestName("listDomainDefinitions"); + Deployer deployer = ((NodeFactoryImpl)nodeFactory).getDeployer(); + Definitions systemDefinitions = deployer.getSystemDefinitions(); + printXML(systemDefinitions); + } + + @Test + public void listEndpoints(){ + printTestName("listEndpoints"); + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + Node firstNode = nodes.values().iterator().next(); + NodeConfiguration firstNodeConfig = ((NodeImpl)firstNode).getConfiguration(); + + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(registry); + // TODO - I don't understand where the scheme gets set/used + EndpointRegistry endpointRegistry = domainRegistryFactory.getEndpointRegistry("vm:" + firstNodeConfig.getDomainRegistryURI(), firstNodeConfig.getDomainURI()); + + for (Endpoint endpoint : endpointRegistry.getEndpoints()){ + System.out.println(endpoint); + printEndpointXML(endpoint); + } + } + + @Test + public void listWires(){ + printTestName("listWires"); + Map nodes = ((NodeFactoryImpl)nodeFactory).getNodes(); + for (Node node : nodes.values()){ + System.out.println("Node: " + ((NodeImpl)node).getURI()); + listComponentWires(((NodeImpl)node).getDomainComposite()); + } + } + + // utils + + private void listComponentWires(Composite composite){ + for(Component component : composite.getComponents()){ + if (component.getImplementation() instanceof Composite){ + listComponentWires((Composite)component.getImplementation()); + } + System.out.println(" Component: " + component.getName()); + + for(ComponentService service : component.getServices()){ + System.out.println(" Service: " + service.getName()); + for(Endpoint endpoint : service.getEndpoints()){ + System.out.println(" Endpoint: " + endpoint); + System.out.println(" Binding: " + endpoint.getBinding().getType()); + printInvocationChains(((RuntimeEndpointImpl)endpoint).getInvocationChains()); + } + } + for(ComponentReference reference : component.getReferences()){ + System.out.println(" Reference: " + reference.getName()); + for(EndpointReference endpointReference : reference.getEndpointReferences()){ + System.out.println(" EndpointReference: " + endpointReference); + Binding binding = endpointReference.getBinding(); + if (binding != null){ + System.out.println(" Binding: " + binding.getType()); + printInvocationChains(((RuntimeEndpointReferenceImpl)endpointReference).getInvocationChains()); + } + } + } + } + } + + private void printInvocationChains(List chains){ + for(InvocationChain chain : chains){ + System.out.println(" Operation: " + chain.getTargetOperation().getName()); + Invoker invoker = chain.getHeadInvoker(); + while(invoker != null){ + System.out.println(" Invoker: " + invoker.getClass().getName()); + if (invoker instanceof Interceptor){ + invoker = ((Interceptor)invoker).getNext(); + } else { + invoker = null; + } + } + } + } + + private void printTestName(String name){ + System.out.println("====================================================================="); + System.out.println(name); + System.out.println("====================================================================="); + } + + private void printXML(Object model){ + try { + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint xmlProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessors, inputFactory, null); + + ProcessorContext context = new ProcessorContext(registry); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class); + XMLStreamWriter writer = new IndentingXMLStreamWriter(outputFactory.createXMLStreamWriter(bos)); + + xmlProcessor.write(model, writer, context); + writer.flush(); + + System.out.println(bos.toString()); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + + // TODO - we don't have a processor registered for RuntimeEndpointImpl? + private void printEndpointXML(Endpoint model){ + try { + ExtensionPointRegistry registry = ((NodeFactoryImpl)nodeFactory).getExtensionPointRegistry(); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint xmlProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor xmlProcessor = xmlProcessors.getProcessor(Endpoint.class); + + ProcessorContext context = new ProcessorContext(registry); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(XMLOutputFactory.class); + XMLStreamWriter writer = new IndentingXMLStreamWriter(outputFactory.createXMLStreamWriter(bos)); + + xmlProcessor.write(model, writer, context); + writer.flush(); + + System.out.println(bos.toString()); + } catch(Exception ex) { + ex.printStackTrace(); + } + } + +} -- cgit v1.2.3