From f860c2f35b2f94e379d2ff7d5c13f54cd4a3132a Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:42 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835119 13f79535-47bb-0310-9956-ffa450edef68 --- .../modules/databinding-sdo/.checkstyle | 25 +++ .../sca-java-0.90/modules/databinding-sdo/.ruleset | 191 +++++++++++++++++ .../modules/databinding-sdo/DISCLAIMER | 8 + .../sca-java-0.90/modules/databinding-sdo/LICENSE | 205 ++++++++++++++++++ .../sca-java-0.90/modules/databinding-sdo/NOTICE | 6 + .../sca-java-0.90/modules/databinding-sdo/pom.xml | 114 ++++++++++ .../sca/databinding/sdo/DataObject2String.java | 58 +++++ .../sdo/DataObject2XMLStreamReader.java | 67 ++++++ .../sdo/DuplicateHelperContextException.java | 37 ++++ .../databinding/sdo/HelperContextProcessor.java | 110 ++++++++++ .../sca/databinding/sdo/HelperContextRegistry.java | 52 +++++ .../databinding/sdo/HelperContextRegistryImpl.java | 49 +++++ .../tuscany/sca/databinding/sdo/ImportSDO.java | 78 +++++++ .../sca/databinding/sdo/ImportSDOProcessor.java | 192 +++++++++++++++++ .../sca/databinding/sdo/SDOContextHelper.java | 106 ++++++++++ .../sca/databinding/sdo/SDODataBinding.java | 122 +++++++++++ .../sca/databinding/sdo/SDOExceptionHandler.java | 124 +++++++++++ .../sca/databinding/sdo/SDOSimpleTypeMapper.java | 66 ++++++ .../sca/databinding/sdo/SDOWrapperHandler.java | 99 +++++++++ .../sca/databinding/sdo/String2DataObject.java | 55 +++++ .../sca/databinding/sdo/XMLDocument2String.java | 59 ++++++ .../sdo/XMLDocument2XMLStreamReader.java | 63 ++++++ .../sdo/XMLStreamReader2DataObject.java | 64 ++++++ .../sdo/XMLStreamReader2XMLDocument.java | 58 +++++ .../sca/databinding/sdo/api/HelperContext.java | 37 ++++ .../sdo/module/SDODataBindingModuleActivator.java | 80 +++++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 ++ .../sdo/fault/InvalidSymbolFault_Exception.java | 67 ++++++ .../databinding/sdo/DataObject2StringTestCase.java | 64 ++++++ .../sdo/DataObject2XMLStreamReaderTestCase.java | 58 +++++ .../sdo/HelperContextProcessorTestCase.java | 83 ++++++++ .../sdo/ImportSDOProcessorTestCase.java | 85 ++++++++ .../databinding/sdo/SDODataBindingTestCase.java | 110 ++++++++++ .../sdo/SDOExceptionHandlerTestCase.java | 82 ++++++++ .../sdo/SDOTransformerTestCaseBase.java | 79 +++++++ .../databinding/sdo/SDOWrapperHandlerTestCase.java | 60 ++++++ .../sca/databinding/sdo/TestModelResolver.java | 63 ++++++ .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 61 ++++++ .../databinding-sdo/src/test/resources/ipo.xsd | 136 ++++++++++++ .../src/test/resources/model/sca-core.xsd | 233 +++++++++++++++++++++ .../resources/model/sca-implementation-mock.xsd | 43 ++++ .../databinding-sdo/src/test/resources/stock.xsd | 33 +++ .../databinding-sdo/src/test/resources/wrapper.xml | 27 +++ .../databinding-sdo/src/test/resources/wrapper.xsd | 38 ++++ 44 files changed, 3465 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/pom.xml create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/stock.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xml create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xsd (limited to 'sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo') diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.checkstyle b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.ruleset b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/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/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/LICENSE b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/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-1.x/branches/sca-java-0.90/modules/databinding-sdo/NOTICE b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/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/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/pom.xml b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/pom.xml new file mode 100755 index 0000000000..4a244a0a58 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.90-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-sdo + Apache Tuscany Data Binding for SDO + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.90-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 0.90-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 0.90-incubating-SNAPSHOT + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubating-beta1 + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubating-beta1 + + + generate-po-sdo + generate-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..405de57ab3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java @@ -0,0 +1,58 @@ +/* + * 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.sdo; + +import javax.xml.namespace.QName; + +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 commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2String extends BaseTransformer implements + PullTransformer { + + public String transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..5b258b5429 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java @@ -0,0 +1,67 @@ +/* + * 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.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +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; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + XMLDocument document = + xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + return streamHelper.createXMLStreamReader(document); + } catch (XMLStreamException e) { + // TODO: Add context to the exception + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java new file mode 100644 index 0000000000..c83e93dc4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + + +/** + * @version $Rev$ $Date$ + */ +public class DuplicateHelperContextException extends RuntimeException { + private static final long serialVersionUID = -5229624905543066038L; + + /** + * Constructor specifying message and the ID of the duplicate HelperContext. + * + * @param message exception message + * @param identifier the id of the HelperContext that is already present + */ + public DuplicateHelperContextException(String message) { + super(message); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java new file mode 100644 index 0000000000..561e5f3b39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java @@ -0,0 +1,110 @@ +/* + * 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.sdo; + +import java.beans.Introspector; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; +import org.apache.tuscany.sca.implementation.java.introspect.IntrospectionException; +import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor; + +import commonj.sdo.helper.HelperContext; + +/** + * Processes {@link @HelperContext} annotations on a component implementation + * and adds a {@link JavaMappedProperty} to the component type which will be + * used to inject the appropriate context + * + * @version $Rev$ $Date$ + */ +public class HelperContextProcessor extends BaseJavaClassVisitor { + private HelperContextRegistry registry; + + /** + * @param registry + */ + public HelperContextProcessor(AssemblyFactory assemblyFactory, HelperContextRegistry registry) { + super(assemblyFactory); + this.registry = registry; + } + + /** + * Takes a setter or getter method name and converts it to a property name + * according to JavaBean conventions. For example, setFoo(var) + * is returned as property foo + */ + public static String toPropertyName(String name) { + if (!name.startsWith("set")) { + return name; + } + return Introspector.decapitalize(name.substring(3)); + } + + public void visitMethod(Method method, + JavaImplementation type) throws IntrospectionException { + if (!method.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { + return; + } + if (method.getParameterTypes().length != 1) { + throw new IllegalArgumentException("HelperContext setter must have one parameter: " + method); + } + Class paramType = method.getParameterTypes()[0]; + if (HelperContext.class == paramType) { + String name = toPropertyName(method.getName()); + JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(method, 0)); +// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); + type.getResources().put(name, resource); + } + } + + public void visitField(Field field, + JavaImplementation type) throws IntrospectionException { + if (!field.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { + return; + } + Class paramType = field.getType(); + if (HelperContext.class == paramType) { + String name = field.getName(); + JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(field)); +// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); + type.getResources().put(name, resource); + } + } + + /* + private class HelperContextFactory implements ObjectFactory { + private URI id; + + public HelperContextFactory(URI id) { + super(); + this.id = id; + } + + public HelperContext getInstance() throws ObjectCreationException { + return registry.getHelperContext(id); + } + + } + */ +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java new file mode 100644 index 0000000000..75d9d33cbb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import commonj.sdo.helper.HelperContext; + +/** + * A registry for SDO HelperContext + * + * @version $Rev$ $Date$ + */ +public interface HelperContextRegistry { + /** + * Register a HelperContext with the id + * + * @param id + * @param context + */ + void register(Object id, HelperContext context) throws DuplicateHelperContextException; + + /** + * Unregister the HelperContext + * + * @param id + */ + void unregister(Object id); + + /** + * Get the HelperContext associated with the id + * + * @param id The URI of the HelperContext + * @return + */ + HelperContext getHelperContext(Object id); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java new file mode 100644 index 0000000000..429946f78d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import commonj.sdo.helper.HelperContext; + +/** + * A registry for SDO HelperContext + * + * @version $Rev$ $Date$ + */ +public class HelperContextRegistryImpl implements HelperContextRegistry { + private final Map registry = new ConcurrentHashMap(); + + public synchronized void register(Object id, HelperContext context) { + if (registry.containsKey(id)) { + throw new DuplicateHelperContextException("Duplicate HelperContext: " + id); + } + registry.put(id, context); + } + + public void unregister(Object id) { + registry.remove(id); + } + + public HelperContext getHelperContext(Object id) { + return registry.get(id); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java new file mode 100644 index 0000000000..30a3e1c3a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.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.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.BaseImpl; + +import commonj.sdo.helper.HelperContext; + +/** + * The model object for import.sdo + * + * @version $Rev$ $Date$ + */ +public class ImportSDO extends BaseImpl { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + private HelperContext helperContext; + private String factoryClassName; + private String schemaLocation; + + public ImportSDO(HelperContext helperContext) { + super(); + this.helperContext = helperContext; + setUnresolved(true); + } + + public HelperContext getHelperContext() { + return helperContext; + } + + /** + * @return the factoryClassName + */ + public String getFactoryClassName() { + return factoryClassName; + } + + /** + * @param factoryClassName the factoryClassName to set + */ + public void setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + } + + /** + * @return the schemaLocation + */ + public String getSchemaLocation() { + return schemaLocation; + } + + /** + * @param schemaLocation the schemaLocation to set + */ + public void setSchemaLocation(String schemaLocation) { + this.schemaLocation = schemaLocation; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java new file mode 100755 index 0000000000..87b6cb3e4a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java @@ -0,0 +1,192 @@ +/* + * 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.sdo; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static org.apache.tuscany.sca.databinding.sdo.ImportSDO.IMPORT_SDO; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessor implements StAXArtifactProcessor { + private HelperContextRegistry helperContextRegistry; + + public ImportSDOProcessor(HelperContextRegistry helperContextRegistry) { + super(); + this.helperContextRegistry = helperContextRegistry; + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ImportSDO read(XMLStreamReader reader) throws ContributionReadException { + assert IMPORT_SDO.equals(reader.getName()); + + HelperContext helperContext = null; + + // FIXME: [rfeng] How to get the enclosing composite? + int id = System.identityHashCode(reader); + // FIXME: [rfeng] How to associate the TypeHelper with deployment + // context? + synchronized (helperContextRegistry) { + helperContext = helperContextRegistry.getHelperContext(id); + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + helperContextRegistry.register(id, helperContext); + } + } + + ImportSDO importSDO = new ImportSDO(helperContext); + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + importSDO.setFactoryClassName(factoryName); + } + String location = reader.getAttributeValue(null, "location"); + if (location != null) { + importSDO.setSchemaLocation(location); + } + + // Skip to end element + try { + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && ImportSDO.IMPORT_SDO.equals(reader.getName())) { + break; + } + } + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + return importSDO; + } + + private void importFactory(ImportSDO importSDO) throws ContributionResolveException { + String factoryName = importSDO.getFactoryClassName(); + if (factoryName != null) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + try { + Class factoryClass = cl.loadClass(factoryName); + register(factoryClass, importSDO.getHelperContext()); + } catch (Exception e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + private static void register(Class factoryClass, HelperContext helperContext) throws Exception { + Field field = factoryClass.getField("INSTANCE"); + Object factory = field.get(null); + Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + method.invoke(factory, new Object[] {defaultContext}); + } + + private void importWSDL(ImportSDO importSDO) throws ContributionResolveException { + String location = importSDO.getSchemaLocation(); + if (location != null) { + try { + URL wsdlURL = null; + URI uri = URI.create(location); + if (uri.isAbsolute()) { + wsdlURL = uri.toURL(); + } + wsdlURL = Thread.currentThread().getContextClassLoader().getResource(location); + if (null == wsdlURL) { + ContributionResolveException loaderException = new ContributionResolveException( + "WSDL location error"); + throw loaderException; + } + InputStream xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + // FIXME: How do we associate the application HelperContext with + // the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = defaultContext.getXSDHelper(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + } catch (IOException e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + public QName getArtifactType() { + return ImportSDO.IMPORT_SDO; + } + + public void write(ImportSDO model, XMLStreamWriter outputSource) throws ContributionWriteException { + // TODO Auto-generated method stub + + } + + public Class getModelType() { + return ImportSDO.class; + } + + public void resolve(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { + importFactory(importSDO); + importWSDL(importSDO); + if (!importSDO.isUnresolved()) { + resolver.addModel(importSDO); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java new file mode 100644 index 0000000000..78058a5969 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java @@ -0,0 +1,106 @@ +/* + * 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.sdo; + +import java.awt.Component; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * Helper class to get TypeHelper from the context + */ +public final class SDOContextHelper { + private SDOContextHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null || context.getMetadata() == null) { + return getDefaultHelperContext(); + } + HelperContext helperContext = null; + Component composite = (Component)context.getMetadata().get(Component.class); + if (composite != null) { + // SDOHelperContext sdoContext = + // (SDOHelperContext)composite.getExtensions().get(HelperContext.class.getName()); + // if (sdoContext != null) { + // helperContext = sdoContext.getHelperContext(); + // } + // AtomicComponent child = + // (AtomicComponent)composite.getSystemChild(HelperContext.class.getName()); + // try { + // helperContext = (HelperContext)child.getTargetInstance(); + // } catch (TargetResolutionException e) { + // helperContext = null; + // } + } + if (helperContext == null) { + return getDefaultHelperContext(); + } else { + return helperContext; + } + } + + public static HelperContext getHelperContext(Composite model) { + HelperContext helperContext = null; + for (Object ext : model.getExtensions()) { + if (ext instanceof HelperContext) { + helperContext = (HelperContext)ext; + break; + } + } + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + model.getExtensions().add(helperContext); + } + + if (helperContext == null) { + helperContext = getDefaultHelperContext(); + } + + return helperContext; + } + + protected static HelperContext getDefaultHelperContext() { + // SDOUtil.createHelperContext(); + return HelperProvider.getDefaultContext(); + } + + public static QName getElement(DataType dataType) { + Object logical = dataType.getLogical(); + QName elementName = SDODataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + return elementName; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..2736d4bbde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO Databinding + * + * @version $Reve$ $Date$ + */ +public class SDODataBinding extends BaseDataBinding { + public static final String NAME = DataObject.class.getName(); + public static final String[] ALIASES = new String[] {"sdo"}; + + public static final String ROOT_NAMESPACE = "commonj.sdo"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); + + private WrapperHandler wrapperHandler; + + public SDODataBinding() { + super(NAME, ALIASES, DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + HelperContext context = HelperProvider.getDefaultContext(); + // FIXME: Need a better to test dynamic SDO + if (DataObject.class.isAssignableFrom(javaType)) { + // Dynamic SDO + dataType.setDataBinding(getName()); + dataType.setLogical(XMLType.UNKNOWN); + return true; + } + // FIXME: We need to access HelperContext + Type type = context.getTypeHelper().getType(javaType); + if (type == null) { + return false; + } + if (type.isDataType()) { + // FIXME: Ignore simple types? + return false; + } + String namespace = type.getURI(); + String name = context.getXSDHelper().getLocalName(type); + QName xmlType = new QName(namespace, name); + dataType.setDataBinding(getName()); + dataType.setLogical(new XMLType(null, xmlType)); + return true; + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SDOSimpleTypeMapper(); + } + + @Override + public Object copy(Object arg) { + HelperContext context = HelperProvider.getDefaultContext(); + CopyHelper copyHelper = context.getCopyHelper(); + if (arg instanceof XMLDocument) { + XMLDocument document = (XMLDocument)arg; + DataObject dataObject = copyHelper.copy(document.getRootObject()); + return context.getXMLHelper().createDocument(dataObject, + document.getRootElementURI(), + document.getRootElementName()); + } else if (arg instanceof DataObject) { + return context.getCopyHelper().copy((DataObject)arg); + } else { + return super.copy(arg); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new SDOExceptionHandler(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java new file mode 100644 index 0000000000..1056d2ec38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java @@ -0,0 +1,124 @@ +/* + * 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.sdo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; + +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; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class SDOExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + // FIXME: Need a way to pass in the HelperContext + private HelperContext helperContext = HelperProvider.getDefaultContext(); + + /** + *
    + *
  • 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 = (Class)exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = (Class)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 exceptionDataType) { + Class exceptionType = (Class) exceptionDataType.getPhysical(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + if (faultBeanClass == null) { + return null; + } + + QName faultElement = null; + try { + Field field = exceptionType.getField("FAULT_ELEMENT"); + faultElement = (QName)field.get(null); + } catch (NoSuchFieldException e) { + // Fall back to type inspection + Type type = helperContext.getTypeHelper().getType(faultBeanClass); + if (type != null) { + String ns = type.getURI(); + String name = helperContext.getXSDHelper().getLocalName(type); + faultElement = new QName(ns, name); + } + } catch (Throwable e) { + // Ignore + } + if (faultElement == null) { + return null; + } + DataType faultType = + new DataTypeImpl(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); + return faultType; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..f4e2044aa2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * SDO Java/XML mapping for simple XSD types + */ +public class SDOSimpleTypeMapper implements SimpleTypeMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public SDOSimpleTypeMapper() { + super(); + } + + public Object toJavaObject(QName typeName, String value, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..d89627da71 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java @@ -0,0 +1,99 @@ +/* + * 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.sdo; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * SDO Wrapper Handler + */ +public class SDOWrapperHandler implements WrapperHandler { + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#create(ElementInfo, TransformationContext) + */ + public Object create(ElementInfo element, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + QName typeName = element.getType().getQName(); + DataFactory dataFactory = helperContext.getDataFactory(); + DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart()); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#setChild(java.lang.Object, int, ElementInfo, + * java.lang.Object) + */ + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + wrapperDO.set(i, value); + } + + @SuppressWarnings("unchecked") + public List getChildren(Object wrapper) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + List properties = wrapperDO.getInstanceProperties(); + List elements = new ArrayList(); + Type type = wrapperDO.getType(); + if (type.isSequenced()) { + // Add values in the sequence + Sequence sequence = wrapperDO.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + // Skip mixed text + if (sequence.getProperty(i) != null) { + elements.add(sequence.getValue(i)); + } + } + } else { + for (Property p : properties) { + Object child = wrapperDO.get(p); + if (p.isMany()) { + for (Object c : (Collection)child) { + elements.add(c); + } + } else { + elements.add(child); + } + } + } + return elements; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..01ec74bb30 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java @@ -0,0 +1,55 @@ +/* + * 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.sdo; + +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 commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class String2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(String source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return String.class; + } + + public Class getTargetType() { + return DataObject.class; + } + + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..d11e6e46d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.io.StringWriter; + +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 commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class XMLDocument2String extends BaseTransformer implements + PullTransformer { + + public String transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..9e888258f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +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; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLDocument2XMLStreamReader extends BaseTransformer implements + PullTransformer { + /** + * @param source + * @param context + * @return + */ + public XMLStreamReader transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..8797ed1f28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.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.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +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; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +public class XMLStreamReader2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + // The XMLStreamHelper requires that the reader is posistioned at + // START_ELEMENT + while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { + source.next(); + } + return streamHelper.loadObject(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return DataObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..43b05d9cb8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java @@ -0,0 +1,58 @@ +/* + * 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.sdo; + +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; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLStreamReader2XMLDocument extends BaseTransformer implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.load(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XMLDocument.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java new file mode 100644 index 0000000000..9b6beead14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * This annotation can be used by component implementation class to receive the + * SDO HelperContext. + * + * @version $Rev$ $Date$ + */ +@Target({METHOD, FIELD}) +@Retention(RUNTIME) +public @interface HelperContext { +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java new file mode 100644 index 0000000000..4f6caa6ec0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.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.databinding.sdo.module; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.sdo.DataObject2String; +import org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader; +import org.apache.tuscany.sca.databinding.sdo.HelperContextProcessor; +import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistry; +import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistryImpl; +import org.apache.tuscany.sca.databinding.sdo.ImportSDOProcessor; +import org.apache.tuscany.sca.databinding.sdo.SDODataBinding; +import org.apache.tuscany.sca.databinding.sdo.String2DataObject; +import org.apache.tuscany.sca.databinding.sdo.XMLDocument2String; +import org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject; +import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospectorExtensionPoint; + +/** + * @version $Rev$ $Date$ + */ +public class SDODataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new SDODataBinding()); + + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + HelperContextRegistry contextRegistry = new HelperContextRegistryImpl(); + processors.addArtifactProcessor(new ImportSDOProcessor(contextRegistry)); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new DataObject2String()); + transformers.addTransformer(new DataObject2XMLStreamReader()); + transformers.addTransformer(new XMLDocument2String()); + transformers.addTransformer(new String2DataObject()); + transformers.addTransformer(new XMLDocument2XMLStreamReader()); + transformers.addTransformer(new XMLStreamReader2DataObject()); + transformers.addTransformer(new XMLStreamReader2XMLDocument()); + + JavaClassIntrospectorExtensionPoint introspectors = registry.getExtensionPoint(JavaClassIntrospectorExtensionPoint.class); + introspectors.addClassVisitor(new HelperContextProcessor(assemblyFactory, contextRegistry)); + + } + + public void stop(ExtensionPointRegistry registry) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..b39b5ae567 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.databinding.sdo.module.SDODataBindingModuleActivator diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..8c4f243df5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,67 @@ +/* + * 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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + */ +public class InvalidSymbolFault_Exception extends Exception { + /** + * Generated QName for the fault element + */ + public static final QName FAULT_ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + /** + * 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/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..3665434cee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.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.sca.databinding.sdo; + +import junit.framework.Assert; + +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.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(String.class, String.class); + } + + public final void testTransform() { + String xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.indexOf("San Jose") != -1); + DataObject po = new String2DataObject().transform(xml, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + + public final void testXML() { + String xml = + ""; + DataObject dataObject = new String2DataObject().transform(xml, reversedContext); + context.setSourceDataType(new DataTypeImpl(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..369912f115 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java @@ -0,0 +1,58 @@ +/* + * 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.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +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.sdo.PurchaseOrderType; + +/** + * + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + break; + } + } + new XMLStreamReader2DataObject().transform(reader, reversedContext); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java new file mode 100644 index 0000000000..c6fc6813e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.xml.stream.XMLInputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; + +import commonj.sdo.helper.HelperContext; + +/** + * @version $Rev$ $Date$ + */ +public class HelperContextProcessorTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testProcessor() throws Exception { + HelperContextRegistry registry = new HelperContextRegistryImpl(); + HelperContextProcessor processor = new HelperContextProcessor(new DefaultAssemblyFactory(), registry); + URI id = URI.create("/composite1/"); + XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); + + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory(); + JavaImplementation componentType = javaImplementationFactory.createJavaImplementation(); + componentType.setJavaClass(FooImpl.class); + for (Field f : FooImpl.class.getDeclaredFields()) { + processor.visitField(f, componentType); + + } + for (Method m : FooImpl.class.getMethods()) { + processor.visitMethod(m, componentType); + } + + JavaResourceImpl r1 = (JavaResourceImpl)componentType.getResources().get("context"); + assertNotNull(r1); + JavaResourceImpl r2 = (JavaResourceImpl)componentType.getResources().get("context2"); + assertNotNull(r2); +// HelperContext c1 = (HelperContext)r1.getObjectFactory().getInstance(); +// HelperContext c2 = (HelperContext)r2.getObjectFactory().getInstance(); +// assertSame(c1, c2); + } + + private static class FooImpl { + @org.apache.tuscany.sca.databinding.sdo.api.HelperContext + protected HelperContext context2; + + private HelperContext context; + + @org.apache.tuscany.sca.databinding.sdo.api.HelperContext + public void setContext(HelperContext context1) { + this.context = context1; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java new file mode 100755 index 0000000000..cd7a02cb88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java @@ -0,0 +1,85 @@ +/* + * 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.sdo; + +import java.io.StringReader; +import java.net.URI; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import com.example.ipo.sdo.SdoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessorTestCase extends TestCase { + private static boolean inited; + + private ImportSDOProcessor loader; + private XMLInputFactory xmlFactory; + + public void testMinimal() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testLocation() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testFactory() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + ImportSDO importSDO = loader.read(reader); + assertNotNull(importSDO); + loader.resolve(importSDO, new TestModelResolver(getClass().getClassLoader())); + assertTrue(inited); + } + + protected void setUp() throws Exception { + super.setUp(); + URI id = URI.create("/composite1/"); + loader = new ImportSDOProcessor(new HelperContextRegistryImpl()); + xmlFactory = XMLInputFactory.newInstance(); + } + + protected XMLStreamReader getReader(String xml) throws XMLStreamException { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); + reader.next(); + return reader; + } + + public static class MockFactory { + public static final Object INSTANCE = SdoFactory.INSTANCE; + + static { + ImportSDOProcessorTestCase.inited = true; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..17e4901cc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java @@ -0,0 +1,110 @@ +/* + * 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.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +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.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * + */ +public class SDODataBindingTestCase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private SDODataBinding binding; + private HelperContext context; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + context = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(context); + } + + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(DataObject.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(PurchaseOrderType.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(PurchaseOrderType.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()); + } + + public final void testCopyRoot() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + Object copy = binding.copy(po); + assertTrue(copy instanceof PurchaseOrderType); + assertTrue(po != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, (DataObject)copy)); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + public final void testCopyNonRoot() { + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + Object copy = binding.copy(address); + assertTrue(copy instanceof USAddress); + assertTrue(address != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)address, (DataObject)copy)); + assertEquals("San Jose", ((USAddress)copy).getCity()); + } + + public final void testCopyXMLDocument() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + XMLDocument doc = + context.getXMLHelper().createDocument((DataObject)po, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + Object copy = binding.copy(doc); + assertTrue(copy instanceof XMLDocument); + XMLDocument docCopy = (XMLDocument)copy; + assertTrue(doc != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, docCopy.getRootObject())); + assertEquals("Comment", ((PurchaseOrderType)docCopy.getRootObject()).getComment()); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java new file mode 100644 index 0000000000..f8373cfd1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import junit.framework.TestCase; + +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.stock.sdo.InvalidSymbolFault; +import com.example.stock.sdo.StockFactory; +import com.example.stock.sdo.fault.InvalidSymbolFault_Exception; +import commonj.sdo.impl.HelperProvider; + +/** + * Test case for SDOExceptionHandler + */ +public class SDOExceptionHandlerTestCase extends TestCase { + // FIXME: Tuscany SDO impl uses _._type for anonymouse type, by the SDO + // spec, it should be same as the + // enclosing element/attribute name + private SDOExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new SDOExceptionHandler(); + StockFactory.INSTANCE.register(HelperProvider.getDefaultContext()); + } + + public void testGetFaultType() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(execType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(InvalidSymbolFault_Exception.FAULT_ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(SDODataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + 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 = StockFactory.INSTANCE.createInvalidSymbolFault(); + 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/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..ff1ac633a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,79 @@ +/* + * 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.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..1c3358a4d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java @@ -0,0 +1,60 @@ +/* + * 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.sdo; + +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandlerTestCase extends TestCase { + private HelperContext context; + private SDOWrapperHandler handler; + + public void setUp() throws Exception { + context = SDOUtil.createHelperContext(); + handler = new SDOWrapperHandler(); + } + + public void testWrapperAnyType() throws Exception { + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + + public void testWrapper() throws Exception { + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java new file mode 100644 index 0000000000..f1caa4e8a7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + public TestModelResolver(ClassLoader classLoader) { + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..78bc62eb3a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -0,0 +1,61 @@ +/* + * 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.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +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.sdo.PurchaseOrderType; +import commonj.sdo.helper.XMLDocument; + +/** + * + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-core.xsd b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/stock.xsd b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xml b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xml new file mode 100644 index 0000000000..2526629409 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xml @@ -0,0 +1,27 @@ + + + + message + symbol + message1 + symbol1 + symbol2 + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xsd b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xsd new file mode 100644 index 0000000000..ea4dc5f7f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/databinding-sdo/src/test/resources/wrapper.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3