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/databinding-jaxb/DISCLAIMER | 8 + .../modules/databinding-jaxb/LICENSE | 205 +++++++++++++++++++++ .../sca-java-1.0.1/modules/databinding-jaxb/NOTICE | 6 + .../modules/databinding-jaxb/pom.xml | 194 +++++++++++++++++++ .../tuscany/sca/databinding/jaxb/JAXB2Node.java | 72 ++++++++ .../sca/databinding/jaxb/JAXBContextHelper.java | 176 ++++++++++++++++++ .../sca/databinding/jaxb/JAXBDataBinding.java | 114 ++++++++++++ .../sca/databinding/jaxb/JAXBExceptionHandler.java | 107 +++++++++++ .../sca/databinding/jaxb/JAXBWrapperHandler.java | 175 ++++++++++++++++++ .../jaxb/JAXWSJavaInterfaceProcessor.java | 117 ++++++++++++ .../tuscany/sca/databinding/jaxb/Node2JAXB.java | 69 +++++++ .../tuscany/sca/databinding/jaxb/Reader2JAXB.java | 70 +++++++ .../sca/databinding/jaxb/XMLStreamReader2JAXB.java | 71 +++++++ .../org.apache.tuscany.sca.databinding.DataBinding | 19 ++ ....apache.tuscany.sca.databinding.PullTransformer | 22 +++ ...terfacedef.java.introspect.JavaInterfaceVisitor | 18 ++ .../databinding/jaxb/JAXBDataBindingTestCase.java | 129 +++++++++++++ .../jaxb/JAXBExceptionHandlerTestCase.java | 81 ++++++++ .../tuscany/databinding/jaxb/JAXBTestCase.java | 160 ++++++++++++++++ .../jaxb/JAXBWrapperHandlerTestCase.java | 72 ++++++++ .../jaxb/JAXWSJavaInterfaceProcessorTestCase.java | 102 ++++++++++ .../databinding/jaxb/fault/InvalidSymbolFault.java | 78 ++++++++ .../jaxb/fault/InvalidSymbolFault_Exception.java | 64 +++++++ .../databinding-jaxb/src/test/resources/ipo.xsd | 136 ++++++++++++++ 24 files changed, 2265 insertions(+) create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/DISCLAIMER create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/LICENSE create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/NOTICE create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/pom.xml create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java create mode 100644 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java create mode 100755 branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/resources/ipo.xsd (limited to 'branches/sca-java-1.0.1/modules/databinding-jaxb') diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/DISCLAIMER b/branches/sca-java-1.0.1/modules/databinding-jaxb/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/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-1.0.1/modules/databinding-jaxb/LICENSE b/branches/sca-java-1.0.1/modules/databinding-jaxb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/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-1.0.1/modules/databinding-jaxb/NOTICE b/branches/sca-java-1.0.1/modules/databinding-jaxb/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/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-1.0.1/modules/databinding-jaxb/pom.xml b/branches/sca-java-1.0.1/modules/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..51e4aaffad --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/pom.xml @@ -0,0 +1,194 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0.1-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-jaxb + Apache Tuscany SCA Data Binding for JAXB + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0.1-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 1.0.1-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.0.1-incubating-SNAPSHOT + + + javax.xml.bind + jaxb-api + 2.1 + + + + javax.xml.ws + jaxws-api + + 2.1 + + + + com.sun.xml.bind + jaxb-impl + 2.1.4 + runtime + + + + javax.xml.bind + jsr173_api + + + + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + generate-sources + + copy + + + + + javax.xml.ws + jaxws-api + 2.1 + jar + + + javax.xml.bind + jaxb-api + 2.1 + jar + + + ${project.build.directory}/endorsed + false + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -Djava.endorsed.dirs=target/endorsed + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + 1.1 + + + generate-jaxb + generate-test-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + + + diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..6e0f03951b --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class JAXB2Node extends BaseTransformer implements PullTransformer { + + public Node transform(Object source, TransformationContext tContext) { + if (source == null) { + return null; + } + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + // FIXME: The default Marshaller doesn't support + // marshaller.getNode() + Document document = DOMHelper.newDocument(); + JAXBElement jaxbElement = JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Object.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..54e51cd97c --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import java.beans.Introspector; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +public class JAXBContextHelper { + // TODO: Do we need to set them for source and target? + public static final String JAXB_CLASSES = "jaxb.classes"; + + public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath"; + + private JAXBContextHelper() { + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + DataType bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + // FIXME: We should check the context path or classes + // FIXME: What should we do if JAXB is an intermediate node? + + String contextPath = null; + JAXBContext context = null; + Class cls = bindingContext.getPhysical(); + if (cls.getPackage() != null) { + contextPath = cls.getPackage().getName(); + context = JAXBContext.newInstance(contextPath); + } + if (context == null) { + throw new TransformationException("JAXB context is not set for the transformation."); + } + return context; + } + + @SuppressWarnings("unchecked") + public static JAXBElement createJAXBElement(DataType dataType, Object value) { + if (value instanceof JAXBElement) { + return (JAXBElement)value; + } else { + Class type = dataType.getPhysical(); + Object logical = dataType.getLogical(); + QName elementName = JAXBDataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } else { + /** + * Set the declared type to Object.class so that xsi:type + * will be produced + */ + type = Object.class; + } + } else { + type = Object.class; + } + return new JAXBElement(elementName, type, value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class cls = getJavaType(dataType); + if (cls == JAXBElement.class) { + return createJAXBElement(dataType, value); + } else { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } + } + + public static Class getJavaType(DataType dataType) { + if (dataType == null) { + return null; + } + Type type = dataType.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (JAXBElement.class.isAssignableFrom(cls)) { + return null; + } else { + return cls; + } + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + return (Class)pType.getRawType(); + } + return null; + } + + public static XMLType getXmlTypeName(Class javaType) { + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + if (schema != null) { + namespace = schema.namespace(); + } + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default") && typeName.equals("")) { + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + namespace = rootElement.namespace(); + } else { + // FIXME: The namespace should be from the referencing + // property + namespace = null; + } + } else if (typeNamespace.equals("##default")) { + // namespace is from the package + } else { + namespace = typeNamespace; + } + + if (typeName.equals("##default")) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } else { + name = typeName; + } + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + if (xmlEnum != null) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } + } + if (name == null) { + return null; + } + return new XMLType(null, new QName(namespace, name)); + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..9706ffdc21 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Document; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends BaseDataBinding { + public static final String NAME = JAXBElement.class.getName(); + public static final String[] ALIASES = new String[] {"jaxb"}; + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public JAXBDataBinding() { + super(NAME, ALIASES, JAXBElement.class); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + if (JAXBElement.class.isAssignableFrom(javaType)) { + Type type = javaType.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = ((ParameterizedType)type); + Type rawType = parameterizedType.getRawType(); + if (rawType == JAXBElement.class) { + Type actualType = parameterizedType.getActualTypeArguments()[0]; + if (actualType instanceof Class) { + XMLType xmlType = JAXBContextHelper.getXmlTypeName((Class)actualType); + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + } + } + dataType.setLogical(XMLType.UNKNOWN); + dataType.setDataBinding(getName()); + return true; + } + + XMLType xmlType = JAXBContextHelper.getXmlTypeName(javaType); + if (xmlType == null) { + return false; + } + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + boolean isElement = false; + Class cls = arg.getClass(); + if (arg instanceof JAXBElement) { + isElement = true; + cls = ((JAXBElement)arg).getDeclaredType(); + } else { + arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg); + } + JAXBContext context = JAXBContext.newInstance(cls); + Document doc = DOMHelper.newDocument(); + context.createMarshaller().marshal(arg, doc); + JAXBElement element = context.createUnmarshaller().unmarshal(doc, cls); + return isElement ? element : element.getValue(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new JAXBExceptionHandler(); + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java new file mode 100644 index 0000000000..aa37031c04 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * JAXB implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class JAXBExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exDataType) { + Class exceptionType = exDataType.getPhysical(); + WebFault webFault = exceptionType.getAnnotation(WebFault.class); + if (webFault == null) { + return null; + } else { + QName element = new QName(webFault.targetNamespace(), webFault.name()); + // TODO: Need to determine the fault bean class + // String faultBean = webFault.faultBean(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + // The logical type of a fault is the QName of the element that the + // only part in + // the fault message references + DataType faultType = + new DataTypeImpl(JAXBDataBinding.NAME, faultBeanClass, new XMLType(element, null)); + // faultType.setMetadata(ElementInfo.class.getName(), new + // ElementInfo(element, null)); + return faultType; + } + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..c3e97a4818 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.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.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +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.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * JAXB WrapperHandler implementation + */ +public class JAXBWrapperHandler implements WrapperHandler> { + + public JAXBElement create(ElementInfo element, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + //FIXME Understand why we need this, the classloader should be passed in + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + Object factory = factoryClass.newInstance(); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + Object value = typeClass.newInstance(); + return (JAXBElement)method.invoke(factory, new Object[] {value}); + } else { + throw new TransformationException("ObjectFactory cannot be resolved."); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement wrapper, int i, ElementInfo childElement, Object value) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + String property = properties[i]; + + try { + for (Method m : wrapperClass.getMethods()) { + if (m.getName().equals("set" + capitalize(property))) { + m.invoke(wrapperValue, new Object[] {value}); + return; + } + } + } catch (Throwable e) { + throw new TransformationException(e); + } + } + + private static String capitalize(String name) { + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getChildren(java.lang.Object, List, TransformationContext) + */ + public List getChildren(JAXBElement wrapper, List childElements, TransformationContext context) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + List elements = new ArrayList(); + for (String p : properties) { + try { + Method method = wrapperClass.getMethod("get" + capitalize(p), (Class[])null); + Object value = method.invoke(wrapperValue, (Object[])null); + elements.add(value); + } catch (Throwable e) { + throw new TransformationException(e); + } + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + //FIXME Understand why we need this, the classloader should be passed in + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + DataType wrapperType = + new DataTypeImpl(JAXBDataBinding.NAME, typeClass, new XMLType(element)); + return wrapperType; + } + + return null; + } catch (Throwable e) { + return null; + } + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, org.apache.tuscany.sca.interfacedef.util.ElementInfo, java.util.List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public boolean isInstance(Object wrapper, + ElementInfo element, + List childElements, + TransformationContext context) { + // TODO: Implement the logic + return true; + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..b5ac3fb47f --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +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; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class JAXWSJavaInterfaceProcessor implements JavaInterfaceVisitor { + + public JAXWSJavaInterfaceProcessor() { + super(); + } + + public void visitInterface(JavaInterface contract) throws InvalidInterfaceException { + + Class clazz = contract.getJavaClass(); + WebService webService = clazz.getAnnotation(WebService.class); + String tns = ""; + if (webService != null) { + tns = webService.targetNamespace(); + // Mark SEI as Remotable + contract.setRemotable(true); + } + if (!contract.isRemotable()) { + return; + } + Map operations = new HashMap(); + for (Operation op : contract.getOperations()) { + operations.put(op.getName(), op); + } + for (Method method : clazz.getMethods()) { + Operation operation = operations.get(method.getName()); + + WebMethod webMethod = method.getAnnotation(WebMethod.class); + if (webMethod == null) { + return; + } + + /* + String operationName = getValue(webMethod.operationName(), operation.getName()); + + RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class); + ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class); + if (requestWrapper == null) { + return; + } + + String ns = getValue(requestWrapper.targetNamespace(), tns); + String name = getValue(requestWrapper.localName(), operationName); + QName inputWrapper = new QName(ns, name); + + ns = getValue(responseWrapper.targetNamespace(), tns); + name = getValue(responseWrapper.localName(), operationName + "Response"); + + QName outputWrapper = new QName(ns, name); + + List inputElements = new ArrayList(); + for (Annotation[] annotations : method.getParameterAnnotations()) { + for (Annotation annotation : annotations) { + if (annotation.annotationType() == WebParam.class) { + WebParam param = (WebParam)annotation; + inputElements.add(new ElementInfo(new QName(param.targetNamespace(), param.name()), null)); + break; + } + } + } + + List outputElements = new ArrayList(); + WebResult result = method.getAnnotation(WebResult.class); + outputElements.add(new ElementInfo(new QName(result.targetNamespace(), result.name()), null)); + + WrapperInfo wrapperInfo = + new WrapperInfo(JAXBDataBinding.NAME, new ElementInfo(inputWrapper, null), + new ElementInfo(outputWrapper, null), inputElements, outputElements); + operation.setWrapper(wrapperInfo); + */ + operation.setWrapperStyle(false); + operation.setDataBinding(JAXBDataBinding.NAME); + } + } + + private static String getValue(String value, String defaultValue) { + return "".equals(value) ? defaultValue : value; + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..1490183edb --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +public class Node2JAXB extends BaseTransformer implements PullTransformer { + + public Node2JAXB() { + super(); + } + + public Object transform(Node source, TransformationContext context) { + if (source == null) + return null; + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..c4aab8a898 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.io.Reader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class Reader2JAXB extends BaseTransformer implements + PullTransformer { + + public Object transform(final Reader source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(source); + Object result = unmarshaller.unmarshal(streamSource); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Reader.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..d74a777fa1 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class XMLStreamReader2JAXB extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2JAXB() { + super(); + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + source.close(); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..58d6123373 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding @@ -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. + +# implementation classes for the databindings +org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding;type=javax.xml.bind.JAXBElement,name=jaxb diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..3bc20461ab --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.jaxb.JAXB2Node;source=javax.xml.bind.JAXBElement,target=org.w3c.dom.Node,weight=500 +org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;source=org.w3c.dom.Node,target=javax.xml.bind.JAXBElement,weight=500 +org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB;source=java.io.Reader,target=javax.xml.bind.JAXBElement,weight=510 +org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB;source=javax.xml.stream.XMLStreamReader,target=javax.xml.bind.JAXBElement,weight=490 \ No newline at end of file diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor new file mode 100644 index 0000000000..28ce24b63a --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..b121e2c99f --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import java.lang.annotation.Annotation; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * + */ +public class JAXBDataBindingTestCase extends TestCase { + private JAXBDataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + binding = new JAXBDataBinding(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class, Annotation)}. + */ + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(JAXBElement.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(MockJAXBElement.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(MockJAXBElement.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USAddress.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USState.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertEquals(USState.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USState"), ((XMLType)dataType.getLogical()).getTypeName()); + + } + + private static class MockJAXBElement extends JAXBElement { + + private static final long serialVersionUID = -2767569071002707973L; + + /** + * @param elementName + * @param type + * @param value + */ + public MockJAXBElement(QName elementName, Class type, PurchaseOrderType value) { + super(elementName, type, value); + } + + } + + @SuppressWarnings("unchecked") + public void testCopy() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + JAXBElement po = factory.createPurchaseOrder(poType); + JAXBElement copy = (JAXBElement)binding.copy(po); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getName()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonElement() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + poType.setComment("Comment"); + PurchaseOrderType copy = (PurchaseOrderType)binding.copy(poType); + assertTrue(copy instanceof PurchaseOrderType); + assertEquals("Comment", (copy).getComment()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonRoot() { + ObjectFactory factory = new ObjectFactory(); + USAddress address = factory.createUSAddress(); + address.setCity("San Jose"); + USAddress copy = (USAddress)binding.copy(address); + assertTrue(copy instanceof USAddress); + assertEquals("San Jose", (copy).getCity()); + + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java new file mode 100644 index 0000000000..9cf40ee9a6 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault; +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault_Exception; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXBExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBExceptionHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + private JAXBExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBExceptionHandler(); + } + + public void testGetFaultType() { + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(exType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(JAXBDataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..05f112aff3 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.sca.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +public class JAXBTestCase 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" + + " " + + " " + + ""; + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform2() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + QName root = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform3() throws Exception { + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); + Node node = t1.transform(po, tContext1); + + Assert.assertNotNull(node); + + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java new file mode 100644 index 0000000000..563d6232b1 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBWrapperHandler; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBWrapperHandlerTestCase extends TestCase { + // private static final QName ELEMENT = new QName("http://www.example.com/IPO", "purchaseOrder"); + private JAXBWrapperHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBWrapperHandler(); + } + + public void testCreate() { + // ElementInfo element = new ElementInfo(ELEMENT, null); + // JAXBElement jaxbElement = handler.create(element, null); + } + + public void testSetChild() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + JAXBElement wrapper = factory.createPurchaseOrder(po); + handler.setChild(wrapper, 2, null, "Comment"); + } + + public void testGetChildren() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + po.setComment("Comment"); + JAXBElement wrapper = factory.createPurchaseOrder(po); + List children = handler.getChildren(wrapper, null, null); + assertNotNull(children); + assertEquals(4, children.size()); + assertEquals("Comment", children.get(2)); + assertNull(children.get(0)); + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..83abdc29f5 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb; + +import javax.jws.WebService; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; + +/** + * + */ +public class JAXWSJavaInterfaceProcessorTestCase extends TestCase { + private JAXWSJavaInterfaceProcessor interfaceProcessor; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + interfaceProcessor = new JAXWSJavaInterfaceProcessor(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor#visitInterface(JavaInterface)}. + */ + public final void testProcessor() throws Exception { + JavaInterface contract = new MockJavaInterfaceImpl(); + contract.setJavaClass(WebServiceInterfaceWithoutAnnotation.class); + + interfaceProcessor.visitInterface(contract); + assertFalse(contract.isRemotable()); + + contract.setJavaClass(WebServiceInterfaceWithAnnotation.class); + interfaceProcessor.visitInterface(contract); + assertTrue(contract.isRemotable()); + } + + @WebService + private static interface WebServiceInterfaceWithAnnotation { + + } + + private static interface WebServiceInterfaceWithoutAnnotation { + + } + + private class MockJavaInterfaceImpl extends InterfaceImpl implements JavaInterface { + private Class javaClass; + + public Class getCallbackClass() { + // TODO Auto-generated method stub + return null; + } + + public Class getJavaClass() { + // TODO Auto-generated method stub + return javaClass; + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + + public void setCallbackClass(Class callbackClass) { + // TODO Auto-generated method stub + + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public void setName(String className) { + // TODO Auto-generated method stub + + } + } +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java new file mode 100644 index 0000000000..fd21d72337 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES 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.databinding.jaxb.fault; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for anonymous complex type. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"message", "symbol"}) +@XmlRootElement(name = "InvalidSymbolFault") +public class InvalidSymbolFault { + + @XmlElement(required = true) + protected String message; + @XmlElement(required = true) + protected String symbol; + + /** + * Gets the value of the message property. + * + * @return possible object is {@link String } + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value allowed object is {@link String } + */ + public void setMessage(String value) { + this.message = value; + } + + /** + * Gets the value of the symbol property. + * + * @return possible object is {@link String } + */ + public String getSymbol() { + return symbol; + } + + /** + * Sets the value of the symbol property. + * + * @param value allowed object is {@link String } + */ + public void setSymbol(String value) { + this.symbol = value; + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..e78889aee0 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb.fault; + +import javax.xml.ws.WebFault; + +/** + * This class was generated by the JAXWS SI. JAX-WS RI 2.1-02/02/2007 09:55 + * AM(vivekp)-FCS Generated source version: 2.1 + */ +@WebFault(name = "InvalidSymbolFault", targetNamespace = "http://www.example.com/stock") +public class InvalidSymbolFault_Exception extends Exception { + private static final long serialVersionUID = -4618497501663457633L; + + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/resources/ipo.xsd b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/databinding-jaxb/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3