summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/LICENSE205
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/META-INF/MANIFEST.MF21
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/NOTICE6
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/pom.xml148
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java142
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java86
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java89
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java65
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer20
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java78
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java86
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java63
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd136
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/stock.xsd33
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/LICENSE205
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/META-INF/MANIFEST.MF37
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/NOTICE6
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/pom.xml157
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java75
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java64
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java82
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java79
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java215
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java76
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java258
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java150
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java82
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java253
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java107
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java192
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java61
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java65
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java69
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java72
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java66
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java234
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java109
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver17
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding19
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer27
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties23
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java70
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java61
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java65
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java76
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java103
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java55
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java115
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java84
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java85
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java64
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java64
-rwxr-xr-xsca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/ipo.xsd136
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/stock.xsd33
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xml27
-rw-r--r--sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xsd38
57 files changed, 5073 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/LICENSE b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..a40e93b8b8
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Data Binding for SDO and AXIOM
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Data Binding for SDO
+Import-Package: commonj.sdo;version="2.1",
+ commonj.sdo.helper;version="2.1",
+ commonj.sdo.impl;version="2.1",
+ javax.xml.namespace,
+ javax.xml.stream,
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.databinding.impl;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.impl;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0"
+Bundle-SymbolicName: org.apache.tuscany.sca.databinding.sdo.axiom
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/NOTICE b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/NOTICE
new file mode 100644
index 0000000000..ad2ba40961
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2010 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/pom.xml b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/pom.xml
new file mode 100644
index 0000000000..5536eb4ac4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/pom.xml
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-databinding-sdo-axiom</artifactId>
+ <name>Apache Tuscany SCA Data Binding for SDO/AXIOM</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-sdo</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-api</artifactId>
+ <version>1.2.8</version>
+ <exclusions>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xml-apis</groupId>
+ <artifactId>xml-apis</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-impl</artifactId>
+ <version>1.2.8</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>add-test-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/sdo-source</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-plugin</artifactId>
+ <version>1.1.1</version>
+ <executions>
+ <execution>
+ <id>generate-po-sdo</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <schemaFile>${basedir}/src/test/resources/ipo.xsd</schemaFile>
+ <javaPackage>com.example.ipo.sdo</javaPackage>
+ <noNotification>true</noNotification>
+ <noContainer>true</noContainer>
+ <noUnsettable>true</noUnsettable>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>generate-stock-sdo</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <schemaFile>${basedir}/src/test/resources/stock.xsd</schemaFile>
+ <javaPackage>com.example.stock.sdo</javaPackage>
+ <prefix>Stock</prefix>
+ <noNotification>true</noNotification>
+ <noContainer>true</noContainer>
+ <noUnsettable>true</noUnsettable>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java
new file mode 100644
index 0000000000..02f43000b4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java
@@ -0,0 +1,142 @@
+/*
+ * 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.sdo2om;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Helper for AXIOM
+ *
+ * @version $Rev$ $Date$
+ */
+public class AxiomHelper {
+ private static final String DEFAULT_PREFIX = "_ns_";
+
+ private AxiomHelper() {
+ }
+
+ /**
+ * See http://issues.apache.org/jira/browse/WSCOMMONS-240
+ * @param om
+ */
+ public static void completeAndClose(OMElement om) {
+ // Get the builder associated with the om element
+ OMXMLParserWrapper builder = om.getBuilder();
+ if (builder != null) {
+ if (builder instanceof StAXBuilder) {
+ ((StAXBuilder)builder).releaseParserOnClose(true);
+ }
+ OMElement document = builder.getDocumentElement();
+ if (document != null) {
+ document.build();
+ }
+ }
+ if (builder instanceof StAXBuilder) {
+ ((StAXBuilder)builder).close();
+ }
+ }
+
+ /**
+ * This method will close the builder immediately. Any subsequent Axiom objects won't
+ * be built or accessible.
+ */
+ public static void closeImmediately(OMElement om) {
+ // Get the builder associated with the om element
+ OMXMLParserWrapper builder = om.getBuilder();
+ if (builder != null) {
+ if (builder instanceof StAXBuilder) {
+ ((StAXBuilder)builder).releaseParserOnClose(true);
+ ((StAXBuilder)builder).close();
+ }
+ // builder.close();
+ }
+ }
+
+ /**
+ * @param context
+ * @param element
+ */
+ public static void adjustElementName(TransformationContext context, OMElement element) {
+ if (context != null) {
+ DataType dataType = context.getTargetDataType();
+ Object logical = dataType == null ? null : dataType.getLogical();
+ if (!(logical instanceof XMLType)) {
+ return;
+ }
+ XMLType xmlType = (XMLType)logical;
+ if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) {
+ // FIXME:: Throw exception or switch to the new Element?
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ QName name = xmlType.getElementName();
+ OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix());
+ element.setNamespace(namespace);
+ element.setLocalName(name.getLocalPart());
+ }
+ }
+ }
+
+ public static OMElement createOMElement(OMFactory factory, QName element) {
+ String localName = element.getLocalPart();
+ OMNamespace ns = createOMNamespace(factory, element);
+
+ return factory.createOMElement(localName, ns);
+
+ }
+
+ public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) {
+ String localName = element.getLocalPart();
+ OMNamespace ns = createOMNamespace(factory, element);
+
+ return factory.createOMElement(dataSource, localName, ns);
+
+ }
+
+ /**
+ * @param factory
+ * @param name
+ * @return
+ */
+ public static OMNamespace createOMNamespace(OMFactory factory, QName name) {
+ String namespaceURI = name.getNamespaceURI();
+ String prefix = name.getPrefix();
+
+ OMNamespace ns = null;
+ if (namespaceURI.length() != 0) {
+ // Qualified Element: we need an OMNamespace
+ if (prefix.length() == 0) {
+ // The prefix does not appear to be specified, let's create one
+ prefix = DEFAULT_PREFIX;
+ }
+ ns = factory.createOMNamespace(namespaceURI, prefix);
+ }
+ return ns;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java
new file mode 100644
index 0000000000..d306290245
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java
@@ -0,0 +1,86 @@
+/*
+ * 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.sdo2om;
+
+import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ * SDO DataObject --> AXIOM OMElement transformer
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataObject2OMElement extends BaseTransformer<DataObject, OMElement> implements
+ PullTransformer<DataObject, OMElement> {
+
+ public OMElement transform(DataObject source, TransformationContext context) {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+
+ QName name = ROOT_ELEMENT;
+ if (context != null) {
+ DataType dataType = context.getTargetDataType();
+ Object logical = dataType == null ? null : dataType.getLogical();
+ if (logical instanceof XMLType) {
+ XMLType xmlType = (XMLType)logical;
+ if (xmlType.isElement()) {
+ name = xmlType.getElementName();
+ }
+ }
+ }
+
+ XMLDocument document = helperContext.getXMLHelper().createDocument(source,
+ name.getNamespaceURI(),
+ name.getLocalPart());
+ SDODataSource dataSource = new SDODataSource(document, helperContext);
+ OMElement element = AxiomHelper.createOMElement(factory, name, dataSource);
+ return element;
+ }
+
+ @Override
+ protected Class<DataObject> getSourceType() {
+ return DataObject.class;
+ }
+
+ @Override
+ protected Class<OMElement> getTargetType() {
+ return OMElement.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java
new file mode 100644
index 0000000000..dc3c2610a4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java
@@ -0,0 +1,89 @@
+/*
+ * 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.sdo2om;
+
+import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class SDODataSource implements OMDataSource {
+ private HelperContext helperContext;
+ private XMLDocument sourceDocument;
+
+ public SDODataSource(XMLDocument source, HelperContext helperContext) {
+ this.sourceDocument = source;
+ this.helperContext = helperContext;
+ }
+
+ public SDODataSource(DataObject obj, HelperContext helperContext) {
+ this.helperContext = helperContext;
+ this.sourceDocument =
+ helperContext.getXMLHelper().createDocument(obj,
+ ROOT_ELEMENT.getNamespaceURI(),
+ ROOT_ELEMENT.getLocalPart());
+ }
+
+ public XMLStreamReader getReader() throws XMLStreamException {
+ XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
+ return streamHelper.createXMLStreamReader(sourceDocument);
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(getReader(), xmlWriter);
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+ try {
+ helperContext.getXMLHelper().save(sourceDocument, output, null);
+ } catch (Exception e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+ try {
+ helperContext.getXMLHelper().save(sourceDocument, writer, null);
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java
new file mode 100644
index 0000000000..3a2391b41a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java
@@ -0,0 +1,65 @@
+/*
+ * 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.sdo2om;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ * SDO XMLDocument --> AXIOM OMElement transformer
+ * @version $Rev$ $Date$
+ */
+public class XMLDocument2OMElement extends BaseTransformer<XMLDocument, OMElement> implements
+ PullTransformer<XMLDocument, OMElement> {
+
+ public OMElement transform(XMLDocument source, TransformationContext context) {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ SDODataSource dataSource = new SDODataSource(source, helperContext);
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ QName name = new QName(source.getRootElementURI(), source.getRootElementName());
+ OMElement element = AxiomHelper.createOMElement(factory, name, dataSource);
+ return element;
+ }
+
+ @Override
+ protected Class<XMLDocument> getSourceType() {
+ return XMLDocument.class;
+ }
+
+ @Override
+ protected Class<OMElement> getTargetType() {
+ return OMElement.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
new file mode 100644
index 0000000000..c870ec2406
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation classes for the transformers
+org.apache.tuscany.sca.databinding.sdo2om.DataObject2OMElement;source=commonj.sdo.DataObject,target=org.apache.axiom.om.OMElement,weight=3000
+org.apache.tuscany.sca.databinding.sdo2om.XMLDocument2OMElement;source=commonj.sdo.helper.XMLDocument,target=org.apache.axiom.om.OMElement,weight=3000
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java
new file mode 100644
index 0000000000..57dd056526
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.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.sdo2om;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+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.DataObject;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataObject2OMElementTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(DataObject.class.getName(), DataObject.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<XMLType>(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ public final void testTransform() throws XMLStreamException {
+ OMElement element = new DataObject2OMElement().transform(dataObject, context);
+ Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI());
+ Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName());
+ // TODO: See https://issues.apache.org/jira/browse/WSCOMMONS-226
+ // element.getBuilder().setCache(false);
+ StringWriter writer = new StringWriter();
+ element.serialize(writer);
+ }
+
+ public final void testTransformWrapper() throws XMLStreamException {
+ OMElement element = new DataObject2OMElement().transform(dataObject, context);
+ Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI());
+ Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName());
+
+ OMNamespace ns = OMAbstractFactory.getOMFactory().createOMNamespace("http://ns1", "ns1");
+ element.setNamespace(ns);
+ element.setLocalName("dummy");
+ // TODO: See https://issues.apache.org/jira/browse/WSCOMMONS-226
+ // element.getBuilder().setCache(true);
+ StringWriter writer = new StringWriter();
+ element.serializeAndConsume(writer);
+ // System.out.println(writer);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java
new file mode 100644
index 0000000000..901217a58e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java
@@ -0,0 +1,86 @@
+/*
+ * 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.sdo2om;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl;
+import org.apache.tuscany.sca.databinding.sdo.SDODataBinding;
+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
+ *
+ * @version $Rev$ $Date$
+ */
+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()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ new SDODataBinding(new DefaultExtensionPointRegistry());
+ 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-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java
new file mode 100644
index 0000000000..5015a1b697
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.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.sdo2om;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamException;
+
+import junit.framework.Assert;
+
+import org.apache.axiom.om.OMElement;
+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.helper.XMLDocument;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLDocument2OMElementTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<XMLType>(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ public final void testTransform() throws XMLStreamException {
+ XMLDocument document =
+ helperContext.getXMLHelper().createDocument(dataObject,
+ ORDER_QNAME.getNamespaceURI(),
+ ORDER_QNAME.getLocalPart());
+ OMElement element = new XMLDocument2OMElement().transform(document, context);
+ Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI());
+ Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName());
+ StringWriter writer = new StringWriter();
+ element.serialize(writer);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd
new file mode 100644
index 0000000000..241ec15d36
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd
@@ -0,0 +1,136 @@
+<!--
+ * 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.
+-->
+<schema targetNamespace="http://www.example.com/IPO"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+
+ <annotation>
+ <documentation xml:lang="en">
+ International Purchase order schema for Example.com
+ Copyright 2000 Example.com. All rights reserved.
+ </documentation>
+ </annotation>
+
+
+ <element name="purchaseOrder" type="ipo:PurchaseOrderType" />
+
+ <element name="comment" type="string" />
+
+ <complexType name="PurchaseOrderType">
+ <sequence>
+ <element name="shipTo" type="ipo:Address" />
+ <element name="billTo" type="ipo:Address" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="items" type="ipo:Items" />
+ </sequence>
+ <attribute name="orderDate" type="date" />
+ </complexType>
+
+ <complexType name="Items">
+ <sequence>
+ <element name="item" minOccurs="0" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" type="string" />
+ <element name="quantity">
+ <simpleType>
+ <restriction base="positiveInteger">
+ <maxExclusive value="100" />
+ </restriction>
+ </simpleType>
+ </element>
+ <element name="USPrice" type="decimal" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="shipDate" type="date"
+ minOccurs="0" />
+ </sequence>
+ <attribute name="partNum" type="ipo:SKU"
+ use="required" />
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <simpleType name="SKU">
+ <restriction base="string">
+ <pattern value="\d{3}-[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+ <complexType name="Address">
+ <sequence>
+ <element name="name" type="string" />
+ <element name="street" type="string" />
+ <element name="city" type="string" />
+ </sequence>
+ </complexType>
+
+ <complexType name="USAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="state" type="ipo:USState" />
+ <element name="zip" type="positiveInteger" />
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="UKAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="postcode" type="ipo:UKPostcode" />
+ </sequence>
+ <attribute name="exportCode" type="positiveInteger"
+ fixed="1" />
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <!-- other Address derivations for more countries -->
+
+ <simpleType name="USState">
+ <restriction base="string">
+ <enumeration value="AK" />
+ <enumeration value="AL" />
+ <enumeration value="AR" />
+ <enumeration value="CA" />
+ <enumeration value="PA" />
+ <!-- and so on ... -->
+ </restriction>
+ </simpleType>
+
+ <simpleType name="Postcode">
+ <restriction base="string">
+ <length value="7" fixed="true" />
+ </restriction>
+ </simpleType>
+
+
+ <simpleType name="UKPostcode">
+ <restriction base="ipo:Postcode">
+ <pattern value="[A-Z]{2}\d\s\d[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+
+
+</schema>
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/stock.xsd b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/stock.xsd
new file mode 100644
index 0000000000..a0a6717371
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo-axiom/src/test/resources/stock.xsd
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<schema targetNamespace="http://www.example.com/stock" xmlns="http://www.w3.org/2001/XMLSchema">
+ <!-- Faults -->
+ <element name="InvalidSymbolFault">
+ <complexType>
+ <sequence>
+ <element name="message" minOccurs="1" type="string" />
+ <element name="symbol" minOccurs="1" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="MarketClosedFault" type="string" />
+
+</schema> \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/LICENSE b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/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-2.x/branches/2.0-Beta1/modules/databinding-sdo/META-INF/MANIFEST.MF b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..98ea88ea0f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/META-INF/MANIFEST.MF
@@ -0,0 +1,37 @@
+Manifest-Version: 1.0
+Export-Package: org.apache.tuscany.sca.databinding.sdo;version="2.0.0"
+SCA-Version: 1.1
+Bundle-Name: Apache Tuscany SCA Data Binding for SDO
+Bundle-Vendor: The Apache Software Foundation
+Bundle-Version: 2.0.0
+Bundle-ManifestVersion: 2
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-Description: Apache Tuscany SCA Data Binding for SDO
+Import-Package: commonj.sdo;version="2.1",
+ commonj.sdo.helper;version="2.1",
+ commonj.sdo.impl;version="2.1",
+ javax.xml.namespace,
+ javax.xml.parsers,
+ javax.xml.stream,
+ javax.xml.transform.dom,
+ org.apache.tuscany.sca.assembly;version="2.0.0",
+ org.apache.tuscany.sca.assembly.impl;version="2.0.0",
+ org.apache.tuscany.sca.common.java.collection;version="2.0.0",
+ org.apache.tuscany.sca.common.xml.dom;version="2.0.0",
+ org.apache.tuscany.sca.contribution;version="2.0.0",
+ org.apache.tuscany.sca.contribution.processor;version="2.0.0",
+ org.apache.tuscany.sca.contribution.resolver;version="2.0.0",
+ org.apache.tuscany.sca.core;version="2.0.0",
+ org.apache.tuscany.sca.databinding;version="2.0.0",
+ org.apache.tuscany.sca.databinding.impl;version="2.0.0",
+ org.apache.tuscany.sca.databinding.util;version="2.0.0",
+ org.apache.tuscany.sca.databinding.xml;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef;version="2.0.0",
+ org.apache.tuscany.sca.interfacedef.impl;version="2.0.0";resolution:=optional,
+ org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
+ org.oasisopen.sca;version="2.0.0",
+ org.w3c.dom
+Bundle-SymbolicName: org.apache.tuscany.sca.databinding.sdo
+Bundle-DocURL: http://www.apache.org/
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
+Require-Bundle: org.apache.tuscany.sca.extensibility
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/NOTICE b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/NOTICE
new file mode 100644
index 0000000000..ad2ba40961
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2010 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/pom.xml b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/pom.xml
new file mode 100644
index 0000000000..d2a6484023
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/pom.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-databinding-sdo</artifactId>
+ <name>Apache Tuscany SCA Data Binding for SDO</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-common-xml</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>2.0-Beta1-SNAPSHOT</version>
+ </dependency>
+ <!-- FIXME: We might want to create a separate module to host the processor -->
+
+ <dependency>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-lib</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-impl</artifactId>
+ <version>1.1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>backport-util-concurrent</groupId>
+ <artifactId>backport-util-concurrent</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>runtime</artifactId>
+ <version>3.4.0-v20080512</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>contenttype</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.core</groupId>
+ <artifactId>contenttype</artifactId>
+ <version>3.3.0-v20080604-1400</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>backport-util-concurrent</groupId>
+ <artifactId>backport-util-concurrent</artifactId>
+ <version>3.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <id>add-test-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/sdo-source</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-plugin</artifactId>
+ <version>1.1.1</version>
+ <executions>
+ <execution>
+ <id>generate-po-sdo</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <schemaFile>${basedir}/src/test/resources/ipo.xsd</schemaFile>
+ <javaPackage>com.example.ipo.sdo</javaPackage>
+ <noNotification>true</noNotification>
+ <noContainer>true</noContainer>
+ <noUnsettable>true</noUnsettable>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>generate-stock-sdo</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <schemaFile>${basedir}/src/test/resources/stock.xsd</schemaFile>
+ <javaPackage>com.example.stock.sdo</javaPackage>
+ <prefix>Stock</prefix>
+ <noNotification>true</noNotification>
+ <noContainer>true</noContainer>
+ <noUnsettable>true</noUnsettable>
+ </configuration>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java
new file mode 100644
index 0000000000..80f4602fac
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2Node.java
@@ -0,0 +1,75 @@
+/*
+ * 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.transform.dom.DOMResult;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class DataObject2Node extends BaseTransformer<DataObject, Node> implements
+ PullTransformer<DataObject, Node> {
+
+ public Node transform(DataObject source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ XMLHelper xmlHelper = helperContext.getXMLHelper();
+ QName elementName = SDOContextHelper.getElement(context);
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ DOMResult result = new DOMResult(doc);
+ XMLDocument xmlDoc = xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart());
+ xmlHelper.save(xmlDoc, result, null);
+ return doc.getDocumentElement();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<DataObject> getSourceType() {
+ return DataObject.class;
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java
new file mode 100644
index 0000000000..eaaf153dd5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.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.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLHelper;
+
+public class DataObject2String extends BaseTransformer<DataObject, String> implements
+ PullTransformer<DataObject, String> {
+
+ public String transform(DataObject source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ XMLHelper xmlHelper = helperContext.getXMLHelper();
+ QName elementName = SDOContextHelper.getElement(context);
+ return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart());
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<DataObject> getSourceType() {
+ return DataObject.class;
+ }
+
+ @Override
+ protected Class<String> getTargetType() {
+ return String.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java
new file mode 100644
index 0000000000..7d66810ca0
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.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 java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class DataObject2XMLStreamReader extends BaseTransformer<DataObject, XMLStreamReader> implements
+ PullTransformer<DataObject, XMLStreamReader> {
+
+ public XMLStreamReader transform(final DataObject source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
+ final QName elementName = SDOContextHelper.getElement(context);
+ final XMLHelper xmlHelper = helperContext.getXMLHelper();
+ // Allow privileged access to read properties. REquires java.util.PropertyPermission
+ // XML.load.form.lax read in security policy.
+ XMLDocument document = AccessController.doPrivileged(new PrivilegedAction<XMLDocument>() {
+ public XMLDocument run() {
+ return xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart());
+ }
+ });
+
+ return streamHelper.createXMLStreamReader(document);
+ } catch (XMLStreamException e) {
+ // TODO: Add context to the exception
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<DataObject> getSourceType() {
+ return DataObject.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java
new file mode 100644
index 0000000000..d59698cdb3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.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 org.apache.tuscany.sca.assembly.Base;
+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(Base.SCA11_TUSCANY_NS, "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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java
new file mode 100644
index 0000000000..117d61ff26
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java
@@ -0,0 +1,215 @@
+/*
+ * 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.URL;
+import java.net.URLConnection;
+
+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.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.monitor.impl.ProblemImpl;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * Loader that handles &lt;import.sdo&gt; elements.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+@Deprecated
+public class ImportSDOProcessor implements StAXArtifactProcessor<ImportSDO> {
+
+ private ContributionFactory contributionFactory;
+
+ public ImportSDOProcessor(ExtensionPointRegistry registry) {
+ FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR,
+ message, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR, message,model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getXMLType() {
+ return IMPORT_SDO;
+ }
+
+ public ImportSDO read(XMLStreamReader reader,ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ assert IMPORT_SDO.equals(reader.getName());
+
+ // FIXME: How do we associate the application HelperContext with the one
+ // imported by the composite
+ ImportSDO importSDO = new ImportSDO(SDOContextHelper.getDefaultHelperContext());
+ 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
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && ImportSDO.IMPORT_SDO.equals(reader.getName())) {
+ break;
+ }
+ }
+ return importSDO;
+ }
+
+ private void importFactory(ImportSDO importSDO, ModelResolver resolver,ProcessorContext context) throws ContributionResolveException {
+ String factoryName = importSDO.getFactoryClassName();
+ if (factoryName != null) {
+ ClassReference reference = new ClassReference(factoryName);
+ ClassReference resolved = resolver.resolveModel(ClassReference.class, reference,context);
+ if (resolved != null && !resolved.isUnresolved()) {
+ try {
+ Class<?> factoryClass = resolved.getJavaClass();
+ register(factoryClass, importSDO.getHelperContext());
+ importSDO.setUnresolved(false);
+ } catch (Exception e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error(context.getMonitor(), "ContributionResolveException", resolver, ce);
+ //throw ce;
+ }
+ } else {
+ error(context.getMonitor(), "FailToResolveClass", resolver, factoryName);
+ //ContributionResolveException loaderException =
+ //new ContributionResolveException("Fail to resolve class: " + factoryName);
+ //throw loaderException;
+ }
+ }
+ }
+
+ 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});
+
+ // HelperContext defaultContext = HelperProvider.getDefaultContext();
+ // method.invoke(factory, new Object[] {defaultContext});
+ }
+
+ private void importWSDL(ImportSDO importSDO, ModelResolver resolver,ProcessorContext context) throws ContributionResolveException {
+ String location = importSDO.getSchemaLocation();
+ if (location != null) {
+ try {
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(location);
+ artifact = resolver.resolveModel(Artifact.class, artifact,context);
+ if (artifact.getLocation() != null) {
+ String wsdlURL = artifact.getLocation();
+ URLConnection connection = new URL(wsdlURL).openConnection();
+ connection.setUseCaches(false);
+ InputStream xsdInputStream = connection.getInputStream();
+ try {
+ XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper();
+ xsdHelper.define(xsdInputStream, wsdlURL);
+ } finally {
+ xsdInputStream.close();
+ }
+ importSDO.setUnresolved(false);
+ } else {
+ error(context.getMonitor(), "FailToResolveLocation", resolver, location);
+ //ContributionResolveException loaderException = new ContributionResolveException("Fail to resolve location: " + location);
+ //throw loaderException;
+ }
+ } catch (IOException e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error(context.getMonitor(), "ContributionResolveException", resolver, ce);
+ //throw ce;
+ }
+ }
+ }
+
+ public QName getArtifactType() {
+ return ImportSDO.IMPORT_SDO;
+ }
+
+ public void write(ImportSDO model, XMLStreamWriter outputSource,ProcessorContext context) throws ContributionWriteException {
+ // Not implemented as <import.sdo> is deprecated
+ }
+
+ public Class<ImportSDO> getModelType() {
+ return ImportSDO.class;
+ }
+
+ public void resolve(ImportSDO importSDO, ModelResolver resolver,ProcessorContext context) throws ContributionResolveException {
+ importFactory(importSDO, resolver,context);
+ importWSDL(importSDO, resolver,context);
+ if (!importSDO.isUnresolved()) {
+ resolver.addModel(importSDO,context);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java
new file mode 100644
index 0000000000..a7fc9aeb5c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/Node2DataObject.java
@@ -0,0 +1,76 @@
+/*
+ * 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.transform.dom.DOMSource;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class Node2DataObject extends BaseTransformer<Node, DataObject> implements PullTransformer<Node, DataObject> {
+
+private DOMHelper helper;
+
+public Node2DataObject(ExtensionPointRegistry registry) {
+ super();
+ helper = DOMHelper.getInstance(registry);
+}
+ public DataObject transform(Node source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
+ XMLHelper xmlHelper = helperContext.getXMLHelper();
+ Document doc = helper.promote(source);
+ DOMSource domSource = new DOMSource(doc);
+ XMLDocument xmlDoc = xmlHelper.load(domSource, doc.getDocumentURI(), null);
+ return xmlDoc.getRootObject();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<DataObject> getTargetType() {
+ return DataObject.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
new file mode 100644
index 0000000000..23063317e7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
@@ -0,0 +1,258 @@
+/*
+ * 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.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.common.java.collection.LRUCache;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.util.DataTypeHelper;
+import org.apache.tuscany.sca.extensibility.ClassLoaderContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ * Helper class to get TypeHelper from the context
+ *
+ * @version $Rev$ $Date$
+ */
+public final class SDOContextHelper {
+ private static final LRUCache<Object, HelperContext> cache = new LRUCache<Object, HelperContext>(1024);
+
+ private static ExtensionPointRegistry registry = null;
+ private static HelperContext defaultHelperContext;
+
+ private SDOContextHelper() {
+ }
+
+ /**
+ * Static method used to set the registry used to locate the SDO implementation provider
+ * MUST be called before using any other methods on this class
+ * @param theRegistry
+ */
+ public static void setRegistry( ExtensionPointRegistry theRegistry ) {
+ registry = theRegistry;
+ } // end setRegistry
+
+ public static HelperContext getHelperContext(TransformationContext context, boolean source) {
+ if (context == null) {
+ return getDefaultHelperContext();
+ }
+
+ HelperContext helperContext = null;
+ Operation op = source ? context.getSourceOperation() : context.getTargetOperation();
+ if (op == null) {
+ DataType<?> dt = source ? context.getSourceDataType() : context.getTargetDataType();
+
+ helperContext = dt.getMetaData(HelperContext.class);
+ if (helperContext != null) {
+ return helperContext;
+ }
+ helperContext = SDOUtil.createHelperContext();
+ boolean found = register(helperContext, dt);
+ if (!found) {
+ helperContext = getDefaultHelperContext();
+ }
+ dt.setMetaData(HelperContext.class, helperContext);
+ return helperContext;
+ } else {
+ return getHelperContext(op);
+ }
+
+ }
+
+ public static HelperContext getHelperContext(Operation op) {
+ if (op == null) {
+ return getDefaultHelperContext();
+ }
+
+ HelperContext helperContext = op.getInputType().getMetaData(HelperContext.class);
+
+ if (helperContext != null) {
+ return helperContext;
+ }
+
+ // Use the default HelperContext until a type is registered later on
+ helperContext = getDefaultHelperContext();
+
+ /*
+ List<DataType> dataTypes = DataTypeHelper.getDataTypes(op, false);
+ boolean found = false;
+ for (DataType d : dataTypes) {
+ if (register(helperContext, d)) {
+ found = true;
+ }
+ }
+ if (!found) {
+ helperContext = getDefaultHelperContext();
+ }
+ */
+ op.getInputType().setMetaData(HelperContext.class, helperContext);
+ return helperContext;
+ }
+
+ /**
+ * @param helperContext
+ * @param dataType
+ * @return
+ */
+ private static boolean register(HelperContext helperContext, DataType dataType) {
+ if (dataType == null) {
+ return false;
+ }
+ Set<Class<?>> classes = DataTypeHelper.findClasses(dataType);
+ boolean found = false;
+ for (Class<?> cls : classes) {
+ found = register(helperContext, dataType.getPhysical()) || found;
+ }
+ return found;
+ }
+
+ /**
+ * FIXME: [rfeng] This is a hack to get the factory out a SDO class
+ * @param helperContext
+ * @param javaType
+ */
+
+ public static boolean register(HelperContext helperContext, Class javaType) {
+ if (javaType == null || DataObject.class == javaType) {
+ return false;
+ }
+ try {
+ Type type = helperContext.getTypeHelper().getType(javaType);
+ return register(helperContext, type);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public static boolean register(HelperContext helperContext, Type type) {
+ if (type != null && (!type.isDataType())) {
+ try {
+ Method method = type.getClass().getMethod("getEPackage");
+ Object factory = method.invoke(type, new Object[] {});
+ method = factory.getClass().getMethod("register", HelperContext.class);
+ method.invoke(factory, new Object[] {helperContext});
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public static HelperContext getDefaultHelperContext( ) {
+ // Return a chached value if available...
+ if( defaultHelperContext != null ) return defaultHelperContext;
+
+ // Try to set up TCCL so that SDO Helper Provider service discovery works in OSGi
+ if( registry == null ) return null;
+
+ ClassLoader oldTccl =
+ ClassLoaderContext.setContextClassLoader(SDOContextHelper.class.getClassLoader(),
+ registry.getServiceDiscovery(),
+ // SDO Helper Provider
+ "commonj.sdo.impl.HelperProvider"
+ );
+ try {
+ // Load the HelperProvider (using the new TCCL) and get the default HelperContext
+ // cache the returned HelperContext...
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ HelperProvider.setDefaultInstance(tccl);
+ defaultHelperContext = HelperProvider.getDefaultContext();
+ return defaultHelperContext;
+ } catch (Exception e ){
+ e.printStackTrace();
+ return null;
+ } finally {
+ if (oldTccl != null) {
+ Thread.currentThread().setContextClassLoader(oldTccl);
+ }
+ } // end try
+ } // end getDefaultHelperContext()
+
+ public static QName getElement(TransformationContext context) {
+ if (context == null) {
+ return SDODataBinding.ROOT_ELEMENT;
+ }
+ DataType<?> dataType = context.getTargetDataType();
+ Object logical = dataType.getLogical();
+ QName elementName = null;
+ if (logical instanceof XMLType) {
+ XMLType xmlType = (XMLType)logical;
+ QName element = xmlType.getElementName();
+ if (element != null) {
+ elementName = element;
+ }
+ }
+ if (elementName == null) {
+ // Try source type
+ dataType = context.getSourceDataType();
+ logical = dataType.getLogical();
+ if (logical instanceof XMLType) {
+ XMLType xmlType = (XMLType)logical;
+ QName element = xmlType.getElementName();
+ if (element != null) {
+ elementName = element;
+ }
+ }
+ }
+ if (elementName != null) {
+ return elementName;
+ } else {
+ return SDODataBinding.ROOT_ELEMENT;
+ }
+ }
+
+ public static String generateSchema(HelperContext context, Class<?>[] classes) {
+ TypeHelper typeHelper = context.getTypeHelper();
+ List<Type> types = new ArrayList<Type>();
+ for (Class<?> cls : classes) {
+ Type type = typeHelper.getType(cls);
+ if (type != null) {
+ types.add(type);
+ }
+ }
+ return generateSchema(context, types);
+ }
+
+ public static String generateSchema(HelperContext context, List<Type> types) {
+ // FIXME: SDO throws IllegalArgumentException for types generated from existing XSDs
+ return context.getXSDHelper().generate(types);
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java
new file mode 100644
index 0000000000..0003e7d46f
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.sdo;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.BaseDataBinding;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ * SDO Databinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class SDODataBinding extends BaseDataBinding {
+ public static final String NAME = DataObject.class.getName();
+
+ public static final String ROOT_NAMESPACE = "commonj.sdo";
+ public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject");
+
+ private WrapperHandler<Object> wrapperHandler;
+ private XMLTypeHelper xmlTypeHelper;
+
+ public SDODataBinding( ExtensionPointRegistry registry ) {
+ super(NAME, DataObject.class);
+ SDOContextHelper.setRegistry( registry );
+ wrapperHandler = new SDOWrapperHandler();
+ xmlTypeHelper = new SDOTypeHelper();
+ }
+
+ @Override
+ public boolean introspect(DataType dataType, final Operation operation) {
+ final Class javaType = dataType.getPhysical();
+ // Allow privileged access to read system properties. Requires PropertyPermission
+ // java.specification.version read in security policy.
+ final HelperContext context = AccessController.doPrivileged(new PrivilegedAction<HelperContext>() {
+ public HelperContext run() {
+ return SDOContextHelper.getHelperContext(operation);
+ }
+ });
+
+ final Type type = context.getTypeHelper().getType(javaType);
+ if (type == null) {
+ // FIXME: Need a better to test dynamic SDO
+ if (DataObject.class.isAssignableFrom(javaType)) {
+ // Dynamic SDO
+ dataType.setDataBinding(getName());
+ if (dataType.getLogical() == null) {
+ dataType.setLogical(XMLType.UNKNOWN);
+ }
+ return true;
+ }
+ return false;
+ }
+ if (type.isDataType()) {
+ // FIXME: Ignore simple types?
+ return false;
+ }
+
+ // Found a SDO type, replace the default context with a private one
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ if (context == SDOContextHelper.getDefaultHelperContext()) {
+ HelperContext newContext = SDOUtil.createHelperContext();
+ SDOContextHelper.register(newContext, type);
+ if (operation != null) {
+ operation.getInputType().setMetaData(HelperContext.class, newContext);
+ }
+ } else {
+ SDOContextHelper.register(context, type);
+ }
+ return null;
+ }
+ });
+
+ String namespace = type.getURI();
+ String name = context.getXSDHelper().getLocalName(type);
+ QName xmlType = new QName(namespace, name);
+ dataType.setDataBinding(getName());
+ QName elementName = null;
+ Object logical = dataType.getLogical();
+ if (logical instanceof XMLType) {
+ elementName = ((XMLType)logical).getElementName();
+ }
+ dataType.setLogical(new XMLType(elementName, xmlType));
+
+ return true;
+ }
+
+ @Override
+ public WrapperHandler getWrapperHandler() {
+ return wrapperHandler;
+ }
+
+ @Override
+ public XMLTypeHelper getXMLTypeHelper() {
+ // return new SDOTypeHelper();
+ return xmlTypeHelper;
+ }
+
+ @Override
+ public Object copy(Object arg, DataType dataType, DataType targetDataType, Operation operation, Operation targetOperation) {
+ HelperContext context = SDOContextHelper.getHelperContext(operation);
+ 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, dataType, targetDataType, operation, targetOperation);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java
new file mode 100644
index 0000000000..7e26990b32
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.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 javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+
+/**
+ * SDO Java/XML mapping for simple XSD types
+ *
+ * @version $Rev$ $Date$
+ */
+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, false);
+ 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, true);
+ TypeHelper typeHelper = helperContext.getTypeHelper();
+ type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
+ }
+ return SDOUtil.convertToString(type, obj);
+ }
+
+ public Class<?> getJavaType(QName xmlType) {
+
+ return null;
+ }
+
+ public TypeInfo getXMLType(Class<?> javaType) {
+ return null;
+ }
+
+ public boolean isSimpleXSDType(QName xmlType) {
+ return false;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java
new file mode 100644
index 0000000000..381249d9bb
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.sdo;
+
+import java.beans.Introspector;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.oasisopen.sca.ServiceRuntimeException;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSParser;
+
+import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class SDOTypeHelper implements XMLTypeHelper {
+ private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
+
+ private TypeHelper typeHelper;
+ private XSDHelper xsdHelper;
+
+ private ProcessorContext context;
+ // private Map<String, List<Type>> xsdTypesMap = new HashMap<String, List<Type>>();
+ // private Map<String, List<Type>> typesMap = new HashMap<String, List<Type>>();
+
+ public SDOTypeHelper( ProcessorContext context ) {
+ super();
+ this.context=context;
+ //Should we use this.context to get helper objects ???
+ typeHelper = SDOContextHelper.getDefaultHelperContext().getTypeHelper();
+ xsdHelper = SDOContextHelper.getDefaultHelperContext().getXSDHelper();
+ }
+ //Should we remove this constructor???? otherwise we context gets created
+ public SDOTypeHelper() {
+ this(null);
+ /*
+ super();
+ this.context=null;
+ //Should we use this.context to get helper objects ???
+ typeHelper = SDOContextHelper.getDefaultHelperContext().getTypeHelper();
+ xsdHelper = SDOContextHelper.getDefaultHelperContext().getXSDHelper();
+ */
+ }
+ public TypeInfo getTypeInfo(Class javaType, Object logical) {
+ QName xmlType = JavaXMLMapper.getXMLType(javaType);
+ if (xmlType != null) {
+ return new TypeInfo(xmlType, true, null);
+ } else {
+ // introspect(javaType, xsdTypesMap, typesMap);
+ if (logical instanceof XMLType) {
+ xmlType = ((XMLType)logical).getTypeName();
+ }
+ if (xmlType == null) {
+ xmlType =
+ new QName(JavaXMLMapper.getNamespace(javaType), Introspector.decapitalize(javaType.getSimpleName()));
+ }
+ return new TypeInfo(xmlType, false, null);
+ }
+ }
+
+ private void introspect(Class javaType, Map<String, List<Type>> xsdTypesMap, Map<String, List<Type>> typesMap) {
+ Type type = typeHelper.getType(javaType);
+ if (type == null) {
+ return;
+ }
+ if (xsdHelper.isXSD(type)) {
+ addToMap(xsdTypesMap, type);
+ } else {
+ addToMap(typesMap, type);
+ }
+ }
+
+ private void addToMap(Map<String, List<Type>> map, Type type) {
+ List<Type> types = map.get(type.getURI());
+ if (types == null) {
+ types = new ArrayList<Type>();
+ map.put(type.getURI(), types);
+ }
+ if (!types.contains(type)) {
+ types.add(type);
+ }
+ }
+
+ /*
+ public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver) {
+ List<XSDefinition> definitions = new ArrayList<XSDefinition>();
+ generateSDOSchemas(definitions, factory, typesMap);
+ addResolvedXSDs(definitions, factory, resolver, xsdTypesMap);
+ return definitions;
+ }
+ */
+
+ private void generateSDOSchemas(List<XSDefinition> definitions, XSDFactory factory, Map<String, List<Type>> map) {
+ for (Map.Entry<String, List<Type>> entry : map.entrySet()) {
+ List<Type> types = entry.getValue();
+ String ns = entry.getKey();
+ generateSchema(definitions, factory, types, ns);
+ }
+ }
+
+ private void generateSchema(List<XSDefinition> definitions, XSDFactory factory, List<Type> types, String ns) {
+ String schema = xsdHelper.generate(types);
+ DOMImplementationRegistry registry = null;
+ try {
+ registry = DOMImplementationRegistry.newInstance();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
+ DOMImplementationLS ls = (DOMImplementationLS)impl.getFeature("LS", "3.0");
+ LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, SCHEMA_NS);
+ LSInput input = ls.createLSInput();
+ input.setCharacterStream(new StringReader(schema));
+ Document document = parser.parse(input);
+ XSDefinition definition = factory.createXSDefinition();
+ definition.setUnresolved(true);
+ definition.setDocument(document);
+ definition.setNamespace(ns);
+ definitions.add(definition);
+ }
+
+ private void addResolvedXSDs(List<XSDefinition> definitions,
+ XSDFactory factory,
+ ModelResolver resolver,
+ Map<String, List<Type>> map) {
+ for (Map.Entry<String, List<Type>> entry : map.entrySet()) {
+ XSDefinition definition = factory.createXSDefinition();
+ definition.setUnresolved(true);
+ definition.setNamespace(entry.getKey());
+ //FIXME: set location URI
+
+ XSDefinition resolved = resolver.resolveModel(XSDefinition.class, definition,context);
+ if (resolved.getSchema() == null) {
+ //FIXME: create a checked exception and propagate it back up to the activator
+ throw new RuntimeException("No XSD found for namespace " + entry.getKey());
+ }
+ // make sure all the required types are defined in the resolved schema
+ for (Type type : entry.getValue()) {
+ String name = xsdHelper.getLocalName(type);
+ QName typeName = null;
+ if (name.endsWith("_._type")) {
+ // FIXME: Anonymous tyype
+ name = name.substring(0, name.length() - "_._type".length());
+ typeName = new QName(type.getURI(), name);
+ if (resolved.getXmlSchemaElement(typeName) == null) {
+ //FIXME: create a checked exception and propagate it back up to the activator
+ throw new RuntimeException("No XSD found for " + typeName.toString());
+ }
+ } else {
+ typeName = new QName(type.getURI(), name);
+ if (resolved.getXmlSchemaType(typeName) == null) {
+ //FIXME: create a checked exception and propagate it back up to the activator
+ throw new RuntimeException("No XSD found for " + typeName.toString());
+ }
+ }
+
+ }
+ definitions.add(resolved);
+ }
+ }
+
+ private static List<DataType> getDataTypes(Interface intf) {
+ List<DataType> dataTypes = new ArrayList<DataType>();
+ for (Operation op : intf.getOperations()) {
+ WrapperInfo wrapperInfo = op.getWrapper();
+
+ if (wrapperInfo != null ) {
+ DataType dt1 = wrapperInfo.getInputWrapperType();
+ if (dt1 != null) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = wrapperInfo.getOutputWrapperType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ } else {
+ for (DataType dt1 : op.getInputType().getLogical()) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = op.getOutputType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ for (DataType<DataType> dt3 : op.getFaultTypes()) {
+ DataType dt4 = dt3.getLogical();
+ if (dt4 != null) {
+ dataTypes.add(dt4);
+ }
+ }
+ }
+ }
+ return dataTypes;
+ }
+
+ public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) {
+ return getSchemaDefinitions(factory, resolver, getDataTypes(intf));
+ }
+
+ public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List<DataType> dataTypes) {
+ Map<String, List<Type>> xsdTypesMap = new HashMap<String, List<Type>>();
+ Map<String, List<Type>> typesMap = new HashMap<String, List<Type>>();
+ for (DataType d : dataTypes) {
+ if (SDODataBinding.NAME.equals(d.getDataBinding())) {
+ introspect(d.getPhysical(), xsdTypesMap, typesMap);
+ }
+ }
+ List<XSDefinition> definitions = new ArrayList<XSDefinition>();
+ generateSDOSchemas(definitions, factory, typesMap);
+ addResolvedXSDs(definitions, factory, resolver, xsdTypesMap);
+ return definitions;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java
new file mode 100644
index 0000000000..1ef689185a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypes.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.sdo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Base;
+
+import commonj.sdo.Type;
+
+/**
+ * The model object for sdo.types
+ *
+ * @version $Rev$ $Date$
+ *
+ * This extends the META-INF/sca-contribution.xml to register SDO types from static factory classes or WSDL/XSD files
+ *
+ * &lt;contribution xmlns=&quot;http://tuscany.apache.org/xmlns/sca/1.1&quot;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;xmlns:tuscany=&quot;http://tuscany.apache.org/xmlns/sca/1.0&quot;&gt;<br>
+ * &nbsp;&nbsp;&nbsp;&nbsp;&lt;tuscany:sdo.types namespace=&quot;http://helloworld&quot; location=&quot;wsdl/helloworld.wsdl&quot;/&gt;<br>
+ * &lt;/contribution&gt;
+ *
+ */
+public class SDOTypes {
+ public static final QName SDO_TYPES = new QName(Base.SCA11_TUSCANY_NS, "sdo.types");
+
+ private String factory;
+ private String schemaLocation;
+ private String namespace;
+
+ private List<Type> types = new ArrayList<Type>();
+
+ private boolean unresolved;
+
+ public SDOTypes() {
+ super();
+ setUnresolved(true);
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean undefined) {
+ this.unresolved = undefined;
+ }
+
+ /**
+ * @return the factoryClassName
+ */
+ public String getFactory() {
+ return factory;
+ }
+
+ /**
+ * @param factoryClassName the factoryClassName to set
+ */
+ public void setFactory(String factoryClassName) {
+ this.factory = factoryClassName;
+ }
+
+ /**
+ * @return the schemaLocation
+ */
+ public String getSchemaLocation() {
+ return schemaLocation;
+ }
+
+ /**
+ * @param schemaLocation the schemaLocation to set
+ */
+ public void setSchemaLocation(String schemaLocation) {
+ this.schemaLocation = schemaLocation;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public List<Type> getTypes() {
+ return types;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java
new file mode 100644
index 0000000000..58c69858b7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+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.XSDHelper;
+
+/**
+ * SDO Wrapper Handler
+ *
+ * @version $Rev$ $Date$
+ */
+public class SDOWrapperHandler implements WrapperHandler<Object> {
+
+ public Object create(Operation operation, boolean input) {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+
+
+ ElementInfo element = input ? wrapperInfo.getInputWrapperElement() :
+ wrapperInfo.getOutputWrapperElement();
+
+ HelperContext helperContext = SDOContextHelper.getHelperContext(operation);
+ Type sdoType = getSDOType(helperContext, element);
+ if (sdoType != null) {
+ DataFactory dataFactory = helperContext.getDataFactory();
+ return dataFactory.create(sdoType);
+ }
+ return null;
+ }
+
+ public void setChildren(Object wrapper, Object[] childObjects, Operation operation, boolean input) {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+
+
+ List<ElementInfo> childElements = input? wrapperInfo.getInputChildElements():
+ wrapperInfo.getOutputChildElements();
+
+ for (int i = 0; i < childElements.size(); i++) {
+ setChild(wrapper, i, childElements.get(i), childObjects[i]);
+ }
+ }
+
+ /**
+ * @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;
+ String name = childElement.getQName().getLocalPart();
+ if (childElement.isMany()) {
+ // FIXME: If we look up by name, we need to make sure the WrapperInfo has the correct element names
+ wrapperDO.getList(i).addAll((Collection)value);
+ } else {
+ wrapperDO.set(i, value);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public List getChildren(Object wrapper, Operation operation, boolean input) {
+ DataObject wrapperDO =
+ (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper;
+ List<Property> properties = wrapperDO.getInstanceProperties();
+ List<Object> elements = new ArrayList<Object>();
+ 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;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean)
+ */
+ public DataType getWrapperType(Operation operation, boolean input) {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+
+
+ ElementInfo element = input ? wrapperInfo.getInputWrapperElement() :
+ wrapperInfo.getOutputWrapperElement();
+
+ HelperContext helperContext = SDOContextHelper.getHelperContext(operation);
+ Type sdoType = getSDOType(helperContext, element);
+ if (sdoType != null) {
+ // Check if child elements matches
+ Class physical = sdoType.getInstanceClass();
+ DataType<XMLType> wrapperType =
+ new DataTypeImpl<XMLType>(SDODataBinding.NAME, physical, new XMLType(element));
+ return wrapperType;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * @param helperContext
+ * @param element
+ * @return
+ */
+ private Type getSDOType(HelperContext helperContext, ElementInfo element) {
+ XSDHelper xsdHelper = helperContext.getXSDHelper();
+ Type sdoType = null;
+ Property prop =
+ xsdHelper.getGlobalProperty(element.getQName().getNamespaceURI(), element.getQName().getLocalPart(), true);
+ if (prop != null) {
+ sdoType = prop.getType();
+ } else {
+ TypeInfo type = element.getType();
+ QName typeName = type != null ? type.getQName() : null;
+ if (typeName != null) {
+ sdoType = helperContext.getTypeHelper().getType(typeName.getNamespaceURI(), typeName.getLocalPart());
+ }
+ }
+ return sdoType;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, Operation, boolean)
+ */
+ public boolean isInstance(Object wrapper, Operation operation, boolean input) {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+
+
+ ElementInfo element = input ? wrapperInfo.getInputWrapperElement() :
+ wrapperInfo.getOutputWrapperElement();
+
+ // List<ElementInfo> childElements =
+ // input ? wrapperInfo.getInputChildElements() : wrapperInfo.getOutputChildElements();
+ HelperContext helperContext = SDOContextHelper.getHelperContext(operation);
+ Type sdoType = getSDOType(helperContext, element);
+ if (sdoType != null) {
+ return sdoType.isInstance(wrapper);
+ }
+ return false;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java
new file mode 100644
index 0000000000..a48e357960
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.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 org.apache.tuscany.sca.databinding.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLHelper;
+
+public class String2DataObject extends BaseTransformer<String, DataObject> implements
+ PullTransformer<String, DataObject> {
+
+ public DataObject transform(String source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
+ XMLHelper xmlHelper = helperContext.getXMLHelper();
+ return xmlHelper.load(source).getRootObject();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<String> getSourceType() {
+ return String.class;
+ }
+
+ @Override
+ protected Class<DataObject> getTargetType() {
+ return DataObject.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java
new file mode 100644
index 0000000000..d73f714384
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java
@@ -0,0 +1,65 @@
+/*
+ * 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.BaseTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class XMLDocument2String extends BaseTransformer<XMLDocument, String> implements
+ PullTransformer<XMLDocument, String> {
+
+ public String transform(XMLDocument source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ XMLHelper xmlHelper = helperContext.getXMLHelper();
+ StringWriter writer = new StringWriter();
+ xmlHelper.save(source, writer, null);
+ return writer.toString();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<XMLDocument> getSourceType() {
+ return XMLDocument.class;
+ }
+
+ @Override
+ protected Class<String> getTargetType() {
+ return String.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java
new file mode 100644
index 0000000000..2f41fb1957
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.sdo;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+public class XMLDocument2XMLStreamReader extends BaseTransformer<XMLDocument, XMLStreamReader> implements
+ PullTransformer<XMLDocument, XMLStreamReader> {
+ /**
+ * @param source
+ * @param context
+ * @return
+ */
+ public XMLStreamReader transform(XMLDocument source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
+ XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
+ return streamHelper.createXMLStreamReader(source);
+ } catch (XMLStreamException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<XMLDocument> getSourceType() {
+ return XMLDocument.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java
new file mode 100644
index 0000000000..fbc13e6fed
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.sdo;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+
+public class XMLStreamReader2DataObject extends BaseTransformer<XMLStreamReader, DataObject> implements
+ PullTransformer<XMLStreamReader, DataObject> {
+
+ public DataObject transform(XMLStreamReader source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
+ XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
+ // The XMLStreamHelper requires that the reader is positioned at
+ // START_ELEMENT
+ while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) {
+ source.next();
+ }
+ DataObject target = streamHelper.loadObject(source);
+ source.close();
+ return target;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<DataObject> getTargetType() {
+ return DataObject.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 15;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java
new file mode 100644
index 0000000000..658fe115a5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.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.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.BaseTransformer;
+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.sdo.api.SDOUtil;
+import org.apache.tuscany.sdo.api.XMLStreamHelper;
+
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+
+public class XMLStreamReader2XMLDocument extends BaseTransformer<XMLStreamReader, XMLDocument> implements
+ PullTransformer<XMLStreamReader, XMLDocument> {
+
+ public XMLDocument transform(XMLStreamReader source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
+ XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext);
+ XMLDocument target = streamHelper.load(source);
+ source.close();
+ return target;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<XMLDocument> getTargetType() {
+ return XMLDocument.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 15;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java
new file mode 100644
index 0000000000..020a8edd7d
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesModelResolver.java
@@ -0,0 +1,234 @@
+/*
+ * 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.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.sdo.SDOTypes;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.monitor.impl.ProblemImpl;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * SDO types model resolver that aggregates the SDO type registration for an SCA contribution
+ */
+public class SDOTypesModelResolver implements ModelResolver {
+ private Contribution contribution;
+ private HelperContext helperContext;
+ private List<SDOTypes> sdoTypes = new ArrayList<SDOTypes>();
+ private ContributionFactory contributionFactory;
+ private XSDFactory xsdFactory;
+ private ProcessorContext context;
+
+ public SDOTypesModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
+ super();
+ this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ this.xsdFactory = modelFactories.getFactory(XSDFactory.class);
+ this.contribution = contribution;
+ }
+
+ public void addModel(Object resolved, ProcessorContext context) {
+ if (helperContext == null) {
+ helperContext = SDOUtil.createHelperContext();
+ }
+ this.context = context;
+ SDOTypes types = (SDOTypes)resolved;
+ try {
+ loadSDOTypes(types, contribution.getModelResolver());
+ } catch (ContributionResolveException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ sdoTypes.add(types);
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ SDOTypes types = (SDOTypes)resolved;
+
+ return sdoTypes.remove(types);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ SDOTypes types = (SDOTypes)unresolved;
+ String ns = types.getNamespace();
+ this.context = context;
+ for (SDOTypes t : sdoTypes) {
+ if (t.getNamespace().equals(types.getNamespace())) {
+ try {
+ loadSDOTypes(types, contribution.getModelResolver());
+ } catch (ContributionResolveException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return (T)t;
+ }
+ }
+ return (T)types;
+ }
+
+ 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});
+ }
+
+ private void defineFromFactory(SDOTypes importSDO, ModelResolver resolver) throws ContributionResolveException {
+ String factoryName = importSDO.getFactory();
+ if (factoryName != null) {
+ ClassReference reference = new ClassReference(factoryName);
+ ClassReference resolved = resolver.resolveModel(ClassReference.class, reference, context);
+ if (resolved != null && !resolved.isUnresolved()) {
+ try {
+ Class<?> factoryClass = resolved.getJavaClass();
+ // Get the namespace
+ Field field = factoryClass.getField("NAMESPACE_URI");
+ importSDO.setNamespace((String)field.get(null));
+ register(factoryClass, helperContext);
+ importSDO.setUnresolved(false);
+ } catch (Exception e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error(context.getMonitor(), "ContributionResolveException", resolver, ce);
+ //throw ce;
+ }
+ } else {
+ error(context.getMonitor(), "FailToResolveClass", resolver, factoryName);
+ //ContributionResolveException loaderException =
+ //new ContributionResolveException("Fail to resolve class: " + factoryName);
+ //throw loaderException;
+ }
+ }
+ }
+
+ private void defineFromXSD(SDOTypes importSDO, ModelResolver resolver) throws ContributionResolveException {
+ String location = importSDO.getSchemaLocation();
+ if (location != null) {
+ try {
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(location);
+ artifact = resolver.resolveModel(Artifact.class, artifact, context);
+ if (artifact.getLocation() != null) {
+ String wsdlURL = artifact.getLocation();
+ URLConnection connection = new URL(wsdlURL).openConnection();
+ connection.setUseCaches(false);
+ InputStream xsdInputStream = connection.getInputStream();
+ try {
+ XSDHelper xsdHelper = helperContext.getXSDHelper();
+ List<Type> sdoTypes = xsdHelper.define(xsdInputStream, wsdlURL);
+ for (Type t : sdoTypes) {
+ importSDO.setNamespace(t.getURI());
+ break;
+ }
+ importSDO.getTypes().addAll(sdoTypes);
+ } finally {
+ xsdInputStream.close();
+ }
+ importSDO.setUnresolved(false);
+ } else {
+ error(context.getMonitor(), "FailToResolveLocation", resolver, location);
+ //ContributionResolveException loaderException = new ContributionResolveException("Fail to resolve location: " + location);
+ //throw loaderException;
+ }
+ } catch (IOException e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error(context.getMonitor(), "ContributionResolveException", resolver, ce);
+ //throw ce;
+ }
+ } else {
+ String ns = importSDO.getNamespace();
+ if (ns != null) {
+ XSDefinition xsd = xsdFactory.createXSDefinition();
+ xsd.setUnresolved(true);
+ xsd.setNamespace(ns);
+ xsd = resolver.resolveModel(XSDefinition.class, xsd, context);
+ if (!xsd.isUnresolved()) {
+ XSDHelper xsdHelper = helperContext.getXSDHelper();
+ xsdHelper.define(xsd.getLocation().toString());
+ }
+ }
+ }
+ }
+
+ private void loadSDOTypes(SDOTypes types, ModelResolver resolver) throws ContributionResolveException {
+ synchronized (types) {
+ if (types.isUnresolved()) {
+ defineFromFactory(types, resolver);
+ defineFromXSD(types, resolver);
+ types.setUnresolved(false);
+ }
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem =
+ new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR,
+ message, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(Monitor monitor, String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem =
+ new ProblemImpl(this.getClass().getName(), "databinding-sdo-validation-messages", Severity.ERROR,
+ message, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java
new file mode 100644
index 0000000000..b851d38dae
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/xml/SDOTypesProcessor.java
@@ -0,0 +1,109 @@
+/*
+ * 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.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+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.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.sdo.SDOTypes;
+
+
+/**
+ * Loader that handles &lt;import.sdo&gt; elements.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SDOTypesProcessor implements StAXArtifactProcessor<SDOTypes> {
+
+ public SDOTypesProcessor(ExtensionPointRegistry registry) {
+ }
+
+ public QName getXMLType() {
+ return SDOTypes.SDO_TYPES;
+ }
+
+ public SDOTypes read(XMLStreamReader reader,ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ assert SDOTypes.SDO_TYPES.equals(reader.getName());
+
+ // FIXME: How do we associate the application HelperContext with the one
+ // imported by the composite
+ SDOTypes sdoTypes = new SDOTypes();
+ String factoryName = reader.getAttributeValue(null, "factory");
+ if (factoryName != null) {
+ sdoTypes.setFactory(factoryName);
+ }
+ String location = reader.getAttributeValue(null, "location");
+ if (location != null) {
+ sdoTypes.setSchemaLocation(location);
+ }
+ String ns = reader.getAttributeValue(null, "namespace");
+ sdoTypes.setNamespace(ns);
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && SDOTypes.SDO_TYPES.equals(reader.getName())) {
+ break;
+ }
+ }
+ return sdoTypes;
+ }
+
+ public QName getArtifactType() {
+ return SDOTypes.SDO_TYPES;
+ }
+
+ public void write(SDOTypes model, XMLStreamWriter writer,ProcessorContext context) throws ContributionWriteException {
+ try {
+ writer.writeStartElement(SDOTypes.SDO_TYPES.getNamespaceURI(), SDOTypes.SDO_TYPES.getLocalPart());
+ if (model.getNamespace() != null) {
+ writer.writeAttribute("namespace", model.getNamespace());
+ }
+ if (model.getSchemaLocation() != null) {
+ writer.writeAttribute("location", model.getSchemaLocation());
+ }
+ if (model.getFactory() != null) {
+ writer.writeAttribute("factory", model.getFactory());
+ }
+ writer.writeEndElement();
+ } catch (XMLStreamException e) {
+ throw new ContributionWriteException(e);
+ }
+ }
+
+ public Class<SDOTypes> getModelType() {
+ return SDOTypes.class;
+ }
+
+ public void resolve(SDOTypes types, ModelResolver resolver,ProcessorContext context) throws ContributionResolveException {
+ // Defer the resolution to SDOTypesResolver which aggragates the type registrations into an instance of HelperContext
+ resolver.addModel(types,context);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..27fa6e85ad
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.databinding.sdo.ImportSDOProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#import.sdo,model=org.apache.tuscany.sca.databinding.sdo.ImportSDO
+org.apache.tuscany.sca.databinding.sdo.xml.SDOTypesProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#sdo.types,model=org.apache.tuscany.sca.databinding.sdo.SDOTypes
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..6252de51c2
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+org.apache.tuscany.sca.databinding.sdo.xml.SDOTypesModelResolver;model=org.apache.tuscany.sca.databinding.sdo.SDOTypes \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding
new file mode 100644
index 0000000000..5ae557cc74
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# implementation classes for the databindings
+org.apache.tuscany.sca.databinding.sdo.SDODataBinding;name=commonj.sdo.DataObject
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
new file mode 100644
index 0000000000..b1916fd32a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -0,0 +1,27 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation classes for the transformers
+org.apache.tuscany.sca.databinding.sdo.DataObject2String;source=commonj.sdo.DataObject,target=java.lang.String,weight=510
+org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader;source=commonj.sdo.DataObject,target=javax.xml.stream.XMLStreamReader,weight=490
+org.apache.tuscany.sca.databinding.sdo.XMLDocument2String;source=commonj.sdo.helper.XMLDocument,target=java.lang.String,weight=510
+org.apache.tuscany.sca.databinding.sdo.String2DataObject;source=java.lang.String,target=commonj.sdo.DataObject,weight=500
+org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader;source=commonj.sdo.helper.XMLDocument,target=javax.xml.stream.XMLStreamReader,weight=490
+org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.DataObject,weight=490
+org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.helper.XMLDocument,weight=490
+org.apache.tuscany.sca.databinding.sdo.DataObject2Node;source=commonj.sdo.DataObject,target=org.w3c.dom.Node,weight=500
+org.apache.tuscany.sca.databinding.sdo.Node2DataObject;source=org.w3c.dom.Node,target=commonj.sdo.DataObject,weight=500
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties
new file mode 100644
index 0000000000..f53f08f377
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/main/resources/databinding-sdo-validation-messages.properties
@@ -0,0 +1,23 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+FailToResolveClass = Fail to resolve class: {0}
+FailToResolveLocation = Fail to resolve location: {0}
+ContributionResolveException = ContributionResolveException occured due to:
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java
new file mode 100644
index 0000000000..5a0208b290
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.example.stock.sdo.fault;
+
+import javax.xml.namespace.QName;
+
+import com.example.stock.sdo.InvalidSymbolFault;
+
+/**
+ * Hand-crafted java exception for SDO fault
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidSymbolFault_Exception extends Exception {
+ private static final long serialVersionUID = 8602157311925253920L;
+
+ /**
+ * 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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.java
new file mode 100644
index 0000000000..012af9ed1c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2NodeTestCase.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 junit.framework.Assert;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import commonj.sdo.DataObject;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataObject2NodeTestCase extends SDOTransformerTestCaseBase {
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<Class<String>>(String.class, String.class);
+ }
+
+ public final void testTransform() {
+ Node node = new DataObject2Node().transform(dataObject, context);
+ Assert.assertNotNull(node);
+ Element element = (Element) node;
+ Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespaceURI());
+ Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName());
+ DataObject po = new Node2DataObject(new DefaultExtensionPointRegistry()).transform(node, reversedContext);
+ Assert.assertTrue(po instanceof PurchaseOrderType);
+ PurchaseOrderType orderType = (PurchaseOrderType)po;
+ Assert.assertEquals("San Jose", orderType.getBillTo().getCity());
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java
new file mode 100644
index 0000000000..44d11cd586
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataObject2StringTestCase extends SDOTransformerTestCaseBase {
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<Class<String>>(String.class, String.class);
+ }
+
+ public final void testTransform() {
+ String xml = new DataObject2String().transform(dataObject, context);
+ Assert.assertTrue(xml.indexOf("<city>San Jose</city>") != -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 =
+ "<foo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ + "xmlns:ipo=\"http://www.example.com/IPO\" xsi:type=\"ipo:USAddress\"/>";
+ DataObject dataObject = new String2DataObject().transform(xml, reversedContext);
+ context.setSourceDataType(new DataTypeImpl<XMLType>(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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..c2a9f46059
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * 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.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.databinding.xml.Node2String;
+import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node;
+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;
+import commonj.sdo.helper.EqualityHelper;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<Class<XMLStreamReader>>(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;
+ }
+ }
+ DataObject d = new XMLStreamReader2DataObject().transform(reader, reversedContext);
+ assertNotNull(d);
+ assertTrue(EqualityHelper.INSTANCE.equal(dataObject, d));
+ }
+
+ public final void testTransform1() throws XMLStreamException {
+ XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context);
+ XMLStreamReader2Node t2 = new XMLStreamReader2Node(new DefaultExtensionPointRegistry());
+ org.w3c.dom.Node node = t2.transform(reader, context);
+ assertNotNull(node);
+ Node2String t3 = new Node2String(new DefaultExtensionPointRegistry());
+ String xml = t3.transform(node, context);
+ assertTrue(xml.contains("xmlns:xsi"));
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java
new file mode 100644
index 0000000000..1fcae3cb73
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java
@@ -0,0 +1,103 @@
+/*
+ * 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 org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.example.ipo.sdo.SdoFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ImportSDOProcessorTestCase {
+ private static boolean inited;
+
+ private static ExtensionPointRegistry registry;
+ private static ImportSDOProcessor loader;
+ private static XMLInputFactory xmlFactory;
+
+ @Test
+ public void testMinimal() throws Exception {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertTrue(loader.read(reader, new ProcessorContext(registry)) instanceof ImportSDO);
+ }
+
+ @Test
+ public void testLocation() throws Exception {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1' location='ipo.xsd'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertTrue(loader.read(reader, new ProcessorContext(registry)) instanceof ImportSDO);
+ }
+
+ @Test
+ public void testFactory() throws Exception {
+ String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/1.1' " + "factory='"
+ + MockFactory.class.getName()
+ + "'/>";
+ XMLStreamReader reader = getReader(xml);
+ assertFalse(inited);
+ ProcessorContext context = new ProcessorContext(registry);
+ ImportSDO importSDO = loader.read(reader, context);
+ assertNotNull(importSDO);
+ ModelResolver resolver = new TestModelResolver();
+ resolver.addModel(new ClassReference(MockFactory.class), context);
+ loader.resolve(importSDO, resolver, context);
+ assertTrue(inited);
+ }
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ registry = new DefaultExtensionPointRegistry();
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+ loader = new ImportSDOProcessor(registry);
+ xmlFactory = factories.getFactory(XMLInputFactory.class);
+ }
+
+ 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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.java
new file mode 100644
index 0000000000..e0d1c9bf12
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelperTestCase.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 java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+import org.junit.Test;
+
+import commonj.sdo.Type;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SDOContextHelperTestCase {
+ @Test
+ public void testGenerateSchema() throws IOException {
+ HelperContext context = SDOUtil.createHelperContext();
+ URL url = getClass().getResource("/ipo.xsd");
+ Assert.assertNotNull(url);
+ InputStream is = url.openStream();
+ XSDHelper xsdHelper = context.getXSDHelper();
+ xsdHelper.define(is, url.toExternalForm());
+ TypeHelper typeHelper = context.getTypeHelper();
+ Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType");
+ Assert.assertNotNull(type);
+ /*
+ SDOContextHelper.generateSchema(context, Arrays.asList(type));
+ */
+ }
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java
new file mode 100644
index 0000000000..400b424a97
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java
@@ -0,0 +1,115 @@
+/*
+ * 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.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ binding = new SDODataBinding(new DefaultExtensionPointRegistry());
+ context = HelperProvider.getDefaultContext();
+ SdoFactory.INSTANCE.register(context);
+ }
+
+ public final void testIntrospect() {
+ Operation op = null;
+ DataType dataType = new DataTypeImpl<Class>(DataObject.class, null);
+ boolean yes = binding.introspect(dataType, op);
+ assertTrue(yes);
+ assertTrue(dataType.getDataBinding().equals(binding.getName()));
+ assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN);
+ dataType = new DataTypeImpl<Class>(PurchaseOrderType.class, null);
+ yes = binding.introspect(dataType, op);
+ assertTrue(yes);
+ assertEquals(PurchaseOrderType.class, dataType.getPhysical());
+ assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical())
+ .getTypeName());
+ dataType = new DataTypeImpl<Class>(USAddress.class, null);
+ yes = binding.introspect(dataType, op);
+ 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, null, null, null, null);
+ 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, null, null, null, null);
+ 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, null, null, null, null);
+ 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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java
new file mode 100644
index 0000000000..4d415f2895
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java
@@ -0,0 +1,84 @@
+/*
+ * 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.core.DefaultExtensionPointRegistry;
+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
+ *
+ * @version $Rev$ $Date$
+ */
+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()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ new SDODataBinding(new DefaultExtensionPointRegistry());
+ 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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java
new file mode 100644
index 0000000000..2326d1b93b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.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.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.impl.HelperProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SDOWrapperHandlerTestCase extends TestCase {
+ private HelperContext context;
+ private SDOWrapperHandler handler;
+
+ @Override
+ public void setUp() throws Exception {
+ new SDODataBinding(new DefaultExtensionPointRegistry());
+ context = SDOUtil.createHelperContext();
+ handler = new SDOWrapperHandler();
+ }
+
+ public void testWrapperAnyType() throws Exception {
+ XMLHelper xmlHelper = context.getXMLHelper();
+ XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml"));
+ Operation op = new OperationImpl();
+ List children = handler.getChildren(document, op, true);
+ 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"));
+ Operation op = new OperationImpl();
+ List children = handler.getChildren(document, op, true);
+ assertEquals(5, children.size());
+ }
+
+ public void testCreate() {
+ HelperContext context = HelperProvider.getDefaultContext();
+ XSDHelper xsdHelper = context.getXSDHelper();
+ xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null);
+ ElementInfo element = new ElementInfo(new QName("http://www.example.com/wrapper", "op"), null);
+ Operation op = new OperationImpl();
+ WrapperInfo wrapperInfo = new WrapperInfo(SDODataBinding.NAME, element, null, null, null);
+ op.setWrapper(wrapperInfo);
+ DataObject wrapper = (DataObject) handler.create(op, true);
+ assertNotNull(wrapper);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java
new file mode 100644
index 0000000000..3f742b49a3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+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<Object, Object> map = new HashMap<Object, Object>();
+
+ public TestModelResolver() {
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
+ 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, ProcessorContext context) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved, ProcessorContext context) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..2beadc5b61
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.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.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import com.example.ipo.sdo.PurchaseOrderType;
+import commonj.sdo.helper.XMLDocument;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase {
+
+ @Override
+ protected DataType<?> getSourceDataType() {
+ return new DataTypeImpl<XMLType>(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null));
+ }
+
+ @Override
+ protected DataType<?> getTargetDataType() {
+ return new DataTypeImpl<Class<XMLStreamReader>>(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-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/ipo.xsd
new file mode 100755
index 0000000000..241ec15d36
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/ipo.xsd
@@ -0,0 +1,136 @@
+<!--
+ * 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.
+-->
+<schema targetNamespace="http://www.example.com/IPO"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+
+ <annotation>
+ <documentation xml:lang="en">
+ International Purchase order schema for Example.com
+ Copyright 2000 Example.com. All rights reserved.
+ </documentation>
+ </annotation>
+
+
+ <element name="purchaseOrder" type="ipo:PurchaseOrderType" />
+
+ <element name="comment" type="string" />
+
+ <complexType name="PurchaseOrderType">
+ <sequence>
+ <element name="shipTo" type="ipo:Address" />
+ <element name="billTo" type="ipo:Address" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="items" type="ipo:Items" />
+ </sequence>
+ <attribute name="orderDate" type="date" />
+ </complexType>
+
+ <complexType name="Items">
+ <sequence>
+ <element name="item" minOccurs="0" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" type="string" />
+ <element name="quantity">
+ <simpleType>
+ <restriction base="positiveInteger">
+ <maxExclusive value="100" />
+ </restriction>
+ </simpleType>
+ </element>
+ <element name="USPrice" type="decimal" />
+ <element ref="ipo:comment" minOccurs="0" />
+ <element name="shipDate" type="date"
+ minOccurs="0" />
+ </sequence>
+ <attribute name="partNum" type="ipo:SKU"
+ use="required" />
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <simpleType name="SKU">
+ <restriction base="string">
+ <pattern value="\d{3}-[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+ <complexType name="Address">
+ <sequence>
+ <element name="name" type="string" />
+ <element name="street" type="string" />
+ <element name="city" type="string" />
+ </sequence>
+ </complexType>
+
+ <complexType name="USAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="state" type="ipo:USState" />
+ <element name="zip" type="positiveInteger" />
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="UKAddress">
+ <complexContent>
+ <extension base="ipo:Address">
+ <sequence>
+ <element name="postcode" type="ipo:UKPostcode" />
+ </sequence>
+ <attribute name="exportCode" type="positiveInteger"
+ fixed="1" />
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <!-- other Address derivations for more countries -->
+
+ <simpleType name="USState">
+ <restriction base="string">
+ <enumeration value="AK" />
+ <enumeration value="AL" />
+ <enumeration value="AR" />
+ <enumeration value="CA" />
+ <enumeration value="PA" />
+ <!-- and so on ... -->
+ </restriction>
+ </simpleType>
+
+ <simpleType name="Postcode">
+ <restriction base="string">
+ <length value="7" fixed="true" />
+ </restriction>
+ </simpleType>
+
+
+ <simpleType name="UKPostcode">
+ <restriction base="ipo:Postcode">
+ <pattern value="[A-Z]{2}\d\s\d[A-Z]{2}" />
+ </restriction>
+ </simpleType>
+
+
+
+</schema>
+
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/stock.xsd b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/stock.xsd
new file mode 100644
index 0000000000..a0a6717371
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/stock.xsd
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<schema targetNamespace="http://www.example.com/stock" xmlns="http://www.w3.org/2001/XMLSchema">
+ <!-- Faults -->
+ <element name="InvalidSymbolFault">
+ <complexType>
+ <sequence>
+ <element name="message" minOccurs="1" type="string" />
+ <element name="symbol" minOccurs="1" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="MarketClosedFault" type="string" />
+
+</schema> \ No newline at end of file
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xml b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xml
new file mode 100644
index 0000000000..2526629409
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<p:op xmlns:p="http://www.example.com/wrapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.example.com/wrapper wrapper.xsd ">
+ <message>message</message>
+ <symbol>symbol</symbol>
+ <message>message1</message>
+ <symbol>symbol1</symbol>
+ <symbol>symbol2</symbol>
+</p:op>
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xsd b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xsd
new file mode 100644
index 0000000000..ea4dc5f7f3
--- /dev/null
+++ b/sca-java-2.x/branches/2.0-Beta1/modules/databinding-sdo/src/test/resources/wrapper.xsd
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<schema targetNamespace="http://www.example.com/wrapper" xmlns="http://www.w3.org/2001/XMLSchema">
+ <!-- Faults -->
+ <element name="op">
+ <complexType>
+ <sequence maxOccurs="unbounded">
+ <element name="message" minOccurs="1" type="string" />
+ <element name="symbol" minOccurs="1" maxOccurs="3" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="opResponse">
+ <complexType>
+ <sequence maxOccurs="1">
+ <element name="price" minOccurs="1" maxOccurs="unbounded" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+</schema> \ No newline at end of file