From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../modules/core-databinding/.checkstyle | 25 +++ .../sca-java-0.91/modules/core-databinding/.pmd | 20 ++ .../modules/core-databinding/.ruleset | 190 +++++++++++++++++ .../modules/core-databinding/DISCLAIMER | 8 + .../sca-java-0.91/modules/core-databinding/LICENSE | 205 ++++++++++++++++++ .../sca-java-0.91/modules/core-databinding/NOTICE | 6 + .../sca-java-0.91/modules/core-databinding/pom.xml | 82 ++++++++ .../module/DataBindingModuleActivator.java | 151 ++++++++++++++ .../DataBindingJavaInterfaceProcessor.java | 135 ++++++++++++ .../Exception2ExceptionTransformer.java | 126 ++++++++++++ .../transformers/Input2InputTransformer.java | 204 ++++++++++++++++++ .../transformers/Output2OutputTransformer.java | 185 +++++++++++++++++ .../wire/DataBindingRuntimeWireProcessor.java | 150 ++++++++++++++ .../wire/DataTransformationInteceptor.java | 224 ++++++++++++++++++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 ++ .../DataBindingJavaInterfaceProcessorTestCase.java | 83 ++++++++ .../transformers/IDLTransformerTestCase.java.fixme | 229 +++++++++++++++++++++ 17 files changed, 2041 insertions(+) create mode 100644 branches/sca-java-0.91/modules/core-databinding/.checkstyle create mode 100644 branches/sca-java-0.91/modules/core-databinding/.pmd create mode 100644 branches/sca-java-0.91/modules/core-databinding/.ruleset create mode 100644 branches/sca-java-0.91/modules/core-databinding/DISCLAIMER create mode 100644 branches/sca-java-0.91/modules/core-databinding/LICENSE create mode 100644 branches/sca-java-0.91/modules/core-databinding/NOTICE create mode 100644 branches/sca-java-0.91/modules/core-databinding/pom.xml create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java create mode 100644 branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme (limited to 'branches/sca-java-0.91/modules/core-databinding') diff --git a/branches/sca-java-0.91/modules/core-databinding/.checkstyle b/branches/sca-java-0.91/modules/core-databinding/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/branches/sca-java-0.91/modules/core-databinding/.pmd b/branches/sca-java-0.91/modules/core-databinding/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/branches/sca-java-0.91/modules/core-databinding/.ruleset b/branches/sca-java-0.91/modules/core-databinding/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER b/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/branches/sca-java-0.91/modules/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/branches/sca-java-0.91/modules/core-databinding/LICENSE b/branches/sca-java-0.91/modules/core-databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/branches/sca-java-0.91/modules/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/branches/sca-java-0.91/modules/core-databinding/NOTICE b/branches/sca-java-0.91/modules/core-databinding/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/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/branches/sca-java-0.91/modules/core-databinding/pom.xml b/branches/sca-java-0.91/modules/core-databinding/pom.xml new file mode 100644 index 0000000000..9fb6d998b6 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/pom.xml @@ -0,0 +1,82 @@ + + + + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + 4.0.0 + org.apache.tuscany.sca + tuscany-core-databinding + jar + Apache Tuscany Core/DataBinding Integration + Apache Tuscany Core/DataBinding Integration + + + org.apache.tuscany.sca + tuscany-databinding + ${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.codehaus.woodstox + wstx-asl + runtime + 3.2.0 + + + + stax + stax-api + 1.0.1 + + + + + diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java new file mode 100644 index 0000000000..32666174b2 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.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.core.databinding.module; + +import org.apache.tuscany.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.core.databinding.transformers.Exception2ExceptionTransformer; +import org.apache.tuscany.core.databinding.transformers.Input2InputTransformer; +import org.apache.tuscany.core.databinding.transformers.Output2OutputTransformer; +import org.apache.tuscany.core.databinding.wire.DataBindingRuntimeWireProcessor; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; +import org.apache.tuscany.sca.databinding.javabeans.DOMNode2JavaBeanTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBean2DOMNodeTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.databinding.xml.InputSource2Node; +import org.apache.tuscany.sca.databinding.xml.InputSource2SAX; +import org.apache.tuscany.sca.databinding.xml.InputStream2Node; +import org.apache.tuscany.sca.databinding.xml.InputStream2SAX; +import org.apache.tuscany.sca.databinding.xml.Node2OutputStream; +import org.apache.tuscany.sca.databinding.xml.Node2String; +import org.apache.tuscany.sca.databinding.xml.Node2Writer; +import org.apache.tuscany.sca.databinding.xml.Node2XMLStreamReader; +import org.apache.tuscany.sca.databinding.xml.Reader2Node; +import org.apache.tuscany.sca.databinding.xml.Reader2SAX; +import org.apache.tuscany.sca.databinding.xml.SAX2DOMPipe; +import org.apache.tuscany.sca.databinding.xml.Source2ResultTransformer; +import org.apache.tuscany.sca.databinding.xml.StreamDataPipe; +import org.apache.tuscany.sca.databinding.xml.String2Node; +import org.apache.tuscany.sca.databinding.xml.String2SAX; +import org.apache.tuscany.sca.databinding.xml.String2XMLStreamReader; +import org.apache.tuscany.sca.databinding.xml.Writer2ReaderDataPipe; +import org.apache.tuscany.sca.databinding.xml.XMLGroupDataBinding; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2SAX; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * @version $Rev$ $Date$ + */ +public class DataBindingModuleActivator implements ModuleActivator { + + private DataBindingExtensionPoint dataBindings; + private TransformerExtensionPoint transformers; + + public Object[] getExtensionPoints() { + dataBindings = new DefaultDataBindingExtensionPoint(); + transformers = new DefaultTransformerExtensionPoint(dataBindings); + return new Object[] { dataBindings, transformers }; + } + + public void start(ExtensionPointRegistry registry) { + MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); + input2InputTransformer.setMediator(mediator); + + Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); + output2OutputTransformer.setMediator(mediator); + + Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(); + exception2ExceptionTransformer.setMediator(mediator); + + transformers.addTransformer(input2InputTransformer); + transformers.addTransformer(output2OutputTransformer); + transformers.addTransformer(exception2ExceptionTransformer); + + JavaInterfaceIntrospectorExtensionPoint introspectors = registry + .getExtensionPoint(JavaInterfaceIntrospectorExtensionPoint.class); + introspectors.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); + + RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry + .getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); + if (wireProcessorExtensionPoint != null) { + wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator)); + } + + DOMDataBinding domDataBinding = new DOMDataBinding(); + domDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(domDataBinding); + XMLStringDataBinding xmlStringDataBinding = new XMLStringDataBinding(); + xmlStringDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(xmlStringDataBinding); + XMLGroupDataBinding xmlGroupDataBinding = new XMLGroupDataBinding(); + xmlGroupDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(xmlGroupDataBinding); + JavaBeansDataBinding javaBeansDataBinding = new JavaBeansDataBinding(); + javaBeansDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(javaBeansDataBinding); + + Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); + group2GroupTransformer.setMediator(mediator); + transformers.addTransformer(group2GroupTransformer); + + transformers.addTransformer(new InputSource2Node()); + transformers.addTransformer(new InputSource2SAX()); + transformers.addTransformer(new InputStream2Node()); + transformers.addTransformer(new InputStream2SAX()); + + transformers.addTransformer(new DOMNode2JavaBeanTransformer()); + transformers.addTransformer(new Node2OutputStream()); + transformers.addTransformer(new Node2String()); + transformers.addTransformer(new Node2Writer()); + transformers.addTransformer(new Node2XMLStreamReader()); + + transformers.addTransformer(new JavaBean2DOMNodeTransformer()); + transformers.addTransformer(new Reader2Node()); + + transformers.addTransformer(new Reader2SAX()); + transformers.addTransformer(new SAX2DOMPipe()); + + transformers.addTransformer(new Source2ResultTransformer()); + transformers.addTransformer(new StreamDataPipe()); + transformers.addTransformer(new String2Node()); + transformers.addTransformer(new String2SAX()); + transformers.addTransformer(new String2XMLStreamReader()); + transformers.addTransformer(new Writer2ReaderDataPipe()); + + transformers.addTransformer(new XMLStreamReader2Node()); + transformers.addTransformer(new XMLStreamReader2SAX()); + transformers.addTransformer(new XMLStreamReader2String()); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java new file mode 100644 index 0000000000..b26846c682 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.processor; + +import java.lang.reflect.Method; +import java.util.HashMap; +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.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.introspect.JavaInterfaceVisitor; +import org.osoa.sca.annotations.Reference; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { + private DataBindingExtensionPoint dataBindingRegistry; + + public DataBindingJavaInterfaceProcessor(@Reference + 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 introspectWrapperStyle(Operation operation) { + if (operation.isWrapperStyle()) { + return; + } + DataType outputType = operation.getOutputType(); + DataType> inputType = operation.getInputType(); + if (outputType == null || inputType == null) { + return; + } + if (inputType.getLogical().size() != 1) { + return; + } + DataType wrapperType = inputType.getLogical().get(0); + if (outputType.getDataBinding().equals(wrapperType.getDataBinding())) { + operation.setWrapperStyle(true); + operation.setDataBinding(outputType.getDataBinding()); + } + } + + 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.wrapperStyle(); + } + + Map opMap = new HashMap(); + for (Operation op : javaInterface.getOperations()) { + opMap.put(op.getName(), op); + if (dataBindingId != null) { + op.setDataBinding(dataBindingId); + op.setWrapperStyle(wrapperStyle); + } + } + for (Method method : clazz.getMethods()) { + 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.wrapperStyle(); + operation.setDataBinding(dataBindingId); + operation.setWrapperStyle(wrapperStyle); + } + + // FIXME: We need a better way to identify simple java types + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getInputType().getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + if (operation.getOutputType() != null) { + DataType d = operation.getOutputType(); + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + + // FIXME: Do we want to heuristically check the wrapper style? + // introspectWrapperStyle(operation); + } + } +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java new file mode 100644 index 0000000000..9711fe881a --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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 org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +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.Transformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the exception from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Exception2ExceptionTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + 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 + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Exception transform(Exception source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + + DataType targetType = context.getTargetDataType(); + + ExceptionHandler exceptionHandler = getExceptionHandler(sourceType); + if (exceptionHandler == null) { + return source; + } + + Object sourceFaultInfo = exceptionHandler.getFaultInfo(source); + Object targetFaultInfo = + mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + + ExceptionHandler targetHandler = getExceptionHandler(targetType); + + if (targetHandler != null) { + Exception targetException = + targetHandler.createException(targetType, source.getMessage(), targetFaultInfo, source.getCause()); + return targetException; + } + + // FIXME + return source; + + } + + private ExceptionHandler getExceptionHandler(DataType targetType) { + DataType targetFaultType = (DataType)targetType.getLogical(); + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(targetFaultType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + return targetHandler; + } +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java new file mode 100644 index 0000000000..88d47deed7 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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 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.Transformer; +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.impl.DataTypeImpl; +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; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the input from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Input2InputTransformer extends BaseTransformer implements + PullTransformer { + + 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() + */ + 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); + if (sourceWrapped) { + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, true); + } + + DataType> targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = null; + if (targetWrapped) { + targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, true); + } + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getInputWrapperElement(); + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[0]); + } + } + Object targetWrapper = targetWrapperHandler.create(wrapperElement, context); + if (source == null) { + return new Object[] {targetWrapper}; + } + 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]; + // List childElements = + // sourceOp.getWrapper().getInputChildElements(); + Object[] target = null; + + targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, false); + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement(); + // Object targetWrapper = + // targetWrapperHandler.create(wrapperElement, context); + DataType targetWrapperType = new DataTypeImpl(targetDataBinding, Object.class, + new XMLType(wrapperElement)); + Object targetWrapper = mediator.mediate(sourceWrapper, + sourceType.getLogical().get(0), + targetWrapperType, + context.getMetadata()); + target = targetWrapperHandler.getChildren(targetWrapper).toArray(); + } else { + Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper).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/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java new file mode 100644 index 0000000000..b1bc8dfe1b --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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 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.Transformer; +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.impl.DataTypeImpl; +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; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +@Service(Transformer.class) +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() + */ + 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; + if (sourceWrapped) { + sourceWrapperHandler = getWrapperHandler(getDataBinding(sourceOp), true); + } + + DataType targetType = context.getTargetDataType(); + Operation targetOp = context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + if (targetWrapped) { + targetWrapperHandler = getWrapperHandler(getDataBinding(targetOp), true); + } + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + Object targetWrapper = targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context); + + List childElements = wrapper.getOutputChildElements(); + 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; + } + targetWrapperHandler = getWrapperHandler(getDataBinding(targetOp), false); + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement(); + // Object targetWrapper = + // targetWrapperHandler.create(wrapperElement, context); + DataType targetWrapperType = new DataTypeImpl(targetType.getLogical() + .getDataBinding(), Object.class, new XMLType(wrapperElement)); + Object targetWrapper = mediator.mediate(sourceWrapper, + sourceType.getLogical(), + targetWrapperType, + context.getMetadata()); + return targetWrapperHandler.getChildren(targetWrapper).get(0); + } else { + Object child = sourceWrapperHandler.getChildren(sourceWrapper).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/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java new file mode 100644 index 0000000000..feaf48f501 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.wire; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +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$ $Date$ + */ +public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { + private Mediator mediator; + + public DataBindingRuntimeWireProcessor(Mediator mediator) { + super(); + this.mediator = mediator; + } + + public boolean isTransformationRequired(DataType source, DataType target) { + if (source == target) { + return false; + } + String sourceDataBinding = source.getDataBinding(); + String targetDataBinding = target.getDataBinding(); + if (sourceDataBinding == targetDataBinding) { + return false; + } + if (sourceDataBinding == null || targetDataBinding == null) { + return true; + } + return !sourceDataBinding.equals(targetDataBinding); + } + + public boolean isTransformationRequired(Operation source, Operation target) { + if (source == target) { + return false; + } + + // 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(); + 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 == targetContract) { + return; + } + List chains = wire.getInvocationChains(); + for (InvocationChain chain : chains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + // Add the interceptor to the source side because multiple + // references can be wired + // to the same service + DataTransformationInteceptor interceptor = new DataTransformationInteceptor(wire, sourceOperation, + targetOperation); + interceptor.setMediator(mediator); + chain.addInterceptor(0, interceptor); + } + } + + // Object targetAddress = UriHelper.getBaseName(source.getUri()); + List callbackChains = wire.getCallbackInvocationChains(); + if (callbackChains == null) { + // callback chains could be null + return; + } + + for (InvocationChain chain : callbackChains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + + // Add the interceptor to the source side because multiple + // references can be wired + // to the same service + DataTransformationInteceptor interceptor = new DataTransformationInteceptor(wire, sourceOperation, + targetOperation); + interceptor.setMediator(mediator); + chain.addInterceptor(0, interceptor); + } + } + } + +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java new file mode 100644 index 0000000000..39bc6cf913 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.wire; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformationException; +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.util.FaultException; +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; + +/** + * An interceptor to transform data accross databindings on the wire + * + * @version $Rev$ $Date$ + */ +public class DataTransformationInteceptor implements Interceptor { + private Invoker next; + + private Operation sourceOperation; + + private Operation targetOperation; + + private Mediator mediator; + + public DataTransformationInteceptor(RuntimeWire wire, + Operation sourceOperation, + Operation targetOperation) { + super(); + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + } + + 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) { + if (((FaultException)result).isMatchingType(exType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + throw new TransformationException("Target fault type cannot be resolved"); + } + + // 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 && targetFaultType.getLogical().equals(faultType.getLogical())) { + sourceDataType = exType; + sourceFaultType = faultType; + break; + } + } + + if (sourceFaultType == null) { + throw new TransformationException("No matching source fault type is found"); + } + + 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); + return mediator.mediate(source, sourceType, targetType, metadata); + } + + private DataType getFaultType(DataType exceptionType) { + // FIXME: We cannot assume the exception will have a databinding set + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + if (targetHandler == null) { + return null; + } + return targetHandler.getFaultType(exceptionType); + } + + /** + * @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); + + 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; + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..60f6de3b96 --- /dev/null +++ b/branches/sca-java-0.91/modules/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.core.databinding.module.DataBindingModuleActivator diff --git a/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..1c521af842 --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.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() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /** + * @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 = new OperationImpl("call"); + Operation operation1 = new OperationImpl("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); + } + +} diff --git a/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme b/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme new file mode 100644 index 0000000000..ecae54188c --- /dev/null +++ b/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/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); + + } + +} -- cgit v1.2.3