From c3db1aac8fb2ec776ccfecdf6804849b5b112adb Mon Sep 17 00:00:00 2001 From: adrianocrestani Date: Tue, 8 Jul 2008 05:19:28 +0000 Subject: -adding the core-databinding, interface-java and interface-java-jaxws modules to android sandbox -commented the RMI code and added workaround for the Java Bean usage -commented the javax.jws code git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@674723 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/mobile-android/core-databinding/.classpath | 41 ++++ sandbox/mobile-android/core-databinding/.project | 39 +++ sandbox/mobile-android/core-databinding/DISCLAIMER | 8 + sandbox/mobile-android/core-databinding/LICENSE | 205 ++++++++++++++++ sandbox/mobile-android/core-databinding/NOTICE | 6 + sandbox/mobile-android/core-databinding/pom.xml | 76 ++++++ .../module/DataBindingModuleActivator.java | 93 ++++++++ .../DataBindingJavaInterfaceProcessor.java | 191 +++++++++++++++ .../transformers/Array2ArrayTransformer.java | 108 +++++++++ .../Exception2ExceptionTransformer.java | 112 +++++++++ .../transformers/Input2InputTransformer.java | 213 +++++++++++++++++ .../transformers/Output2OutputTransformer.java | 203 ++++++++++++++++ .../wire/DataBindingRuntimeWireProcessor.java | 186 +++++++++++++++ .../wire/DataTransformationInterceptor.java | 263 +++++++++++++++++++++ .../databinding/wire/PassByValueInterceptor.java | 247 +++++++++++++++++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 ++ .../DataBindingJavaInterfaceProcessorTestCase.java | 88 +++++++ .../transformers/IDLTransformerTestCase.java.fixme | 229 ++++++++++++++++++ .../mobile-android/interface-java-jaxws/.classpath | 42 ++++ .../mobile-android/interface-java-jaxws/.project | 38 +++ .../mobile-android/interface-java-jaxws/DISCLAIMER | 8 + .../mobile-android/interface-java-jaxws/LICENSE | 205 ++++++++++++++++ sandbox/mobile-android/interface-java-jaxws/NOTICE | 6 + .../mobile-android/interface-java-jaxws/pom.xml | 188 +++++++++++++++ .../java/jaxws/JAXWSFaultExceptionMapper.java | 253 ++++++++++++++++++++ .../java/jaxws/JAXWSJavaInterfaceProcessor.java | 232 ++++++++++++++++++ .../tuscany/sca/interfacedef/java/jaxws/Bean.java | 23 ++ .../tuscany/sca/interfacedef/java/jaxws/Bean1.java | 36 +++ .../tuscany/sca/interfacedef/java/jaxws/Bean2.java | 36 +++ .../jaxws/JAXWSJavaInterfaceProcessorTestCase.java | 98 ++++++++ .../sca/interfacedef/java/jaxws/MyException.java | 49 ++++ .../sca/interfacedef/java/jaxws/MyServiceImpl.java | 52 ++++ .../test/resources/wsdl/StockExceptionTest.wsdl | 148 ++++++++++++ sandbox/mobile-android/interface-java/.classpath | 18 ++ sandbox/mobile-android/interface-java/.project | 29 +++ sandbox/mobile-android/interface-java/DISCLAIMER | 8 + sandbox/mobile-android/interface-java/LICENSE | 205 ++++++++++++++++ sandbox/mobile-android/interface-java/NOTICE | 6 + sandbox/mobile-android/interface-java/pom.xml | 63 +++++ .../java/DefaultJavaInterfaceFactory.java | 97 ++++++++ .../sca/interfacedef/java/JavaInterface.java | 72 ++++++ .../interfacedef/java/JavaInterfaceContract.java | 32 +++ .../interfacedef/java/JavaInterfaceFactory.java | 82 +++++++ .../sca/interfacedef/java/JavaOperation.java | 45 ++++ .../java/impl/JavaInterfaceContractImpl.java | 39 +++ .../java/impl/JavaInterfaceFactoryImpl.java | 71 ++++++ .../interfacedef/java/impl/JavaInterfaceImpl.java | 101 ++++++++ .../java/impl/JavaInterfaceIntrospectorImpl.java | 225 ++++++++++++++++++ .../interfacedef/java/impl/JavaInterfaceUtil.java | 151 ++++++++++++ .../interfacedef/java/impl/JavaOperationImpl.java | 73 ++++++ .../java/impl/PolicyJavaInterfaceVisitor.java | 159 +++++++++++++ .../java/introspect/JavaInterfaceVisitor.java | 39 +++ ...cany.sca.interfacedef.java.JavaInterfaceFactory | 18 ++ .../java/impl/JavaInterfaceUtilTestCase.java | 121 ++++++++++ .../impl/ConversationalIntrospectionTestCase.java | 98 ++++++++ ...JavaInterfaceProcessorRegistryImplTestCase.java | 107 +++++++++ .../impl/PolicyProcessorTestCase.java | 108 +++++++++ .../introspect/impl/JavaIntrospectionHelper.java | 13 +- 58 files changed, 5719 insertions(+), 1 deletion(-) create mode 100644 sandbox/mobile-android/core-databinding/.classpath create mode 100644 sandbox/mobile-android/core-databinding/.project create mode 100644 sandbox/mobile-android/core-databinding/DISCLAIMER create mode 100644 sandbox/mobile-android/core-databinding/LICENSE create mode 100644 sandbox/mobile-android/core-databinding/NOTICE create mode 100644 sandbox/mobile-android/core-databinding/pom.xml create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java create mode 100644 sandbox/mobile-android/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java create mode 100644 sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme create mode 100644 sandbox/mobile-android/interface-java-jaxws/.classpath create mode 100644 sandbox/mobile-android/interface-java-jaxws/.project create mode 100644 sandbox/mobile-android/interface-java-jaxws/DISCLAIMER create mode 100644 sandbox/mobile-android/interface-java-jaxws/LICENSE create mode 100644 sandbox/mobile-android/interface-java-jaxws/NOTICE create mode 100644 sandbox/mobile-android/interface-java-jaxws/pom.xml create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean1.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean2.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyException.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyServiceImpl.java create mode 100644 sandbox/mobile-android/interface-java-jaxws/src/test/resources/wsdl/StockExceptionTest.wsdl create mode 100644 sandbox/mobile-android/interface-java/.classpath create mode 100644 sandbox/mobile-android/interface-java/.project create mode 100644 sandbox/mobile-android/interface-java/DISCLAIMER create mode 100644 sandbox/mobile-android/interface-java/LICENSE create mode 100644 sandbox/mobile-android/interface-java/NOTICE create mode 100644 sandbox/mobile-android/interface-java/pom.xml create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java create mode 100644 sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java create mode 100644 sandbox/mobile-android/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory create mode 100644 sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java create mode 100644 sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java create mode 100644 sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java create mode 100644 sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java (limited to 'sandbox/mobile-android') diff --git a/sandbox/mobile-android/core-databinding/.classpath b/sandbox/mobile-android/core-databinding/.classpath new file mode 100644 index 0000000000..57c14f73d6 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/.classpath @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/mobile-android/core-databinding/.project b/sandbox/mobile-android/core-databinding/.project new file mode 100644 index 0000000000..db1e66c6e8 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/.project @@ -0,0 +1,39 @@ + + + tuscany-core-databinding + Parent POM defining settings that can be used across Tuscany + + tuscany-core-spi + tuscany-extensibility + tuscany-sca-api + tuscany-assembly + tuscany-policy + tuscany-interface + tuscany-definitions + tuscany-contribution + tuscany-databinding + tuscany-core + tuscany-contribution-java + tuscany-interface-java + tuscany-databinding-jaxb + tuscany-interface-java-xml + tuscany-assembly-xml + tuscany-contribution-namespace + tuscany-interface-java-jaxws + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder (33).launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/mobile-android/core-databinding/DISCLAIMER b/sandbox/mobile-android/core-databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sandbox/mobile-android/core-databinding/LICENSE b/sandbox/mobile-android/core-databinding/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sandbox/mobile-android/core-databinding/NOTICE b/sandbox/mobile-android/core-databinding/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/sandbox/mobile-android/core-databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/mobile-android/core-databinding/pom.xml b/sandbox/mobile-android/core-databinding/pom.xml new file mode 100644 index 0000000000..2d0facb551 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/pom.xml @@ -0,0 +1,76 @@ + + + + + org.apache.tuscany.sca + tuscany-modules + 2.0-incubating-SNAPSHOT + ../pom.xml + + 4.0.0 + org.apache.tuscany.sca + tuscany-core-databinding + jar + Apache Tuscany SCA Core/DataBinding Integration + + + + org.apache.tuscany.sca + tuscany-databinding + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-databinding-jaxb + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-core-spi + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-jaxws + ${project.version} + compile + + + + org.codehaus.woodstox + wstx-asl + runtime + 3.2.1 + + + diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java new file mode 100644 index 0000000000..d936de20ab --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.module; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer; +import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer; +import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * @version $Rev: 629687 $ $Date: 2008-02-20 20:11:14 -0800 (Wed, 20 Feb 2008) $ + */ +public class DataBindingModuleActivator implements ModuleActivator { + + public void start(ExtensionPointRegistry registry) { + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + + TransformerExtensionPoint transformers = new DefaultTransformerExtensionPoint();//registry.getExtensionPoint(TransformerExtensionPoint.class); + + FaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings); + registry.addExtensionPoint(faultExceptionMapper); + + MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); + input2InputTransformer.setMediator(mediator); + transformers.addTransformer(input2InputTransformer, true); + + Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); + output2OutputTransformer.setMediator(mediator); + transformers.addTransformer(output2OutputTransformer, true); + + Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(mediator, faultExceptionMapper); + transformers.addTransformer(exception2ExceptionTransformer, false); + + Array2ArrayTransformer array2ArrayTransformer = new Array2ArrayTransformer(); + array2ArrayTransformer.setMediator(mediator); + transformers.addTransformer(array2ArrayTransformer, true); + + Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); + group2GroupTransformer.setMediator(mediator); + transformers.addTransformer(group2GroupTransformer, true); + + ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + + // [rfeng] The JAX-WS processor should come before the Databinding processor to make sure @WebService + // is honored as Remoteable + javaFactory.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor(faultExceptionMapper)); + + javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); + + RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); + if (wireProcessorExtensionPoint != null) { + wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings, faultExceptionMapper)); + } + + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java new file mode 100644 index 0000000000..05d1d71558 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.processor; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +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.java.introspect.JavaInterfaceVisitor; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev: 639350 $ $Date: 2008-03-20 08:43:46 -0800 (Thu, 20 Mar 2008) $ + */ +public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { + private DataBindingExtensionPoint dataBindingRegistry; + + public DataBindingJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) { + super(); + this.dataBindingRegistry = dataBindingRegistry; + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + if (!javaInterface.isRemotable()) { + return; + } + List operations = javaInterface.getOperations(); + processInterface(javaInterface, operations); + } + + private void processInterface(JavaInterface javaInterface, List operations) { + Class clazz = javaInterface.getJavaClass(); + DataBinding dataBinding = clazz.getAnnotation(DataBinding.class); + String dataBindingId = null; + boolean wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapped(); + } + + Map opMap = new HashMap(); + for (Operation op : javaInterface.getOperations()) { + opMap.put(op.getName(), op); + // In the case of @WebMethod, the method name can be different from the operation name + if (op instanceof JavaOperation) { + opMap.put(((JavaOperation)op).getJavaMethod().getName(), op); + } + if (dataBindingId != null) { + op.setDataBinding(dataBindingId); + op.setWrapperStyle(wrapperStyle); + } + } + for (Method method : clazz.getMethods()) { + if (method.getDeclaringClass() == Object.class) { + continue; + } + Operation operation = opMap.get(method.getName()); + DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class); + if (methodDataBinding == null) { + methodDataBinding = dataBinding; + } + dataBindingId = null; + wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapped(); + operation.setDataBinding(dataBindingId); + operation.setWrapperStyle(wrapperStyle); + } + + // FIXME: We need a better way to identify simple java types + int i = 0; + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getInputType().getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + for (Annotation a : method.getParameterAnnotations()[i]) { + if (a.annotationType() == org.apache.tuscany.sca.databinding.annotation.DataType.class) { + String value = ((org.apache.tuscany.sca.databinding.annotation.DataType)a).value(); + d.setDataBinding(value); + } + } + dataBindingRegistry.introspectType(d, method.getParameterAnnotations()[i]); + i++; + } + if (operation.getOutputType() != null) { + DataType d = operation.getOutputType(); + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + org.apache.tuscany.sca.databinding.annotation.DataType dt = + method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class); + if (dt != null) { + d.setDataBinding(dt.value()); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + // TODO: Handle exceptions + dataBindingRegistry.introspectType(d, method.getAnnotations(), true); + } + + // JIRA: TUSCANY-842 + if (operation.getDataBinding() == null) { + assignOperationDataBinding(operation); + } + + // FIXME: Do we want to heuristically check the wrapper style? + // introspectWrapperStyle(operation); + } + } + + /* + * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB. + * However, if two of the input types, output type, fault types have two different non-default DBs + * ( e.g. SDO and JAXB), then we do nothing to the operation DB. + * + * The method logic assumes the JavaBeans DataBinding is the default + */ + private void assignOperationDataBinding(Operation operation) { + + String nonDefaultDataBindingName = null; + + // Can't use DataType since operation.getInputType() returns: DataType> + List opDataTypes = new LinkedList(); + + opDataTypes.addAll(operation.getInputType().getLogical()); + opDataTypes.add(operation.getOutputType()); + opDataTypes.addAll(operation.getFaultTypes()); + + for (DataType d : opDataTypes) { + if (d != null) { + String dataBinding = d.getDataBinding(); + // Assumes JavaBeans DB is default + if (dataBinding != null && !dataBinding.equals(JavaBeansDataBinding.NAME) + && !dataBinding.equals(SimpleJavaDataBinding.NAME)) { + if (nonDefaultDataBindingName != null) { + if (!nonDefaultDataBindingName.equals(dataBinding)) { + // We've seen two different non-default DBs, e.g. SDO and JAXB + // so unset the string and break out of the loop + nonDefaultDataBindingName = null; + break; + } else { + continue; + } + } else { + nonDefaultDataBindingName = dataBinding; + } + } + } + } + + // We have a DB worthy of promoting to operation level. + if (nonDefaultDataBindingName != null) { + operation.setDataBinding(nonDefaultDataBindingName); + } + } +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java new file mode 100644 index 0000000000..e33b7ffbfa --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.databinding.transformers; + +import java.lang.reflect.Array; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +public class Array2ArrayTransformer extends BaseTransformer implements PullTransformer { + + protected Mediator mediator; + + public Array2ArrayTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return "java:array"; + } + + @Override + public String getTargetDataBinding() { + return "java:array"; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10; + } + + @SuppressWarnings("unchecked") + public Object transform(Object array, TransformationContext context) { + try { + if (array == null) { + return null; + } + DataType sourceType = context.getSourceDataType(); + DataType targetType = context.getTargetDataType(); + int length = Array.getLength(array); + Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length); + for (int i = 0; i < length; i++) { + Object sourceItem = Array.get(array, i); + Object targetItem = + mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context + .getMetadata()); + Array.set(targetArray, i, targetItem); + } + return targetArray; + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java new file mode 100644 index 0000000000..0c1721ae08 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.transformers; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; + +/** + * This is a special transformer to transform the exception from one IDL to the + * other one + */ +public class Exception2ExceptionTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + protected FaultExceptionMapper faultExceptionMapper; + + public Exception2ExceptionTransformer(Mediator mediator, FaultExceptionMapper faultExceptionMapper) { + super(); + this.mediator = mediator; + this.faultExceptionMapper = faultExceptionMapper; + } + + public Exception2ExceptionTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_FAULT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_FAULT; + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Throwable.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Throwable.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Throwable transform(Throwable source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + + DataType targetType = context.getTargetDataType(); + + Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical()); + Object targetFaultInfo = + mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + + Throwable targetException = + faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause()); + + // FIXME + return targetException == null ? source : targetException; + + } + + public void setFaultExceptionMapper(FaultExceptionMapper faultExceptionMapper) { + this.faultExceptionMapper = faultExceptionMapper; + } +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java new file mode 100644 index 0000000000..b8ec19b985 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.transformers; + +import java.util.List; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the input from one IDL to the + * other one + */ +public class Input2InputTransformer extends BaseTransformer implements + PullTransformer { + private static final Logger logger = Logger.getLogger(Input2InputTransformer.class.getName()); + + protected Mediator mediator; + + public Input2InputTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_INPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_INPUT; + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Object[] transform(Object[] source, TransformationContext context) { + DataType> sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + + WrapperHandler sourceWrapperHandler = null; + String sourceDataBinding = getDataBinding(sourceOp); + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); + + DataType> targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getInputWrapperElement(); + + if (source == null) { + Object targetWrapper = targetWrapperHandler.create(wrapperElement, context); + return new Object[] {targetWrapper}; + } + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + DataType sourceWrapperType = + sourceWrapperHandler.getWrapperType(wrapperElement, wrapper.getInputChildElements(), context); + if (sourceWrapperType != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + if (sourceWrapper != null) { + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[i]); + } + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context + .getMetadata()); + return new Object[] {targetWrapper}; + } + } + } + // Fall back to child by child transformation + Object targetWrapper = targetWrapperHandler.create(wrapperElement, context); + List argTypes = wrapper.getUnwrappedInputType().getLogical(); + + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + DataType argType = argTypes.get(i); + Object child = source[i]; + child = mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, i, argElement, child); + } + return new Object[] {targetWrapper}; + + } else if (sourceWrapped && (!targetWrapped)) { + // Wrapped to Unwrapped + Object sourceWrapper = source[0]; + Object[] target = null; + + List childElements = sourceOp.getWrapper().getInputChildElements(); + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement(); + // FIXME: This is a workaround for the wsdless support as it passes in child elements + // under the wrapper that only matches by position + if (sourceWrapperHandler.isInstance(sourceWrapper, wrapperElement, childElements, context)) { + DataType targetWrapperType = + targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (targetWrapperType != null) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context + .getMetadata()); + target = targetWrapperHandler.getChildren(targetWrapper, childElements, context).toArray(); + return target; + } + } + } + Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).toArray(); + target = new Object[sourceChildren.length]; + for (int i = 0; i < sourceChildren.length; i++) { + DataType childType = sourceOp.getWrapper().getUnwrappedInputType().getLogical().get(i); + target[i] = + mediator.mediate(sourceChildren[i], childType, targetType.getLogical().get(i), context + .getMetadata()); + } + return target; + } else { + // Assuming wrapper to wrapper conversion can be handled here as well + Object[] newArgs = new Object[source.length]; + for (int i = 0; i < source.length; i++) { + Object child = + mediator.mediate(source[i], sourceType.getLogical().get(i), targetType.getLogical().get(i), context + .getMetadata()); + newArgs[i] = child; + } + return newArgs; + } + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + private String getDataBinding(Operation operation) { + return operation.getDataBinding(); + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java new file mode 100644 index 0000000000..7fed2e5eaa --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.databinding.transformers; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +public class Output2OutputTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + /** + * @param wrapperHandler + */ + public Output2OutputTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10; + } + + private String getDataBinding(Operation operation) { + return operation.getDataBinding(); + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + @SuppressWarnings("unchecked") + public Object transform(Object response, TransformationContext context) { + try { + DataType sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + + WrapperHandler sourceWrapperHandler = null; + String sourceDataBinding = getDataBinding(sourceOp); + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped); + + DataType targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getOutputWrapperElement(); + List childElements = wrapper.getOutputChildElements(); + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + DataType sourceWrapperType = + sourceWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (sourceWrapperType != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + if (sourceWrapper != null) { + if (!childElements.isEmpty()) { + // Set the return value + ElementInfo returnElement = wrapper.getOutputChildElements().get(0); + sourceWrapperHandler.setChild(sourceWrapper, 0, returnElement, response); + } + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context + .getMetadata()); + return targetWrapper; + } + } + } + Object targetWrapper = targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context); + + if (childElements.isEmpty()) { + // void output + return targetWrapper; + } + ElementInfo argElement = childElements.get(0); + DataType argType = wrapper.getUnwrappedOutputType(); + Object child = response; + child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, 0, argElement, child); + return targetWrapper; + } else if (sourceWrapped && (!targetWrapped)) { + // Wrapped to Unwrapped + Object sourceWrapper = response; + List childElements = sourceOp.getWrapper().getOutputChildElements(); + if (childElements.isEmpty()) { + // The void output + return null; + } + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement(); + + // FIXME: This is a workaround for the wsdless support as it passes in child elements + // under the wrapper that only matches by position + if (sourceWrapperHandler.isInstance(sourceWrapper, wrapperElement, childElements, context)) { + DataType targetWrapperType = + targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (targetWrapperType != null) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context + .getMetadata()); + return targetWrapperHandler.getChildren(targetWrapper, childElements, context).get(0); + } + } + } + Object child = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).get(0); + DataType childType = sourceOp.getWrapper().getUnwrappedOutputType(); + return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata()); + } else { + // FIXME: Do we want to handle wrapped to wrapped? + return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context + .getMetadata()); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java new file mode 100644 index 0000000000..0dbe92dfa4 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.wire; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; + +/** + * This processor is responsible to add an interceptor to invocation chain if + * the source and target operations have different databinding requirements + * + * @version $Rev: 632064 $ $Date: 2008-02-28 09:18:51 -0800 (Thu, 28 Feb 2008) $ + */ +public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { + private Mediator mediator; + private DataBindingExtensionPoint dataBindings; + private FaultExceptionMapper faultExceptionMapper; + + public DataBindingRuntimeWireProcessor(Mediator mediator, + DataBindingExtensionPoint dataBindings, + FaultExceptionMapper faultExceptionMapper) { + super(); + this.mediator = mediator; + this.dataBindings = dataBindings; + this.faultExceptionMapper = faultExceptionMapper; + } + + public boolean isTransformationRequired(DataType source, DataType target) { + if (source == null || target == null) { // void return type + return false; + } + if (source == target) { + return false; + } + + // Output type can be null + if (source == null && target == null) { + return false; + } else if (source == null || target == null) { + return true; + } + String sourceDataBinding = source.getDataBinding(); + String targetDataBinding = target.getDataBinding(); + if (sourceDataBinding == targetDataBinding) { + return false; + } + if (sourceDataBinding == null || targetDataBinding == null) { + // TODO: If any of the databinding is null, then no transformation + return false; + } + return !sourceDataBinding.equals(targetDataBinding); + } + + public boolean isTransformationRequired(Operation source, Operation target) { + if (source == target) { + return false; + } + + if (source.isWrapperStyle() != target.isWrapperStyle()) { + return true; + } + + // Check output type + DataType sourceOutputType = source.getOutputType(); + DataType targetOutputType = target.getOutputType(); + + // Note the target output type is now the source for checking + // compatibility + if (isTransformationRequired(targetOutputType, sourceOutputType)) { + return true; + } + + List sourceInputType = source.getInputType().getLogical(); + List targetInputType = target.getInputType().getLogical(); + + int size = sourceInputType.size(); + if (size != targetInputType.size()) { + // TUSCANY-1682: The wrapper style may have different arguments + return true; + } + for (int i = 0; i < size; i++) { + if (isTransformationRequired(sourceInputType.get(i), targetInputType.get(i))) { + return true; + } + } + + return false; + } + + private boolean isTransformationRequired(InterfaceContract sourceContract, + Operation sourceOperation, + InterfaceContract targetContract, + Operation targetOperation) { + if (targetContract == null) { + targetContract = sourceContract; + } + if (sourceContract == targetContract) { + return false; + } + return isTransformationRequired(sourceOperation, targetOperation); + } + + public void process(RuntimeWire wire) { + InterfaceContract sourceContract = wire.getSource().getInterfaceContract(); + InterfaceContract targetContract = wire.getTarget().getInterfaceContract(); + if (targetContract == null) { + targetContract = sourceContract; + } + + if (!sourceContract.getInterface().isRemotable()) { + return; + } + List chains = wire.getInvocationChains(); + for (InvocationChain chain : chains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + + Interceptor interceptor = null; + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + // Add the interceptor to the source side because multiple + // references can be wired to the same service + interceptor = + new DataTransformationInterceptor(wire, sourceOperation, targetOperation, mediator, + faultExceptionMapper); + } else { + // assume pass-by-values copies are required if interfaces are remotable and there is no data binding + // transformation, i.e. a transformation will result in a copy so another pass-by-value copy is unnecessary + if (isRemotable(chain, sourceOperation, targetOperation)) { + interceptor = + new PassByValueInterceptor(dataBindings, faultExceptionMapper, chain, targetOperation); + } + } + if (interceptor != null) { + String phase = + (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_INTERFACE + : Phase.SERVICE_INTERFACE; + chain.addInterceptor(phase, interceptor); + } + } + + } + + /** + * Pass-by-value copies are required if the interfaces are remotable unless the + * implementation uses the @AllowsPassByReference annotation. + */ + protected boolean isRemotable(InvocationChain chain, Operation sourceOperation, Operation targetOperation) { + if (!sourceOperation.getInterface().isRemotable()) { + return false; + } + if (!targetOperation.getInterface().isRemotable()) { + return false; + } + return true; + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java new file mode 100644 index 0000000000..193ba98283 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.wire; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceRuntimeException; + +/** + * An interceptor to transform data across databindings on the wire + * + * @version $Rev: 643467 $ $Date: 2008-04-01 08:12:08 -0800 (Tue, 01 Apr 2008) $ + */ +public class DataTransformationInterceptor implements Interceptor, DataExchangeSemantics { + private Invoker next; + + private Operation sourceOperation; + + private Operation targetOperation; + private RuntimeWire wire; + private Mediator mediator; + private FaultExceptionMapper faultExceptionMapper; + + public DataTransformationInterceptor(RuntimeWire wire, + Operation sourceOperation, + Operation targetOperation, + Mediator mediator, + FaultExceptionMapper faultExceptionMapper) { + super(); + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + this.mediator = mediator; + this.wire = wire; + this.faultExceptionMapper = faultExceptionMapper; + } + + public Invoker getNext() { + return next; + } + + public Message invoke(Message msg) { + Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false); + msg.setBody(input); + Message resultMsg = next.invoke(msg); + Object result = resultMsg.getBody(); + if (sourceOperation.isNonBlocking()) { + // Not to reset the message body + return resultMsg; + } + + // FIXME: Should we fix the Operation model so that getOutputType + // returns DataType>? + DataType targetType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + + DataType sourceType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + + if (resultMsg.isFault()) { + + // FIXME: We need to figure out what fault type it is and then + // transform it + // back the source fault type + // throw new InvocationRuntimeException((Throwable) result); + + if ((result instanceof Exception) && !(result instanceof RuntimeException)) { + // FIXME: How to match fault data to a fault type for the + // operation? + + // If the result is from an InvocationTargetException look at + // the actual cause. + if (result instanceof InvocationTargetException) { + result = ((InvocationTargetException)result).getCause(); + } + DataType targetDataType = null; + for (DataType exType : targetOperation.getFaultTypes()) { + if (((Class)exType.getPhysical()).isInstance(result)) { + if (result instanceof FaultException) { + DataType faultType = (DataType)exType.getLogical(); + if (((FaultException)result).isMatchingType(faultType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + /* + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + */ + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable) result; + throw new ServiceRuntimeException(cause); + } + + // FIXME: How to match a source fault type to a target fault + // type? + DataType sourceDataType = null; + DataType sourceFaultType = null; + for (DataType exType : sourceOperation.getFaultTypes()) { + DataType faultType = getFaultType(exType); + // Match by the QName (XSD element) of the fault type + if (faultType != null && typesMatch(targetFaultType.getLogical(), faultType.getLogical())) { + sourceDataType = exType; + sourceFaultType = faultType; + break; + } + } + + if (sourceFaultType == null) { + // No matching fault type, it's a system exception + Throwable cause = (Throwable) result; + throw new ServiceRuntimeException(cause); + } + + Object newResult = + transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType); + if (newResult != result) { + resultMsg.setFaultBody(newResult); + } + } + + } else { + assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; + + Object newResult = transform(result, targetType, sourceType, true); + if (newResult != result) { + resultMsg.setBody(newResult); + } + } + + return resultMsg; + } + + private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", isResponse ? targetOperation : sourceOperation); + metadata.put("target.operation", isResponse ? sourceOperation : targetOperation); + metadata.put("wire", wire); + return mediator.mediate(source, sourceType, targetType, metadata); + } + + private DataType getFaultType(DataType exceptionType) { + return exceptionType == null ? null : (DataType)exceptionType.getLogical(); + } + + private boolean typesMatch(Object first, Object second) { + if (first.equals(second)) { + return true; + } + if (first instanceof XMLType && second instanceof XMLType) { + XMLType t1 = (XMLType)first; + XMLType t2 = (XMLType)second; + return matches(t1.getElementName(), t2.getElementName()) || matches(t1.getTypeName(), t2.getTypeName()); + } + return false; + } + + /** + * @param qn1 + * @param qn2 + */ + private boolean matches(QName qn1, QName qn2) { + if (qn1 == qn2) { + return true; + } + if (qn1 == null || qn2 == null) { + return false; + } + String ns1 = qn1.getNamespaceURI(); + String ns2 = qn2.getNamespaceURI(); + String e1 = qn1.getLocalPart(); + String e2 = qn2.getLocalPart(); + if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") || ns2.equals(ns1 + "/"))) { + // Tolerating the trailing / which is required by JAX-WS java package --> xml ns mapping + return true; + } + return false; + } + + /** + * @param source The source exception + * @param sourceExType The data type for the source exception + * @param targetExType The data type for the target exception + * @param sourceType The fault type for the source + * @param targetType The fault type for the target + * @return + */ + private Object transformException(Object source, + DataType sourceExType, + DataType targetExType, + DataType sourceType, + DataType targetType) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", targetOperation); + metadata.put("target.operation", sourceOperation); + metadata.put("wire", wire); + DataType eSourceDataType = + new DataTypeImpl("idl:fault", sourceExType.getPhysical(), sourceType); + DataType eTargetDataType = + new DataTypeImpl("idl:fault", targetExType.getPhysical(), targetType); + + return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata); + } + + public void setNext(Invoker next) { + this.next = next; + } + + public boolean allowsPassByReference() { + return true; + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java new file mode 100644 index 0000000000..3e0741d0a7 --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.databinding.wire; + +import java.io.Serializable; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +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.invocation.Message; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of an interceptor that enforces pass-by-value semantics + * on operation invocations by copying the operation input and output data. + * + * @version $Rev: 639276 $ $Date: 2008-03-20 05:02:00 -0800 (Thu, 20 Mar 2008) $ + */ +public class PassByValueInterceptor implements Interceptor { + + private DataBindingExtensionPoint dataBindings; + private FaultExceptionMapper faultExceptionMapper; + + private DataBinding[] inputDataBindings; + private DataBinding outputDataBinding; + private DataBinding javaBeanDataBinding; + private DataBinding jaxbDataBinding; + private Operation operation; + private Invoker nextInvoker; + private InvocationChain chain; + + /** + * Constructs a new PassByValueInterceptor. + * @param dataBindings databinding extension point + * @param operation the intercepted operation + */ + public PassByValueInterceptor(DataBindingExtensionPoint dataBindings, + FaultExceptionMapper faultExceptionMapper, + InvocationChain chain, + Operation operation) { + this.chain = chain; + this.operation = operation; + + // Cache data bindings to use + this.dataBindings = dataBindings; + this.faultExceptionMapper = faultExceptionMapper; + + jaxbDataBinding = dataBindings.getDataBinding(JAXBDataBinding.NAME); + javaBeanDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME); + + // Determine the input databindings + if (operation.getInputType() != null) { + List inputTypes = operation.getInputType().getLogical(); + inputDataBindings = new DataBinding[inputTypes.size()]; + int i = 0; + for (DataType inputType : inputTypes) { + String id = inputType.getDataBinding(); + inputDataBindings[i++] = dataBindings.getDataBinding(id); + } + } + + // Determine the output databinding + if (operation.getOutputType() != null) { + String id = operation.getOutputType().getDataBinding(); + outputDataBinding = dataBindings.getDataBinding(id); + } + } + + public Message invoke(Message msg) { + if (chain.allowsPassByReference()) { + return nextInvoker.invoke(msg); + } + + msg.setBody(copy((Object[])msg.getBody(), inputDataBindings)); + + Message resultMsg = nextInvoker.invoke(msg); + + if (!msg.isFault() && operation.getOutputType() != null) { + resultMsg.setBody(copy(resultMsg.getBody(), outputDataBinding)); + } + + if (msg.isFault()) { + msg.setFaultBody(copyFault(msg.getBody())); + } + return resultMsg; + } + + private Object copyFault(Object fault) { + if (faultExceptionMapper == null) { + return fault; + } + Throwable ex = (Throwable)fault; + DataType exType = + new DataTypeImpl(ex.getClass(), new DataTypeImpl(ex.getClass(), XMLType.UNKNOWN)); + faultExceptionMapper.introspectFaultDataType(exType); + DataType faultType = exType.getLogical(); + Object faultInfo = faultExceptionMapper.getFaultInfo(ex, faultType.getPhysical()); + faultInfo = copy(faultInfo, dataBindings.getDataBinding(faultType.getDataBinding())); + fault = faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause()); + return fault; + } + + /** + * Copy an array of data objects passed to an operation + * @param data array of objects to copy + * @return the copy + */ + private Object[] copy(Object[] data, DataBinding[] dataBindings) { + if (data == null) { + return null; + } + Object[] copy = new Object[data.length]; + Map map = new IdentityHashMap(); + for (int i = 0; i < data.length; i++) { + Object arg = data[i]; + if (arg == null) { + copy[i] = null; + } else { + Object copiedArg = map.get(arg); + if (copiedArg != null) { + copy[i] = copiedArg; + } else { + copiedArg = copy(arg, dataBindings[i]); + map.put(arg, copiedArg); + copy[i] = copiedArg; + } + } + } + return copy; + } + + /** + * Copy data using the specified databinding. + * @param data input data + * @param dataBinding databinding to use + * @return a copy of the data + */ + private Object copy(Object data, DataBinding dataBinding) { + if (data == null) { + return null; + } + + // If no databinding was specified, introspect the given arg to + // determine its databinding + if (dataBinding == null) { + DataType dataType = dataBindings.introspectType(data); + if (dataType != null) { + String db = dataType.getDataBinding(); + dataBinding = dataBindings.getDataBinding(db); + if (dataBinding == null && db != null) { + return data; + } + } + if (dataBinding == null) { + + // Default to the JavaBean databinding + dataBinding = javaBeanDataBinding; + } + } + + // Use the JAXB databinding to copy non-Serializable data + if (dataBinding == javaBeanDataBinding) { + + // If the input data is an array containing non Serializable elements + // use JAXB + Class clazz = data.getClass(); + if (clazz.isArray()) { + if (Array.getLength(data) != 0) { + Object element = Array.get(data, 0); + if (element != null && !(element instanceof Serializable)) { + dataBinding = jaxbDataBinding; + } + } + } else { + + // If the input data is not Serializable use JAXB + if (!(data instanceof Serializable)) { + dataBinding = jaxbDataBinding; + } + + if (data instanceof Cloneable) { + Method clone; + try { + clone = data.getClass().getMethod("clone", (Class[])null); + try { + return clone.invoke(data, (Object[])null); + } catch (InvocationTargetException e) { + if (e.getTargetException() instanceof CloneNotSupportedException) { + // Ignore + } else { + throw new ServiceRuntimeException(e); + } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } catch (NoSuchMethodException e) { + // Ignore it + } + } + } + } + + Object copy = dataBinding.copy(data); + return copy; + } + + public Invoker getNext() { + return nextInvoker; + } + + public void setNext(Invoker next) { + this.nextInvoker = next; + } + +} diff --git a/sandbox/mobile-android/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sandbox/mobile-android/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..baba638c9b --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.core.databinding.module.DataBindingModuleActivator diff --git a/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..ea08166dfe --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.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 org.apache.tuscany.sca.core.databinding.processor; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.osoa.sca.annotations.Remotable; +import org.w3c.dom.Node; + +/** + * + */ +public class DataBindingJavaInterfaceProcessorTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + } + + /** + * @throws InvalidServiceContractException + */ + public final void testVisitInterface() throws InvalidInterfaceException { + DataBindingExtensionPoint registry = new DefaultDataBindingExtensionPoint(); + DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + + JavaInterface contract = javaFactory.createJavaInterface(); + contract.setJavaClass(MockInterface.class); + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(contract); + Operation operation = newOperation("call"); + Operation operation1 = newOperation("call1"); + contract.getOperations().add(operation); + contract.getOperations().add(operation1); + contract.setRemotable(true); + processor.visitInterface(contract); + // Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding()); + // Assert.assertEquals("org.w3c.dom.Node", + // contract.getOperations().get("call").getDataBinding()); + // Assert.assertEquals("xml:string", + // contract.getOperations().get("call1").getDataBinding()); + } + + @DataBinding("org.w3c.dom.Node") + @Remotable + public static interface MockInterface { + Node call(Node msg); + + @DataBinding("xml:string") + String call1(String msg); + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme b/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme new file mode 100644 index 0000000000..be2f3fe7cb --- /dev/null +++ b/sandbox/mobile-android/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.core.databinding.transformers; + +import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT; +import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl; +import org.apache.tuscany.databinding.impl.MediatorImpl; +import org.apache.tuscany.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.databinding.impl.TransformerRegistryImpl; +import org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer; +import org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer; +import org.apache.tuscany.databinding.xml.DOMDataBinding; +import org.apache.tuscany.databinding.xml.Node2String; +import org.apache.tuscany.databinding.xml.String2Node; +import org.apache.tuscany.interfacedef.DataType; +import org.apache.tuscany.interfacedef.Operation; +import org.apache.tuscany.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.interfacedef.impl.OperationImpl; +import org.apache.tuscany.interfacedef.util.ElementInfo; +import org.apache.tuscany.interfacedef.util.TypeInfo; +import org.apache.tuscany.interfacedef.util.WrapperInfo; +import org.apache.tuscany.interfacedef.util.XMLType; +import org.apache.tuscany.spi.databinding.DataBindingRegistry; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class IDLTransformerTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private static final String URI_ORDER_XSD = "http://example.com/order.xsd"; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + List types0 = new ArrayList(); + DataType wrapperType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, + "checkOrderStatus"), null)); + types0.add(wrapperType); + DataType> inputType0 = new DataTypeImpl>(IDL_INPUT, + Object[].class, types0); + + List types1 = new ArrayList(); + DataType customerIdType = new DataTypeImpl( + null, + Object.class, + new XMLType( + new QName(URI_ORDER_XSD, "customerId"), + null)); + DataType orderType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, "order"), null)); + DataType flagType = new DataTypeImpl(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, + "flag"), null)); + types1.add(customerIdType); + types1.add(orderType); + types1.add(flagType); + + DataType statusType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, "status"), null)); + DataType responseType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, + "checkOrderStatusResponse"), + null)); + + Operation op = new OperationImpl("checkOrderStatus"); + op.setInputType(inputType0); + op.setOutputType(responseType); +// op.setDataBinding(DOMDataBinding.NAME); +// +// inputType0.setOperation(op); + op.setWrapperStyle(true); + ElementInfo inputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null, + false, + null)); +// wrapperType.setMetadata(ElementInfo.class.getName(), inputElement); + + ElementInfo customerId = new ElementInfo(new QName("", "customerId"), + SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string")); + ElementInfo order = new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null)); + ElementInfo flag = new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int")); + +// customerIdType.setMetadata(ElementInfo.class.getName(), customerId); +// orderType.setMetadata(ElementInfo.class.getName(), order); +// flagType.setMetadata(ElementInfo.class.getName(), flag); +// +// customerIdType.setOperation(op); +// orderType.setOperation(op); +// flagType.setOperation(op); + + List inputElements = new ArrayList(); + inputElements.add(customerId); + inputElements.add(order); + inputElements.add(flag); + + ElementInfo statusElement = new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES + .get("string")); + +// statusType.setMetadata(ElementInfo.class.getName(), statusElement); +// statusType.setOperation(op); + + List outputElements = new ArrayList(); + outputElements.add(statusElement); + + ElementInfo outputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), + new TypeInfo(null, false, null)); + +// responseType.setMetadata(ElementInfo.class.getName(), inputElement); +// responseType.setOperation(op); + + WrapperInfo wrapperInfo = new WrapperInfo(DOMDataBinding.NAME, inputElement, outputElement, inputElements, + outputElements); + op.setWrapper(wrapperInfo); +// op.setDataBinding(DOMDataBinding.NAME); + + MediatorImpl m = new MediatorImpl(); + TransformerRegistryImpl tr = new TransformerRegistryImpl(); + tr.registerTransformer(new String2Node()); + tr.registerTransformer(new Node2String()); + tr.registerTransformer(new DOMNode2JavaBeanTransformer()); + tr.registerTransformer(new JavaBean2DOMNodeTransformer()); + m.setTransformerRegistry(tr); + DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl(); + dataBindingRegistry.register(new DOMDataBinding()); + m.setDataBindingRegistry(dataBindingRegistry); + + Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)}; + Input2InputTransformer t = new Input2InputTransformer(); + t.setMediator(m); + + TransformationContext context = new TransformationContextImpl(); + context.setSourceOperation(op); + List> types = new ArrayList>(); + types.add(new DataTypeImpl(Object.class.getName(), String.class, String.class)); + types.add(new DataTypeImpl("java.lang.String", String.class, String.class)); + types.add(new DataTypeImpl(Object.class.getName(), int.class, int.class)); + DataType>> inputType1 = new DataTypeImpl>>(IDL_INPUT, Object[].class, + types); + context.setSourceDataType(inputType1); + context.setTargetDataType(op.getInputType()); + Object[] results = t.transform(source, context); + assertEquals(1, results.length); + assertTrue(results[0] instanceof Element); + Element element = (Element)results[0]; + assertEquals("http://example.com/order.xsd", element.getNamespaceURI()); + assertEquals("checkOrderStatus", element.getLocalName()); + + TransformationContext context1 = new TransformationContextImpl(); + DataType sourceType = new DataTypeImpl(IDL_OUTPUT, Object.class, op.getOutputType()); + + context1.setSourceDataType(sourceType); + DataType targetType = new DataTypeImpl(IDL_OUTPUT, Object.class, + new DataTypeImpl("java.lang.Object", + String.class, String.class)); + context1.setTargetDataType(targetType); + + Document factory = DOMHelper.newDocument(); + Element responseElement = factory + .createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse"); + Element status = factory.createElement("status"); + responseElement.appendChild(status); + status.appendChild(factory.createTextNode("shipped")); + Output2OutputTransformer t2 = new Output2OutputTransformer(); + t2.setMediator(m); + Object st = t2.transform(responseElement, context1); + assertEquals("shipped", st); + + } + +} diff --git a/sandbox/mobile-android/interface-java-jaxws/.classpath b/sandbox/mobile-android/interface-java-jaxws/.classpath new file mode 100644 index 0000000000..c86b7b792b --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/.classpath @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/mobile-android/interface-java-jaxws/.project b/sandbox/mobile-android/interface-java-jaxws/.project new file mode 100644 index 0000000000..51f13aaddc --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/.project @@ -0,0 +1,38 @@ + + + tuscany-interface-java-jaxws + Parent POM defining settings that can be used across Tuscany + + tuscany-core-spi + tuscany-extensibility + tuscany-sca-api + tuscany-assembly + tuscany-policy + tuscany-interface + tuscany-definitions + tuscany-contribution + tuscany-databinding-jaxb + tuscany-databinding + tuscany-core + tuscany-contribution-java + tuscany-interface-java + tuscany-interface-java-xml + tuscany-assembly-xml + tuscany-contribution-namespace + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder (82).launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/mobile-android/interface-java-jaxws/DISCLAIMER b/sandbox/mobile-android/interface-java-jaxws/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sandbox/mobile-android/interface-java-jaxws/LICENSE b/sandbox/mobile-android/interface-java-jaxws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sandbox/mobile-android/interface-java-jaxws/NOTICE b/sandbox/mobile-android/interface-java-jaxws/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/mobile-android/interface-java-jaxws/pom.xml b/sandbox/mobile-android/interface-java-jaxws/pom.xml new file mode 100644 index 0000000000..e8d83e816e --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/pom.xml @@ -0,0 +1,188 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-incubating-SNAPSHOT + ../pom.xml + + tuscany-interface-java-jaxws + Apache Tuscany Java Interface for JAXWS + + + + org.apache.tuscany.sca + tuscany-core-spi + 2.0-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding-jaxb + 2.0-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 2.0-incubating-SNAPSHOT + + + + junit + junit + 4.2 + test + + + + javax.xml.ws + jaxws-api + 2.1 + + + + + + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + java.net2 + java.net Maven 2.x Repository + http://download.java.net/maven/2 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djava.endorsed.dirs=target/endorsed + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + generate-sources + + copy + + + + + javax.xml.ws + jaxws-api + 2.1 + jar + + + javax.xml.bind + jaxb-api + 2.1 + jar + + + ${project.build.directory}/endorsed + false + true + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxws-source + + + + + + + org.codehaus.mojo + jaxws-maven-plugin + 1.9 + + + process-resources + + wsimport + + + + + com.example.stock + ${basedir}/src/test/resources/wsdl + + + StockExceptionTest.wsdl + + ${project.build.directory}/jaxws-source + false + true + + + + + + + diff --git a/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java b/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java new file mode 100644 index 0000000000..dbbc7b4635 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSFaultExceptionMapper.java @@ -0,0 +1,253 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java.jaxws; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.ServiceRuntimeException; + +/** + * JAX-WS ExceptionHandler + * + * @version $Rev: 639821 $ $Date: 2008-03-21 12:42:37 -0800 (Fri, 21 Mar 2008) $ + */ +public class JAXWSFaultExceptionMapper implements FaultExceptionMapper { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private DataBindingExtensionPoint dataBindingExtensionPoint; + + public JAXWSFaultExceptionMapper(DataBindingExtensionPoint dataBindingExtensionPoint) { + super(); + this.dataBindingExtensionPoint = dataBindingExtensionPoint; + } + + /** + * The following is quoted from the JAX-WS Specification v2.1 + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + @SuppressWarnings("unchecked") + public Throwable wrapFaultInfo(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = exceptionType.getPhysical(); + if (exceptionClass.isInstance(faultInfo)) { + return (Throwable)faultInfo; + } + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = faultBeanType.getPhysical(); + try { + Exception exc = null; + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + exc = (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (NoSuchMethodException e) { + // Create a generic fault exception + exc = new FaultException(message, faultInfo, cause); + } + // Include the elem name into the FaultException we build so it can be used for matching in the DataTransformationInterceptor + // + // Note this may happen even if we find a constructor above, that is the type of the non-generic fault exc may be an instance + // of FaultException + // + if ((exc instanceof FaultException) && (faultBeanType.getLogical() instanceof XMLType)) { + FaultException faultExc = (FaultException)exc; + DataType faultBeanXMLType = (DataType)faultBeanType; + XMLType faultLogical = faultBeanXMLType.getLogical(); + faultExc.setFaultName(faultLogical.getElementName()); + } + return exc; + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Throwable exception, Class faultBeanClass) { + if (exception == null) { + return null; + } + + // Check if it's the generic FaultException + if (exception instanceof FaultException) { + return ((FaultException)exception).getFaultInfo(); + } + + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (NoSuchMethodException e) { + // Follow the JAX-WS v2.1 Specification section 3.7 + return createFaultBean(exception, faultBeanClass); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + private Object createFaultBean(Throwable exception, Class faultBeanClass) { + /** + * For each getter in the exception and its superclasses, a property of the same + * type and name is added to the bean. The getCause, getLocalizedMessage and + * getStackTrace getters from java.lang.Throwable and the getClass getter from + * java.lang.Object are excluded from the list of getters to be mapped. + */ + // Return the exception as-is if it's already the fault bean + if (faultBeanClass.isInstance(exception)) { + return exception; + } + try { + Object faultBean = null; + for (Constructor ctor : faultBeanClass.getConstructors()) { + Class[] params = ctor.getParameterTypes(); + if (params.length == 1 && String.class == params[0]) { + faultBean = ctor.newInstance(exception.getMessage()); + } else if (params.length == 2 && String.class == params[0] + && Throwable.class.isAssignableFrom(params[1])) { + faultBean = ctor.newInstance(exception.getMessage(), exception); + } else if (params.length == 0) { + faultBean = ctor.newInstance(); + } + if (faultBean != null) { + break; + } + } + if (faultBean == null) { + return exception; + } + BeanInfo beanInfo = Introspector.getBeanInfo(exception.getClass()); + for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { + Method getter = pd.getReadMethod(); + String name = getter.getName(); + if ("getClass".equals(name) || "getStackTrace".equals(name) + || "getCause".equals(name) + || "getLocalizedMessage".equals(name)) { + continue; + } + String prefix = "get"; + if (name.startsWith("get")) { + prefix = "get"; + } else if (name.startsWith("is")) { + prefix = "is"; + } + Method setter = null; + try { + setter = + faultBeanClass.getMethod("set" + name.substring(prefix.length()), new Class[] {getter + .getReturnType()}); + } catch (NoSuchMethodException e) { + continue; + } + Object prop = setter.invoke(faultBean, getter.invoke(exception, (Object[])null)); + setter.invoke(faultBean, prop); + } + return faultBean; + } catch (Throwable ex) { + throw new IllegalArgumentException(ex); + } + } + + @SuppressWarnings("unchecked") + public boolean introspectFaultDataType(DataType exceptionType) { + QName faultName = null; + boolean result = false; + + Class cls = exceptionType.getPhysical(); + if (cls == FaultException.class) { + return true; + } + DataType faultType = (DataType)exceptionType.getLogical(); + Class faultBean = null; + WebFault fault = cls.getAnnotation(WebFault.class); + if (fault != null) { + faultName = new QName(fault.targetNamespace(), fault.name()); + XMLType xmlType = new XMLType(faultName, null); + faultType.setLogical(xmlType); + if (!"".equals(fault.faultBean())) { + try { + faultBean = Class.forName(fault.faultBean(), false, cls.getClassLoader()); + } catch (ClassNotFoundException e) { + throw new ServiceRuntimeException(e); + } + } else { + Method m; + try { + m = cls.getMethod("getFaultInfo", (Class[])null); + faultBean = m.getReturnType(); + } catch (NoSuchMethodException e) { + // Ignore + } + } + } + + if (faultBean == null) { + String faultBeanClassName = cls.getPackage().getName() + ".jaxws." + cls.getSimpleName() + "Bean"; + try { + faultBean = Class.forName(faultBeanClassName, false, cls.getClassLoader()); + } catch (ClassNotFoundException e) { + faultBean = cls; + } + } + + faultType.setPhysical(faultBean); + // TODO: Use the databinding framework to introspect the fault bean class + if (dataBindingExtensionPoint != null) { + result = + dataBindingExtensionPoint.introspectType(faultType, null, Throwable.class.isAssignableFrom(faultBean)); + } + + /* + The introspection of the fault DT may not have calculated the correct element name, + though we may have already done this in this method. Let's look at the DataType now + that introspection is done, and, if it has an XMLType, let's set the element to the + 'faultName' if we calculated one. + */ + if ((faultName != null) && (faultType.getLogical() instanceof XMLType)) { + XMLType faultTypeXML = (XMLType)faultType.getLogical(); + // The element name (if set) should match the fault name + faultTypeXML.setElementName(faultName); + } + + return result; + } + + public void setDataBindingExtensionPoint(DataBindingExtensionPoint dataBindingExtensionPoint) { + this.dataBindingExtensionPoint = dataBindingExtensionPoint; + } + +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java b/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..f25425f286 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessor.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java.jaxws; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/*import javax.jws.Oneway; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.jws.soap.SOAPBinding.Style;*/ +import javax.xml.namespace.QName; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +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.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Introspect the java class/interface with JSR-181 and JAXWS annotations + * + * @version $Rev: 643696 $ $Date: 2008-04-01 19:24:11 -0800 (Tue, 01 Apr 2008) $ + */ +public class JAXWSJavaInterfaceProcessor implements JavaInterfaceVisitor { + private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement"; + private FaultExceptionMapper faultExceptionMapper; + + public JAXWSJavaInterfaceProcessor(FaultExceptionMapper faultExceptionMapper) { + super(); + this.faultExceptionMapper = faultExceptionMapper; + } + + public JAXWSJavaInterfaceProcessor() { + super(); + } + + public void visitInterface(JavaInterface contract) throws InvalidInterfaceException { + + Class clazz = contract.getJavaClass(); + //WebService webService = clazz.getAnnotation(WebService.class); + String tns = JavaInterfaceUtil.getNamespace(clazz); + //if (webService != null) { + // tns = getValue(webService.targetNamespace(), tns); + // Mark SEI as Remotable + //contract.setRemotable(true); + //} + if (!contract.isRemotable()) { + return; + } + + // SOAP binding (doc/lit/wrapped|bare or rpc/lit) + //SOAPBinding soapBinding = clazz.getAnnotation(SOAPBinding.class); + + for (Iterator it = contract.getOperations().iterator(); it.hasNext();) { + JavaOperation operation = (JavaOperation)it.next(); + Method method = operation.getJavaMethod(); + introspectFaultTypes(operation); + + // SOAP binding (doc/lit/wrapped|bare or rpc/lit) + //SOAPBinding methodSOAPBinding = method.getAnnotation(SOAPBinding.class); + //if (methodSOAPBinding == null) { + // methodSOAPBinding = soapBinding; + //} + + boolean documentStyle = true; + boolean bare = false; + //if (methodSOAPBinding != null) { + // bare = methodSOAPBinding.parameterStyle() == SOAPBinding.ParameterStyle.BARE; + // For BARE parameter style, the data is in the wrapped format already + // operation.setWrapperStyle(bare); + //documentStyle = methodSOAPBinding.style() == Style.DOCUMENT; + //} + + String operationName = operation.getName(); + // WebMethod + //WebMethod webMethod = method.getAnnotation(WebMethod.class); + //if (webMethod != null) { + // if (webMethod.exclude()) { + // Exclude the method + // it.remove(); + // continue; + //} + //operationName = getValue(webMethod.operationName(), operationName); + //operation.setName(operationName); + //} + + // Is one way? + /*Oneway oneway = method.getAnnotation(Oneway.class); + if (oneway != null) { + // JSR 181 + assert method.getReturnType() == void.class; + operation.setNonBlocking(true); + }*/ + + // Handle BARE mapping + if (bare) { + for (int i = 0; i < method.getParameterTypes().length; i++) { + /*WebParam param = getAnnotation(method, i, WebParam.class); + if (param != null) { + String ns = getValue(param.targetNamespace(), tns); + // Default to for doc-bare + String name = getValue(param.name(), documentStyle ? operationName : "arg" + i); + QName element = new QName(ns, name); + Object logical = operation.getInputType().getLogical().get(i).getLogical(); + if (logical instanceof XMLType) { + ((XMLType)logical).setElementName(element); + } + }*/ + } + /* WebResult result = method.getAnnotation(WebResult.class); + if (result != null) { + String ns = getValue(result.targetNamespace(), tns); + // Default to Response for doc-bare + String name = getValue(result.name(), documentStyle ? operationName + "Response" : "return"); + QName element = new QName(ns, name); + Object logical = operation.getOutputType().getLogical(); + if (logical instanceof XMLType) { + ((XMLType)logical).setElementName(element); + } + }*/ + // FIXME: [rfeng] For the BARE mapping, do we need to create a Wrapper? + // it's null at this point + } else { + + RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class); + String ns = requestWrapper == null ? tns : getValue(requestWrapper.targetNamespace(), tns); + String name = + requestWrapper == null ? operationName : getValue(requestWrapper.localName(), operationName); + QName inputWrapper = new QName(ns, name); + + ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class); + ns = responseWrapper == null ? tns : getValue(responseWrapper.targetNamespace(), tns); + name = + responseWrapper == null ? operationName + "Response" : getValue(responseWrapper.localName(), + operationName + "Response"); + QName outputWrapper = new QName(ns, name); + + List inputElements = new ArrayList(); + for (int i = 0; i < method.getParameterTypes().length; i++) { +// WebParam param = getAnnotation(method, i, WebParam.class); + ns = /*param != null ? param.targetNamespace() :*/ ""; + // Default to "" for doc-lit-wrapped && non-header + ns = getValue(ns, documentStyle && (/*param == null || !param.header()*/ true) ? "" : tns); + name = /*param != null ? param.name() :*/ ""; + name = getValue(name, "arg" + i); + QName element = new QName(ns, name); + Object logical = operation.getInputType().getLogical().get(i).getLogical(); + if (logical instanceof XMLType) { + ((XMLType)logical).setElementName(element); + } + inputElements.add(new ElementInfo(element, null)); + } + + List outputElements = new ArrayList(); + //WebResult result = method.getAnnotation(WebResult.class); + // Default to "" for doc-lit-wrapped && non-header + ns = /*result != null ? result.targetNamespace() :*/ ""; + ns = getValue(ns, documentStyle && (/*result == null || !result.header()*/true) ? "" : tns); + name = /*result != null ? result.name() :*/ ""; + name = getValue(name, "return"); + QName element = new QName(ns, name); + + if (operation.getOutputType() != null) { + Object logical = operation.getOutputType().getLogical(); + if (logical instanceof XMLType) { + ((XMLType)logical).setElementName(element); + } + } + outputElements.add(new ElementInfo(element, null)); + + WrapperInfo wrapperInfo = + new WrapperInfo(JAXB_DATABINDING, new ElementInfo(inputWrapper, null), + new ElementInfo(outputWrapper, null), inputElements, outputElements); + operation.setWrapper(wrapperInfo); + } + } + } + + @SuppressWarnings("unchecked") + private void introspectFaultTypes(Operation operation) { + for (DataType exceptionType : operation.getFaultTypes()) { + faultExceptionMapper.introspectFaultDataType(exceptionType); + } + } + + private T getAnnotation(Method method, int index, Class annotationType) { + Annotation[] annotations = method.getParameterAnnotations()[index]; + for (Annotation annotation : annotations) { + if (annotation.annotationType() == annotationType) { + return annotationType.cast(annotation); + } + } + return null; + } + + private static String getValue(String value, String defaultValue) { + return "".equals(value) ? defaultValue : value; + } + +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean.java new file mode 100644 index 0000000000..9a31cb6127 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.jaxws; + +public interface Bean { + T getP1(); +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean1.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean1.java new file mode 100644 index 0000000000..b41ff14af0 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean1.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 org.apache.tuscany.sca.interfacedef.java.jaxws; + +public class Bean1 { + private String p1; + private int p2; + public String getP1() { + return p1; + } + public void setP1(String p1) { + this.p1 = p1; + } + public int getP2() { + return p2; + } + public void setP2(int p2) { + this.p2 = p2; + } +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean2.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean2.java new file mode 100644 index 0000000000..34c8d2c67d --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/Bean2.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 org.apache.tuscany.sca.interfacedef.java.jaxws; + +public class Bean2 implements Bean{ + private String p1; + private int p2; + public String getP1() { + return p1; + } + public void setP1(String p1) { + this.p1 = p1; + } + public int getP2() { + return p2; + } + public void setP2(int p2) { + this.p2 = p2; + } +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..7e4114d854 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/JAXWSJavaInterfaceProcessorTestCase.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 org.apache.tuscany.sca.interfacedef.java.jaxws; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; + +/** + * + */ +public class JAXWSJavaInterfaceProcessorTestCase extends TestCase { + private JAXWSJavaInterfaceProcessor interfaceProcessor; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + interfaceProcessor = new JAXWSJavaInterfaceProcessor(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor#visitInterface(JavaInterface)}. + */ + public final void testProcessor() throws Exception { + DefaultJavaInterfaceFactory iFactory = new DefaultJavaInterfaceFactory(); + JavaInterface contract = iFactory.createJavaInterface(WebServiceInterfaceWithoutAnnotation.class); + + interfaceProcessor.visitInterface(contract); + assertFalse(contract.isRemotable()); + + contract = iFactory.createJavaInterface(WebServiceInterfaceWithAnnotation.class); + interfaceProcessor.visitInterface(contract); + assertTrue(contract.isRemotable()); + + Operation op1 = contract.getOperations().get(0); + Operation op2 = contract.getOperations().get(1); + + Operation op = null; + if ("m1".equals(op1.getName())) { + op = op1; + } else { + op = op2; + } + + assertTrue(op.isWrapperStyle()); + + if ("M2".equals(op2.getName())) { + op = op2; + } else { + op = op1; + } + assertTrue(!op2.isWrapperStyle() && op2.getWrapper() != null); + + } + + @WebService + private static interface WebServiceInterfaceWithAnnotation { + + @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) + @WebMethod(operationName = "m1") + String m1(String str); + + @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) + @WebMethod(operationName = "M2") + String m2(String str, int i); + } + + private static interface WebServiceInterfaceWithoutAnnotation { + + } +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyException.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyException.java new file mode 100644 index 0000000000..b0478f6c71 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java.jaxws; + +public class MyException extends Exception { + private String error; + + public MyException() { + super(); + } + + public MyException(String message, Throwable cause) { + super(message, cause); + } + + public MyException(String message) { + super(message); + } + + public MyException(Throwable cause) { + super(cause); + } + + public String getError() { + return error; + } + + public void setError(String error) { + this.error = error; + } + +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyServiceImpl.java b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyServiceImpl.java new file mode 100644 index 0000000000..9597cd892b --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/MyServiceImpl.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 org.apache.tuscany.sca.interfacedef.java.jaxws; + +import java.util.List; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +/** + * @version $Rev: 639350 $ $Date: 2008-03-20 08:43:46 -0800 (Thu, 20 Mar 2008) $ + */ +@WebService +public class MyServiceImpl { + + public MyServiceImpl() { + super(); + } + + @WebMethod + public T getBean(T b, Bean2 b2) { + return null; + } + + @WebMethod + public List getBeans() { + return null; + } + + @WebMethod + public String convert(String str, int i) throws MyException { + return "ME"; + } + +} diff --git a/sandbox/mobile-android/interface-java-jaxws/src/test/resources/wsdl/StockExceptionTest.wsdl b/sandbox/mobile-android/interface-java-jaxws/src/test/resources/wsdl/StockExceptionTest.wsdl new file mode 100644 index 0000000000..87f75cca39 --- /dev/null +++ b/sandbox/mobile-android/interface-java-jaxws/src/test/resources/wsdl/StockExceptionTest.wsdl @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/mobile-android/interface-java/.classpath b/sandbox/mobile-android/interface-java/.classpath new file mode 100644 index 0000000000..553679d82e --- /dev/null +++ b/sandbox/mobile-android/interface-java/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/mobile-android/interface-java/.project b/sandbox/mobile-android/interface-java/.project new file mode 100644 index 0000000000..370a7e03b7 --- /dev/null +++ b/sandbox/mobile-android/interface-java/.project @@ -0,0 +1,29 @@ + + + tuscany-interface-java + Parent POM defining settings that can be used across Tuscany + + tuscany-assembly + tuscany-policy + tuscany-extensibility + tuscany-interface + tuscany-definitions + tuscany-contribution + tuscany-sca-api + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.jdt.core.javabuilder (81).launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/mobile-android/interface-java/DISCLAIMER b/sandbox/mobile-android/interface-java/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sandbox/mobile-android/interface-java/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sandbox/mobile-android/interface-java/LICENSE b/sandbox/mobile-android/interface-java/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sandbox/mobile-android/interface-java/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sandbox/mobile-android/interface-java/NOTICE b/sandbox/mobile-android/interface-java/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/sandbox/mobile-android/interface-java/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sandbox/mobile-android/interface-java/pom.xml b/sandbox/mobile-android/interface-java/pom.xml new file mode 100644 index 0000000000..a197b7bd77 --- /dev/null +++ b/sandbox/mobile-android/interface-java/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-incubating-SNAPSHOT + ../pom.xml + + tuscany-interface-java + Apache Tuscany SCA Java Interface Model + + + + org.apache.tuscany.sca + tuscany-extensibility + 2.0-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 2.0-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 2.0-incubating-SNAPSHOT + + + + diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java new file mode 100644 index 0000000000..7c4d6ea400 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java; + +import java.io.IOException; +import java.util.List; +import java.util.Set; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; +import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceFactoryImpl; +import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A factory for the Java interface model. + */ +public class DefaultJavaInterfaceFactory extends JavaInterfaceFactoryImpl implements JavaInterfaceFactory { + private ModelFactoryExtensionPoint modelFactoryExtensionPoint; + private boolean loadedVisitors; + + public DefaultJavaInterfaceFactory() { + } + + public DefaultJavaInterfaceFactory(ModelFactoryExtensionPoint modelFactoryExtensionPoint) { + this.modelFactoryExtensionPoint = modelFactoryExtensionPoint; + } + + @Override + public List getInterfaceVisitors() { + loadVisitors(); + return super.getInterfaceVisitors(); + } + + /** + * Load visitors declared under META-INF/services + */ + @SuppressWarnings("unchecked") + private void loadVisitors() { + if (loadedVisitors) + return; + + if (modelFactoryExtensionPoint != null) { + PolicyFactory policyFactory = modelFactoryExtensionPoint.getFactory(PolicyFactory.class); + if (policyFactory != null) { + addInterfaceVisitor(new PolicyJavaInterfaceVisitor(policyFactory)); + } + } + + // Get the databinding service declarations + Set visitorDeclarations; + try { + visitorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(JavaInterfaceVisitor.class); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load data bindings + for (ServiceDeclaration visitorDeclaration: visitorDeclarations) { + JavaInterfaceVisitor visitor; + try { + Class visitorClass = (Class)visitorDeclaration.loadClass(); + visitor = visitorClass.newInstance(); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } + addInterfaceVisitor(visitor); + } + + loadedVisitors = true; + } + + + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java new file mode 100644 index 0000000000..58297d3746 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.interfacedef.Interface; + +/** + * Represents a Java interface. + * + * @version $Rev: 574428 $ $Date: 2007-09-10 18:01:37 -0800 (Mon, 10 Sep 2007) $ + */ +public interface JavaInterface extends Interface, Base { + + /** + * Returns the name of the Java interface class. + * + * @return the name of the Java interface class + */ + String getName(); + + /** + * Sets the name of the Java interface class. + * + * @param className the name of the Java interface class + */ + void setName(String className); + + /** + * Returns the Java interface class. + * + * @return the Java interface class + */ + Class getJavaClass(); + + /** + * Sets the Java interface class. + * + * @param javaClass the Java interface class + */ + void setJavaClass(Class javaClass); + + /** + * Returns the callback class specified in an @Callback annotation. + * + * @return the callback class specified in an @Callback annotation + */ + Class getCallbackClass(); + + /** + * Sets the callback class specified in an @Callback annotation. + * + * @param callbackClass the callback class specified in an @Callback annotation + */ + void setCallbackClass(Class callbackClass); +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java new file mode 100644 index 0000000000..012834afd9 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * Represents a Java interface contract. + * JavaInterfaceContract + * + * @version $Rev: 537404 $ $Date: 2007-05-12 04:51:42 -0800 (Sat, 12 May 2007) $ + */ +public interface JavaInterfaceContract extends InterfaceContract { + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java new file mode 100644 index 0000000000..0559e7c7f2 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; + +/** + * Factory for the Java interface model + * + * @version $Rev: 564364 $ $Date: 2007-08-09 12:14:52 -0800 (Thu, 09 Aug 2007) $ + */ +public interface JavaInterfaceFactory { + + /** + * Creates a new Java interface model. + * + * @return + */ + JavaInterface createJavaInterface(); + + /** + * Creates a new Java interface model from an interface class. + * @param interfaceClass the interface class to introspect. + * @return + */ + JavaInterface createJavaInterface(Class interfaceClass) throws InvalidInterfaceException; + + /** + * Creates the contents of a Java interface model from an interface class. + * @param javaInterface the Java interface model + * @param interfaceClass the interface class to introspect. + * @return + */ + void createJavaInterface(JavaInterface javaInterface, Class interfaceClass) throws InvalidInterfaceException; + + /** + * Creates a new Java interface contract. + * + * @return + */ + JavaInterfaceContract createJavaInterfaceContract(); + + /** + * Registers the given visitor. + * + * @param visitor + */ + void addInterfaceVisitor(JavaInterfaceVisitor visitor); + + /** + * Deregisters the given visitor. + * + * @param visitor + */ + void removeInterfaceVisitor(JavaInterfaceVisitor visitor); + + /** + * Returns a list of interface visitors. + * + * @return + */ + List getInterfaceVisitors(); +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java new file mode 100644 index 0000000000..e34f109272 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Represents a Java operation. + * + * @version $Rev: 614967 $ $Date: 2008-01-24 12:00:04 -0800 (Thu, 24 Jan 2008) $ + */ +public interface JavaOperation extends Operation { + + /** + * Returns the Java method defining the operation. + * @return the Java method + */ + Method getJavaMethod(); + + /** + * Sets the Java method defining the operation. + * @param method the Java method + */ + void setJavaMethod(Method method); + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java new file mode 100644 index 0000000000..67bf167aa3 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; + +/** + * Represents a Java interface contract. + * + * @version $Rev: 557493 $ $Date: 2007-07-18 21:28:26 -0800 (Wed, 18 Jul 2007) $ + */ +public class JavaInterfaceContractImpl extends InterfaceContractImpl implements JavaInterfaceContract { + + protected JavaInterfaceContractImpl() { + } + + @Override + public JavaInterfaceContractImpl clone() throws CloneNotSupportedException { + return (JavaInterfaceContractImpl) super.clone(); + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java new file mode 100644 index 0000000000..79b76eaa3f --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; + +/** + * A factory for the Java model. + */ +public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory { + + private List visitors = new ArrayList(); + private JavaInterfaceIntrospectorImpl introspector; + + public JavaInterfaceFactoryImpl() { + introspector = new JavaInterfaceIntrospectorImpl(this); + } + + public JavaInterface createJavaInterface() { + return new JavaInterfaceImpl(); + } + + public JavaInterface createJavaInterface(Class interfaceClass) throws InvalidInterfaceException { + JavaInterface javaInterface = createJavaInterface(); + introspector.introspectInterface(javaInterface, interfaceClass); + return javaInterface; + } + + public void createJavaInterface(JavaInterface javaInterface, Class interfaceClass) throws InvalidInterfaceException { + introspector.introspectInterface(javaInterface, interfaceClass); + } + + public JavaInterfaceContract createJavaInterfaceContract() { + return new JavaInterfaceContractImpl(); + } + + public void addInterfaceVisitor(JavaInterfaceVisitor extension) { + visitors.add(extension); + } + + public void removeInterfaceVisitor(JavaInterfaceVisitor extension) { + visitors.remove(extension); + } + + public List getInterfaceVisitors() { + return visitors; + } +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java new file mode 100644 index 0000000000..0ff0e174b5 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; + +/** + * Represents a Java interface. + * + * @version $Rev: 639350 $ $Date: 2008-03-20 08:43:46 -0800 (Thu, 20 Mar 2008) $ + */ +public class JavaInterfaceImpl extends InterfaceImpl implements JavaInterface { + + private String className; + private Class javaClass; + private Class callbackClass; + + protected JavaInterfaceImpl() { + } + + public String getName() { + if (isUnresolved()) { + return className; + } else if (javaClass != null) { + return javaClass.getName(); + } else { + return null; + } + } + + public void setName(String className) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.className = className; + } + + public Class getJavaClass() { + return javaClass; + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public Class getCallbackClass() { + return callbackClass; + } + + public void setCallbackClass(Class callbackClass) { + this.callbackClass = callbackClass; + } + + @Override + public String toString() { + return getName(); + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof JavaInterface) { + if (getName() != null) { + return getName().equals(((JavaInterface)obj).getName()); + } else { + return ((JavaInterface)obj).getName() == null; + } + } else { + return false; + } + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java new file mode 100644 index 0000000000..a0292d3327 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.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 org.apache.tuscany.sca.interfacedef.java.impl; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +//import java.rmi.Remote; +//import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidCallbackException; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.InvalidOperationException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.OverloadedOperationException; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +/** + * Default implementation of a Java interface introspector. + * + * @version $Rev: 641897 $ $Date: 2008-03-27 09:07:00 -0800 (Thu, 27 Mar 2008) $ + */ +public class JavaInterfaceIntrospectorImpl { + public static final String IDL_INPUT = "idl:input"; + + private static final String UNKNOWN_DATABINDING = null; + + private List visitors = new ArrayList(); + + public JavaInterfaceIntrospectorImpl(JavaInterfaceFactory javaFactory) { + this.visitors = javaFactory.getInterfaceVisitors(); + } + + public void introspectInterface(JavaInterface javaInterface, Class clazz) throws InvalidInterfaceException { + javaInterface.setJavaClass(clazz); + + boolean remotable = clazz.isAnnotationPresent(Remotable.class); + + // Consider @javax.ejb.Remote, java.rmi.Remote and javax.ejb.EJBObject + // equivalent to @Remotable + if (!remotable) { + for (Annotation annotation: clazz.getAnnotations()) { + if ("javax.ejb.Remote".equals(annotation.annotationType().getName())) { + remotable = true; + break; + } + } + } + if (!remotable) { + for (Class superInterface: clazz.getInterfaces()) { + if (/*Remote.class == superInterface || */"javax.ejb.EJBObject".equals(superInterface.getName())) { + remotable = true; + break; + } + } + } + + javaInterface.setRemotable(remotable); + + boolean conversational = clazz.isAnnotationPresent(Conversational.class); + javaInterface.setConversational(conversational); + + Class callbackClass = null; + org.osoa.sca.annotations.Callback callback = clazz.getAnnotation(org.osoa.sca.annotations.Callback.class); + if (callback != null && !Void.class.equals(callback.value())) { + callbackClass = callback.value(); + } else if (callback != null && Void.class.equals(callback.value())) { + throw new InvalidCallbackException("No callback interface specified on annotation"); + } + javaInterface.setCallbackClass(callbackClass); + + String ns = JavaInterfaceUtil.getNamespace(clazz); + javaInterface.getOperations().addAll(getOperations(clazz, remotable, conversational, ns)); + + for (JavaInterfaceVisitor extension : visitors) { + extension.visitInterface(javaInterface); + } + } + + private Class[] getActualTypes(Type[] types, Class[] rawTypes, Map typeBindings) { + Class[] actualTypes = new Class[types.length]; + for (int i = 0; i < actualTypes.length; i++) { + actualTypes[i] = getActualType(types[i], rawTypes[i], typeBindings); + } + return actualTypes; + } + + private Class getActualType(Type type, Class rawType, Map typeBindings) { + if (type instanceof TypeVariable) { + TypeVariable typeVariable = (TypeVariable)type; + type = typeBindings.get(typeVariable.getName()); + if (type instanceof Class) { + return (Class)type; + } + } + return rawType; + } + + private List getOperations(Class clazz, boolean remotable, boolean conversational, String ns) + throws InvalidInterfaceException { + + Type[] genericInterfaces = clazz.getGenericInterfaces(); + Map typeBindings = new HashMap(); + for (Type genericInterface : genericInterfaces) { + if (genericInterface instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType)genericInterface; + TypeVariable[] typeVariables = ((Class)parameterizedType.getRawType()).getTypeParameters(); + Type[] typeArguments = parameterizedType.getActualTypeArguments(); + for (int i = 0; i < typeArguments.length; i++) { + typeBindings.put(typeVariables[i].getName(), typeArguments[i]); + } + } + } + + Method[] methods = clazz.getMethods(); + List operations = new ArrayList(methods.length); + Set names = remotable ? new HashSet() : null; + for (Method method : methods) { + if (method.getDeclaringClass() == Object.class) { + // Skip the methods on the Object.class + continue; + } + String name = method.getName(); + if (remotable && names.contains(name)) { + throw new OverloadedOperationException(method); + } + if (remotable) { + names.add(name); + } + + Class returnType = getActualType(method.getGenericReturnType(), method.getReturnType(), typeBindings); + Class[] parameterTypes = + getActualTypes(method.getGenericParameterTypes(), method.getParameterTypes(), typeBindings); + Class[] faultTypes = + getActualTypes(method.getGenericExceptionTypes(), method.getExceptionTypes(), typeBindings); + + boolean nonBlocking = method.isAnnotationPresent(OneWay.class); + ConversationSequence conversationSequence = ConversationSequence.CONVERSATION_NONE; + if (method.isAnnotationPresent(EndsConversation.class)) { + if (!conversational) { + throw new InvalidOperationException( + "Method is marked as end conversation but contract is not conversational", + method); + } + conversationSequence = ConversationSequence.CONVERSATION_END; + } else if (conversational) { + conversationSequence = ConversationSequence.CONVERSATION_CONTINUE; + } + + // Set outputType to null for void + XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null); + DataType returnDataType = + returnType == void.class ? null : new DataTypeImpl(UNKNOWN_DATABINDING, returnType, + xmlReturnType); + List paramDataTypes = new ArrayList(parameterTypes.length); + for (int i = 0; i < parameterTypes.length; i++) { + Class paramType = parameterTypes[i]; + XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i), null); + paramDataTypes.add(new DataTypeImpl(UNKNOWN_DATABINDING, paramType, xmlParamType)); + } + List faultDataTypes = new ArrayList(faultTypes.length); + for (Class faultType : faultTypes) { + // Only add checked exceptions + // JAXWS Specification v2.1 section 3.7 says RemoteException should not be mapped + if (Exception.class.isAssignableFrom(faultType) && (!RuntimeException.class.isAssignableFrom(faultType)) + /*&& (!RemoteException.class.isAssignableFrom(faultType))*/) { + XMLType xmlFaultType = new XMLType(new QName(ns, faultType.getSimpleName()), null); + DataType faultDataType = new DataTypeImpl(faultType, xmlFaultType); + faultDataTypes.add(new DataTypeImpl(UNKNOWN_DATABINDING, faultType, faultDataType)); + } + } + + DataType> inputType = + new DataTypeImpl>(IDL_INPUT, Object[].class, paramDataTypes); + JavaOperation operation = new JavaOperationImpl(); + operation.setName(name); + operation.setInputType(inputType); + operation.setOutputType(returnDataType); + operation.setFaultTypes(faultDataTypes); + operation.setConversationSequence(conversationSequence); + operation.setNonBlocking(nonBlocking); + operation.setJavaMethod(method); + operations.add(operation); + } + return operations; + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java new file mode 100644 index 0000000000..328fc38ee9 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; + +/** + * Contains methods for mapping between an operation in a + * {@link org.apache.tuscany.spi.model.ServiceContract} and a method defined by + * a Java interface + * + * @version $Rev: 634877 $ $Date: 2008-03-07 16:45:07 -0800 (Fri, 07 Mar 2008) $ + */ +public final class JavaInterfaceUtil { + + private JavaInterfaceUtil() { + } + + /** + * Return the method on the implementation class that matches the operation. + * + * @param implClass the implementation class or interface + * @param operation the operation to match + * @return the method described by the operation + * @throws NoSuchMethodException if no such method exists + * @Deprecated + */ + public static Method findMethod(Class implClass, Operation operation) throws NoSuchMethodException { + String name = operation.getName(); + if (operation instanceof JavaOperation) { + name = ((JavaOperation)operation).getJavaMethod().getName(); + } + Interface interface1 = operation.getInterface(); + if (interface1 != null && interface1.isRemotable()) { + for (Method m : implClass.getMethods()) { + if (m.getName().equals(name)) { + return m; + } + } + throw new NoSuchMethodException("No matching method for operation " + operation.getName() + + " is found on " + + implClass); + } + Class[] paramTypes = getPhysicalTypes(operation); + return implClass.getMethod(name, paramTypes); + } + + /** + * @Deprecated + */ + private static Class[] getPhysicalTypes(Operation operation) { + DataType> inputType = operation.getInputType(); + if (inputType == null) { + return new Class[] {}; + } + List types = inputType.getLogical(); + Class[] javaTypes = new Class[types.size()]; + for (int i = 0; i < javaTypes.length; i++) { + Type physical = types.get(i).getPhysical(); + if (physical instanceof Class) { + javaTypes[i] = (Class)physical; + } else { + throw new UnsupportedOperationException(); + } + } + return javaTypes; + } + + /** + * Searches a collection of operations for a match against the given method + * + * @param method the method to match + * @param operations the operations to match against + * @return a matching operation or null + * @Deprecated + */ + public static Operation findOperation(Method method, Collection operations) { + for (Operation operation : operations) { + if (match(operation, method)) { + return operation; + } + } + return null; + } + + /** + * Determines if the given operation matches the given method + * + * @return true if the operation matches, false if does not + */ + private static boolean match(Operation operation, Method method) { + Class[] params = method.getParameterTypes(); + DataType> inputType = operation.getInputType(); + List types = inputType.getLogical(); + boolean found = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + Class clazz = params[i]; + if (!clazz.equals(operation.getInputType().getLogical().get(i).getPhysical())) { + found = false; + } + } + } else { + found = false; + } + return found; + + } + + public static String getNamespace(Class cls) { + Package pkg = cls.getPackage(); + if (pkg == null) { + return ""; + } + StringBuffer ns = new StringBuffer("http://"); + String[] names = pkg.getName().split("\\."); + for (int i = names.length - 1; i >= 0; i--) { + ns.append(names[i]); + if (i != 0) { + ns.append('.'); + } + } + ns.append('/'); + return ns.toString(); + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java new file mode 100644 index 0000000000..6853f7931d --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.interfacedef.java.impl; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; + +/** + * Represents a Java operation. + * + * @version $Rev: 616060 $ $Date: 2008-01-28 13:39:55 -0800 (Mon, 28 Jan 2008) $ + */ +public class JavaOperationImpl extends OperationImpl implements JavaOperation { + + private Method method; + + public Method getJavaMethod() { + return method; + } + + public void setJavaMethod(Method method) { + this.method = method; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((method == null) ? 0 : method.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + final JavaOperationImpl other = (JavaOperationImpl)obj; + if (method == null) { + if (other.method != null) + return false; + } else if (!method.equals(other.method)) + return false; + return true; + } + + public String toString() { + return method == null ? "null" : method.toGenericString(); + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java new file mode 100644 index 0000000000..cba865593d --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import java.lang.reflect.Method; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +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.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.osoa.sca.annotations.PolicySets; +import org.osoa.sca.annotations.Requires; + +/** + * Processes an {@link org.osoa.sca.annotations.Requires} annotation + * + * @version $Rev: + */ +public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor { + private PolicyFactory policyFactory; + + public PolicyJavaInterfaceVisitor(PolicyFactory policyFactory) { + super(); + this.policyFactory = policyFactory; + } + + private QName getQName(String intentName) { + QName qname; + if (intentName.startsWith("{")) { + int i = intentName.indexOf('}'); + if (i != -1) { + qname = new QName(intentName.substring(1, i), intentName.substring(i + 1)); + } else { + qname = new QName("", intentName); + } + } else { + qname = new QName("", intentName); + } + return qname; + } + + /** + * Read policy intents on the given interface or class + * @param clazz + * @param requiredIntents + */ + private void readIntentsAndPolicySets(Class clazz, List requiredIntents, List policySets) { + Requires intentAnnotation = clazz.getAnnotation(Requires.class); + if (intentAnnotation != null) { + String[] intentNames = intentAnnotation.value(); + if (intentNames.length != 0) { + for (String intentName : intentNames) { + + // Add each intent to the list + Intent intent = policyFactory.createIntent(); + intent.setName(getQName(intentName)); + requiredIntents.add(intent); + } + } + } + + PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class); + if (policySetAnnotation != null) { + String[] policySetNames = policySetAnnotation.value(); + if (policySetNames.length != 0) { + for (String policySetName : policySetNames) { + + // Add each intent to the list + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(getQName(policySetName)); + policySets.add(policySet); + } + } + } + } + + private void readIntents(Requires intentAnnotation, List requiredIntents) { + //Requires intentAnnotation = method.getAnnotation(Requires.class); + if (intentAnnotation != null) { + String[] intentNames = intentAnnotation.value(); + if (intentNames.length != 0) { + //Operation operation = assemblyFactory.createOperation(); + //operation.setName(method.getName()); + //operation.setUnresolved(true); + for (String intentName : intentNames) { + + // Add each intent to the list, associated with the + // operation corresponding to the annotated method + Intent intent = policyFactory.createIntent(); + intent.setName(getQName(intentName)); + //intent.getOperations().add(operation); + requiredIntents.add(intent); + } + } + } + } + + private void readPolicySets(PolicySets policySetAnnotation, List policySets) { + if (policySetAnnotation != null) { + String[] policySetNames = policySetAnnotation.value(); + if (policySetNames.length != 0) { + //Operation operation = assemblyFactory.createOperation(); + //operation.setName(method.getName()); + //operation.setUnresolved(true); + for (String policySetName : policySetNames) { + // Add each intent to the list, associated with the + // operation corresponding to the annotated method + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(getQName(policySetName)); + //intent.getOperations().add(operation); + policySets.add(policySet); + } + } + } + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + + if (javaInterface.getJavaClass() != null) { + readIntentsAndPolicySets(javaInterface.getJavaClass(), javaInterface.getRequiredIntents(), javaInterface + .getPolicySets()); + + // Read intents on the service interface methods + List operations = javaInterface.getOperations(); + for (Operation op : operations) { + JavaOperation operation = (JavaOperation)op; + Method method = operation.getJavaMethod(); + if (method.getAnnotation(Requires.class) != null || method.getAnnotation(PolicySets.class) != null) { + readIntents(method.getAnnotation(Requires.class), op.getRequiredIntents()); + readPolicySets(method.getAnnotation(PolicySets.class), op.getPolicySets()); + } + } + } + } + +} diff --git a/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java new file mode 100644 index 0000000000..49f019a9d2 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.introspect; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; + +/** + * Implementations introspect metadata on a Java interface, populating the + * corresponding {@link JavaInterface} + * + * @version $Rev: 537404 $ $Date: 2007-05-12 04:51:42 -0800 (Sat, 12 May 2007) $ + */ +public interface JavaInterfaceVisitor { + + /** + * Visit a java interface + * @param javaInterface + * @throws InvalidInterfaceException + */ + void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException; + +} diff --git a/sandbox/mobile-android/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory b/sandbox/mobile-android/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory new file mode 100644 index 0000000000..5ba12ec137 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory \ No newline at end of file diff --git a/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java new file mode 100644 index 0000000000..d86c029863 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.impl; + +import static org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil.findOperation; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * @version $Rev: 614967 $ $Date: 2008-01-24 12:00:04 -0800 (Thu, 24 Jan 2008) $ + */ +public class JavaInterfaceUtilTestCase extends TestCase { + private List operations; + + public void testNoParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo"); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(0, method.getParameterTypes().length); + } + + public void testParamsFindOperation() throws Exception { + Method method = Foo.class.getMethod("foo", String.class); + Operation ret = findOperation(method, operations); + assertEquals("foo", ret.getName()); + assertEquals(String.class, method.getParameterTypes()[0]); + } + + public void testPrimitiveParamFindOperation() throws NoSuchMethodException { + Method method = Foo.class.getMethod("foo", Integer.TYPE); + Operation operation = findOperation(method, operations); + assertEquals(Integer.TYPE, operation.getInputType().getLogical().get(0).getPhysical()); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + Operation operation = newOperation("foo"); + List types = new ArrayList(); + DataType> inputType = new DataTypeImpl>(Object[].class, types); + operation.setInputType(inputType); + + operations = new ArrayList(); + operations.add(operation); + + types = new ArrayList(); + inputType = new DataTypeImpl>(Object[].class, types); + DataType type = new DataTypeImpl(String.class, Object.class); + types.add(type); + operation = newOperation("foo"); + operation.setInputType(inputType); + operations.add(operation); + + types = new ArrayList(); + type = new DataTypeImpl(String.class, Object.class); + DataType type2 = new DataTypeImpl(String.class, Object.class); + types.add(type); + types.add(type2); + inputType = new DataTypeImpl>(Object[].class, types); + operation = newOperation("foo"); + operation.setInputType(inputType); + operations.add(operation); + + types = new ArrayList(); + type = new DataTypeImpl(Integer.class, Object.class); + types.add(type); + inputType = new DataTypeImpl>(Object[].class, types); + operation = newOperation("foo"); + operation.setInputType(inputType); + operations.add(operation); + + types = new ArrayList(); + type = new DataTypeImpl(Integer.TYPE, Object.class); + types.add(type); + inputType = new DataTypeImpl>(Object[].class, types); + operation = newOperation("foo"); + operation.setInputType(inputType); + operations.add(operation); + + } + + private interface Foo { + void foo(); + + void foo(String foo); + + void foo(int b); + } + + private static Operation newOperation(String name) { + Operation operation = new OperationImpl(); + operation.setName(name); + return operation; + } +} diff --git a/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java new file mode 100644 index 0000000000..62c1105d50 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.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 org.apache.tuscany.sca.interfacedef.java.introspection.impl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InvalidOperationException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; + +/** + * @version $Rev: 567542 $ $Date: 2007-08-19 21:13:29 -0800 (Sun, 19 Aug 2007) $ + */ +public class ConversationalIntrospectionTestCase extends TestCase { + private JavaInterfaceFactory javaFactory; + + @Override + protected void setUp() throws Exception { + javaFactory = new DefaultJavaInterfaceFactory(); + } + + private Operation getOperation(Interface i, String name) { + for (Operation op : i.getOperations()) { + if (op.getName().equals(name)) { + return op; + } + } + return null; + } + + public void testServiceContractConversationalInformationIntrospection() throws Exception { + Interface i = javaFactory.createJavaInterface(Foo.class); + assertNotNull(i); + assertTrue(i.isConversational()); + ConversationSequence seq = getOperation(i, "operation").getConversationSequence(); + assertEquals(ConversationSequence.CONVERSATION_CONTINUE, seq); + seq = getOperation(i, "endOperation").getConversationSequence(); + assertEquals(ConversationSequence.CONVERSATION_END, seq); + } + + public void testBadServiceContract() throws Exception { + try { + javaFactory.createJavaInterface(BadFoo.class); + fail(); + } catch (InvalidOperationException e) { + // expected + } + } + + public void testNonConversationalInformationIntrospection() throws Exception { + Interface i = javaFactory.createJavaInterface(NonConversationalFoo.class); + assertFalse(i.isConversational()); + ConversationSequence seq = getOperation(i, "operation") + .getConversationSequence(); + assertEquals(ConversationSequence.CONVERSATION_NONE, seq); + } + + @Conversational + private interface Foo { + void operation(); + + @EndsConversation + void endOperation(); + } + + private interface BadFoo { + void operation(); + + @EndsConversation + void endOperation(); + } + + private interface NonConversationalFoo { + void operation(); + } + +} diff --git a/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java new file mode 100644 index 0000000000..d230b55fa3 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.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 org.apache.tuscany.sca.interfacedef.java.introspection.impl; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; + +import java.io.IOException; +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.easymock.EasyMock; + +/** + * @version $Rev: 629687 $ $Date: 2008-02-20 20:11:14 -0800 (Wed, 20 Feb 2008) $ + */ +public class JavaInterfaceProcessorRegistryImplTestCase extends TestCase { + private JavaInterfaceFactory factory; + + @SuppressWarnings("unchecked") + public void testSimpleInterface() throws InvalidInterfaceException { + JavaInterface intf = factory.createJavaInterface(Simple.class); + + assertEquals(Simple.class, intf.getJavaClass()); + List operations = intf.getOperations(); + assertEquals(1, operations.size()); + Operation baseInt = operations.get(0); + assertEquals("baseInt", baseInt.getName()); + + QName element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "return"); + + DataType returnType = baseInt.getOutputType(); + assertEquals(Integer.TYPE, returnType.getPhysical()); + assertEquals(element, returnType.getLogical().getElementName()); + + List parameterTypes = baseInt.getInputType().getLogical(); + assertEquals(1, parameterTypes.size()); + DataType arg0 = parameterTypes.get(0); + assertEquals(Integer.TYPE, arg0.getPhysical()); + + element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "arg0"); + assertEquals(element, arg0.getLogical().getElementName()); + + List faultTypes = baseInt.getFaultTypes(); + assertEquals(1, faultTypes.size()); + DataType> fault0 = faultTypes.get(0); + assertEquals(IOException.class, fault0.getPhysical()); + element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "IOException"); + assertEquals(element, fault0.getLogical().getLogical().getElementName()); + } + + public void testUnregister() throws Exception { + JavaInterfaceVisitor extension = createMock(JavaInterfaceVisitor.class); + extension.visitInterface(EasyMock.isA(JavaInterface.class)); + expectLastCall().once(); + replay(extension); + factory.addInterfaceVisitor(extension); + factory.createJavaInterface(Base.class); + factory.removeInterfaceVisitor(extension); + factory.createJavaInterface(Base.class); + verify(extension); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + factory = new DefaultJavaInterfaceFactory(); + + } + + private static interface Base { + int baseInt(int param) throws IllegalArgumentException, IOException; + } + + private static interface Simple extends Base { + + } +} diff --git a/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java new file mode 100644 index 0000000000..71e4fb3cf4 --- /dev/null +++ b/sandbox/mobile-android/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.interfacedef.java.introspection.impl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.osoa.sca.annotations.PolicySets; +import org.osoa.sca.annotations.Requires; + +/** + * @version $Rev: 639350 $ $Date: 2008-03-20 08:43:46 -0800 (Thu, 20 Mar 2008) $ + */ +public class PolicyProcessorTestCase extends TestCase { + private JavaInterfaceFactory factory = new DefaultJavaInterfaceFactory(); + private PolicyJavaInterfaceVisitor policyProcessor; + + public void testInterfaceLevel() throws Exception { + JavaInterface type = factory.createJavaInterface(Interface1.class); + policyProcessor.visitInterface(type); + assertEquals(1, type.getRequiredIntents().size()); + assertEquals(1, type.getPolicySets().size()); + } + + public void testMethodLevel() throws Exception { + JavaInterface type = factory.createJavaInterface(Interface2.class); + policyProcessor.visitInterface(type); + assertEquals(0, type.getRequiredIntents().size()); + assertEquals(1, type.getOperations().get(0).getRequiredIntents().size()); + assertEquals(1, type.getOperations().get(1).getRequiredIntents().size()); + assertEquals(0, type.getPolicySets().size()); + assertEquals(1, type.getOperations().get(0).getPolicySets().size()); + assertEquals(1, type.getOperations().get(1).getPolicySets().size()); + } + + public void testInterfaceAndMethodLevel() throws Exception { + JavaInterface type = factory.createJavaInterface(Interface3.class); + policyProcessor.visitInterface(type); + assertEquals(1, type.getRequiredIntents().size()); + assertEquals(1, type.getOperations().get(0).getRequiredIntents().size()); + assertEquals(1, type.getOperations().get(1).getRequiredIntents().size()); + assertEquals(1, type.getPolicySets().size()); + assertEquals(1, type.getOperations().get(0).getPolicySets().size()); + assertEquals(1, type.getOperations().get(1).getPolicySets().size()); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + policyProcessor = new PolicyJavaInterfaceVisitor(new DefaultPolicyFactory()); + } + + // @Remotable + @Requires( {"transaction.global"}) + @PolicySets( {"{http://ns1}PS1"}) + private interface Interface1 { + int method1(); + + int method2(); + + int method3(); + + int method4(); + } + + private interface Interface2 { + @Requires( {"transaction.global"}) + @PolicySets( {"{http://ns1}PS1"}) + int method1(); + + @Requires( {"transaction.local"}) + @PolicySets( {"{http://ns1}PS2"}) + int method2(); + } + + @Requires( {"transaction.global.Interface6"}) + @PolicySets( {"{http://ns1}PS1"}) + private interface Interface3 { + @Requires( {"transaction.global.Interface6.method1"}) + @PolicySets( {"{http://ns1}PS2"}) + int method1(); + + @Requires( {"transaction.local.Interface6.method2"}) + @PolicySets( {"{http://ns1}PS3"}) + int method2(); + } + +} diff --git a/sandbox/mobile-android/tuscany-implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java b/sandbox/mobile-android/tuscany-implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java index 8297738be8..d800450453 100644 --- a/sandbox/mobile-android/tuscany-implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java +++ b/sandbox/mobile-android/tuscany-implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java @@ -306,7 +306,18 @@ public final class JavaIntrospectionHelper { if (!name.startsWith("set")) { return name; } - return Introspector.decapitalize(name.substring(3)); + + if (name == null || name.length() == 0) { + return name; + } + if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) && + Character.isUpperCase(name.charAt(0))){ + return name; + } + char chars[] = name.toCharArray(); + chars[0] = Character.toLowerCase(chars[0]); + return new String(chars); + } public static Class getErasure(Type type) { -- cgit v1.2.3