summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding')
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/LICENSE205
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/META-INF/MANIFEST.MF32
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/NOTICE6
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/pom.xml78
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java130
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java175
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java104
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Collection2CollectionTransformer.java108
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java112
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java286
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Map2MapTransformer.java108
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java328
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java123
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java173
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java80
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer30
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor19
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessor17
18 files changed, 2114 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/LICENSE b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/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/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/META-INF/MANIFEST.MF b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..c5b555f33b
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/META-INF/MANIFEST.MF
@@ -0,0 +1,32 @@
+Manifest-Version: 1.0
+Private-Package: org.apache.tuscany.sca.core.databinding.module;versio
+ n="2.0.0",org.apache.tuscany.sca.core.databinding.processor;version="2.0.0",
+ org.apache.tuscany.sca.core.databinding.transformers;version="2.0.0"
+ ,org.apache.tuscany.sca.core.databinding.wire;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Core/DataBinding Integration
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Core/DataBinding Integration
+Import-Package: javax.xml.namespace,
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.core.invocation;version="2.0.0",
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.databinding.annotation;version="2.0.0",
+ org.apache.tuscany.sca.databinding.impl;version="2.0.0",
+ org.apache.tuscany.sca.databinding.javabeans;version="2.0.0",
+ org.apache.tuscany.sca.databinding.util;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.java.introspect;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.apache.tuscany.sca.invocation;version="2.0.0",
+ org.apache.tuscany.sca.runtime;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.core.databinding
+Bundle-DocURL: http://www.apache.org/
+Export-Package: org.apache.tuscany.sca.core.databinding.processor;
+ version="2.0.0";uses:="org.w3c.dom"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/NOTICE b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/NOTICE
new file mode 100644
index 0000000000..4dc9c94cd5
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2013 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/pom.xml b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/pom.xml
new file mode 100644
index 0000000000..d302139408
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/pom.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0.1</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany SCA Core/DataBinding Integration</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-jaxws</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
new file mode 100644
index 0000000000..7c10ae45e9
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.List;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+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.JavaOperation;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+
+/**
+ * The databinding annotation processor for java interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor {
+ private DataBindingExtensionPoint dataBindingRegistry;
+
+ public DataBindingJavaInterfaceProcessor(ExtensionPointRegistry registry) {
+ super();
+ this.dataBindingRegistry = registry.getExtensionPoint(DataBindingExtensionPoint.class);
+ }
+
+ public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException {
+ // Set the data types regardless in case the
+ // user overrides the remotable status in the SCDL
+ //if (!javaInterface.isRemotable()) {
+ // return;
+ //}
+ List<Operation> operations = javaInterface.getOperations();
+ processInterface(javaInterface, operations);
+ }
+
+ private void processInterface(JavaInterface javaInterface, List<Operation> 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();
+ }
+
+ for (Operation op : javaInterface.getOperations()) {
+ JavaOperation operation = (JavaOperation) op;
+ // In the case of @WebMethod, the method name can be different from the operation name
+
+ if (dataBindingId != null) {
+ op.setDataBinding(dataBindingId);
+ op.setInputWrapperStyle(wrapperStyle);
+ op.setOutputWrapperStyle(wrapperStyle);
+ }
+
+ Method method = operation.getJavaMethod();
+
+ 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.setInputWrapperStyle(wrapperStyle);
+ operation.setOutputWrapperStyle(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, operation);
+ i++;
+ }
+ if (operation.getOutputType() != null) {
+ for ( org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getOutputType().getLogical()) {
+ if ( d != null ) {
+ // The DataType is null for void operations
+ if ( d.getDataBinding() == null ) {
+ d.setDataBinding(dataBindingId);
+ }
+ dataBindingRegistry.introspectType(d, operation);
+ }
+ }
+
+ org.apache.tuscany.sca.databinding.annotation.DataType dt =
+ method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class);
+ if (dt != null) {
+ operation.getOutputType().getLogical().get(0).setDataBinding(dt.value());
+ }
+
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java
new file mode 100644
index 0000000000..dcea53d3ae
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/WrapperJavaInterfaceProcessor.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+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.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+
+/**
+ * The databinding annotation processor for java interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class WrapperJavaInterfaceProcessor implements JavaInterfaceVisitor {
+ private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement";
+ private DataBindingExtensionPoint dataBindingRegistry;
+
+ public WrapperJavaInterfaceProcessor(ExtensionPointRegistry registry) {
+ super();
+ this.dataBindingRegistry = registry.getExtensionPoint(DataBindingExtensionPoint.class);
+ }
+
+ public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException {
+ // create regardless in case the user overrides the remotable flag
+ // in the SCDL
+ //if (!javaInterface.isRemotable()) {
+ // return;
+ //}
+ for (Operation operation : javaInterface.getOperations()) {
+ WrapperInfo inputWrapperInfo = operation.getInputWrapper();
+ WrapperInfo outputWrapperInfo = operation.getOutputWrapper();
+ if (inputWrapperInfo == null || outputWrapperInfo == null) {
+ continue;
+ }
+ // TUSCANY-824
+ // TUSCANY-3804 - modify the existing code to set up the input wrapper
+ String db = inputWrapperInfo.getDataBinding();
+ if (db == null || JAXB_DATABINDING.equals(db)) {
+ db = assignInputDataBinding(operation);
+ }
+
+ // Introspect the wrapper data type
+ DataBinding dbObj = dataBindingRegistry.getDataBinding(db);
+ WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler();
+ if (handler != null) {
+ inputWrapperInfo.setWrapperType(handler.getWrapperType(operation, true));
+ }
+ if (dbObj != null && handler == null) {
+ // To avoid JAXB wrapper bean generation
+ inputWrapperInfo.setWrapperType(null);
+ }
+
+ // TUSCANY-3804 - handle output wrapper separately
+ db = outputWrapperInfo.getDataBinding();
+ if (db == null || JAXB_DATABINDING.equals(db)) {
+ db = assignOutputDataBinding(operation);
+ }
+
+ // Introspect the wrapper data type
+ dbObj = dataBindingRegistry.getDataBinding(db);
+ handler = dbObj == null ? null : dbObj.getWrapperHandler();
+ if (handler != null) {
+ outputWrapperInfo.setWrapperType(handler.getWrapperType(operation, false));
+ }
+
+ if (dbObj != null && handler == null) {
+ // To avoid JAXB wrapper bean generation
+ outputWrapperInfo.setWrapperType(null);
+ }
+ }
+ }
+
+ /*
+ * Assigns an operation DB if one of the input types has a non-default DB.
+ * However, if two of the input 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 String assignInputDataBinding(Operation operation) {
+
+ Set<String> dbs = new HashSet<String>();
+ List<DataType> opDataTypes = new LinkedList<DataType>();
+
+ opDataTypes.addAll(operation.getInputType().getLogical());
+
+ for (DataType<?> d : opDataTypes) {
+ if (d != null) {
+ String dataBinding = d.getDataBinding();
+ if ("java:array".equals(dataBinding)) {
+ dataBinding = ((DataType)d.getLogical()).getDataBinding();
+ }
+ if (dataBinding != null) {
+ dbs.add(dataBinding);
+ }
+ }
+ }
+
+ dbs.remove(JavaBeansDataBinding.NAME);
+ dbs.remove(SimpleJavaDataBinding.NAME);
+
+ if (dbs.size() == 1) {
+ String db = dbs.iterator().next();
+ operation.getInputWrapper().setDataBinding(db);
+ return db;
+ } else {
+ return operation.getInputWrapper().getDataBinding();
+ }
+ }
+
+ // TUSCANY-3804: handle output wrapper separately. Ignore faults
+ // in this calculation, as they're not part of the output wrapper, and
+ // we have our own introspection/framework to deal with fault databindings.
+ //
+ private String assignOutputDataBinding(Operation operation) {
+ Set<String> dbs = new HashSet<String>();
+ List<DataType> opDataTypes = new LinkedList<DataType>();
+
+ opDataTypes.addAll(operation.getOutputType().getLogical());
+
+ for (DataType<?> d : opDataTypes) {
+ if (d != null) {
+ String dataBinding = d.getDataBinding();
+ if ("java:array".equals(dataBinding)) {
+ dataBinding = ((DataType)d.getLogical()).getDataBinding();
+ }
+ if (dataBinding != null) {
+ dbs.add(dataBinding);
+ }
+ }
+ }
+
+ dbs.remove(JavaBeansDataBinding.NAME);
+ dbs.remove(SimpleJavaDataBinding.NAME);
+
+ if (dbs.size() == 1) {
+ String db = dbs.iterator().next();
+ operation.getOutputWrapper().setDataBinding(db);
+ return db;
+ } else {
+ return operation.getOutputWrapper().getDataBinding();
+ }
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java
new file mode 100644
index 0000000000..4997a872ba
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.lang.reflect.Array;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+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.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Array2ArrayTransformer extends BaseTransformer<Object, Object> implements PullTransformer<Object, Object> {
+
+ protected Mediator mediator;
+
+ public Array2ArrayTransformer(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return "java:array";
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return "java:array";
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object> 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<DataType> sourceType = context.getSourceDataType();
+ DataType<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/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Collection2CollectionTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Collection2CollectionTransformer.java
new file mode 100644
index 0000000000..dcd3c3fda3
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Collection2CollectionTransformer.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.util.Collection;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.interfacedef.DataType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Collection2CollectionTransformer extends BaseTransformer<Collection, Collection> implements
+ PullTransformer<Collection, Collection> {
+
+ private static final String JAVA_COLLECTION = "java:collection";
+ protected Mediator mediator;
+
+ public Collection2CollectionTransformer(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return JAVA_COLLECTION;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return JAVA_COLLECTION;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Collection> getSourceType() {
+ return Collection.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Collection> getTargetType() {
+ return Collection.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection transform(Collection sourceCollection, TransformationContext context) {
+ try {
+ if (sourceCollection == null) {
+ return null;
+ }
+ DataType<DataType> sourceType = context.getSourceDataType();
+ DataType<DataType> targetType = context.getTargetDataType();
+ Collection targetCollection = createCollection(targetType.getPhysical());
+ for (Object sourceItem : sourceCollection) {
+ Object targetItem =
+ mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context
+ .getMetadata());
+ targetCollection.add(targetItem);
+ }
+ return targetCollection;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ private Collection createCollection(Class<?> collectionClass) throws Exception {
+ return (Collection) collectionClass.newInstance();
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java
new file mode 100644
index 0000000000..f0e4a0fa10
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/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.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+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.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+import static org.apache.tuscany.sca.interfacedef.Operation.IDL_FAULT;
+
+/**
+ * This is a special transformer to transform the exception from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Exception2ExceptionTransformer extends BaseTransformer<Throwable, Throwable> implements
+ PullTransformer<Throwable, Throwable> {
+
+ protected Mediator mediator;
+ protected FaultExceptionMapper faultExceptionMapper;
+
+ public Exception2ExceptionTransformer(ExtensionPointRegistry registry) {
+ super();
+ UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ this.mediator = utilityExtensionPoint.getUtility(Mediator.class);
+ this.faultExceptionMapper = utilityExtensionPoint.getUtility(FaultExceptionMapper.class);
+ }
+
+ protected Exception2ExceptionTransformer(Mediator mediator, FaultExceptionMapper faultExceptionMapper) {
+ super();
+ this.mediator = mediator;
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_FAULT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_FAULT;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Throwable> getSourceType() {
+ return Throwable.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Throwable> 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<DataType> sourceType = context.getSourceDataType();
+
+ DataType<DataType> targetType = context.getTargetDataType();
+
+ Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation());
+ Object targetFaultInfo =
+ mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata());
+
+ Throwable targetException =
+ faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation());
+
+ // FIXME
+ return targetException == null ? source : targetException;
+
+ }
+
+ public void setFaultExceptionMapper(FaultExceptionMapper faultExceptionMapper) {
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java
new file mode 100644
index 0000000000..dfb6827762
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+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.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import static org.apache.tuscany.sca.interfacedef.Operation.IDL_INPUT;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Input2InputTransformer extends BaseTransformer<Object[], Object[]> implements
+ PullTransformer<Object[], Object[]> {
+ protected Mediator mediator;
+
+ public Input2InputTransformer(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_INPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_INPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object[]> getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object[]> getTargetType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10000;
+ }
+
+ /**
+ * Match the structure of the wrapper element. If it matches, then we can do
+ * wrapper to wrapper transformation. Otherwise, we do child to child.
+ * @param w1
+ * @param w2
+ * @return
+ */
+ private boolean matches(WrapperInfo w1, WrapperInfo w2) {
+ if (w1 == null || w2 == null) {
+ return false;
+ }
+ if (!w1.getWrapperElement().equals(w2.getWrapperElement())) {
+ return false;
+ }
+
+ // Compare the child elements
+ List<ElementInfo> list1 = w1.getChildElements();
+ List<ElementInfo> list2 = w2.getChildElements();
+ if (list1.size() != list2.size()) {
+ return false;
+ }
+ // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace
+ // of the interface instead of "". We only compare the local parts only to work around
+ // the namespace mismatch
+ for (int i = 0; i < list1.size(); i++) {
+ String n1 = list1.get(i).getQName().getLocalPart();
+ String n2 = list2.get(i).getQName().getLocalPart();
+ // TUSCANY-3298: In the following situation:
+ // 1. The child is a java.util.Map type
+ // 2. The child's name is a Java keyword (e.g., return)
+ // 3. Tuscany is using a generated JAXB wrapper class for WSDL generation
+ // the Java to WSDL generation process results in the WSDL element name
+ // having a leading underscore added to the actual element name. This is
+ // because of a known JAXB issue that prevents the @XmlElement annotation
+ // being used on a java.util.Map type property field in the wrapper bean
+ // (see https://jaxb.dev.java.net/issues/show_bug.cgi?id=268).
+ // To prevent the compatibility match from failing in this situation,
+ // we strip any leading underscore before doing the comparison.
+ if (!stripLeadingUnderscore(n1).equals(stripLeadingUnderscore(n2))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static String stripLeadingUnderscore(String name) {
+ return name.startsWith("_") ? name.substring(1) : name;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ // Check if the source operation is wrapped
+ DataType<List<DataType>> sourceType = context.getSourceDataType();
+ Operation sourceOp = context.getSourceOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isInputWrapperStyle() && sourceOp.getInputWrapper() != null;
+ boolean sourceNotSubjectToWrapping = sourceOp != null && sourceOp.isNotSubjectToWrapping();
+
+ // Find the wrapper handler for source data
+ WrapperHandler sourceWrapperHandler = null;
+ String sourceDataBinding = getDataBinding(sourceOp);
+ sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped);
+
+ // Check if the target operation is wrapped
+ DataType<List<DataType>> targetType = context.getTargetDataType();
+ Operation targetOp = (Operation)context.getTargetOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isInputWrapperStyle() && targetOp.getInputWrapper() != null;
+ boolean targetNotSubjectToWrapping = targetOp != null && targetOp.isNotSubjectToWrapping();
+
+ // Find the wrapper handler for target data
+ WrapperHandler targetWrapperHandler = null;
+ String targetDataBinding = getDataBinding(targetOp);
+ targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped);
+
+ if ((!sourceWrapped && !sourceNotSubjectToWrapping) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getInputWrapper();
+ // ElementInfo wrapperElement = wrapper.getInputWrapperElement();
+
+ // Class<?> targetWrapperClass = wrapper != null ? wrapper.getInputWrapperClass() : null;
+
+ if (source == null) {
+ // Empty child elements
+ Object targetWrapper = targetWrapperHandler.create(targetOp, true);
+ return new Object[] {targetWrapper};
+ }
+
+ // If the source can be wrapped, wrapped it first
+ if (sourceWrapperHandler != null) {
+ WrapperInfo sourceWrapperInfo = sourceOp.getInputWrapper();
+ DataType sourceWrapperType = sourceWrapperInfo != null ? sourceWrapperInfo.getWrapperType() : null;
+
+ // We only do wrapper to wrapper transformation if the source has a wrapper and both sides
+ // match by XML structure
+ if (sourceWrapperType != null && matches(sourceOp.getInputWrapper(), targetOp.getInputWrapper())) {
+ Class<?> sourceWrapperClass = sourceWrapperType.getPhysical();
+
+ // Create the source wrapper
+ Object sourceWrapper = sourceWrapperHandler.create(sourceOp, true);
+
+ // Populate the source wrapper
+ if (sourceWrapper != null) {
+ sourceWrapperHandler.setChildren(sourceWrapper,
+ source,
+ sourceOp,
+ true);
+
+ // Transform the data from source wrapper to target wrapper
+ 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(targetOp, true);
+ List<DataType> argTypes = wrapper.getUnwrappedType().getLogical();
+ Object[] targetChildren = new Object[source.length];
+ for (int i = 0; i < source.length; i++) {
+ // ElementInfo argElement = wrapper.getInputChildElements().get(i);
+ DataType<XMLType> argType = argTypes.get(i);
+ targetChildren[i] =
+ mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata());
+ }
+ targetWrapperHandler.setChildren(targetWrapper,
+ targetChildren,
+ targetOp,
+ true);
+ return new Object[] {targetWrapper};
+
+ } else if (sourceWrapped && (!targetWrapped && !targetNotSubjectToWrapping)) {
+ // Wrapped to Unwrapped
+ Object sourceWrapper = source[0];
+ Object[] target = null;
+
+ // List<ElementInfo> 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, sourceOp, true)) {
+
+ WrapperInfo targetWrapperInfo = targetOp.getInputWrapper();
+ DataType targetWrapperType =
+ targetWrapperInfo != null ? targetWrapperInfo.getWrapperType() : null;
+ if (targetWrapperType != null && matches(sourceOp.getInputWrapper(), targetOp.getInputWrapper())) {
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context
+ .getMetadata());
+ target = targetWrapperHandler.getChildren(targetWrapper, targetOp, true).toArray();
+ return target;
+ }
+ }
+ }
+ Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, true).toArray();
+ target = new Object[sourceChildren.length];
+ for (int i = 0; i < sourceChildren.length; i++) {
+ DataType<XMLType> childType = sourceOp.getInputWrapper().getUnwrappedType().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) {
+ WrapperInfo wrapper = operation.getInputWrapper();
+ if (wrapper != null) {
+ return wrapper.getDataBinding();
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Map2MapTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Map2MapTransformer.java
new file mode 100644
index 0000000000..5be7ba1da4
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Map2MapTransformer.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.util.Map;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.interfacedef.DataType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Map2MapTransformer extends BaseTransformer<Map, Map> implements PullTransformer<Map, Map> {
+
+ private static final String JAVA_MAP = "java:map";
+ protected Mediator mediator;
+
+ public Map2MapTransformer(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return JAVA_MAP;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return JAVA_MAP;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Map> getSourceType() {
+ return Map.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Map> getTargetType() {
+ return Map.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map transform(Map sourceMap, TransformationContext context) {
+ try {
+ if (sourceMap == null) {
+ return null;
+ }
+ DataType<DataType> sourceType = context.getSourceDataType();
+ DataType<DataType> targetType = context.getTargetDataType();
+ Map targetMap = createMap(targetType.getPhysical());
+ for (Object sourceItem : sourceMap.entrySet()) {
+ Map.Entry entry = (Map.Entry)sourceItem;
+ Object targetValue =
+ mediator.mediate(entry.getValue(), sourceType.getLogical(), targetType.getLogical(), context
+ .getMetadata());
+ targetMap.put(entry.getKey(), targetValue);
+ }
+ return targetMap;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ private Map createMap(Class<?> collectionClass) throws Exception {
+ return (Map)collectionClass.newInstance();
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
new file mode 100644
index 0000000000..b12d75e513
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import static org.apache.tuscany.sca.interfacedef.Operation.IDL_OUTPUT;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Output2OutputTransformer extends BaseTransformer<Object, Object> implements
+ PullTransformer<Object, Object> {
+
+ protected Mediator mediator;
+
+ /**
+ * @param wrapperHandler
+ */
+ public Output2OutputTransformer(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return IDL_OUTPUT;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ private String getDataBinding(Operation operation) {
+ WrapperInfo wrapper = operation.getOutputWrapper();
+ if (wrapper != null) {
+ return wrapper.getDataBinding();
+ } else {
+ return null;
+ }
+ }
+
+ 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;
+ }
+
+ /**
+ * Match the structure of the wrapper element. If it matches, then we can do
+ * wrapper to wrapper transformation. Otherwise, we do child to child.
+ * @param w1
+ * @param w2
+ * @return
+ */
+ private boolean matches(WrapperInfo w1, WrapperInfo w2) {
+ if (w1 == null || w2 == null) {
+ return false;
+ }
+ if (!w1.getWrapperElement().equals(w2.getWrapperElement())) {
+ return false;
+ }
+
+ // Compare the child elements
+ List<ElementInfo> list1 = w1.getChildElements();
+ List<ElementInfo> list2 = w2.getChildElements();
+ if (list1.size() != list2.size()) {
+ return false;
+ }
+ // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace
+ // of the interface instead of "". We only compare the local parts only to work around
+ // the namespace mismatch
+ for (int i = 0; i < list1.size(); i++) {
+ String n1 = list1.get(i).getQName().getLocalPart();
+ String n2 = list2.get(i).getQName().getLocalPart();
+
+ // TUSCANY-3298: In the following situation:
+ // 1. The child is a java.util.Map type
+ // 2. The child's name is a Java keyword (e.g., return)
+ // 3. Tuscany is using a generated JAXB wrapper class for WSDL generation
+ // the Java to WSDL generation process results in the WSDL element name
+ // having a leading underscore added to the actual element name. This is
+ // because of a known JAXB issue that prevents the @XmlElement annotation
+ // being used on a java.util.Map type property field in the wrapper bean
+ // (see https://jaxb.dev.java.net/issues/show_bug.cgi?id=268).
+ // To prevent the compatibility match from failing in this situation,
+ // we strip any leading underscore before doing the comparison.
+ if (!stripLeadingUnderscore(n1).equals(stripLeadingUnderscore(n2))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static String stripLeadingUnderscore(String name) {
+ return name.startsWith("_") ? name.substring(1) : name;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ try {
+
+ DataType<List<DataType>> sourceType = context.getSourceDataType();
+ Operation sourceOp = context.getSourceOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isOutputWrapperStyle() && sourceOp.getOutputWrapper() != null;
+ boolean sourceNotSubjectToWrapping = sourceOp != null && sourceOp.isNotSubjectToWrapping();
+
+ WrapperHandler sourceWrapperHandler = null;
+ String sourceDataBinding = getDataBinding(sourceOp);
+ sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped);
+
+ DataType<List<DataType>> targetType = context.getTargetDataType();
+ Operation targetOp = (Operation)context.getTargetOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isOutputWrapperStyle() && targetOp.getOutputWrapper() != null;
+ boolean targetNotSubjectToWrapping = targetOp != null && targetOp.isNotSubjectToWrapping();
+
+ WrapperHandler targetWrapperHandler = null;
+ String targetDataBinding = getDataBinding(targetOp);
+ targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped);
+
+ if ((!sourceWrapped &&!sourceNotSubjectToWrapping) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getOutputWrapper();
+ ElementInfo wrapperElement = wrapper.getWrapperElement();
+ List<ElementInfo> childElements = wrapper.getChildElements();
+ Class<?> targetWrapperClass = wrapper != null ? wrapper.getWrapperClass() : null;
+
+ Object[] outputs = null;
+ if ( !sourceOp.hasArrayWrappedOutput() ) {
+ outputs = new Object[] {response};
+ } else {
+ outputs = (Object[])response;
+ }
+
+ // If the source can be wrapped, wrapped it first
+ if (sourceWrapperHandler != null) {
+ WrapperInfo sourceWrapperInfo = sourceOp.getOutputWrapper();
+ DataType sourceWrapperType =
+ sourceWrapperInfo != null ? sourceWrapperInfo.getWrapperType() : null;
+
+ if (sourceWrapperType != null && matches(sourceOp.getOutputWrapper(), targetOp.getOutputWrapper())) {
+ Class<?> sourceWrapperClass = sourceWrapperType.getPhysical();
+
+ Object sourceWrapper = sourceWrapperHandler.create(sourceOp, false);
+ if (sourceWrapper != null) {
+ if (!childElements.isEmpty()) {
+ // Set the return value
+ sourceWrapperHandler.setChildren(sourceWrapper,
+ outputs,
+ sourceOp,
+ false);
+ }
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context
+ .getMetadata());
+ return targetWrapper;
+ }
+ }
+ }
+ Object targetWrapper = targetWrapperHandler.create(targetOp, false);
+
+ if (childElements.isEmpty()) {
+ // void output
+ return targetWrapper;
+ }
+
+ // No source wrapper, so we want to transform the child and then wrap the child-level target with the
+ // target wrapper handler.
+
+ Object[] targetChildren = new Object[outputs.length];
+ for (int i = 0; i < outputs.length; i++) {
+ DataType<XMLType> targetOutputType = wrapper.getUnwrappedType().getLogical().get(i);
+ targetChildren[i] =
+ mediator.mediate(outputs[i], sourceType.getLogical().get(i), targetOutputType, context.getMetadata());
+ }
+ targetWrapperHandler.setChildren(targetWrapper,
+ targetChildren,
+ targetOp,
+ false);
+ return targetWrapper;
+
+ } else if (sourceWrapped && (!targetWrapped && !targetNotSubjectToWrapping)) {
+ // Wrapped to Unwrapped
+ Object sourceWrapper = response;
+ List<ElementInfo> childElements = sourceOp.getOutputWrapper().getChildElements();
+ if (childElements.isEmpty()) {
+ // The void output
+ return null;
+ }
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getOutputWrapper().getWrapperElement();
+
+ // 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, sourceOp, false)) {
+
+ WrapperInfo targetWrapperInfo = targetOp.getOutputWrapper();
+ DataType targetWrapperType =
+ targetWrapperInfo != null ? targetWrapperInfo.getWrapperType() : null;
+
+ if (targetWrapperType != null && matches(sourceOp.getOutputWrapper(), targetOp.getOutputWrapper())) {
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context
+ .getMetadata());
+ List targetChildren = targetWrapperHandler.getChildren(targetWrapper, targetOp, false);
+ if (targetOp.hasArrayWrappedOutput()) {
+ return targetChildren.toArray();
+ } else {
+ return targetChildren.get(0);
+ }
+ }
+ }
+ }
+
+ // Otherwise we need to unwrap on the source side, and then transform each child
+ Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).toArray();
+ Object[] target = new Object[sourceChildren.length];
+ for (int i = 0; i < sourceChildren.length; i++) {
+ DataType<XMLType> childType = sourceOp.getOutputWrapper().getUnwrappedType().getLogical().get(i);
+ target[i] =
+ mediator.mediate(sourceChildren[i], childType, targetType.getLogical().get(i), context
+ .getMetadata());
+ }
+
+ if (targetOp.hasArrayWrappedOutput()) {
+ return target;
+ } else {
+ if (target.length > 1 ) {
+ throw new IllegalStateException("Expecting only one output based on Operation model, found: " +
+ target.length + " # of outputs.");
+ }
+ return target[0];
+ }
+ } else {
+ Object[] outputs = null;
+ if ( !sourceOp.hasArrayWrappedOutput() ) {
+ outputs = new Object[] {response};
+ } else {
+ outputs = (Object[])response;
+ }
+ Object[] target = new Object[outputs.length];
+ for (int i = 0; i < outputs.length; i++) {
+ Object child =
+ mediator.mediate(outputs[i], sourceType.getLogical().get(i), targetType.getLogical().get(i), context
+ .getMetadata());
+ target[i] = child;
+ }
+ if (targetOp.hasArrayWrappedOutput()) {
+ return target;
+ } else {
+ if (target.length > 1 ) {
+ throw new IllegalStateException("Expecting only one output based on Operation model, found: " +
+ target.length + " # of outputs.");
+ }
+ return target[0];
+ }
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
new file mode 100644
index 0000000000..29a4551a5a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.util.OperationDataBindingHelper;
+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.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+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(ExtensionPointRegistry registry) {
+ super();
+ this.mediator = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(Mediator.class);
+ }
+
+ public void process(RuntimeEndpoint endpoint) {
+ InterfaceContract sourceContract = endpoint.getBindingInterfaceContract();
+ InterfaceContract targetContract = endpoint.getComponentTypeServiceInterfaceContract();
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+
+ if (!sourceContract.getInterface().isRemotable()) {
+ return;
+ }
+ List<InvocationChain> chains = endpoint.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(endpoint, sourceOperation, targetOperation, mediator);
+ }
+ if (interceptor != null) {
+ String phase = Phase.SERVICE_INTERFACE;
+ chain.addInterceptor(phase, interceptor);
+ }
+ }
+
+ }
+
+ public void process(RuntimeEndpointReference endpointReference) {
+ InterfaceContract sourceContract = endpointReference.getComponentTypeReferenceInterfaceContract();
+ InterfaceContract targetContract = endpointReference.getBindingInterfaceContract();
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+
+ if (sourceContract == null || !sourceContract.getInterface().isRemotable()) {
+ return;
+ }
+ List<InvocationChain> chains = endpointReference.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(endpointReference, sourceOperation, targetOperation, mediator);
+ }
+ if (interceptor != null) {
+ String phase = Phase.REFERENCE_INTERFACE;
+ chain.addInterceptor(phase, interceptor);
+ }
+ }
+
+ }
+
+
+ private boolean isTransformationRequired(InterfaceContract sourceContract,
+ Operation sourceOperation,
+ InterfaceContract targetContract,
+ Operation targetOperation) {
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+ if (sourceContract == targetContract) {
+ return false;
+ }
+ return OperationDataBindingHelper.isTransformationRequired(sourceOperation, targetOperation);
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
new file mode 100644
index 0000000000..8b15d616ac
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.invocation.InterceptorAsyncImpl;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.Invocable;
+
+/**
+ * An interceptor to transform data across databindings on the wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataTransformationInterceptor extends InterceptorAsyncImpl {
+
+ private Operation sourceOperation;
+
+ private Operation targetOperation;
+ private Invocable invocable;
+ private Mediator mediator;
+
+ public DataTransformationInterceptor(Invocable invocable,
+ Operation sourceOperation,
+ Operation targetOperation,
+ Mediator mediator) {
+ super();
+ this.sourceOperation = sourceOperation;
+ this.targetOperation = targetOperation;
+ if ( sourceOperation instanceof JavaOperation ) {
+ JavaOperation javaOp = (JavaOperation) sourceOperation;
+ Method sourceMethod = javaOp.getJavaMethod();
+ }
+
+ this.mediator = mediator;
+ this.invocable = invocable;
+ }
+
+ public Message processRequest(Message msg) {
+ Map<String, Object> metadata = new HashMap<String, Object>();
+ metadata.put(Invocable.class.getName(), invocable);
+ Object input = mediator.mediateInput(msg.getBody(), sourceOperation, targetOperation, metadata);
+ msg.setBody(input);
+ return msg;
+ }
+
+ public Message processResponse(Message msg) {
+ Message resultMsg = msg;
+ Map<String, Object> metadata = new HashMap<String, Object>();
+ metadata.put(Invocable.class.getName(), invocable);
+
+ if (sourceOperation.isNonBlocking()) {
+ // Not to reset the message body
+ return resultMsg;
+ }
+
+ Object result = resultMsg.getBody();
+
+ if (resultMsg.isFault()) {
+ Object transformedFault = null;
+ if ((result instanceof Exception) && !(result instanceof RuntimeException)) {
+ transformedFault = mediator.mediateFault(result, sourceOperation, targetOperation, metadata);
+ if (transformedFault != result) {
+ resultMsg.setFaultBody(transformedFault);
+ }
+ }
+ //
+ // Leave it to another layer to actually throw the Exception which constitutes
+ // the message body. We don't throw it here.
+ //
+ } else {
+ assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result;
+ Object newResult = mediator.mediateOutput(result, sourceOperation, targetOperation, metadata);
+ resultMsg.setBody(newResult);
+ }
+
+ return resultMsg;
+ }
+
+/*
+ public Message invoke(Message msg) {
+ Map<String, Object> metadata = new HashMap<String, Object>();
+ metadata.put(Invocable.class.getName(), invocable);
+ Object input = mediator.mediateInput(msg.getBody(), sourceOperation, targetOperation, metadata);
+ msg.setBody(input);
+ Message resultMsg = next.invoke(msg);
+
+ if (sourceOperation.isNonBlocking()) {
+ // Not to reset the message body
+ return resultMsg;
+ }
+
+ Object result = resultMsg.getBody();
+
+ if (resultMsg.isFault()) {
+ Object transformedFault = null;
+ if ((result instanceof Exception) && !(result instanceof RuntimeException)) {
+ transformedFault = mediator.mediateFault(result, sourceOperation, targetOperation, metadata);
+ if (transformedFault != result) {
+ resultMsg.setFaultBody(transformedFault);
+ }
+ }
+ //
+ // Leave it to another layer to actually throw the Exception which constitutes
+ // the message body. We don't throw it here.
+ //
+ } else {
+ assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result;
+ Object newResult = mediator.mediateOutput(result, sourceOperation, targetOperation, metadata);
+ resultMsg.setBody(newResult);
+ }
+
+ return resultMsg;
+ }
+*/
+
+
+ /**
+ * Returns return type for first Holder in input list.
+ * Returns null if the inputs do not contain a Holder.
+ */
+ protected List<DataType<DataType>> getHolderTypes( DataType<List<DataType>> inputTypes ) {
+ ArrayList<DataType<DataType>> returnTypes = new ArrayList<DataType<DataType>>();
+ if (inputTypes != null) {
+
+ List<DataType> logicalType = inputTypes.getLogical();
+ if (logicalType != null) {
+ for (int i = 0; i < logicalType.size(); i++) {
+ DataType dataType = logicalType.get(i);
+ if (isHolder(dataType.getGenericType())) {
+ returnTypes.add(dataType);
+ }
+ }
+ }
+ }
+ return returnTypes;
+ }
+
+ protected static boolean isHolder( Type type ) {
+ String typeString = type.toString();
+ if ( typeString.startsWith( "javax.xml.ws.Holder" ) ) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java
new file mode 100644
index 0000000000..44e5072e61
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES 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 org.apache.tuscany.sca.databinding.Mediator;
+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.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Implementation of an interceptor that enforces pass-by-value semantics
+ * on operation invocations by copying the operation input and output data.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueInterceptor implements Interceptor {
+
+ private Mediator mediator;
+ 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(Mediator mediator, InvocationChain chain, Operation operation) {
+ this.mediator = mediator;
+ this.chain = chain;
+ this.operation = operation;
+ }
+
+ public Message invoke(Message msg) {
+ if (chain.allowsPassByReference()) {
+ return nextInvoker.invoke(msg);
+ }
+
+ msg.setBody(mediator.copyInput(msg.getBody(), operation));
+
+ Message resultMsg = nextInvoker.invoke(msg);
+
+ if (!resultMsg.isFault() && operation.getOutputType() != null) {
+ resultMsg.setBody(mediator.copyOutput(resultMsg.getBody(), operation));
+ }
+
+ if (resultMsg.isFault()) {
+ resultMsg.setFaultBody(mediator.copyFault(resultMsg.getBody(), operation));
+ }
+ return resultMsg;
+ }
+
+ public Invoker getNext() {
+ return nextInvoker;
+ }
+
+ public void setNext(Invoker next) {
+ this.nextInvoker = next;
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
new file mode 100644
index 0000000000..a1f5d37ff3
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation classes for special transformers
+#
+# Java array --> Java array
+org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer;source=java:array,target=java:array,weight=10,public=false
+# Java exception --> Java exception
+org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer;source=idl:fault,target=idl:fault,weight=10,public=false
+# Input to Input
+org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer;source=idl:input,target=idl:input,weight=10,public=false
+# Output to Output
+org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer;source=idl:output,target=idl:output,weight=10,public=false
+# Group to Group
+org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer;source=databinding:group,target=databinding:group,weight=10,public=false
+
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor
new file mode 100644
index 0000000000..875814fccc
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor;ranking=300
+org.apache.tuscany.sca.core.databinding.processor.WrapperJavaInterfaceProcessor;ranking=200
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessor b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessor
new file mode 100644
index 0000000000..dfd86a3a53
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessor
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT 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.core.databinding.wire.DataBindingRuntimeWireProcessor