diff options
Diffstat (limited to 'sca-java-1.x/branches/pre-spec-changes/services')
188 files changed, 17849 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml new file mode 100755 index 0000000000..9f5b4a31e1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/pom.xml @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-axiom</artifactId> + <name>Apache Tuscany Data Binding for Axiom</name> + <description>Tuscany Axiom Data Binding</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.1</version> + </dependency> + + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-impl</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + <dependency> + <groupId>woodstox</groupId> + <artifactId>wstx-asl</artifactId> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..771e7221ef --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/AxiomDataBinding.java @@ -0,0 +1,72 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.databinding.axiom;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * DataBinding for AXIOM
+ */
+@Service(DataBinding.class)
+public class AxiomDataBinding extends DataBindingExtension {
+
+ public static final String NAME = OMElement.class.getName();
+
+ public AxiomDataBinding() {
+ super(OMElement.class);
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.DataBindingExtension#getWrapperHandler()
+ */
+ @Override
+ public WrapperHandler getWrapperHandler() {
+ return new OMElementWrapperHandler();
+ }
+
+ public Object copy(Object source) {
+ if ( OMElement.class.isAssignableFrom(source.getClass()) ) {
+ try {
+ OMElement sourceElement = (OMElement)source;
+ StringWriter writer = new StringWriter();
+ sourceElement.serialize(writer);
+
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(writer.toString().getBytes()));
+ OMElement copyElement = builder.getDocumentElement();
+ return copyElement;
+ } catch ( XMLStreamException e ) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return super.copy(source);
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..91b1f4da90 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2Object.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.SimpleType2JavaTransformer; +import org.osoa.sca.annotations.Service; + +/** + * Transformer to convert data from a simple java bject to OMElement + */ +@Service(Transformer.class) +public class OMElement2Object extends SimpleType2JavaTransformer<OMElement> { + + @Override + protected String getText(OMElement source) { + return source.getText(); + } + + public Class getSourceType() { + return OMElement.class; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java new file mode 100755 index 0000000000..52be08537d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2String.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +/** + * Transformer to convert data from an OMElement to XML String + */ +@Service(Transformer.class) +public class OMElement2String extends TransformerExtension<OMElement, String> implements PullTransformer<OMElement, String> { + // private XmlOptions options; + + public String transform(OMElement source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + source.serialize(writer); + return writer.toString(); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100755 index 0000000000..343408a027 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElement2XMLStreamReader.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class OMElement2XMLStreamReader extends TransformerExtension<OMElement, XMLStreamReader> implements PullTransformer<OMElement, XMLStreamReader> { + // private XmlOptions options; + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + return source.getXMLStreamReader(); + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..0ba2863735 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/OMElementWrapperHandler.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.axiom; + +import java.util.Iterator; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +/** + * OMElement wrapper handler implementation + */ +public class OMElementWrapperHandler implements WrapperHandler<OMElement> { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(ElementInfo element, TransformationContext context) { + OMElement wrapper = factory.createOMElement(element.getQName(), null); + return wrapper; + } + + public Object getChild(OMElement wrapper, int i, ElementInfo element) { + int index = 0; + for (Iterator e = wrapper.getChildElements(); e.hasNext();) { + OMElement child = (OMElement) e.next(); + if (index != i) { + index++; + continue; + } + if (child.getQName().equals(element.getQName())) { + return child; + } + } + return null; + } + + public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { + wrapper.addChild((OMElement) value); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..5416b5239e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/Object2OMElement.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.Java2SimpleTypeTransformer; +import org.apache.tuscany.spi.idl.ElementInfo; +import org.osoa.sca.annotations.Service; + +/** + * Transformer to convert data from an simple OMElement to Java Object + */ +@Service(Transformer.class) +public class Object2OMElement extends Java2SimpleTypeTransformer<OMElement> { + + private OMFactory factory; + + public Object2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + protected OMElement createElement(ElementInfo element, String text, TransformationContext context) { + OMElement omElement = factory.createOMElement(element.getQName(), null); + factory.createOMText(omElement, text); + return omElement; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java new file mode 100755 index 0000000000..59ac5423d7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/String2OMElement.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import java.io.ByteArrayInputStream; + +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.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.tuscany.spi.model.DataType; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class String2OMElement extends TransformerExtension<String, OMElement> implements + PullTransformer<String, OMElement> { + + @SuppressWarnings("unchecked") + public OMElement transform(String source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(source.getBytes())); + OMElement element = builder.getDocumentElement(); + adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + /** + * @param context + * @param element + */ + private void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (!(targetQName instanceof QName)) { + return; + } + if (!element.getQName().equals(targetQName)) { + // TODO: Throw expection or switch to the new Element + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = (QName)targetQName; + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100755 index 0000000000..5b2c89b443 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/java/org/apache/tuscany/databinding/axiom/XMLStreamReader2OMElement.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.tuscany.spi.model.DataType; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2OMElement extends TransformerExtension<XMLStreamReader, OMElement> implements + PullTransformer<XMLStreamReader, OMElement> { + + public XMLStreamReader2OMElement() { + super(); + } + + public OMElement transform(XMLStreamReader source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(source); + OMElement element = builder.getDocumentElement(); + adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + /** + * @param context + * @param element + */ + private void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (!(targetQName instanceof QName)) { + return; + } + if (!element.getQName().equals(targetQName)) { + // TODO: Throw expection or switch to the new Element + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = (QName)targetQName; + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl new file mode 100644 index 0000000000..ecdaab994e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/databinding.axiom.scdl @@ -0,0 +1,57 @@ +<?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.
+-->
+<!-- This is the copy ot be included by other extensions --> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.axiom.include">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.databinding</group>
+ <name>databinding-axiom</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="databinding.axiom">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.AxiomDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.XMLStreamReader2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2XMLStreamReader" />
+ </component>
+
+ <component name="transformer.String2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.String2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2String" />
+ </component>
+
+ <component name="transformer.Object2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.Object2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2Object">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2Object" />
+ </component>
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..2350c77b17 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,56 @@ +<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.axiom">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.databinding</group>
+ <name>databinding-axiom</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="databinding.axiom">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.AxiomDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.XMLStreamReader2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2XMLStreamReader" />
+ </component>
+
+ <component name="transformer.String2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.String2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2String" />
+ </component>
+
+ <component name="transformer.Object2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.Object2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2Object">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2Object" />
+ </component>
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java new file mode 100755 index 0000000000..2351b7da97 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/java/org/apache/tuscany/databinding/axiom/OMElementTestCase.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; + +public class OMElementTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + " </shipTo>" + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + " <state>PA</state>" + " <zip>95819</zip>" + " </billTo>" + + " <items>" + " <item partNum=\"833-AA\">" + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + " </item>" + " </items>" + "</ipo:purchaseOrder>"; + + public final void testStringTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("<ipo:comment>") != -1); + } + + public final void testStringTransform2() { + String str = + "<p0:firstName xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" " + + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + + "xmlns:p0=\"http://helloworld\">Robert</p0:firstName>"; + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(str, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("<ipo:comment>") != -1); + } + + public final void testStAXTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + + OMElement2XMLStreamReader t2 = new OMElement2XMLStreamReader(); + XMLStreamReader reader = t2.transform(element, null); + + XMLStreamReader2OMElement t3 = new XMLStreamReader2OMElement(); + OMElement element2 = t3.transform(reader, null); + + Assert.assertEquals(element2.getQName(), element.getQName()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), element2.getQName()); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml new file mode 100755 index 0000000000..58058dbe1a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xml @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<ipo:purchaseOrder + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ipo="http://www.example.com/IPO" + xsi:schemaLocation="http://www.example.com/IPO ipo.xsd" + orderDate="1999-12-01"> + + <shipTo exportCode="1" xsi:type="ipo:UKAddress"> + <name>Helen Zoe</name> + <street>47 Eden Street</street> + <city>Cambridge</city> + <postcode>CB1 1JR</postcode> + </shipTo> + + <billTo xsi:type="ipo:USAddress"> + <name>Robert Smith</name> + <street>8 Oak Avenue</street> + <city>Old Town</city> + <state>PA</state> + <zip>95819</zip> + </billTo> + + <items> + <item partNum="833-AA"> + <productName>Lapis necklace</productName> + <quantity>1</quantity> + <USPrice>99.95</USPrice> + <ipo:comment>Want this for the holidays</ipo:comment> + <shipDate>1999-12-05</shipDate> + </item> + </items> +</ipo:purchaseOrder> + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl new file mode 100644 index 0000000000..cde45f12ae --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-axiom/src/test/resources/order.wsdl @@ -0,0 +1,58 @@ +<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/order.wsdl" xmlns:tns="http://example.com/order.wsdl"
+ xmlns:xsd1="http://example.com/order.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/order.xsd" xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:ipo="http://www.example.com/IPO">
+ <import namespace="http://www.example.com/IPO" schemaLocation="ipo.xsd"/>
+ <element name="checkOrderStatus">
+ <complexType>
+ <sequence>
+ <element name="customerId" type="string" />
+ <element name="order" type="ipo:PurchaseOrderType" />
+ <element name="flag" type="int" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="checkOrderStatusResponse">
+ <complexType>
+ <sequence>
+ <element name="status" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="note" type="string" />
+ </schema>
+ </types>
+
+ <message name="CheckOrderStatusInput1">
+ <part name="body" element="xsd1:checkOrderStatus" />
+ </message>
+
+ <message name="CheckOrderStatusOutput1">
+ <part name="body" element="xsd1:checkOrderStatusResponse" />
+ </message>
+
+ <message name="CheckOrderStatusInput2">
+ <part name="p1" element="xsd1:checkOrderStatus" />
+ <part name="p2" element="xsd1:note" />
+ </message>
+
+ <message name="CheckOrderStatusOutput2">
+ <part name="p1" element="xsd1:checkOrderStatusResponse" />
+ </message>
+
+ <portType name="OrderPortType">
+ <operation name="checkOrderStatus">
+ <input message="tns:CheckOrderStatusInput1" />
+ <output message="tns:CheckOrderStatusOutput1" />
+ </operation>
+ <operation name="checkOrderStatus2">
+ <input message="tns:CheckOrderStatusInput2" />
+ <output message="tns:CheckOrderStatusOutput2" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml new file mode 100755 index 0000000000..a0db5b75d5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/pom.xml @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-castor</artifactId> + <name>Apache Tuscany Data Binding for Castor</name> + <description>Tuscany Castor Data Binding</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.codehaus.castor</groupId> + <artifactId>castor</artifactId> + <version>1.0.5</version> + <scope>compile</scope> + <exclusions> + <exclusion> + <groupId>adaptx</groupId> + <artifactId>adaptx</artifactId> + </exclusion> + <exclusion> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.codehaus.castor</groupId> + <artifactId>adaptx</artifactId> + <version>0.9.14</version> + <scope>compile</scope> + </dependency> + + <!-- Adding Apache xerces to workaround the castor references for SAX parser --> + <!-- + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + <version>2.8.0</version> + <scope>runtime</scope> + </dependency> + --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </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/castor-source</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>generate-castor</id> + <phase>generate-test-sources</phase> + <configuration> + <tasks> + <taskdef name="castor-srcgen" + classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask" + classpathref="maven.test.classpath" /> + <mkdir dir="${project.build.directory}/castor-source"></mkdir> + <castor-srcgen file="${basedir}/src/test/resources/ipo.xsd" + todir="${project.build.directory}/castor-source" package="com.example.ipo.castor" types="j2" + warnings="false" + properties="${basedir}/src/test/resources/org/exolab/castor/builder/castorbuilder.properties" + bindingfile="${basedir}/src/test/resources/binding.xml" /> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java new file mode 100755 index 0000000000..9ae0335ada --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class Castor2Node<T> extends TransformerExtension<T, Node> implements PullTransformer<T, Node> { + private Class<T> type; + + public Castor2Node(Class<T> type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return Node.class; + } + + public Class getSourceType() { + return type; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public Node transform(Object source, TransformationContext context) { + try { + Document document = DOMHelper.newDocument(); + Marshaller.marshal(source, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java new file mode 100644 index 0000000000..643d6fb4ad --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.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.databinding.castor; + +import java.io.Writer; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; + +public class Castor2SAX<T> extends TransformerExtension<T, Writer> implements PushTransformer<T, Writer> { + private Class<T> type; + + /** + * @param type + */ + public Castor2SAX(Class<T> type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return Writer.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, Writer writer, TransformationContext context) { + try { + Marshaller.marshal(source, writer); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java new file mode 100644 index 0000000000..f477273387 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.castor; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.xml.sax.ContentHandler; + +public class Castor2Writer<T> extends TransformerExtension<T, ContentHandler> implements PushTransformer<T, ContentHandler> { + private Class<T> type; + + /** + * @param type + */ + public Castor2Writer(Class<T> type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return ContentHandler.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, ContentHandler contentHandler, TransformationContext context) { + try { + Marshaller.marshal(source, contentHandler); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java new file mode 100644 index 0000000000..61bac7d20f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +public class InputSource2Castor<T> extends TransformerExtension<InputSource, T> implements PullTransformer<InputSource, T> { + private Class<T> type; + + /** + * @param type + */ + public InputSource2Castor(Class<T> type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return InputSource.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(InputSource source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java new file mode 100644 index 0000000000..fa5a15b3ba --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.w3c.dom.Node; + +public class Node2Castor<T> extends TransformerExtension<Node, T> implements PullTransformer<Node, T> { + private Class<T> type; + + /** + * @param type + */ + public Node2Castor(Class<T> type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Node.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Node source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java new file mode 100644 index 0000000000..a8ade1bda5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.castor; + +import java.io.Reader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; + +public class Reader2Castor<T> extends TransformerExtension<Reader, T> implements PullTransformer<Reader, T> { + private Class<T> type; + + /** + * @param type + */ + public Reader2Castor(Class<T> type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Reader.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Reader source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java new file mode 100644 index 0000000000..3ea86321e7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.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.databinding.castor; + +import java.io.StringReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.w3c.dom.Node; + +import com.example.ipo.castor.PurchaseOrderType; + +public class Castor2NodeTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + public void testTransform() throws Exception { + Reader2Castor<PurchaseOrderType> t1 = new Reader2Castor<PurchaseOrderType>(PurchaseOrderType.class); + PurchaseOrderType po = t1.transform(new StringReader(IPO_XML), null); + Castor2Node t2 = new Castor2Node(PurchaseOrderType.class); + Node node = t2.transform(po, null); + Assert.assertNotNull(node); + + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml new file mode 100755 index 0000000000..9b66de4cca --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/binding.xml @@ -0,0 +1,9 @@ +<binding xmlns="http://www.castor.org/SourceGenerator/Binding" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + defaultBinding="type"> + + <elementBinding name="complexType:PurchaseOrderType/items"> + <java-class name="ItemsElement"/> + </elementBinding> + +</binding> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties new file mode 100644 index 0000000000..d6f593fd00 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties @@ -0,0 +1,67 @@ +# +# Property file for SourceCodeGenerator +# +# $Id: castorbuilder.properties,v 1.3 2004/05/06 08:20:51 kvisco Exp $ + +# To enable bound properties uncomment the following line. Please +# note that currently *all* fields will be treated as bound properties +# when enabled. This will change in the future when we introduce +# fine grained control over each class and it's properties. +# +#org.exolab.castor.builder.boundproperties=true + +# Java class mapping of <xsd:element>'s and <xsd:complexType>'s +# +# FIXME: There's a bug in the castor-generated code which cannot handle subutype correctly +# http://jira.codehaus.org/browse/CASTOR-1475 +org.exolab.castor.builder.javaclassmapping=type +org.exolab.castor.builder.javaVersion=5.0 + + +# This property allows one to specify the super class of *all* +# generated classes +# +#org.exolab.castor.builder.superclass=com.xyz.BaseObject + +# XML namespace mapping to Java packages +# +#org.exolab.castor.builder.nspackages=\ + http://www.xyz.com/schemas/project=com.xyz.schemas.project,\ + http://www.xyz.com/schemas/person=com.xyz.schemas.person + +# Set to true if you want to generate the equals method +# for each generated class +# false by default +# +#org.exolab.castor.builder.equalsmethod=true + +# Set to true if you want to use Object Wrappers instead +# of primitives (e.g Float instead of float). +# false by default. +# +#org.exolab.castor.builder.primitivetowrapper=false + +# Set to true if you want the generated class descriptors to +# expose the element and attribute names they contain. +# false by default. +# +#org.exolab.castor.builder.classdescfieldnames=false + +# Set to true if you want the generated source code to contain +# Extra methods for the collection fields, such as get/set using +# the collection type in addition to the type-safe array. +# Set this to true if you want your code to be more compatible +# with Castor JDO. This is false by default. +# +#org.exolab.castor.builder.extraCollectionMethods=true + +# Use old-style (Castor 0.9.3.9) of naming that uppercases +# names after an underscore +# +#org.exolab.castor.xml.JavaNaming.upperCaseAfterUnderscore=true + +# This property specifies whether generated enumerated type +# classes implement the EnumeratedTypeAccess interface. +# false by default +#org.exolab.castor.builder.enumTypeAccessInterface=true + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..99ad0f9d39 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/pom.xml @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-jaxb</artifactId> + <name>Apache Tuscany Data Binding for JAXB</name> + <description>Tuscany JAXB Data Binding</description> + + <repositories> + <repository> + <snapshots> + <enabled>true</enabled> + </snapshots> + <id>java.net</id> + <name>java.net Maven 1.x Repository</name> + <url>https://maven-repository.dev.java.net/nonav/repository</url> + <layout>legacy</layout> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <snapshots> + <enabled>true</enabled> + </snapshots> + <id>java.net</id> + <name>java.net Maven 1.x Repository</name> + <url>https://maven-repository.dev.java.net/repository</url> + <layout>legacy</layout> + </pluginRepository> + </pluginRepositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.0.4</version> + <scope>runtime</scope> + <!-- Relacing stax 1.0 with stax 1.0.1 --> + <exclusions> + <exclusion> + <groupId>javax.xml.bind</groupId> + <artifactId>jsr173_api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </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/jaxb-source</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>com.sun.tools.xjc.maven2</groupId> + <artifactId>maven-jaxb-plugin</artifactId> + <version>1.1</version> + <executions> + <execution> + <id>generate-jaxb</id> + <phase>generate-test-sources</phase> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <configuration> + <generatePackage>com.example.ipo.jaxb</generatePackage> + <generateDirectory>${project.build.directory}/jaxb-source</generateDirectory> + <schemaDirectory>${basedir}/src/test/resources</schemaDirectory> + <includeSchemas> + <includeSchema>ipo.xsd</includeSchema> + </includeSchemas> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..607b515809 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXB2Node.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class JAXB2Node extends TransformerExtension<Object, Node> implements PullTransformer<Object, Node> { + + public Node transform(Object source, TransformationContext tContext) { + if (source == null) { + return null; + } + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + // FIXME: The default Marshaller doesn't support + // marshaller.getNode() + Document document = DOMHelper.newDocument(); + marshaller.marshal(JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source), + document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Object.class; + } + + public Class getTargetType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..457232635f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBContextHelper.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; + +public class JAXBContextHelper { + private static final QName JAXB_ELEMENT = new QName("http://jaxb", "element"); + // TODO: Do we need to set them for source and target? + public static final String JAXB_CLASSES = "jaxb.classes"; + + public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath"; + + private JAXBContextHelper() { + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) + throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + // FIXME: We should check the context path or classes + // FIXME: What should we do if JAXB is an intermediate node? + DataType<?> bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + String contextPath = (String)bindingContext.getMetadata(JAXB_CONTEXT_PATH); + if (contextPath == null) { + Operation op = (Operation)bindingContext.getOperation(); + contextPath = op != null ? (String)op.getMetaData().get(JAXB_CONTEXT_PATH) : null; + } + JAXBContext context = null; + if (contextPath != null) { + context = JAXBContext.newInstance(contextPath); + } else { + Class[] classes = (Class[])bindingContext.getMetadata(JAXB_CLASSES); + if (classes != null) { + context = JAXBContext.newInstance(classes); + } else { + Type type = bindingContext.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (cls.getPackage() != null) { + contextPath = cls.getPackage().getName(); + context = JAXBContext.newInstance(contextPath); + } + } + } + } + if (context == null) { + throw new TransformationException("JAXB context is not set for the transformation."); + } + return context; + } + + @SuppressWarnings("unchecked") + public static JAXBElement createJAXBElement(DataType dataType, Object value) { + if (value instanceof JAXBElement) { + return (JAXBElement)value; + } else { + Object logical = dataType.getLogical(); + if (!(logical instanceof QName)) { + logical = JAXB_ELEMENT; + } + return new JAXBElement((QName)logical, (Class)dataType.getPhysical(), value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class<?> cls = (Class)dataType.getPhysical(); + XmlRootElement element = cls.getAnnotation(XmlRootElement.class); + if (element == null) { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } else { + QName root = new QName(element.namespace(), element.name()); + return new JAXBElement(root, (Class)dataType.getPhysical(), value); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..c43e9bcd42 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBDataBinding.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.databinding.jaxb; + +import java.beans.Introspector; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.tuscany.spi.model.DataType; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends DataBindingExtension { + + public static final String NAME = JAXBElement.class.getName(); + + @Override + public DataType introspect(Class<?> javaType) { + if (JAXBElement.class.isAssignableFrom(javaType)) { + Type type = javaType.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = ((ParameterizedType) type); + Type rawType = parameterizedType.getRawType(); + if (rawType == JAXBElement.class) { + Type actualType = parameterizedType.getActualTypeArguments()[0]; + if (actualType instanceof Class) { + return introspect((Class<?>) actualType); + } + } + } + return new DataType<QName>(getName(), javaType, null); + } + + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + namespace = schema.namespace(); + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default") && typeName.equals("")) { + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + namespace = rootElement.namespace(); + } else { + // FIXME: The namespace should be from the referencing property + namespace = null; + } + } else if (typeNamespace.equals("##default")) { + // namespace is from the package + } else { + namespace = typeNamespace; + } + + if (typeName.equals("##default")) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } else { + name = typeName; + } + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + if (xmlEnum != null) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } + } + if (namespace == null && name == null) { + return null; + } + QName xmlType = new QName(namespace, name); + DataType<QName> dataType = new DataType<QName>(getName(), javaType, xmlType); + return dataType; + } + + public JAXBDataBinding() { + super(NAME, JAXBElement.class); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..507f36eb19 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandler.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Method; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +/** + * JAXB WrapperHandler implementation + */ +public class JAXBWrapperHandler implements WrapperHandler<JAXBElement<?>> { + + public JAXBElement<?> create(ElementInfo element, TransformationContext context) { + try { + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + Class<?> factoryClass = Class.forName(factoryClassName, true, context.getClassLoader()); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + Object factory = factoryClass.newInstance(); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + Object value = typeClass.newInstance(); + return (JAXBElement<?>) method.invoke(factory, new Object[] { value }); + } else { + throw new TransformationException("ObjectFactory cannot be resolved."); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Object getChild(JAXBElement<?> wrapper, int i, ElementInfo element) { + try { + Object value = wrapper.getValue(); + PropertyDescriptor descriptors[] = + Introspector.getBeanInfo(wrapper.getDeclaredType()).getPropertyDescriptors(); + for (PropertyDescriptor d : descriptors) { + if (d.getName().equals(element.getQName().getLocalPart())) { + return d.getReadMethod().invoke(value, new Object[] {}); + } + } + return null; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement<?> wrapper, int i, ElementInfo childElement, Object value) { + try { + Object wrapperValue = wrapper.getValue(); + PropertyDescriptor descriptors[] = + Introspector.getBeanInfo(wrapper.getDeclaredType()).getPropertyDescriptors(); + for (PropertyDescriptor d : descriptors) { + if (d.getName().equals(childElement.getQName().getLocalPart())) { + d.getWriteMethod().invoke(wrapperValue, new Object[] { value }); + break; + } + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..301e316889 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Node2JAXB.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class Node2JAXB extends TransformerExtension<Node, Object> implements PullTransformer<Node, Object> { + + public Node2JAXB() { + super(); + } + + public Object transform(Node source, TransformationContext context) { + if (source == null) + return null; + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Node.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..273c15db1b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/Reader2JAXB.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import java.io.Reader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class Reader2JAXB extends TransformerExtension<Reader, Object> implements + PullTransformer<Reader, Object> { + + public Object transform(final Reader source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(source); + Object result = unmarshaller.unmarshal(streamSource); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Reader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..3f6a2f64d3 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/java/org/apache/tuscany/databinding/jaxb/XMLStreamReader2JAXB.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2JAXB extends TransformerExtension<XMLStreamReader, Object> implements + PullTransformer<XMLStreamReader, Object> { + + public XMLStreamReader2JAXB() { + super(); + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl new file mode 100644 index 0000000000..be6b90026e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/databinding.jaxb.scdl @@ -0,0 +1,49 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.jaxb.include">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.databinding</group>
+ <name>databinding-jaxb</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="databinding.jaxb">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXBDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB" />
+ </component>
+
+ <component name="transformer.Node2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Node2JAXB" />
+ </component>
+
+ <component name="transformer.JAXB2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXB2Node" />
+ </component>
+
+ <component name="transformer.Reader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Reader2JAXB" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..02800fd3e9 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,49 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.jaxb">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.databinding</group>
+ <name>databinding-jaxb</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <component name="databinding.jaxb">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXBDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB" />
+ </component>
+
+ <component name="transformer.Node2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Node2JAXB" />
+ </component>
+
+ <component name="transformer.JAXB2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXB2Node" />
+ </component>
+
+ <component name="transformer.Reader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Reader2JAXB" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..1b80be724f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * + */ +public class JAXBDataBindingTestCase extends TestCase { + private JAXBDataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new JAXBDataBinding(); + } + + /** + * Test method for {@link org.apache.tuscany.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class)}. + */ + public final void testIntrospect() { + DataType<?> dataType = binding.introspect(JAXBElement.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == null); + dataType = binding.introspect(MockJAXBElement.class); + Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical()); + dataType = binding.introspect(USAddress.class); + Assert.assertEquals(USAddress.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical()); + dataType = binding.introspect(USState.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertEquals(USState.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USState"), dataType.getLogical()); + + } + + private static class MockJAXBElement extends JAXBElement<PurchaseOrderType> { + + private static final long serialVersionUID = -2767569071002707973L; + + /** + * @param elementName + * @param type + * @param value + */ + public MockJAXBElement(QName elementName, Class<PurchaseOrderType> type, PurchaseOrderType value) { + super(elementName, type, value); + } + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..08583d9729 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +public class JAXBTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + DataType targetDataType = new DataType<Class>(Object.class, null); + targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataType<Class>(Object.class, null); + sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform2() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + QName root = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataType<QName>(PurchaseOrderType.class, root); + // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataType<QName>(PurchaseOrderType.class, root); + // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform3() throws Exception { + + DataType sourceDataType = new DataType<Class>(PurchaseOrderType.class, null); + sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); + Node node = t1.transform(po, tContext1); + + Assert.assertNotNull(node); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-jaxb/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml new file mode 100755 index 0000000000..84e8b084ea --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/pom.xml @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-sdo</artifactId> + <name>Apache Tuscany Data Binding for SDO</name> + <description>Data Binding based on SDO.</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sdo</groupId> + <artifactId>tuscany-sdo-impl</artifactId> + <version>1.0-incubator-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>core</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </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.0-incubator-SNAPSHOT</version> + <executions> + <execution> + <id>generate-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> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..9125980eed --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2String.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class DataObject2String extends TransformerExtension<DataObject, String> implements + PullTransformer<DataObject, String> { + + private static final String TUSCANY_SDO = "http://tuscany.apache.org/xmlns/sdo/1.0-SNAPSHOT"; + + public String transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + Object logicalType = context.getSourceDataType().getLogical(); + if (logicalType instanceof QName) { + QName elementName = (QName) logicalType; + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } else { + return xmlHelper.save(source, TUSCANY_SDO, "dataObject"); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..2892b1bc4d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReader.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class DataObject2XMLStreamReader extends TransformerExtension<DataObject, XMLStreamReader> implements + PullTransformer<DataObject, XMLStreamReader> { + + public XMLStreamReader transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + Object logicalType = context.getSourceDataType().getLogical(); + QName elementName = + (logicalType instanceof QName) ? (QName) logicalType : new QName("commonj.sdo", "dataObject"); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + XMLDocument document = + xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + return streamHelper.createXMLStreamReader(document); + } catch (XMLStreamException e) { + // TODO: Add context to the exception + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.java new file mode 100755 index 0000000000..5706005252 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/DataObjectLoader.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.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.StAXElementLoader; +import org.apache.tuscany.spi.model.ModelObject; +import org.apache.tuscany.spi.annotation.Autowire; +import org.osoa.sca.annotations.EagerInit; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Destroy; + +/** + * A SDO model-based Loader to load DataObject from the XML stream + * + */ +@EagerInit +public class DataObjectLoader implements StAXElementLoader<ModelObject> { + protected LoaderRegistry registry; + private QName propertyQName; + + public DataObjectLoader(Property property) { + super(); + this.propertyQName = new QName(XSDHelper.INSTANCE.getNamespaceURI(property), + XSDHelper.INSTANCE.getLocalName(property)); + } + + public DataObjectLoader(QName propertyQName) { + super(); + this.propertyQName = propertyQName; + } + + public ModelObject load(CompositeComponent parent, ModelObject object, XMLStreamReader reader, DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert propertyQName.equals(reader.getName()); + // TODO: We need a way to get TypeHelper from deploymentContext + TypeHelper typeHelper = TypeHelper.INSTANCE; + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + DataObject dataObject = streamHelper.loadObject(reader); + // TODO: Is it required that the object always extends from ModelObject? + return new ModelDataObject(dataObject); + } + + @Autowire + public void setRegistry(LoaderRegistry registry) { + this.registry = registry; + } + + @Init + public void start() { + registry.registerLoader(propertyQName, this); + } + + @Destroy + public void stop() { + registry.unregisterLoader(propertyQName, this); + } + + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java new file mode 100755 index 0000000000..92b1036bc0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ImportSDOLoader.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.LoaderUtil; +import org.apache.tuscany.spi.model.ModelObject; +import org.osoa.sca.annotations.Constructor; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + */ +public class ImportSDOLoader extends LoaderExtension { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + @Constructor( {"registry"}) + public ImportSDOLoader(@Autowire + LoaderRegistry registry) { + super(registry); + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ModelObject load(CompositeComponent parent, + ModelObject object, + XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert IMPORT_SDO.equals(reader.getName()); + + // FIXME: [rfeng] How to associate the TypeHelper with deployment + // context? + HelperContext helperContext = null; + if (deploymentContext != null && deploymentContext.getParent() != null) { + helperContext = (HelperContext)deploymentContext.getParent().getExtension(HelperContext.class.getName()); + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + deploymentContext.getParent().putExtension(HelperContext.class.getName(), helperContext); + } + } + + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + } + + importFactory(reader, deploymentContext); + importWSDL(reader, deploymentContext, helperContext); + LoaderUtil.skipToEndElement(reader); + return new SDOType(helperContext); + } + + private void importFactory(XMLStreamReader reader, DeploymentContext deploymentContext) throws LoaderException { + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); + try { + // set TCCL as SDO needs it + ClassLoader cl = deploymentContext.getClassLoader(); + Thread.currentThread().setContextClassLoader(cl); + Class<?> factoryClass = cl.loadClass(factoryName); + // FIXME: We require the SDO to provide an API to register + // static types in a given TypeHelper + SDOUtil.registerStaticTypes(factoryClass); + } catch (ClassNotFoundException e) { + throw new LoaderException(e.getMessage(), e); + } finally { + Thread.currentThread().setContextClassLoader(oldCL); + } + } + } + + private void importWSDL(XMLStreamReader reader, DeploymentContext deploymentContext, HelperContext helperContext) + throws LoaderException { + String location = reader.getAttributeValue(null, "location"); + if (location == null) + location = reader.getAttributeValue(null, "wsdlLocation"); + if (location != null) { + try { + URL wsdlURL = null; + URI uri = URI.create(location); + if (uri.isAbsolute()) { + wsdlURL = uri.toURL(); + } + wsdlURL = deploymentContext.getClassLoader().getResource(location); + if (null == wsdlURL) { + LoaderException loaderException = new LoaderException("WSDL location error"); + loaderException.setResourceURI(location); + throw loaderException; + } + InputStream xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = helperContext.getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + } catch (IOException e) { + LoaderException sfe = new LoaderException(e.getMessage()); + sfe.setResourceURI(location); + throw sfe; + } + } + } + + public static class SDOType extends ModelObject { + private HelperContext helperContext; + + public SDOType(HelperContext typeHelper) { + super(); + this.helperContext = typeHelper; + } + + public HelperContext getHelperContext() { + return helperContext; + } + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java new file mode 100755 index 0000000000..a3870b5e9a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/ModelDataObject.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.model.ModelObject; + +import commonj.sdo.DataObject; + +public class ModelDataObject extends ModelObject { + private DataObject dataObject; + + public ModelDataObject(DataObject dataObject) { + super(); + this.dataObject = dataObject; + } + + public DataObject getDataObject() { + return dataObject; + } + + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..213dfd9280 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataBinding.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.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.tuscany.spi.model.DataType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * + */ +public class SDODataBinding extends DataBindingExtension { + private WrapperHandler<Object> wrapperHandler; + + @Override + public DataType introspect(Class<?> javaType) { + if (javaType == DataObject.class) { + return new DataType<QName>(getName(), javaType, null); + } + Type type = TypeHelper.INSTANCE.getType(javaType); + if (type == null || type.isDataType()) { + return null; + } + String namespace = type.getURI(); + String name = XSDHelper.INSTANCE.getLocalName(type); + QName xmlType = new QName(namespace, name); + DataType<QName> dataType = new DataType<QName>(getName(), javaType, xmlType); + return dataType; + } + + public SDODataBinding() { + super(DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java new file mode 100644 index 0000000000..7cb52e366e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDODataTypeHelper.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.databinding.TransformationContext; + +import commonj.sdo.helper.HelperContext; + +/** + * Helper class to get TypeHelper from the transformation context + */ +public class SDODataTypeHelper { + private SDODataTypeHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null || context.getMetadata() == null) { + return SDOUtil.createHelperContext(); + } + HelperContext helperContext = null; + CompositeComponent composite = (CompositeComponent)context.getMetadata().get(CompositeComponent.class); + if (composite != null) { + SDOType sdoType = (SDOType)composite.getExtensions().get(SDOType.class); + if (sdoType != null) { + helperContext = sdoType.getHelperContext(); + } + } + if (helperContext == null) { + return SDOUtil.createHelperContext(); + } else { + return helperContext; + } + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java new file mode 100755 index 0000000000..0c3e74cdc7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOObjectFactory.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.CopyHelper; +import org.apache.tuscany.spi.ObjectFactory; +import org.apache.tuscany.spi.ObjectCreationException; + +/** + * Creates new instances of an SDO + * + * @version $Rev$ $Date$ + */ +public class SDOObjectFactory implements ObjectFactory<DataObject> { + + private DataObject dataObject; + + public SDOObjectFactory(DataObject dataObject) { + this.dataObject = dataObject; + } + + public DataObject getInstance() throws ObjectCreationException { + return CopyHelper.INSTANCE.copy(dataObject); + } + + public void releaseInstance(DataObject instance) { + } + +} + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..a363a8a3ec --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOSimpleTypeMapper.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.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.SimpleTypeMapper; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.idl.TypeInfo; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * SDO Java/XML mapping for simple XSD types + */ +public class SDOSimpleTypeMapper implements SimpleTypeMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public SDOSimpleTypeMapper() { + super(); + } + + public Object toJavaObject(TypeInfo simpleType, String value, TransformationContext context) { + QName typeName = simpleType.getQName(); + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(TypeInfo simpleType, Object obj, TransformationContext context) { + QName typeName = simpleType.getQName(); + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..7074687722 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/SDOWrapperHandler.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.WrapperHandler; +import org.apache.tuscany.spi.idl.ElementInfo; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * SDO Wrapper Handler + */ +public class SDOWrapperHandler implements WrapperHandler<Object> { + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#create(ElementInfo, + * TransformationContext) + */ + public Object create(ElementInfo element, TransformationContext context) { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + QName typeName = element.getType().getQName(); + DataFactory dataFactory = helperContext.getDataFactory(); + DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart()); + } + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#getChild(java.lang.Object, + * int, ElementInfo) + */ + public Object getChild(Object wrapper, int i, ElementInfo element) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + return wrapperDO.get(element.getQName().getLocalPart()); + } + + /** + * @see org.apache.tuscany.spi.databinding.WrapperHandler#setChild(java.lang.Object, + * int, ElementInfo, java.lang.Object) + */ + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + wrapperDO.set(childElement.getQName().getLocalPart(), value); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..64c79a3bd0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/String2DataObject.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class String2DataObject extends TransformerExtension<String, DataObject> implements + PullTransformer<String, DataObject> { + + public DataObject transform(String source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return String.class; + } + + public Class getTargetType() { + return DataObject.class; + } + + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..16e2714a89 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2String.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import java.io.StringWriter; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +@Service(Transformer.class) +public class XMLDocument2String extends TransformerExtension<XMLDocument, String> implements + PullTransformer<XMLDocument, String> { + + public String transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..53343aba6b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReader.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.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +@Service(Transformer.class) +public class XMLDocument2XMLStreamReader extends TransformerExtension<XMLDocument, XMLStreamReader> implements + PullTransformer<XMLDocument, XMLStreamReader> { + /** + * @param source + * @param context + * @return + */ + public XMLStreamReader transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..2a4ce83eb6 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2DataObject.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +@Service(Transformer.class) +public class XMLStreamReader2DataObject extends TransformerExtension<XMLStreamReader, DataObject> implements + PullTransformer<XMLStreamReader, DataObject> { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + // The XMLStreamHelper requires that the reader is posistioned at + // START_ELEMENT + while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { + source.next(); + } + return streamHelper.loadObject(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return DataObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..616d2139d4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/java/org/apache/tuscany/databinding/sdo/XMLStreamReader2XMLDocument.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.databinding.sdo; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.osoa.sca.annotations.Service; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +@Service(Transformer.class) +public class XMLStreamReader2XMLDocument extends TransformerExtension<XMLStreamReader, XMLDocument> implements + PullTransformer<XMLStreamReader, XMLDocument> { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDODataTypeHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.load(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XMLDocument.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl new file mode 100644 index 0000000000..84ac5cc58a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/databinding.sdo.scdl @@ -0,0 +1,68 @@ +<?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.
+-->
+<!--
+ SDO databinding extension
+
+ This is the copy to be included by other extensions
+
+ $Rev: 431086 $ $Date: 2006-08-12 13:58:17 -0700 (Sat, 12 Aug 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.sdo.include">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.databinding</group>
+ <name>databinding-sdo</name>
+ <version>1.0-incubator-SNAPSHOT</version>
+ </dependency>
+
+ <!-- import.sdo element loader implementations -->
+ <component name="elementLoader.import.sdo">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.ImportSDOLoader"/>
+ </component>
+
+ <component name="databinding.sdo">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.SDODataBinding" />
+ </component>
+
+ <component name="transformer.DataObject2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2String"/>
+ </component>
+ <component name="transformer.DataObject2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2XMLStreamReader"/>
+ </component>
+ <component name="transformer.XMLDocument2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2String"/>
+ </component>
+ <component name="transformer.String2DataObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.String2DataObject"/>
+ </component>
+ <component name="transformer.XMLDocument2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader"/>
+ </component>
+ <component name="transformer.XMLStreamReader2DataObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2DataObject"/>
+ </component>
+ <component name="transformer.XMLStreamReader2XMLDocument">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..19a00aa147 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,66 @@ +<?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. +--> +<!-- + SDO databinding extension + + $Rev: 431086 $ $Date: 2006-08-12 13:58:17 -0700 (Sat, 12 Aug 2006) $ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT" + name="org.apache.tuscany.databinding.sdo"> + + <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT"> + <group>org.apache.tuscany.sca.services.databinding</group> + <name>databinding-sdo</name> + <version>1.0-incubator-SNAPSHOT</version> + </dependency> + + <!-- import.sdo element loader implementations --> + <component name="elementLoader.import.sdo"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.ImportSDOLoader"/> + </component> + + <component name="databinding.sdo"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.SDODataBinding" /> + </component> + + <component name="transformer.DataObject2String"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2String"/> + </component> + <component name="transformer.DataObject2XMLStreamReader"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2XMLStreamReader"/> + </component> + <component name="transformer.XMLDocument2String"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2String"/> + </component> + <component name="transformer.String2DataObject"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.String2DataObject"/> + </component> + <component name="transformer.XMLDocument2XMLStreamReader"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader"/> + </component> + <component name="transformer.XMLStreamReader2DataObject"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2DataObject"/> + </component> + <component name="transformer.XMLStreamReader2XMLDocument"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument"/> + </component> + +</composite> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..28a885cd16 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2StringTestCase.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.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType<?> getSourceDataType() { + return new DataType<QName>(binding, PurchaseOrderType.class, orderQName); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataType<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 DataType<QName>(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..5ab23c6df1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObject2XMLStreamReaderTestCase.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; + +/** + * + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType<?> getSourceDataType() { + return new DataType<QName>(binding, PurchaseOrderType.class, orderQName); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataType<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; + } + new XMLStreamReader2DataObject().transform(reader, reversedContext); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java new file mode 100755 index 0000000000..33ae6bbe97 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/DataObjectLoaderTestCase.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import java.io.StringReader; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.core.component.scope.CompositeScopeContainer; +import org.apache.tuscany.core.deployer.RootDeploymentContext; +import org.apache.tuscany.spi.deployer.DeploymentContext; + +import commonj.sdo.helper.XSDHelper; + +public class DataObjectLoaderTestCase extends TestCase { + + private XSDHelper xsdHelper = XSDHelper.INSTANCE; + + private QName name = new QName("http://www.osoa.org/xmlns/mock/0.9", "implementation.mock"); + + private String xml = "<module name=\"m\" xmlns=\"http://www.osoa.org/xmlns/sca/0.9\" xmlns:mock=\"http://www.osoa.org/xmlns/mock/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.osoa.org/xmlns/mock/0.9 sca-implementation-mock.xsd http://www.osoa.org/xmlns/sca/0.9 sca-core.xsd \"><component name=\"c\"><mock:implementation.mock myAttr=\"helloworld.HelloWorldImpl\" /></component></module>"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + URL url = getClass().getClassLoader().getResource("model/sca-implementation-mock.xsd"); + // URL url = getClass().getClassLoader().getResource("model/sca-core.xsd"); + xsdHelper.define(url.openStream(), url.toExternalForm()); + } + + public void testLoader() throws Exception { + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); + int event = reader.getEventType(); + while (!(event == XMLStreamConstants.START_ELEMENT && reader.getName().equals(name)) && reader.hasNext()) { + event = reader.nextTag(); + } + DataObjectLoader loader = new DataObjectLoader(name); + DeploymentContext context = new RootDeploymentContext(getClass().getClassLoader(), inputFactory, new CompositeScopeContainer(null), null); + ModelDataObject modelObject = (ModelDataObject) loader.load(null, null, reader, context); + Assert.assertNotNull(modelObject.getDataObject()); + Assert.assertTrue(modelObject.getDataObject().getString("myAttr").equals("helloworld.HelloWorldImpl")); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java new file mode 100755 index 0000000000..ff6f07427c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/ImportSDOLoaderTestCase.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sdo; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.deployer.RootDeploymentContext; +import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.sdo.model.ModelFactory; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOLoaderTestCase extends TestCase { + private static boolean inited; + + private ImportSDOLoader loader; + private XMLInputFactory xmlFactory; + private DeploymentContext deploymentContext; + + public void testMinimal() throws XMLStreamException, LoaderException { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0'/>"; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof SDOType); + } + + public void testLocation() throws XMLStreamException, LoaderException { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0' location='ipo.xsd'/>"; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof SDOType); + } + + public void testFactory() throws XMLStreamException, LoaderException { + String xml = "<import.sdo xmlns='http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0' " + + "factory='org.apache.tuscany.databinding.sdo.ImportSDOLoaderTestCase$MockFactory'/>"; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + assertTrue(loader.load(null, null, reader, deploymentContext) instanceof SDOType); + assertTrue(inited); + } + + protected void setUp() throws Exception { + super.setUp(); + loader = new ImportSDOLoader(null); + xmlFactory = XMLInputFactory.newInstance(); + deploymentContext = new RootDeploymentContext(getClass().getClassLoader(), xmlFactory, null, null); + } + + 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 = ModelFactory.INSTANCE; + + static { + ImportSDOLoaderTestCase.inited = true; + } + } +} + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..438de93c76 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDODataBindingTestCase.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.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; + +/** + * + */ +public class SDODataBindingTestCase extends TestCase { + private SDODataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + SDOUtil.registerStaticTypes(SdoFactory.class); + } + + public final void testIntrospect() { + DataType<?> dataType = binding.introspect(DataObject.class); + Assert.assertTrue(dataType.getDataBinding().equals(binding.getName())); + Assert.assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == null); + dataType = binding.introspect(PurchaseOrderType.class); + Assert.assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), dataType.getLogical()); + dataType = binding.introspect(USAddress.class); + Assert.assertEquals(USAddress.class, dataType.getPhysical()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "USAddress"), dataType.getLogical()); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..c7403410ef --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/SDOTransformerTestCaseBase.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.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.core.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected String binding = DataObject.class.getName(); + + protected static final QName orderQName = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + SDOUtil.registerStaticTypes(SdoFactory.class); + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType<?> getSourceDataType(); + + protected abstract DataType<?> getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..a7f391216b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/java/org/apache/tuscany/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.spi.model.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; + +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType<?> getSourceDataType() { + return new DataType<QName>(XMLDocument.class.getName(), XMLDocument.class, orderQName); + } + + @Override + protected DataType<?> getTargetDataType() { + return new DataType<Class<XMLStreamReader>>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + XMLHelper.INSTANCE.createDocument(dataObject, orderQName.getNamespaceURI(), orderQName.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(orderQName.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(orderQName.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..8f4ee4be3e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/META-INF/tuscany/databinding.sdo.scdl @@ -0,0 +1,34 @@ +<?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. +--> +<!-- + import.sdo configuration + + $Rev: 431086 $ $Date: 2006-08-12 13:58:17 -0700 (Sat, 12 Aug 2006) $ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT" + name="org.apache.tuscany.databinding.sdo"> + + <!-- import.sdo element loader implementations --> + <component name="elementLoader.import.sdo"> + <system:implementation.system class="org.apache.tuscany.databinding.sdo.ImportSDOLoader"/> + </component> + +</composite> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ +<?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 xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/0.9" + xmlns:sca="http://www.osoa.org/xmlns/sca/0.9" + elementFormDefault="qualified"> + + <element name="componentType" type="sca:ComponentType"/> + <complexType name="ComponentType"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="service" type="sca:Service"/> + <element minOccurs="0" maxOccurs="unbounded" name="reference" type="sca:Reference"/> + <element minOccurs="0" maxOccurs="unbounded" name="property" type="sca:Property"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="Service"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:interface"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="interface" type="sca:Interface"/> + <complexType name="Interface"/> + + <complexType name="Reference"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:interface"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="multiplicity" type="sca:Multiplicity" use="optional" default="1..1"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="Property"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="type" type="QName" use="required"/> + <attribute name="many" type="boolean" default="false" use="optional"/> + <attribute name="required" type="boolean" default="false" use="optional"/> + <attribute name="default" type="string" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <element name="moduleFragment" type="sca:ModuleFragment"/> + <complexType name="ModuleFragment"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="entryPoint" type="sca:EntryPoint"/> + <element minOccurs="0" maxOccurs="unbounded" name="component" type="sca:Component"/> + <element minOccurs="0" maxOccurs="unbounded" name="externalService" type="sca:ExternalService"/> + <element minOccurs="0" maxOccurs="unbounded" name="wire" type="sca:ModuleWire"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="module" type="sca:Module"/> + <complexType name="Module"> + <complexContent> + <extension base="sca:ModuleFragment"/> + </complexContent> + </complexType> + + <complexType name="EntryPoint"> + <sequence> + <element minOccurs="0" maxOccurs="1" ref="sca:interface"/> + <element minOccurs="1" maxOccurs="unbounded" ref="sca:binding"/> + <element minOccurs="1" maxOccurs="unbounded" name="reference" type="anyURI"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="multiplicity" type="sca:Multiplicity" use="optional" default="1..1"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + <!-- a multiplicity 1..1 or 0..n sample + <reference>StockQuoteComponent</reference> - type must be URI + a multiplicity 1..n or 0..n sample + <reference>StockQuoteComponent1</reference> - type must be URI + <reference>StockQuoteComponent2</reference> + --> + + <element name="binding" type="sca:Binding"/> + <complexType name="Binding"> + <attribute name="uri" type="anyURI" use="optional"/> + </complexType> + + <complexType name="Component"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:implementation"/> + <element minOccurs="0" maxOccurs="1" name="properties" type="sca:PropertyValues"/> + <element minOccurs="0" maxOccurs="1" name="references" type="sca:ReferenceValues"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + <!-- a multiplicity 1..1 or 0..1 sample + <references> + <v:stockQuote>StockQuoteComponent</v:stockquote> - type must be URI + </references> + a multiplicity 1..n or 0..n sample + <references> + <v:stockQuote>StockQuoteComponent1</v:stockQuote> - type must be URI + <v:stockQuote>StockQuoteComponent2</v:stockQuote> + </references> + --> + + <element name="implementation" type="sca:Implementation"/> + <complexType name="Implementation"/> + + <complexType name="PropertyValues"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="ReferenceValues"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <complexType name="ExternalService"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:interface"/> + <element minOccurs="0" maxOccurs="unbounded" ref="sca:binding"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="overridable" type="sca:OverrideOptions" default="may" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <complexType name="ModuleWire"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:source.uri"/> + <element minOccurs="1" maxOccurs="1" ref="sca:target.uri"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="source" type="anyType"/> + <element name="target" type="anyType"/> + + <element name="source.uri" type="anyURI" substitutionGroup="sca:source"/> + <element name="target.uri" type="anyURI" substitutionGroup="sca:target"/> + + <element name="subsystem" type="sca:Subsystem"/> + <complexType name="Subsystem"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="entryPoint" type="sca:EntryPoint"/> + <element minOccurs="0" maxOccurs="unbounded" name="moduleComponent" type="sca:ModuleComponent"/> + <element minOccurs="0" maxOccurs="unbounded" name="externalService" type="sca:ExternalService"/> + <element minOccurs="0" maxOccurs="unbounded" name="wire" type="sca:SystemWire"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="uri" type="anyURI" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="ModuleComponent"> + <sequence> + <element minOccurs="0" maxOccurs="1" name="properties" type="sca:PropertyValues"/> + <element minOccurs="0" maxOccurs="1" name="references" type="sca:ReferenceValues"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="module" type="NCName" use="required"/> + <attribute name="uri" type="anyURI" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="SystemWire"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="sca:source"/> + <element minOccurs="1" maxOccurs="1" ref="sca:target"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="source.epr" type="anyType" substitutionGroup="sca:source"/> + <element name="target.epr" type="anyType" substitutionGroup="sca:target"/> + + <simpleType name="Multiplicity"> + <restriction base="string"> + <enumeration value="0..1"/> + <enumeration value="1..1"/> + <enumeration value="0..n"/> + <enumeration value="1..n"/> + </restriction> + </simpleType> + + <simpleType name="OverrideOptions"> + <restriction base="string"> + <enumeration value="no"/> + <enumeration value="may"/> + <enumeration value="must"/> + </restriction> + </simpleType> + +</schema> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ +<?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 xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/mock/0.9" + elementFormDefault="qualified" + xmlns:mock="http://www.osoa.org/xmlns/mock/0.9" + xmlns:sca="http://www.osoa.org/xmlns/sca/0.9"> + + <import namespace="http://www.osoa.org/xmlns/sca/0.9" + schemaLocation="sca-core.xsd" /> + + <element name="implementation.mock" type="mock:MockImplementation" + substitutionGroup="sca:implementation" /> + <complexType name="MockImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" + minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="myAttr" type="NCName" use="required" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml new file mode 100755 index 0000000000..37386075a0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/pom.xml @@ -0,0 +1,222 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-test</artifactId> + <packaging>jar</packaging> + <name>Apache Tuscany Data Binding Integration Test</name> + <description>Apache Tuscany Data Binding Integration Test</description> + + <repositories> + <repository> + <snapshots> + <enabled>true</enabled> + </snapshots> + <id>java.net</id> + <name>java.net Maven 1.x Repository</name> + <url>https://maven-repository.dev.java.net/nonav/repository</url> + <layout>legacy</layout> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>databinding-jaxb</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>databinding-xmlbeans</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>databinding-axiom</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>databinding-sdo</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.services.idl</groupId> + <artifactId>wsdl</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </dependency> + + <dependency> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.0.4</version> + <scope>test</scope> + <!-- Relacing stax 1.0 with stax 1.0.1 --> + <exclusions> + <exclusion> + <groupId>javax.xml.bind</groupId> + <artifactId>jsr173_api</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>test</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>test</scope> + </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/jaxb-source</source> + <source>target/sdo-source</source> + <source>target/xmlbeans-source</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.tuscany.sdo</groupId> + <artifactId>tuscany-sdo-plugin</artifactId> + <executions> + <execution> + <id>generate-sdo</id> + <phase>generate-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> + </executions> + </plugin> + + <plugin> + <groupId>com.sun.tools.xjc.maven2</groupId> + <artifactId>maven-jaxb-plugin</artifactId> + <version>1.1</version> + <executions> + <execution> + <id>generate-jaxb</id> + <phase>generate-sources</phase> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <configuration> + <generatePackage>com.example.ipo.jaxb</generatePackage> + <generateDirectory>${project.build.directory}/jaxb-source</generateDirectory> + <schemaDirectory>${basedir}/src/test/resources</schemaDirectory> + <includeSchemas> + <includeSchema>ipo.xsd</includeSchema> + </includeSchemas> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <dependencies> + <dependency> + <groupId>xmlbeans</groupId> + <artifactId>xbean</artifactId> + <version>2.1.0</version> + </dependency> + <dependency> + <groupId>stax</groupId> + <artifactId>stax-api</artifactId> + <version>1.0.1</version> + </dependency> + + </dependencies> + + <executions> + <execution> + <id>generate-xmlbeans</id> + <phase>generate-sources</phase> + <configuration> + <tasks> + <taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpathref="maven.compile.classpath"/> + <xmlbean schema="${basedir}/src/test/resources" classpathref="maven.compile.classpath" + destfile="${project.build.directory}/ipo-xmlbeans.jar" srcgendir="${project.build.directory}/xmlbeans-source" + javasource="1.5" classgendir="${project.build.directory}/test-classes" /> + </tasks> + <!-- + <sourceRoot>${project.build.directory}/xmlbeans-source</sourceRoot> + <testSourceRoot>${project.build.directory}/xmlbeans-source</testSourceRoot> + --> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java new file mode 100755 index 0000000000..894bee16e4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/JAXBTestCase.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB; +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +public class JAXBTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + DataType targetDataType = new DataType<Class>(Object.class, null); + targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + // XMLStreamReader to JAXB + XMLStreamReader2JAXB t2 = new XMLStreamReader2JAXB(); + Object object2 = t2.transform(reader, tContext); + + DataType sourceDataType = new DataType<Class>(Object.class, null); + sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t3 = new JAXB2Node(); + Node node = t3.transform(object2, tContext1); + + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + + Assert.assertNotNull(object3); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java new file mode 100755 index 0000000000..613bcd9cf8 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/TransformationTestCase.java @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.bind.JAXBElement; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.core.databinding.impl.TransformerRegistryImpl; +import org.apache.tuscany.core.databinding.xml.Node2String; +import org.apache.tuscany.core.databinding.xml.String2Node; +import org.apache.tuscany.core.databinding.xml.String2XMLStreamReader; +import org.apache.tuscany.core.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.databinding.axiom.OMElement2String; +import org.apache.tuscany.databinding.axiom.OMElement2XMLStreamReader; +import org.apache.tuscany.databinding.axiom.String2OMElement; +import org.apache.tuscany.databinding.axiom.XMLStreamReader2OMElement; +import org.apache.tuscany.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB; +import org.apache.tuscany.databinding.sdo.DataObject2XMLStreamReader; +import org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2DataObject; +import org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument; +import org.apache.tuscany.databinding.sdo.ImportSDOLoader.SDOType; +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2Node; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.TransformerRegistry; +import org.apache.tuscany.spi.model.DataType; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class TransformationTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + private TransformerRegistry registry; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + registry = new TransformerRegistryImpl(); + + List<Transformer> transformers = new ArrayList<Transformer>(); + + // Adding JAXB transformers + transformers.add(new JAXB2Node()); + transformers.add(new Node2JAXB()); + transformers.add(new XMLStreamReader2JAXB()); + + // Adding XMLBeans transformers + transformers.add(new XmlObject2Node()); + transformers.add(new XmlObject2XMLStreamReader()); + transformers.add(new Node2XmlObject()); + transformers.add(new XMLStreamReader2XmlObject()); + + transformers.add(new DataObject2XMLStreamReader()); + transformers.add(new XMLStreamReader2DataObject()); + + transformers.add(new XMLDocument2XMLStreamReader()); + transformers.add(new XMLStreamReader2XMLDocument()); + + transformers.add(new String2XMLStreamReader()); + transformers.add(new XMLStreamReader2String()); + + transformers.add(new String2Node()); + transformers.add(new Node2String()); + + transformers.add(new OMElement2String()); + transformers.add(new String2OMElement()); + + transformers.add(new XMLStreamReader2OMElement()); + transformers.add(new OMElement2XMLStreamReader()); + + for (Transformer transformer : transformers) { + registry.registerTransformer(transformer); + } + + // System.out.println(registry); + + URL xsdFile = getClass().getClassLoader().getResource("ipo.xsd"); + XSDHelper.INSTANCE.define(xsdFile.openStream(), null); + } + + @SuppressWarnings("unchecked") + // XMLBeans --> SDO + public void testTransformation1() throws Exception { + URL xsdFile = getClass().getClassLoader().getResource("ipo.xsd"); + HelperContext helperContext = SDOUtil.createHelperContext(); + XSDHelper xsdHelper = helperContext.getXSDHelper(); + xsdHelper.define(xsdFile.openStream(), xsdFile.toExternalForm()); + + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + List<Transformer> path = + registry.getTransformerChain(XmlObject.class.getName(), DataObject.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + tContext.getMetadata().put(SDOType.class, new SDOType(helperContext)); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof DataObject); + + } + + @SuppressWarnings("unchecked") + // SDO --> DOM + public void testTransformation2() throws Exception { + // System.out.println(registry); + + URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + XMLDocument object = XMLHelper.INSTANCE.load(xmlFile.openStream()); + + List<Transformer> path = + registry.getTransformerChain(XMLDocument.class.getName(), Node.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof Node); + + } + + @SuppressWarnings("unchecked") + // SDO --> JAXB + public void testTransformation3() throws Exception { + // System.out.println(registry); + + URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + XMLDocument object = XMLHelper.INSTANCE.load(xmlFile.openStream()); + + List<Transformer> path = + registry.getTransformerChain(XMLDocument.class.getName(), JAXBElement.class.getName()); + System.out.println("Path: " + path); + + TransformationContext tContext = createTransformationContext(); + + Object result = object; + for (Transformer transformer : path) { + result = ((PullTransformer)transformer).transform(result, tContext); + } + System.out.println("Result: " + result); + Assert.assertNotNull(result); + Assert.assertTrue(result instanceof Object); + + } + + private TransformationContext createTransformationContext() { + DataType dataType = new DataType<Class>(Object.class, null); + dataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(dataType).anyTimes(); + + expect(tContext.getSourceDataType()).andReturn(dataType).anyTimes(); + Map<Class<?>, Object> metadata = new HashMap<Class<?>, Object>(); + expect(tContext.getMetadata()).andReturn(metadata).anyTimes(); + replay(tContext); + return tContext; + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java new file mode 100755 index 0000000000..78d51352cb --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/XmlObjectTestCase.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding; + +import java.io.StringReader; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.xmlbeans.Node2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2Node; +import org.apache.tuscany.databinding.xmlbeans.XmlObject2XMLStreamReader; +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +public class XmlObjectTestCase extends TestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + XmlObject object2 = t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + Assert.assertNotNull(object3); + } + + /* + * public void testGeneratedXmlObject() throws Exception { URL xmlFile = + * getClass().getClassLoader().getResource("ipo.xml"); // URL/Stream/Reader + * to XmlObject PurchaseOrderDocument object = + * PurchaseOrderDocument.Factory.parse(xmlFile); // XmlObject to + * XMLStreamReader XmlObject2XMLStreamReader t1 = new + * XmlObject2XMLStreamReader(); XMLStreamReader reader = + * t1.transform(object, null); // XMLStreamReader to XmlObject + * XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); XmlObject + * object2 = t2.transform(reader, null); // XmlObject to Node XmlObject2Node + * t3 = new XmlObject2Node(); Node node = t3.transform(object2, null); // + * Node to XmlObject Node2XmlObject t4 = new Node2XmlObject(); XmlObject + * object3 = t4.transform(node, null); Assert.assertNotNull(object3); } + */ + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java new file mode 100644 index 0000000000..8ddc625d66 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Client.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sample; + +/** + * @version $Rev$ $Date$ + */ +public interface Client { + void call(Object po); +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java new file mode 100644 index 0000000000..2d33a8666b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/ClientImpl.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sample; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class ClientImpl implements Client { + + private Echo echoReference; + + @Constructor + public ClientImpl(@Reference(name = "echoReference", required = true) + Echo echoReference) { + this.echoReference = echoReference; + } + + public void call(Object po) { + Object ret = null; + if (po instanceof PurchaseOrderType) { + ret = echoReference.echoJAXB((PurchaseOrderType)po); + } else if (po instanceof com.example.ipo.sdo.PurchaseOrderType) { + ret = echoReference.echoSDO((com.example.ipo.sdo.PurchaseOrderType)po); + } else if (po instanceof com.example.ipo.xmlbeans.PurchaseOrderType) { + ret = echoReference.echoXMLBeans((com.example.ipo.xmlbeans.PurchaseOrderType)po); + } + System.out.println("Returned message: " + ret); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.java new file mode 100644 index 0000000000..ff44dfb68d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/DataBindingBootStrapTest.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.databinding.sample; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.bind.JAXBElement; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.databinding.jaxb.JAXBContextHelper; +import org.apache.tuscany.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.databinding.sdo.String2DataObject; +import org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.xmlbeans.PurchaseOrderDocument; +import commonj.sdo.DataObject; + +/** + * @version $Rev$ $Date$ + */ +public class DataBindingBootStrapTest extends SCATestCase { + private static final String IPO_XML = + "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + + " <name>Helen Zoe</name>" + + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + + " <postcode>CB1 1JR</postcode>" + + " </shipTo>" + + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + + " <street>8 Oak Avenue</street>" + + " <city>Old Town</city>" + + " <state>PA</state>" + + " <zip>95819</zip>" + + " </billTo>" + + " <items>" + + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + + " <quantity>1</quantity>" + + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + + " <shipDate>1999-12-05</shipDate>" + + " </item>" + + " </items>" + + "</ipo:purchaseOrder>"; + + private Client client; + private String contextPath = "com.example.ipo.jaxb"; + + @SuppressWarnings("unchecked") + public void testDataBindingBootstrap() throws Exception { + DataType targetDataType = new DataType<Class>(Object.class, null); + targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + String2DataObject t1 = new String2DataObject(); + DataObject po1 = t1.transform(IPO_XML, null); + client.call(po1); + + XMLStreamReader reader = + XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + PurchaseOrderDocument po2 = (PurchaseOrderDocument)t2.transform(reader, null); + client.call(po2.getPurchaseOrder()); + + Reader2JAXB t3 = new Reader2JAXB(); + JAXBElement<PurchaseOrderType> po3 = + (JAXBElement<PurchaseOrderType>)t3.transform(new StringReader(IPO_XML), tContext); + client.call(po3.getValue()); + + } + + protected void setUp() throws Exception { + setApplicationSCDL(getClass(), "META-INF/sca/default.scdl"); + addExtension("test-extensions", getClass().getClassLoader() + .getResource("META-INF/tuscany/test-extensions.scdl")); + super.setUp(); + CompositeContext context = CurrentCompositeContext.getContext(); + client = context.locateService(Client.class, "Client"); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java new file mode 100644 index 0000000000..c44e575e26 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/Echo.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sample; + +import org.apache.tuscany.api.annotation.DataType; +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +import com.example.ipo.jaxb.PurchaseOrderType; + + +/** + * @version $Rev$ $Date$ + */ +@Remotable +@Service +public interface Echo { + @DataType(name="javax.xml.bind.JAXBElement") + PurchaseOrderType echoJAXB(PurchaseOrderType po); + + @DataType(name="commonj.sdo.DataObject") + com.example.ipo.sdo.PurchaseOrderType echoSDO(com.example.ipo.sdo.PurchaseOrderType po); + + @DataType(name="org.apache.xmlbeans.XmlObject") + com.example.ipo.xmlbeans.PurchaseOrderType echoXMLBeans(com.example.ipo.xmlbeans.PurchaseOrderType po); +}
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java new file mode 100644 index 0000000000..775c0317a4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/java/org/apache/tuscany/databinding/sample/EchoImpl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.sample; + +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * @version $Rev$ $Date$ + */ +public class EchoImpl implements Echo { + + public PurchaseOrderType echoJAXB(PurchaseOrderType po) { + System.out.println("JAXB: " + po); + return po; + } + + public com.example.ipo.sdo.PurchaseOrderType echoSDO(com.example.ipo.sdo.PurchaseOrderType po) { + System.out.println("SDO: " + po); + return po; + } + + public com.example.ipo.xmlbeans.PurchaseOrderType echoXMLBeans(com.example.ipo.xmlbeans.PurchaseOrderType po) { + System.out.println("XMLBeans: " + po); + return po; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..7e4ed88498 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/sca/default.scdl @@ -0,0 +1,34 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:db="http://tuscany.apache.org/xmlns/databinding/1.0"
+ name="org.apache.tuscany.databinding.sample">
+ + <dbsdo:import.sdo xmlns:dbsdo="http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0" factory="com.example.ipo.sdo.SdoFactory"/>
+ + <component name="Client"> + <implementation.java class="org.apache.tuscany.databinding.sample.ClientImpl" /> + <reference name="echoReference">Echo</reference> + </component> +
+ <component name="Echo">
+ <implementation.java class="org.apache.tuscany.databinding.sample.EchoImpl" />
+ </component>
+ +</composite> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl new file mode 100644 index 0000000000..e4fe956e61 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.axiom.scdl @@ -0,0 +1,52 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.Axiom">
+
+ <component name="databinding.axiom">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.AxiomDataBinding" />
+ </component>
+
+ <!-- Transformers -->
+ <component name="transformer.XMLStreamReader2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.XMLStreamReader2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2XMLStreamReader" />
+ </component>
+
+ <component name="transformer.String2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.String2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2String" />
+ </component>
+
+ <component name="transformer.Object2OMElement">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.Object2OMElement" />
+ </component>
+
+ <component name="transformer.OMElement2Object">
+ <system:implementation.system class="org.apache.tuscany.databinding.axiom.OMElement2Object" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl new file mode 100644 index 0000000000..3b7cd0c32a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.jaxb.scdl @@ -0,0 +1,43 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.JAXB">
+
+ <component name="databinding.jaxb">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXBDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.XMLStreamReader2JAXB" />
+ </component>
+
+ <component name="transformer.Node2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Node2JAXB" />
+ </component>
+
+ <component name="transformer.JAXB2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.JAXB2Node" />
+ </component>
+
+ <component name="transformer.Reader2JAXB">
+ <system:implementation.system class="org.apache.tuscany.databinding.jaxb.Reader2JAXB" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl new file mode 100644 index 0000000000..36577487ba --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.sdo.scdl @@ -0,0 +1,58 @@ +<?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.
+-->
+<!--
+ import.sdo configuration
+
+ $Rev: 431086 $ $Date: 2006-08-12 13:58:17 -0700 (Sat, 12 Aug 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.sdo">
+
+ <!-- import.sdo element loader implementations -->
+ <component name="elementLoader.import.sdo">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.ImportSDOLoader"/>
+ </component>
+ <component name="databinding.sdo">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.SDODataBinding" />
+ </component>
+ <component name="transformer.DataObject2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2String"/>
+ </component>
+ <component name="transformer.DataObject2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.DataObject2XMLStreamReader"/>
+ </component>
+ <component name="transformer.XMLDocument2String">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2String"/>
+ </component>
+ <component name="transformer.String2DataObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.String2DataObject"/>
+ </component>
+ <component name="transformer.XMLDocument2XMLStreamReader">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLDocument2XMLStreamReader"/>
+ </component>
+ <component name="transformer.XMLStreamReader2DataObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2DataObject"/>
+ </component>
+ <component name="transformer.XMLStreamReader2XMLDocument">
+ <system:implementation.system class="org.apache.tuscany.databinding.sdo.XMLStreamReader2XMLDocument"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl new file mode 100644 index 0000000000..2cadfbbca1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/databinding.xmlbeans.scdl @@ -0,0 +1,43 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.XMLBeans">
+
+ <component name="databinding.XMLBeans">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLBeansDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject" />
+ </component>
+
+ <component name="transformer.Node2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.Node2XmlObject" />
+ </component>
+
+ <component name="transformer.XmlObject2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XmlObject2Node" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl new file mode 100644 index 0000000000..9a15675f9f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/interface.wsdl.scdl @@ -0,0 +1,44 @@ +<?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.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev: 440894 $ $Date: 2006-09-06 15:52:01 -0700 (Wed, 06 Sep 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.idl.WSDL">
+
+ <component name="interface.wsdl.Loader">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLLoader" />
+ </component>
+
+ <component name="wsdl.Registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl" initLevel="40" />
+ </component>
+
+ <component name="xmlSchema.registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl" initLevel="35" />
+ </component>
+
+ <component name="interface.wsdl.Introspector">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospectorImpl" initLevel="40" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl new file mode 100644 index 0000000000..88bb3b856d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/META-INF/tuscany/test-extensions.scdl @@ -0,0 +1,30 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="test.extensions">
+
+ <include name="org.apache.tuscany.databinding.axiom" scdlLocation="databinding.axiom.scdl"/>
+ <include name="org.apache.tuscany.databinding.sdo" scdlLocation="databinding.sdo.scdl"/>
+ <include name="org.apache.tuscany.databinding.jaxb" scdlLocation="databinding.jaxb.scdl"/>
+ <include name="org.apache.tuscany.databinding.xmlbeans" scdlLocation="databinding.xmlbeans.scdl"/>
+ <include name="org.apache.tuscany.interface.wsdl" scdlLocation="interface.wsdl.scdl"/>
+
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml new file mode 100755 index 0000000000..58058dbe1a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xml @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<ipo:purchaseOrder + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ipo="http://www.example.com/IPO" + xsi:schemaLocation="http://www.example.com/IPO ipo.xsd" + orderDate="1999-12-01"> + + <shipTo exportCode="1" xsi:type="ipo:UKAddress"> + <name>Helen Zoe</name> + <street>47 Eden Street</street> + <city>Cambridge</city> + <postcode>CB1 1JR</postcode> + </shipTo> + + <billTo xsi:type="ipo:USAddress"> + <name>Robert Smith</name> + <street>8 Oak Avenue</street> + <city>Old Town</city> + <state>PA</state> + <zip>95819</zip> + </billTo> + + <items> + <item partNum="833-AA"> + <productName>Lapis necklace</productName> + <quantity>1</quantity> + <USPrice>99.95</USPrice> + <ipo:comment>Want this for the holidays</ipo:comment> + <shipDate>1999-12-05</shipDate> + </item> + </items> +</ipo:purchaseOrder> + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-test/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ +<!-- Copyright 2004 The Apache Software Foundation + + 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. --> +<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config" + xmlns:ipo="http://www.example.com/IPO"> + + <xb:namespace uri="http://www.example.com/IPO"> + <xb:package>com.example.ipo.xmlbeans</xb:package> + </xb:namespace> + +</xb:config> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/.ruleset @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml new file mode 100755 index 0000000000..9cdc7660ec --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/pom.xml @@ -0,0 +1,97 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>databinding-xmlbeans</artifactId> + <name>Apache Tuscany Data Binding for XmlBeans</name> + <description>Tuscany XmlBeans Data Binding</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>xmlbeans</groupId> + <artifactId>xbean</artifactId> + <version>2.1.0</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </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/xmlbeans-source</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-antrun-plugin</artifactId> + <executions> + <execution> + <id>generate-xmlbeans</id> + <phase>generate-test-sources</phase> + <configuration> + <tasks> + <taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" + classpathref="maven.compile.classpath" /> + <xmlbean schema="${basedir}/src/test/resources" classpathref="maven.compile.classpath" + destfile="${project.build.directory}/ipo-xmlbeans.jar" + srcgendir="${project.build.directory}/xmlbeans-source" javasource="1.5" + classgendir="${project.build.directory}/test-classes" /> + </tasks> + </configuration> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java new file mode 100755 index 0000000000..0b4da53473 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/Node2XmlObject.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class Node2XmlObject extends TransformerExtension<Node, XmlObject> implements + PullTransformer<Node, XmlObject> { + // private XmlOptions options; + + public XmlObject transform(Node source, TransformationContext context) { + try { + return XmlObject.Factory.parse(source); + } catch (XmlException e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XmlObject.class; + } + + public Class getSourceType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java new file mode 100644 index 0000000000..12057982e4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLBeansDataBinding.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.extension.DataBindingExtension; +import org.apache.xmlbeans.XmlObject; + +/** + * XMLBeans DataBinding + */ +public class XMLBeansDataBinding extends DataBindingExtension { + public static final String NAME = XmlObject.class.getName(); + + public XMLBeansDataBinding() { + super(NAME, XmlObject.class); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java new file mode 100755 index 0000000000..0e61bd9571 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XMLStreamReader2XmlObject.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; + +@Service(Transformer.class) +public class XMLStreamReader2XmlObject extends TransformerExtension<XMLStreamReader, XmlObject> implements PullTransformer<XMLStreamReader, XmlObject> { + // private XmlOptions options; + + public XmlObject transform(XMLStreamReader source, TransformationContext context) { + try { + return XmlObject.Factory.parse(source); + } catch (XmlException e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XmlObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java new file mode 100755 index 0000000000..8fc1e58bd5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2Node.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.xmlbeans; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.Transformer; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlObject; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Node; + +@Service(Transformer.class) +public class XmlObject2Node extends TransformerExtension<XmlObject, Node> implements + PullTransformer<XmlObject, Node> { + // private XmlOptions options; + + public Node transform(XmlObject source, TransformationContext context) { + if (source == null) + return null; + return source.newDomNode(); + } + + public Class getSourceType() { + return XmlObject.class; + } + + public Class getTargetType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java new file mode 100755 index 0000000000..8a12cf34f0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/java/org/apache/tuscany/databinding/xmlbeans/XmlObject2XMLStreamReader.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.xmlbeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.apache.xmlbeans.XmlObject; + +public class XmlObject2XMLStreamReader extends TransformerExtension<XmlObject, XMLStreamReader> implements PullTransformer<XmlObject, XMLStreamReader> { + // private XmlOptions options; + + public XMLStreamReader transform(XmlObject source, TransformationContext context) { + return source.newXMLStreamReader(); + } + + public Class getSourceType() { + return XmlObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..2cadfbbca1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,43 @@ +<?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.
+--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.databinding.XMLBeans">
+
+ <component name="databinding.XMLBeans">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLBeansDataBinding" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject" />
+ </component>
+
+ <component name="transformer.Node2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.Node2XmlObject" />
+ </component>
+
+ <component name="transformer.XmlObject2Node">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XmlObject2Node" />
+ </component>
+
+ <component name="transformer.XMLStreamReader2XmlObject">
+ <system:implementation.system class="org.apache.tuscany.databinding.xmlbeans.XMLStreamReader2XmlObject" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java new file mode 100755 index 0000000000..57fbae7e35 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/java/org/apache/tuscany/databinding/xmlbeans/XmlObjectTestCase.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.xmlbeans; + +import java.io.StringReader; +import java.net.URL; + +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.xmlbeans.XmlObject; +import org.w3c.dom.Node; + +import com.example.ipo.xmlbeans.PurchaseOrderDocument; + +public class XmlObjectTestCase extends TestCase { + private static final String IPO_XML = "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ipo=\"http://www.example.com/IPO\"" + + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" + " orderDate=\"1999-12-01\">" + + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" + " <name>Helen Zoe</name>" + " <street>47 Eden Street</street>" + + " <city>Cambridge</city>" + " <postcode>CB1 1JR</postcode>" + " </shipTo>" + " <billTo xsi:type=\"ipo:USAddress\">" + + " <name>Robert Smith</name>" + " <street>8 Oak Avenue</street>" + " <city>Old Town</city>" + " <state>PA</state>" + + " <zip>95819</zip>" + " </billTo>" + " <items>" + " <item partNum=\"833-AA\">" + + " <productName>Lapis necklace</productName>" + " <quantity>1</quantity>" + " <USPrice>99.95</USPrice>" + + " <ipo:comment>Want this for the holidays</ipo:comment>" + " <shipDate>1999-12-05</shipDate>" + " </item>" + " </items>" + + "</ipo:purchaseOrder>"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testXmlObject() throws Exception { + // URL/Stream/Reader to XmlObject + XmlObject object = XmlObject.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + XmlObject object2 = t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + XmlObject object3 = t4.transform(node, null); + Assert.assertNotNull(object3); + } + + public void testGeneratedXmlObject() throws Exception { + // URL xmlFile = getClass().getClassLoader().getResource("ipo.xml"); + // URL/Stream/Reader to XmlObject + PurchaseOrderDocument object = PurchaseOrderDocument.Factory.parse(new StringReader(IPO_XML)); + + // XmlObject to XMLStreamReader + XmlObject2XMLStreamReader t1 = new XmlObject2XMLStreamReader(); + XMLStreamReader reader = t1.transform(object, null); + + // XMLStreamReader to XmlObject + XMLStreamReader2XmlObject t2 = new XMLStreamReader2XmlObject(); + PurchaseOrderDocument object2 = (PurchaseOrderDocument) t2.transform(reader, null); + + // XmlObject to Node + XmlObject2Node t3 = new XmlObject2Node(); + Node node = t3.transform(object2, null); + + // Node to XmlObject + Node2XmlObject t4 = new Node2XmlObject(); + PurchaseOrderDocument object3 = (PurchaseOrderDocument) t4.transform(node, null); + Assert.assertNotNull(object3); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/databinding-xmlbeans/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ +<!-- Copyright 2004 The Apache Software Foundation + + 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. --> +<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config" + xmlns:ipo="http://www.example.com/IPO"> + + <xb:namespace uri="http://www.example.com/IPO"> + <xb:package>com.example.ipo.xmlbeans</xb:package> + </xb:namespace> + +</xb:config> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml new file mode 100644 index 0000000000..af5af8c5f0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/databinding/pom.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + + <parent> + <groupId>org.apache.tuscany.sca.services</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.services.databinding</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <name>Tuscany SCA Data Bindings</name> + + <modules> + <module>databinding-axiom</module> + <module>databinding-castor</module> + <module>databinding-jaxb</module> + <module>databinding-sdo</module> + <module>databinding-xmlbeans</module> + <module>databinding-test</module> + </modules> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/idl/pom.xml new file mode 100644 index 0000000000..7c46142a9f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/pom.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.services.idl</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <name>Tuscany SCA Interface Definition Languages</name> + + <!-- definition of repositories where the parent pom can be found --> + <repositories> + <repository> + <id>apache.snapshots</id> + <name>Apache Snapshot Repository</name> + <url>http://people.apache.org/repo/m2-snapshot-repository</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + <repository> + <id>apache.incubator</id> + <name>Apache Incubator Repository</name> + <url>http://people.apache.org/repo/m2-incubating-repository/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <modules> + <module>wsdl</module> + </modules> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/.ruleset b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/.ruleset @@ -0,0 +1,190 @@ +<?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. +--> +<ruleset name="pmd-eclipse"> + <description>PMD Plugin preferences rule set</description> + + + <rule ref="rulesets/basic.xml/BooleanInstantiation"/> + <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/> + <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/> +<!--<rule ref="rulesets/basic.xml/EmptyCatchBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyFinallyBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyIfStmt"/>--> + <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/> +<!--<rule ref="rulesets/basic.xml/EmptyStaticInitializer"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySwitchStatements"/>--> +<!--<rule ref="rulesets/basic.xml/EmptySynchronizedBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyTryBlock"/>--> +<!--<rule ref="rulesets/basic.xml/EmptyWhileStmt"/>--> + <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/> + <rule ref="rulesets/basic.xml/JumbledIncrementer"/> +<!--<rule ref="rulesets/basic.xml/OverrideBothEqualsAndHashcode"/>--> + <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/> + <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/> + <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/> + <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/> + <rule ref="rulesets/basic.xml/UnnecessaryReturn"/> +<!--<rule ref="rulesets/basic.xml/UselessOverridingMethod"/>--> + +<!--<rule ref="rulesets/braces.xml/ForLoopsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfElseStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/IfStmtsMustUseBraces"/>--> +<!--<rule ref="rulesets/braces.xml/WhileLoopsMustUseBraces"/>--> + +<!--<rule ref="rulesets/clone.xml/CloneMethodMustImplementCloneable"/>--> +<!--<rule ref="rulesets/clone.xml/CloneThrowsCloneNotSupportedException"/>--> +<!--<rule ref="rulesets/clone.xml/ProperCloneImplementation"/>--> + +<!--<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>--> +<!--<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>--> +<!--<rule ref="rulesets/codesize.xml/TooManyFields"/>--> + +<rule ref="rulesets/controversial.xml/AssignmentInOperand"/> +<!--<rule ref="rulesets/controversial.xml/AtLeastOneConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/CallSuperInConstructor"/>--> +<!--<rule ref="rulesets/controversial.xml/DontImportSun"/>--> +<!--<rule ref="rulesets/controversial.xml/NullAssignment"/>--> +<!--<rule ref="rulesets/controversial.xml/OnlyOneReturn"/>--> +<!--<rule ref="rulesets/controversial.xml/SingularField"/>--> +<!--<rule ref="rulesets/controversial.xml/SuspiciousOctalEscape"/>--> +<!--<rule ref="rulesets/controversial.xml/UnnecessaryConstructor"/>--> +<rule ref="rulesets/controversial.xml/UnnecessaryParentheses"/> +<!--<rule ref="rulesets/controversial.xml/UnusedModifier"/>--> + +<!--<rule ref="rulesets/coupling.xml/CouplingBetweenObjects"/>--> +<!--<rule ref="rulesets/coupling.xml/ExcessiveImports"/>--> +<!--<rule ref="rulesets/coupling.xml/LooseCoupling"/>--> + +<!--<rule ref="rulesets/design.xml/AbstractClassWithoutAbstractMethod"/>--> +<!--<rule ref="rulesets/design.xml/AccessorClassGeneration"/>--> +<!--<rule ref="rulesets/design.xml/AssignmentToNonFinalStatic"/>--> +<!--<rule ref="rulesets/design.xml/AvoidDeeplyNestedIfStmts"/>--> +<!--<rule ref="rulesets/design.xml/AvoidInstanceofChecksInCatchClause"/>--> +<rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/> +<!--<rule ref="rulesets/design.xml/AvoidReassigningParameters"/>--> +<!--<rule ref="rulesets/design.xml/AvoidSynchronizedAtMethodLevel"/>--> +<!--<rule ref="rulesets/design.xml/BadComparison"/>--> +<!--<rule ref="rulesets/design.xml/CloseConnection"/>--> +<!--<rule ref="rulesets/design.xml/CompareObjectsWithEquals"/>--> +<!--<rule ref="rulesets/design.xml/ConfusingTernary"/>--> +<rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/> +<!--<rule ref="rulesets/design.xml/DefaultLabelNotLastInSwitchStmt"/>--> +<!--<rule ref="rulesets/design.xml/FinalFieldCouldBeStatic"/>--> +<rule ref="rulesets/design.xml/IdempotentOperations"/> +<!--<rule ref="rulesets/design.xml/ImmutableField"/>--> +<!--<rule ref="rulesets/design.xml/InstantiationToGetClass"/>--> +<!--<rule ref="rulesets/design.xml/MissingBreakInSwitch"/>--> +<!--<rule ref="rulesets/design.xml/MissingStaticMethodInNonInstantiatableClass"/>--> +<!--<rule ref="rulesets/design.xml/NonCaseLabelInSwitchStatement"/>--> +<!--<rule ref="rulesets/design.xml/NonStaticInitializer"/>--> +<rule ref="rulesets/design.xml/OptimizableToArrayCall"/> +<rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/> +<rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/> +<rule ref="rulesets/design.xml/SimplifyBooleanReturns"/> +<rule ref="rulesets/design.xml/SimplifyConditional"/> +<!--<rule ref="rulesets/design.xml/SwitchDensity"/>--> +<!--<rule ref="rulesets/design.xml/SwitchStmtsShouldHaveDefault"/>--> +<rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/> +<!--<rule ref="rulesets/design.xml/UseLocaleWithCaseConversions"/>--> +<!--<rule ref="rulesets/design.xml/UseNotifyAllInsteadOfNotify"/>--> +<!--<rule ref="rulesets/design.xml/UseSingleton"/>--> + +<!--<rule ref="rulesets/finalizers.xml/EmptyFinalizer"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOnlyCallsSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeOverloaded"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeDoesNotCallSuperFinalize"/>--> +<!--<rule ref="rulesets/finalizers.xml/FinalizeShouldBeProtected"/>--> +<!--<rule ref="rulesets/finalizers.xml/AvoidCallingFinalize"/>--> + +<!--<rule ref="rulesets/imports.xml/DuplicateImports"/>--> +<!--<rule ref="rulesets/imports.xml/DontImportJavaLang"/>--> +<!--<rule ref="rulesets/imports.xml/UnusedImports"/>--> +<!--<rule ref="rulesets/imports.xml/ImportFromSamePackage"/>--> + +<!--<rule ref="rulesets/javabeans.xml/BeanMembersShouldSerialize"/>--> +<!--<rule ref="rulesets/javabeans.xml/MissingSerialVersionUID"/>--> + +<!--<rule ref="rulesets/junit.xml/JUnitStaticSuite"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitSpelling"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitAssertionsShouldIncludeMessage"/>--> +<!--<rule ref="rulesets/junit.xml/JUnitTestsShouldIncludeAssert"/>--> +<!--<rule ref="rulesets/junit.xml/TestClassWithoutTestCases"/>--> +<!--<rule ref="rulesets/junit.xml/UnnecessaryBooleanAssertion"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertEqualsInsteadOfAssertTrue"/>--> +<!--<rule ref="rulesets/junit.xml/UseAssertSameInsteadOfAssertTrue"/>--> + + <!--<rule ref="rulesets/logging-java.xml/AvoidPrintStackTrace"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/MoreThanOneLogger"/>--> + <!--<rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>--> + <!--<rule ref="rulesets/logging-java.xml/LogBlockWithoutIf"/>--> + <!--<rule ref="rulesets/logging-java.xml/SystemPrintln"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/UseCorrectExceptionLogging"/>--> + <!--<rule ref="rulesets/logging-jakarta-commons.xml/ProperLogger"/>--> + + <!--<rule ref="rulesets/naming.xml/ShortVariable"/>--> + <!--<rule ref="rulesets/naming.xml/LongVariable"/>--> + <!--<rule ref="rulesets/naming.xml/ShortMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/VariableNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/MethodNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/ClassNamingConventions"/>--> + <!--<rule ref="rulesets/naming.xml/AbstractNaming"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidDollarSigns"/>--> + <!--<rule ref="rulesets/naming.xml/MethodWithSameNameAsEnclosingClass"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousHashcodeMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/SuspiciousConstantFieldName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingTypeName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidFieldNameMatchingMethodName"/>--> + <!--<rule ref="rulesets/naming.xml/AvoidNonConstructorMethodsWithClassName"/>--> + <!--<rule ref="rulesets/naming.xml/NoPackage"/>--> + <!--<rule ref="rulesets/naming.xml/PackageCase"/>--> + + <!--<rule ref="rulesets/optimizations.xml/LocalVariableCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/MethodArgumentCouldBeFinal"/>--> + <!--<rule ref="rulesets/optimizations.xml/AvoidInstantiatingObjectsInLoops"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseArrayListInsteadOfVector"/>--> + <!--<rule ref="rulesets/optimizations.xml/SimplifyStartsWith"/>--> + <!--<rule ref="rulesets/optimizations.xml/UseStringBufferForStringAppends"/>--> + + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingThrowable"/>--> + <!--<rule ref="rulesets/strictexception.xml/SignatureDeclareThrowsException"/>--> + <!--<rule ref="rulesets/strictexception.xml/ExceptionAsFlowControl"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidCatchingNPE"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingRawExceptionTypes"/>--> + <!--<rule ref="rulesets/strictexception.xml/AvoidThrowingNullPointerException"/>--> + + <!--<rule ref="rulesets/strings.xml/AvoidDuplicateLiterals"/>--> + <!--<rule ref="rulesets/strings.xml/StringInstantiation"/>--> + <!--<rule ref="rulesets/strings.xml/StringToString"/>--> + <!--<rule ref="rulesets/strings.xml/AvoidConcatenatingNonLiteralsInStringBuffer"/>--> + <!--<rule ref="rulesets/strings.xml/UnnecessaryCaseChange"/>--> + + <!--<rule ref="rulesets/sunsecure.xml/MethodReturnsInternalArray"/>--> + <!--<rule ref="rulesets/sunsecure.xml/ArrayIsStoredDirectly"/>--> + + <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/> + <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/> + <!--<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>--> + +</ruleset> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/LICENSE.txt @@ -0,0 +1,202 @@ + + 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, serviceDefinition marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/pom.xml new file mode 100644 index 0000000000..69a2577256 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/pom.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services.idl</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>wsdl</artifactId> + <packaging>jar</packaging> + <name>Apache Tuscany WSDL</name> + <description>Tuscany WSDL Support.</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.ws.commons.schema</groupId> + <artifactId>XmlSchema</artifactId> + </dependency> + + <dependency> + <groupId>wsdl4j</groupId> + <artifactId>wsdl4j</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </dependency> + </dependencies> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java new file mode 100644 index 0000000000..1b9326acab --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospector.java @@ -0,0 +1,48 @@ +/* + * 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.idl.wsdl; + +import javax.wsdl.PortType; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes. + * + * @version $Rev$ $Date$ + */ +public interface InterfaceWSDLIntrospector { + + /** + * Introspect a WSDL portType and return a service contract definition. + * + * @param type the portType to inspect + * @return a WSDLServiceContract corresponding to the WSDL portType + */ + WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException; + + /** + * Introspect a WSDL portType and return a service contract definition. + * + * @param type the portType to inspect + * @param callback the callback portType to inspec + * @return a WSDLServiceContract corresponding to the WSDL portType + */ + WSDLServiceContract introspect(PortType type, PortType callback) throws InvalidServiceContractException; +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.java new file mode 100644 index 0000000000..bbfb3b3d01 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImpl.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.idl.wsdl; + +import java.util.HashMap; +import java.util.Map; + +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.model.InteractionScope; +import org.osoa.sca.annotations.Constructor; + +/** + * Introspector for creating WSDLServiceContract definitions from WSDL PortTypes. + */ +public class InterfaceWSDLIntrospectorImpl implements InterfaceWSDLIntrospector { + public static final String INPUT_PARTS = "idl:input"; + + private WSDLDefinitionRegistry wsdlDefinitionRegistry; + + /** + * @param wsdlDefinitionRegistry + */ + @Constructor("wsdlDefinitionRegistry") + public InterfaceWSDLIntrospectorImpl(@Autowire WSDLDefinitionRegistry wsdlDefinitionRegistry) { + super(); + this.wsdlDefinitionRegistry = wsdlDefinitionRegistry; + } + + // FIXME: Do we want to deal with document-literal wrapped style based on the JAX-WS spec? + protected Map<String, org.apache.tuscany.spi.model.Operation<QName>> introspectOperations(PortType portType) + throws InvalidServiceContractException { + Map<String, org.apache.tuscany.spi.model.Operation<QName>> operations = + new HashMap<String, org.apache.tuscany.spi.model.Operation<QName>>(); + for (Object op : portType.getOperations()) { + Operation wsdlOp = (Operation) op; + operations.put(wsdlOp.getName(), introspectOperation(wsdlOp)); + } + return operations; + } + + protected org.apache.tuscany.spi.model.Operation<QName> introspectOperation(Operation wsdlOp) + throws InvalidServiceContractException { + + WSDLOperation op = new WSDLOperation(wsdlOp, null, wsdlDefinitionRegistry.getSchemaRegistry()); + return op.getOperation(); + } + + /** + * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType) + */ + public WSDLServiceContract introspect(PortType portType) throws InvalidServiceContractException { + WSDLServiceContract contract = new WSDLServiceContract(); + contract.setPortType(portType); + contract.setInterfaceName(portType.getQName().getLocalPart()); + contract.setOperations(introspectOperations(portType)); + // FIXME: set to Non-conversational for now + contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); + return contract; + } + + /** + * @see org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector#introspect(javax.wsdl.PortType, javax.wsdl.PortType) + */ + public WSDLServiceContract introspect(PortType portType, PortType callbackPortType) + throws InvalidServiceContractException { + assert portType != null : "PortType cannot be null"; + WSDLServiceContract contract = new WSDLServiceContract(); + // FIXME: set to Non-conversational for now + contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); + contract.setPortType(portType); + contract.setInterfaceName(portType.getQName().getLocalPart()); + contract.setOperations(introspectOperations(portType)); + if (callbackPortType != null) { + contract.setCallbackPortType(callbackPortType); + contract.setCallbackName(callbackPortType.getQName().getLocalPart()); + contract.setCallbackOperations(introspectOperations(callbackPortType)); + } + return contract; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java new file mode 100644 index 0000000000..fc2de45eb3 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLLoader.java @@ -0,0 +1,146 @@ +/* + * 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.idl.wsdl; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import static org.osoa.sca.Version.XML_NAMESPACE_1_0; +import org.osoa.sca.annotations.Constructor; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.extension.LoaderExtension; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.loader.InvalidValueException; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; +import org.apache.tuscany.spi.loader.MissingResourceException; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.ModelObject; + +/** + * Loads a WSDL interface definition from an XML-based assembly file + * + * @version $Rev$ $Date$ + */ +public class InterfaceWSDLLoader extends LoaderExtension { + public static final QName INTERFACE_WSDL = new QName(XML_NAMESPACE_1_0, "interface.wsdl"); + + private static final String WSDLI = "http://www.w3.org/2006/01/wsdl-instance"; + + private static final String WSDLI_LOCATION = "wsdlLocation"; + + private WSDLDefinitionRegistry wsdlRegistry; + + private InterfaceWSDLIntrospector introspector; + + @Constructor({"registry", "wsdlRegistry", "introspector"}) + public InterfaceWSDLLoader(@Autowire LoaderRegistry registry, + @Autowire WSDLDefinitionRegistry wsdlRegistry, + @Autowire InterfaceWSDLIntrospector introspector) { + super(registry); + this.wsdlRegistry = wsdlRegistry; + this.introspector = introspector; + } + + public QName getXMLType() { + return INTERFACE_WSDL; + } + + public WSDLServiceContract load( + CompositeComponent parent, + ModelObject object, XMLStreamReader reader, + DeploymentContext deploymentContext) throws XMLStreamException, LoaderException { + assert INTERFACE_WSDL.equals(reader.getName()); + + String interfaceURI = reader.getAttributeValue(null, "interface"); + if (interfaceURI == null) { + throw new InvalidValueException("interface"); + } + + String callbackURI = reader.getAttributeValue(null, "callbackInterface"); + String wsdlLocation = reader.getAttributeValue(WSDLI, WSDLI_LOCATION); + + Map<Class<?>, ModelObject> extensions = new HashMap<Class<?>, ModelObject>(); + while (true) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + ModelObject mo = registry.load(parent, null, reader, deploymentContext); + if (mo != null) { + extensions.put(mo.getClass(), mo); + } + } else if (event == XMLStreamConstants.END_ELEMENT) { + if (reader.getName().equals(INTERFACE_WSDL)) { + break; + } + } + } + // FIXME set the interaction scope + // serviceContract.setInteractionScope(StAXUtil.interactionScope(reader.getAttributeValue(null, "scope"))); + + if (wsdlLocation != null) { + try { + wsdlRegistry.loadDefinition(wsdlLocation, deploymentContext.getClassLoader()); + } catch (IOException e) { + throw new LoaderException(wsdlLocation, e); + } catch (WSDLException e) { + throw new LoaderException(wsdlLocation, e); + } + } + + PortType portType = getPortType(interfaceURI); + if (portType == null) { + throw new MissingResourceException(interfaceURI); + } + PortType callback = null; + if (callbackURI != null) { + callback = getPortType(callbackURI); + } + try { + WSDLServiceContract contract = introspector.introspect(portType, callback); + DataType<?> dataType = (DataType<?>) extensions.get(DataType.class); + if (dataType != null) { + contract.setDataBinding(dataType.getDataBinding()); + } + contract.getExtensions().putAll(extensions); + return contract; + } catch (InvalidServiceContractException e) { + throw new LoaderException(wsdlLocation, e); + } + } + + protected PortType getPortType(String uri) { + // Syntax: <WSDL-namespace-URI>#wsdl.interface(<portTypeOrInterface-name>) + int index = uri.indexOf('#'); + String namespace = uri.substring(0, index); + String name = uri.substring(index + 1); + name = name.substring("wsdl.interface(".length(), name.length() - 1); + QName qname = new QName(namespace, name); + return wsdlRegistry.getPortType(qname); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java new file mode 100644 index 0000000000..a629ff4fbb --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidFragmentException.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidFragmentException extends WSDLLoaderException { + + public InvalidFragmentException(String message) { + super(message); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java new file mode 100644 index 0000000000..a22ab92863 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLException.java @@ -0,0 +1,34 @@ +/* + * 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.idl.wsdl; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * An exception to indicate the WSDL definition is invalid + * + * @version $Rev$ $Date$ + */ +public class InvalidWSDLException extends InvalidServiceContractException { + + public InvalidWSDLException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java new file mode 100644 index 0000000000..b2d77bf52f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/InvalidWSDLLocationException.java @@ -0,0 +1,33 @@ +/* + * 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.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidWSDLLocationException extends WSDLLoaderException { + + public InvalidWSDLLocationException(String message) { + super(message); + } + + public InvalidWSDLLocationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java new file mode 100644 index 0000000000..04cea4cefd --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/NotSupportedWSDLException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; + +/** + * An exception to indicate some WSDL styles that we don't support + * + * @version $Rev$ $Date$ + */ +public class NotSupportedWSDLException extends InvalidServiceContractException { + + public NotSupportedWSDLException(String message) { + super(message); + } + + public NotSupportedWSDLException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java new file mode 100644 index 0000000000..afb4ed3d40 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/UnresolveableResourceException.java @@ -0,0 +1,34 @@ +/* + * 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.idl.wsdl; + +/** + * @version $Rev$ $Date$ + */ +public class UnresolveableResourceException extends WSDLLoaderException { + + public UnresolveableResourceException(String message) { + super(message); + } + + public UnresolveableResourceException(String message, String identifier) { + super(message, identifier); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.java new file mode 100644 index 0000000000..0694811f0d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistry.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.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.xml.namespace.QName; + +/** + * A service for caching WSDLs + * + * @version $Rev$ $Date$ + */ +@Deprecated +public interface WSDLDefinitionRegistry { + /** + * Loads and registers a WSDL Definition. + * + * @param namespace the expected namespace, or null if any namespace should be allowed + * @param location the location to load the definition from + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws WSDLException if there was a problem parsing the definition + */ + Definition loadDefinition(String namespace, URL location) throws IOException, WSDLException; + + /** + * Load and register a WSDL definition as specified in a WSDL2.0 wsdlLocation attribute. + * + * @param wsdlLocation the value of the wsdlLocation attribute + * @param classLoader application classloader used to support relative locations + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws WSDLException if there was a problem parsing the definition + */ + Definition loadDefinition(String wsdlLocation, ClassLoader classLoader) throws IOException, WSDLException; + + /** + * Returns the PortType with the supplied qualified name, or null if no such port has been defined. + * + * @param name the qualified name of the WSDL portType + * @return the PortType for the supplied name, or null if none has been defined + */ + PortType getPortType(QName name); + + /** + * Returns the ServiceDefinition with the supplied qualified name, or null if no such service has been defined. + * + * @param name the qualified name of the WSDL service + * @return the ServiceDefinition for the supplied name, or null if none has been defined + */ + Service getService(QName name); + + + /** + * Returns the ExtensionRegistry that is used when parsing WSDL documents during the loadDefinition call. + * + * @return the ExtensionRegistry that is used when parsing WSDL documents. + */ + ExtensionRegistry getExtensionRegistry(); + + /** + * Get the XMLSchemaRegistry + * + * @return + */ + XMLSchemaRegistry getSchemaRegistry(); +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java new file mode 100644 index 0000000000..976a09caca --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryImpl.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.wsdl.Definition; +import javax.wsdl.Import; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.annotation.Autowire; + +/** + * The default implementation of the runtime WSDL registry + * + * @version $Rev$ $Date$ + */ +public class WSDLDefinitionRegistryImpl implements WSDLDefinitionRegistry { + private final WSDLFactory wsdlFactory; + + private final ExtensionRegistry registry; + + private final Map<URL, Definition> definitionsByLocation = new HashMap<URL, Definition>(); + + private final Map<String, List<Definition>> definitionsByNamespace = new HashMap<String, List<Definition>>(); + + private Monitor monitor; + + private XMLSchemaRegistry schemaRegistry; + + public WSDLDefinitionRegistryImpl() throws WSDLException { + wsdlFactory = WSDLFactory.newInstance(); + registry = wsdlFactory.newPopulatedExtensionRegistry(); + } + + @Autowire + public void setSchemaRegistry(XMLSchemaRegistry schemaRegistry) { + this.schemaRegistry = schemaRegistry; + } + + @org.apache.tuscany.api.annotation.Monitor + public void setMonitor(Monitor monitor) { + this.monitor = monitor; + } + + public ExtensionRegistry getExtensionRegistry() { + return registry; + } + + public Definition loadDefinition(String wsdlLocation, ClassLoader classLoader) throws IOException, WSDLException { + int index = wsdlLocation.indexOf(' '); + if (index == -1) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); + } + String namespace = wsdlLocation.substring(0, index).trim(); + URL url; + URI uri; + try { + uri = new URI(wsdlLocation.substring(index + 1).trim()); + } catch (URISyntaxException e) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Invalid wsdlLocation: " + wsdlLocation); + } + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = classLoader.getResource(uri.toString()); + if (url == null) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, "Resource not found: " + uri); + } + } + return loadDefinition(namespace, url); + } + + public Definition loadDefinition(String namespace, URL location) throws IOException, WSDLException { + Definition definition = definitionsByLocation.get(location); + if (definition != null) { + // return cached copy + return definition; + } + + if (monitor != null) { + monitor.readingWSDL(namespace, location); + } + WSDLReader reader = wsdlFactory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setExtensionRegistry(registry); + + definition = reader.readWSDL(location.toString()); + String definitionNamespace = definition.getTargetNamespace(); + if (namespace != null && !namespace.equals(definitionNamespace)) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + + definition.getTargetNamespace()); + } + + // Load inline schemas + getSchemaRegistry().loadSchemas(definition); + for (Object i : definition.getImports().values()) { + Import imp = (Import) i; + Definition imported = imp.getDefinition(); + if (imported != null) { + getSchemaRegistry().loadSchemas(imported); + } + } + + if (monitor != null) { + monitor.cachingDefinition(definitionNamespace, location); + } + definitionsByLocation.put(location, definition); + List<Definition> definitions = definitionsByNamespace.get(definitionNamespace); + if (definitions == null) { + definitions = new ArrayList<Definition>(); + definitionsByNamespace.put(definitionNamespace, definitions); + } + definitions.add(definition); + + return definition; + } + + public PortType getPortType(QName name) { + String namespace = name.getNamespaceURI(); + List<Definition> definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + PortType portType = definition.getPortType(name); + if (portType != null) { + return portType; + } + } + return null; + } + + public Service getService(QName name) { + String namespace = name.getNamespaceURI(); + List<Definition> definitions = definitionsByNamespace.get(namespace); + if (definitions == null) { + return null; + } + for (Definition definition : definitions) { + Service service = definition.getService(name); + if (service != null) { + return service; + } + } + return null; + } + + public static interface Monitor { + /** + * Monitor event emitted immediately before an attempt is made to read WSDL for the supplied namespace from the + * supplied location. + * + * @param namespace the target namespace expected in the WSDL; may be null + * @param location the location where we will attempt to read the WSDL definition from + */ + void readingWSDL(String namespace, URL location); + + /** + * Monitor event emitted immediately before registering a WSDL definition in the cache. + * + * @param namespace the target namespace for the WSDL + * @param location the location where the WSDL definition was read from + */ + void cachingDefinition(String namespace, URL location); + } + + public XMLSchemaRegistry getSchemaRegistry() { + if (schemaRegistry == null) { + // Default + schemaRegistry = new XMLSchemaRegistryImpl(); + } + return schemaRegistry; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java new file mode 100644 index 0000000000..fb90e839f5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoader.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import java.net.URI; +import java.util.Collection; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; + +/** + * Interface for implementations that allow WSDL definitions to be loaded. Currently we do not have a complete solution + * for handling both WSDL2.0 and WSDL1.1 definitions so the current implementation only deals with loading WSDL1.1. This + * will change in the near future (for example when Woden supports both forms) so all WSDL1.1 specific methods are + * deprecated. + * + * @version $Rev$ $Date$ + */ +public interface WSDLLoader { + /** + * Load a WSDL 1.1 Definition for a namespace from one of specified locations. + * + * @param namespace the namespace whose definition should be loaded + * @param locations a set of possible locations to load from + * @return the loaded Definition + * @throws WSDLException if there was a problem loading the definition + */ + @Deprecated + Definition loadDefinition(String namespace, Collection<WSDLLocation> locations) + throws WSDLException, UnresolveableResourceException; + + /** + * Load a WSDL 1.1 Definition from the specified location + * + * @param location the location to load from + * @return the loaded Definition + * @throws WSDLException if there was a problem loading the definition + */ + @Deprecated + Definition loadDefinition(WSDLLocation location) throws WSDLException; + + /** + * Return the WSDL1.1 PortType for the specified interface IRI. + * + * @param interfaceIRI the WSDL2.0 interface IRI + * @param wsdlLocation the location of the WSDL instance + * @param base a Classloader from which to load + * @return the specified port type + */ + @Deprecated + PortType loadPortType(URI interfaceIRI, String wsdlLocation, ClassLoader base) + throws WSDLLoaderException, WSDLException; + + /** + * Parses a WSDL2.0 wsdlLocation attribute definition and returns a Collection of all locations it contains. + * + * @param wsdlLocation a list of namespace/location pairs as specified by WSDL2.0 + * @param base a ClassLoader to use to resolve relative URLs + * @return a collection of locations parsed from the string + * @throws InvalidWSDLLocationException + */ + Collection<WSDLLocation> getLocations(String wsdlLocation, ClassLoader base) throws InvalidWSDLLocationException; + + /** + * Returns the fully qualified name of a WSDL interface parsed from a IRI as defined by WSDL2.0. The value of the + * IRI defines the namespace, the fragment specifies the interface component; for example + * <code>http://example.org/TicketAgent.wsdl20#wsdl.interface(TicketAgent)</code> + * + * @param interfaceIRI the IRI for the interface + * @return the qualified name of the interface + * @throws UnresolveableResourceException if the URI is relative + * @throws InvalidFragmentException if the fragment is incorrectly formed + */ + QName getInterfaceName(URI interfaceIRI) throws UnresolveableResourceException, InvalidFragmentException; + + /** + * Returns an interface parsed from a wsdl.interface fragment. + * + * @param fragment the fragment value + * @return the interface name + * @throws InvalidFragmentException if the fragment is incorrectly formed + */ + String getInterfaceName(String fragment) throws InvalidFragmentException; + + /** + * Returns a namespace parsed from an IRI. This is the URI with any fragment removed. + * + * @param iri the IRI + * @return a namespace created by stripping fragment information from the URI + * @throws UnresolveableResourceException if the URI is relative + */ + String getNamespace(URI iri) throws UnresolveableResourceException; +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java new file mode 100644 index 0000000000..1fececa62c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderException.java @@ -0,0 +1,45 @@ +/* + * 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.idl.wsdl; + +import org.apache.tuscany.api.TuscanyException; + +/** + * @version $Rev$ $Date$ + */ +public abstract class WSDLLoaderException extends TuscanyException { + protected WSDLLoaderException() { + } + + protected WSDLLoaderException(String message) { + super(message); + } + + protected WSDLLoaderException(String message, String identifier) { + super(message, identifier); + } + + protected WSDLLoaderException(String message, Throwable cause) { + super(message, cause); + } + + protected WSDLLoaderException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java new file mode 100644 index 0000000000..ebf8cafedc --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImpl.java @@ -0,0 +1,141 @@ +/* + * 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.idl.wsdl; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.ExtensionRegistry; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +/** + * @version $Rev$ $Date$ + */ +public class WSDLLoaderImpl implements WSDLLoader { + private final WSDLFactory wsdlFactory; + + private final ExtensionRegistry registry; + + public WSDLLoaderImpl() throws WSDLException { + wsdlFactory = WSDLFactory.newInstance(); + registry = wsdlFactory.newPopulatedExtensionRegistry(); + } + + public PortType loadPortType(URI interfaceIRI, String wsdlLocation, ClassLoader base) + throws WSDLLoaderException, WSDLException { + Collection<WSDLLocation> locations = getLocations(wsdlLocation, base); + QName interfaceName = getInterfaceName(interfaceIRI); + + Definition definition = loadDefinition(interfaceName.getNamespaceURI(), locations); + return definition.getPortType(interfaceName); + } + + public Definition loadDefinition(String namespace, Collection<WSDLLocation> locations) + throws WSDLException, UnresolveableResourceException { + for (WSDLLocation location : locations) { + if (namespace.equals(location.getNamespace()) && location.getLocation() != null) { + return loadDefinition(location); + } + } + throw new UnresolveableResourceException(namespace); + } + + public Definition loadDefinition(WSDLLocation location) throws WSDLException { + String namespace = location.getNamespace(); + + WSDLReader reader = wsdlFactory.newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setExtensionRegistry(registry); + + Definition definition = reader.readWSDL(location.getLocation().toString()); + String definitionNamespace = definition.getTargetNamespace(); + if (namespace != null && !namespace.equals(definitionNamespace)) { + throw new WSDLException(WSDLException.CONFIGURATION_ERROR, namespace + " != " + + definition.getTargetNamespace()); + } + return definition; + } + + public Collection<WSDLLocation> getLocations(String wsdlLocation, ClassLoader base) + throws InvalidWSDLLocationException { + String parts[] = wsdlLocation.split("\\s"); + // check the number of parts is a multiple of two + if ((parts.length & 1) != 0) { + throw new InvalidWSDLLocationException(wsdlLocation); + } + List<WSDLLocation> locations = new ArrayList<WSDLLocation>(parts.length >>> 1); + for (int i = 0; i < parts.length; i += 2) { + URL url; + try { + URI uri = new URI(parts[i + 1]); + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = base.getResource(uri.toString()); + } + } catch (MalformedURLException e) { + throw new InvalidWSDLLocationException(e); + } catch (URISyntaxException e) { + throw new InvalidWSDLLocationException(e); + } + WSDLLocation location = new WSDLLocation(parts[i], url); + locations.add(location); + } + return locations; + } + + public QName getInterfaceName(URI interfaceIRI) throws UnresolveableResourceException, InvalidFragmentException { + String namespace = getNamespace(interfaceIRI); + String interfaceName = getInterfaceName(interfaceIRI.getFragment()); + return new QName(namespace, interfaceName); + } + + public String getInterfaceName(String fragment) throws InvalidFragmentException { + if (fragment == null) { + throw new InvalidFragmentException("missing fragment"); + } + String[] parts = fragment.split("\\s"); + for (String part : parts) { + if (part.startsWith("wsdl.interface(") && part.charAt(part.length() - 1) == ')') { + return part.substring(15, part.length() - 1); + } + } + throw new InvalidFragmentException(fragment); + } + + public String getNamespace(URI iri) throws UnresolveableResourceException { + if (!iri.isAbsolute()) { + throw new UnresolveableResourceException("No namespace defined in", iri.toString()); + } + StringBuilder s = new StringBuilder(); + s.append(iri.getScheme()); + s.append(':'); + s.append(iri.getSchemeSpecificPart()); + return s.toString(); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java new file mode 100644 index 0000000000..a124294c3a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLLocation.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import java.net.URL; + +/** + * A location where the WSDL for a namespace can be found. + * + * @version $Rev$ $Date$ + */ +public class WSDLLocation { + private final String namespace; + private final URL location; + + /** + * Constructor specifying a namespace and where its WSDL can be found. + * + * @param namespace the target namespace + * @param location the location of the WSDL + */ + public WSDLLocation(String namespace, URL location) { + this.namespace = namespace; + this.location = location; + } + + /** + * Returns the target namespace. + * + * @return the target namespace + */ + public String getNamespace() { + return namespace; + } + + /** + * Returns the location where the WSDL definition can be found. + * + * @return the location where the WSDL definition can be found + */ + public URL getLocation() { + return location; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java new file mode 100644 index 0000000000..c8d26a5626 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLOperation.java @@ -0,0 +1,505 @@ +/* + * 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.idl.wsdl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import javax.wsdl.Fault; +import javax.wsdl.Input; +import javax.wsdl.Message; +import javax.wsdl.Operation; +import javax.wsdl.Output; +import javax.wsdl.Part; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.idl.ElementInfo; +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.idl.TypeInfo; +import org.apache.tuscany.spi.model.WrapperInfo; +import org.apache.tuscany.spi.model.DataType; + +import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaObject; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; +import org.apache.ws.commons.schema.XmlSchemaParticle; +import org.apache.ws.commons.schema.XmlSchemaSequence; +import org.apache.ws.commons.schema.XmlSchemaSimpleType; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * Metadata for a WSDL operation + * + * @version $Rev$ $Date$ + */ +public class WSDLOperation { + protected XMLSchemaRegistry schemaRegistry; + protected Operation operation; + protected org.apache.tuscany.spi.model.Operation<QName> operationModel; + protected DataType<List<DataType<QName>>> inputType; + protected DataType<QName> outputType; + protected List<DataType<QName>> faultTypes; + private String dataBinding; + + /** + * @param operation The WSDL4J operation + * @param dataBinding The default databinding + * @param schemaRegistry The XML Schema registry + */ + public WSDLOperation(Operation operation, String dataBinding, XMLSchemaRegistry schemaRegistry) { + super(); + this.operation = operation; + this.dataBinding = dataBinding; + this.schemaRegistry = schemaRegistry; + this.wrapper = new Wrapper(); + } + + private Wrapper wrapper; + + private Boolean wrapperStyle; + + /** + * Test if the operation qualifies wrapper style as defined by the JAX-WS 2.0 spec + * + * @return true if the operation qualifies wrapper style, otherwise false + */ + public boolean isWrapperStyle() throws InvalidWSDLException { + if (wrapperStyle == null) { + wrapperStyle = + wrapper.getInputChildElements() != null + && (operation.getOutput() == null || wrapper.getOutputChildElements() != null); + } + return wrapperStyle; + } + + public Wrapper getWrapper() throws InvalidWSDLException { + if (!isWrapperStyle()) { + throw new IllegalStateException("The operation is not wrapper style."); + } else { + return wrapper; + } + } + + /** + * @return + * @throws InvalidServiceContractException + * + */ + public DataType<List<DataType<QName>>> getInputType() throws InvalidServiceContractException { + if (inputType == null) { + Input input = operation.getInput(); + Message message = (input == null) ? null : input.getMessage(); + inputType = getMessageType(message); + inputType.setDataBinding("idl:input"); + } + return inputType; + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public DataType<QName> getOutputType() throws InvalidServiceContractException { + if (outputType == null) { + Output output = operation.getOutput(); + Message outputMsg = (output == null) ? null : output.getMessage(); + + List outputParts = (outputMsg == null) ? null : outputMsg.getOrderedParts(null); + if (outputParts != null && outputParts.size() > 0) { + if (outputParts.size() > 1) { + // We don't support output with multiple parts + throw new NotSupportedWSDLException("Multi-part output is not supported"); + } + Part part = (Part) outputParts.get(0); + outputType = new WSDLPart(part).getDataType(); + // outputType.setMetadata(WSDLOperation.class.getName(), this); + } + } + return outputType; + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public List<DataType<QName>> getFaultTypes() throws InvalidServiceContractException { + if (faultTypes == null) { + Collection faults = operation.getFaults().values(); + faultTypes = new ArrayList<DataType<QName>>(); + for (Object f : faults) { + Fault fault = (Fault) f; + Message faultMsg = fault.getMessage(); + List faultParts = faultMsg.getOrderedParts(null); + if (faultParts.size() != 1) { + throw new NotSupportedWSDLException("The fault message MUST have a single part"); + } + Part part = (Part) faultParts.get(0); + WSDLPart wsdlPart = new WSDLPart(part); + faultTypes.add(wsdlPart.getDataType()); + } + } + return faultTypes; + } + + private DataType<List<DataType<QName>>> getMessageType(Message message) throws InvalidServiceContractException { + List<DataType<QName>> partTypes = new ArrayList<DataType<QName>>(); + if (message != null) { + Collection parts = message.getOrderedParts(null); + for (Object p : parts) { + WSDLPart part = new WSDLPart((Part) p); + DataType<QName> partType = part.getDataType(); + partTypes.add(partType); + } + } + return new DataType<List<DataType<QName>>>(dataBinding, Object[].class, partTypes); + } + + /** + * @return + * @throws NotSupportedWSDLException + */ + public org.apache.tuscany.spi.model.Operation<QName> getOperation() throws InvalidServiceContractException { + if (operationModel == null) { + boolean oneway = (operation.getOutput() == null); + operationModel = new org.apache.tuscany.spi.model.Operation<QName>(operation.getName(), + getInputType(), + getOutputType(), + getFaultTypes(), + oneway, + dataBinding, + org.apache.tuscany.spi.model.Operation.NO_CONVERSATION); + operationModel.setWrapperStyle(isWrapperStyle()); + // operationModel.setMetaData(WSDLOperation.class.getName(), this); + if (isWrapperStyle()) { + operationModel.setWrapper(getWrapper().getWrapperInfo()); + // Register the operation with the types + for (DataType<?> d : wrapper.getUnwrappedInputType().getLogical()) { + d.setOperation(operationModel); + } + if (wrapper.getUnwrappedOutputType() != null) { + wrapper.getUnwrappedOutputType().setOperation(operationModel); + } + } + } + inputType.setOperation(operationModel); + if (outputType != null) { + outputType.setOperation(operationModel); + } + return operationModel; + } + + /** + * Metadata for a WSDL part + */ + public class WSDLPart { + private Part part; + + private XmlSchemaElement element; + + private DataType<QName> dataType; + + public WSDLPart(Part part) throws InvalidWSDLException { + this.part = part; + QName elementName = part.getElementName(); + if (elementName != null) { + element = schemaRegistry.getElement(elementName); + if (element == null) { + throw new InvalidWSDLException("Element cannot be resolved", elementName.toString()); + } + } else { + // Create an faked XSD element to host the metadata + element = new XmlSchemaElement(); + element.setName(part.getName()); + element.setQName(new QName(null, part.getName())); + QName typeName = part.getTypeName(); + if (typeName != null) { + XmlSchemaType type = schemaRegistry.getType(typeName); + if (type == null) { + throw new InvalidWSDLException("Type cannot be resolved", typeName.toString()); + } + element.setSchemaType(type); + element.setSchemaTypeName(type.getQName()); + } + } + dataType = new DataType<QName>(dataBinding, Object.class, element.getQName()); + // dataType.setMetadata(WSDLPart.class.getName(), this); + dataType.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + } + + /** + * @return the element + */ + public XmlSchemaElement getElement() { + return element; + } + + /** + * @return the part + */ + public Part getPart() { + return part; + } + + /** + * @return the dataType + */ + public DataType<QName> getDataType() { + return dataType; + } + } + + /** + * The "Wrapper Style" WSDL operation is defined by The Java API for XML-Based Web Services (JAX-WS) 2.0 + * specification, section 2.3.1.2 Wrapper Style. + * <p/> + * A WSDL operation qualifies for wrapper style mapping only if the following criteria are met: <ul> <li>(i) The + * operation’s input and output messages (if present) each contain only a single part <li>(ii) The input message + * part refers to a global element declaration whose localname is equal to the operation name <li>(iii) The output + * message part refers to a global element declaration <li>(iv) The elements referred to by the input and output + * message parts (henceforth referred to as wrapper elements) are both complex types defined using the xsd:sequence + * compositor <li>(v) The wrapper elements only contain child elements, they must not contain other structures such + * as wildcards (element or attribute), xsd:choice, substitution groups (element references are not permitted) or + * attributes; furthermore, they must not be nillable. </ul> + */ + public class Wrapper { + private XmlSchemaElement inputWrapperElement; + + private XmlSchemaElement outputWrapperElement; + + private List<XmlSchemaElement> inputElements; + + private List<XmlSchemaElement> outputElements; + + private DataType<List<DataType<QName>>> unwrappedInputType; + + private DataType<QName> unwrappedOutputType; + + private transient WrapperInfo wrapperInfo; + + private List<XmlSchemaElement> getChildElements(XmlSchemaElement element) throws InvalidWSDLException { + if (element == null) { + return null; + } + if(element.isNillable()) { + // Wrapper element cannot be nillable + return null; + } + XmlSchemaType type = element.getSchemaType(); + if (type == null) { + String qName = element.getQName().toString(); + throw new InvalidWSDLException("The XML schema element does not have a type", qName); + } + if (!(type instanceof XmlSchemaComplexType)) { + // Has to be a complexType + return null; + } + XmlSchemaComplexType complexType = (XmlSchemaComplexType) type; + if (complexType.getAttributes().getCount() != 0 || complexType.getAnyAttribute() != null) { + // No attributes + return null; + } + XmlSchemaParticle particle = complexType.getParticle(); + if (particle == null) { + // No particle + return Collections.emptyList(); + } + if (!(particle instanceof XmlSchemaSequence)) { + return null; + } + XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle(); + XmlSchemaObjectCollection items = sequence.getItems(); + List<XmlSchemaElement> childElements = new ArrayList<XmlSchemaElement>(); + for (int i = 0; i < items.getCount(); i++) { + XmlSchemaObject schemaObject = items.getItem(i); + if (!(schemaObject instanceof XmlSchemaElement)) { + return null; + } + XmlSchemaElement childElement = (XmlSchemaElement) schemaObject; + if (childElement.getName() == null || childElement.getRefName() != null) { + return null; + } + // TODO: Do we support maxOccurs >1 ? + if (childElement.getMaxOccurs() > 1) { + return null; + } + childElements.add(childElement); + } + return childElements; + } + + /** + * Return a list of child XSD elements under the wrapped request element + * + * @return a list of child XSD elements or null if if the request element is not wrapped + */ + public List<XmlSchemaElement> getInputChildElements() throws InvalidWSDLException { + if (inputElements != null) { + return inputElements; + } + Input input = operation.getInput(); + if (input != null) { + Message inputMsg = input.getMessage(); + Collection parts = inputMsg.getParts().values(); + if (parts.size() != 1) { + return null; + } + Part part = (Part) parts.iterator().next(); + QName elementName = part.getElementName(); + if (elementName == null) { + return null; + } + if (!operation.getName().equals(elementName.getLocalPart())) { + return null; + } + inputWrapperElement = schemaRegistry.getElement(elementName); + if (inputWrapperElement == null) { + throw new InvalidWSDLException("The element is not declared in a XML schema", + elementName.toString()); + } + inputElements = getChildElements(inputWrapperElement); + return inputElements; + } else { + return null; + } + } + + /** + * Return a list of child XSD elements under the wrapped response element + * + * @return a list of child XSD elements or null if if the response element is not wrapped + */ + public List<XmlSchemaElement> getOutputChildElements() throws InvalidWSDLException { + if (outputElements != null) { + return outputElements; + } + Output output = operation.getOutput(); + if (output != null) { + Message outputMsg = output.getMessage(); + Collection parts = outputMsg.getParts().values(); + if (parts.size() != 1) { + return null; + } + Part part = (Part) parts.iterator().next(); + QName elementName = part.getElementName(); + if (elementName == null) { + throw new InvalidWSDLException("The element is not declared in the XML schema", part.getName()); + } + outputWrapperElement = schemaRegistry.getElement(elementName); + if (outputWrapperElement == null) { + return null; + } + outputElements = getChildElements(outputWrapperElement); + // FIXME: Do we support multiple child elements for the response? + return outputElements; + } else { + return null; + } + } + + /** + * @return the inputWrapperElement + */ + public XmlSchemaElement getInputWrapperElement() { + return inputWrapperElement; + } + + /** + * @return the outputWrapperElement + */ + public XmlSchemaElement getOutputWrapperElement() { + return outputWrapperElement; + } + + public DataType<List<DataType<QName>>> getUnwrappedInputType() throws InvalidWSDLException { + if (unwrappedInputType == null) { + List<DataType<QName>> childTypes = new ArrayList<DataType<QName>>(); + for (XmlSchemaElement element : getInputChildElements()) { + DataType<QName> type = new DataType<QName>(dataBinding, Object.class, element.getQName()); + type.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + childTypes.add(type); + } + unwrappedInputType = + new DataType<List<DataType<QName>>>("idl:unwrapped.input", Object[].class, childTypes); + } + return unwrappedInputType; + } + + public DataType<QName> getUnwrappedOutputType() throws InvalidServiceContractException { + if (unwrappedOutputType == null) { + List<XmlSchemaElement> elements = getOutputChildElements(); + if (elements != null && elements.size() > 0) { + if (elements.size() > 1) { + // We don't support output with multiple parts + throw new NotSupportedWSDLException("Multi-part output is not supported"); + } + XmlSchemaElement element = elements.get(0); + unwrappedOutputType = new DataType<QName>(dataBinding, Object.class, element.getQName()); + unwrappedOutputType.setMetadata(ElementInfo.class.getName(), getElementInfo(element)); + } + } + return unwrappedOutputType; + } + + public WrapperInfo getWrapperInfo() throws InvalidServiceContractException { + if (wrapperInfo == null) { + ElementInfo in = getElementInfo(getInputWrapperElement()); + ElementInfo out = getElementInfo(getOutputWrapperElement()); + List<ElementInfo> inChildren = new ArrayList<ElementInfo>(); + for (XmlSchemaElement e : getInputChildElements()) { + inChildren.add(getElementInfo(e)); + } + List<ElementInfo> outChildren = new ArrayList<ElementInfo>(); + if (out != null) { + for (XmlSchemaElement e : getOutputChildElements()) { + outChildren.add(getElementInfo(e)); + } + } + wrapperInfo = + new WrapperInfo(in, out, inChildren, outChildren, getUnwrappedInputType(), + getUnwrappedOutputType()); + } + return wrapperInfo; + } + } + + private static ElementInfo getElementInfo(XmlSchemaElement element) { + if (element == null) { + return null; + } + return new ElementInfo(element.getQName(), getTypeInfo(element.getSchemaType())); + } + + private static TypeInfo getTypeInfo(XmlSchemaType type) { + if (type == null) { + return null; + } + XmlSchemaType baseType = (XmlSchemaType) type.getBaseSchemaType(); + QName name = type.getQName(); + boolean simple = (type instanceof XmlSchemaSimpleType); + if (baseType == null) { + return new TypeInfo(name, simple, null); + } else { + return new TypeInfo(name, simple, getTypeInfo(baseType)); + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java new file mode 100644 index 0000000000..868ad0f3b4 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/WSDLServiceContract.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.model.ServiceContract; + +/** + * Represents a service contract specified by a WSDL + * + * @version $Rev$ $Date$ + */ +public class WSDLServiceContract extends ServiceContract<QName> { + private PortType portType; + private PortType callbackPortType; + + /** + * + */ + public WSDLServiceContract() { + super(); + this.remotable = true; // WSDL interface is always remotable by the SCA spec + } + + + public PortType getPortType() { + return portType; + } + + public void setPortType(PortType portType) { + this.portType = portType; + } + + public PortType getCallbackPortType() { + return callbackPortType; + } + + public void setCallbackPortType(PortType callbackPortType) { + this.callbackPortType = callbackPortType; + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java new file mode 100644 index 0000000000..681e08be4d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistry.java @@ -0,0 +1,87 @@ +/* + * 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.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * A service for caching XML Schemas + * + * @version $Rev$ $Date$ + */ +public interface XMLSchemaRegistry { + /** + * Load all inline schemas from the WSDL definition + * + * @param definition The WSDL defintion whose types element contains a list of schemas + * @return A list of inline schemas + */ + List<XmlSchema> loadSchemas(Definition definition); + + /** + * Loads and registers a XML schema. + * + * @param namespace the expected namespace, or null if any namespace should be allowed + * @param location the location to load the schema from + * @return the loaded Definition + * @throws IOException if there was a problem reading the document + * @throws XmlSchemaException if there was a problem parsing the schema + */ + XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException; + + /** + * Load and register a XML schema as specified in a XSD schemaLocation attribute. + * + * @param schemaLocation the value of the schemaLocation attribute + * @param classLoader application classloader used to support relative locations + * @return the loaded schema + * @throws IOException if there was a problem reading the document + * @throws XmlSchemaException if there was a problem parsing the schema + */ + XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException; + + /** + * Returns the XSD Element with the supplied qualified name, or null if no such element has been defined. + * + * @param name the qualified name of the XSD element + * @return the XSD element for the supplied name, or null if none has been defined + */ + XmlSchemaElement getElement(QName name); + + /** + * Returns the XmlSchemaType with the supplied qualified name, or null if no such type has been defined. + * + * @param name the qualified name of the XSD type + * @return the XSD type for the supplied name, or null if none has been defined + */ + XmlSchemaType getType(QName name); + + + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java new file mode 100644 index 0000000000..08600e4b7e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImpl.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.idl.wsdl; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Types; +import javax.wsdl.extensions.schema.Schema; +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaType; +import org.osoa.sca.annotations.Service; +import org.w3c.dom.Element; + +/** + * Default implementation of XMLSchemaRegistry + */ +@Service(XMLSchemaRegistry.class) +public class XMLSchemaRegistryImpl implements XMLSchemaRegistry { + private final XmlSchemaCollection collection; + + /** + * @param collection + */ + public XMLSchemaRegistryImpl(XmlSchemaCollection collection) { + super(); + this.collection = collection; + } + + public XMLSchemaRegistryImpl() { + super(); + this.collection = new XmlSchemaCollection(); + } + + public XmlSchemaElement getElement(QName name) { + return collection.getElementByQName(name); + } + + public XmlSchemaType getType(QName name) { + return collection.getTypeByQName(name); + } + + public List<XmlSchema> loadSchemas(Definition definition) { + Types types = definition.getTypes(); + if (types == null) { + return Collections.emptyList(); + } + List<XmlSchema> schemas = new ArrayList<XmlSchema>(); + for (Object ext : types.getExtensibilityElements()) { + if (ext instanceof Schema) { + Element element = ((Schema) ext).getElement(); + XmlSchema s = collection.read(element, element.getBaseURI()); + schemas.add(s); + } + } + return schemas; + } + + public XmlSchema loadSchema(String namespace, URL location) throws IOException, XmlSchemaException { + XmlSchema schema; + XmlSchema[] schemaList = collection.getXmlSchema(location.toExternalForm()); + if (schemaList != null && schemaList.length > 0) { + schema = schemaList[0]; + } else { + InputStream is = location.openStream(); + schema = collection.read(new InputStreamReader(is), null); + is.close(); + } + if (namespace != null && schema != null && !namespace.equals(schema.getTargetNamespace())) { + throw new XmlSchemaException(namespace + " != " + schema.getTargetNamespace()); + } + return schema; + } + + public XmlSchema loadSchema(String schemaLocation, ClassLoader classLoader) throws IOException, XmlSchemaException { + int index = schemaLocation.indexOf(' '); + if (index == -1) { + throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation); + } + String namespace = schemaLocation.substring(0, index).trim(); + URL url; + URI uri; + try { + uri = new URI(schemaLocation.substring(index + 1).trim()); + } catch (URISyntaxException e) { + throw new XmlSchemaException("Invalid schemaLocation: " + schemaLocation); + } + if (uri.isAbsolute()) { + url = uri.toURL(); + } else { + url = classLoader.getResource(uri.toString()); + if (url == null) { + throw new XmlSchemaException("Resource cannot be resolved: schemaLocation: " + schemaLocation); + } + } + return loadSchema(namespace, url); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl new file mode 100644 index 0000000000..99dd44b11e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/default.scdl @@ -0,0 +1,50 @@ +<?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.
+-->
+<!--
+ IDL WSDL extension
+
+ $Rev: 440894 $ $Date: 2006-09-06 15:52:01 -0700 (Wed, 06 Sep 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.idl.wsdl">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.idl</group>
+ <name>wsdl</name>
+ <version>0.1-pre-spec-SNAPSHOT</version>
+ </dependency>
+
+ <component name="interface.wsdl.Loader">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLLoader" />
+ </component>
+
+ <component name="wsdl.Registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl" initLevel="40" />
+ </component>
+
+ <component name="xmlSchema.registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl" initLevel="35" />
+ </component>
+
+ <component name="interface.wsdl.Introspector">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospectorImpl" initLevel="40" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl new file mode 100644 index 0000000000..be1cf749dd --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/main/resources/META-INF/sca/idl.wsdl.scdl @@ -0,0 +1,52 @@ +<?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.
+-->
+<!--
+ IDL WSDL extension
+
+ This is a copy to be included by other extensions
+
+ $Rev: 440894 $ $Date: 2006-09-06 15:52:01 -0700 (Wed, 06 Sep 2006) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.idl.wsdl.include">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.idl</group>
+ <name>wsdl</name>
+ <version>0.1-pre-spec-SNAPSHOT</version>
+ </dependency>
+
+ <component name="interface.wsdl.Loader">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLLoader" />
+ </component>
+
+ <component name="wsdl.Registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistryImpl" initLevel="40" />
+ </component>
+
+ <component name="xmlSchema.registry">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.XMLSchemaRegistryImpl" initLevel="35" />
+ </component>
+
+ <component name="interface.wsdl.Introspector">
+ <system:implementation.system class="org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospectorImpl" initLevel="40" />
+ </component>
+
+</composite>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.java new file mode 100644 index 0000000000..8f263607e0 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/InterfaceWSDLIntrospectorImplTestCase.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.idl.wsdl; + +import java.net.URL; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.InvalidServiceContractException; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; + +/** + * Test case for InterfaceWSDLIntrospectorImpl + */ +public class InterfaceWSDLIntrospectorImplTestCase extends TestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + private PortType portType; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + portType = definition.getPortType(PORTTYPE_NAME); + } + + public final void testIntrospectPortType() throws InvalidServiceContractException { + InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry); + WSDLServiceContract contract = introspector.introspect(portType); + Assert.assertEquals(contract.getInterfaceName(), "StockQuotePortType"); + Map<String, Operation<QName>> operations = contract.getOperations(); + Assert.assertEquals(1, operations.size()); + Operation<QName> operation = operations.get("getLastTradePrice"); + Assert.assertNotNull(operation); + DataType<List<DataType<QName>>> inputType = operation.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + DataType<QName> returnType = operation.getOutputType(); + Assert.assertNotNull(returnType); + Assert.assertEquals(0, operation.getFaultTypes().size()); + Assert.assertEquals(1, operation.getWrapper().getInputChildElements().size()); + Assert.assertEquals(1, operation.getWrapper().getOutputChildElements().size()); + } + + public final void testIntrospectPortTypePortType() throws InvalidServiceContractException { + InterfaceWSDLIntrospector introspector = new InterfaceWSDLIntrospectorImpl(registry); + WSDLServiceContract contract = introspector.introspect(portType, portType); + Assert.assertEquals("StockQuotePortType", contract.getInterfaceName()); + Assert.assertEquals("StockQuotePortType", contract.getCallbackName()); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java new file mode 100644 index 0000000000..a7d7457f76 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLDefinitionRegistryTestCase.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import javax.wsdl.Definition; +import javax.wsdl.WSDLException; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; +import junit.framework.Assert; + +/** + * Verifies the default WSDL registry implementation + * + * @version $Rev$ $Date$ + */ +public class WSDLDefinitionRegistryTestCase extends TestCase { + private static final String NS = "http://www.example.org"; + private static final WSDLDefinitionRegistryImpl.Monitor NULL_MONITOR = new WSDLDefinitionRegistryImpl.Monitor() { + public void readingWSDL(String namespace, URL location) { + } + + public void cachingDefinition(String namespace, URL location) { + } + }; + private WSDLDefinitionRegistryImpl wsdlRegistry; + private ClassLoader cl; + private URL exampleWsdl; + + + public void testLoadFromAbsoluteWSDLLocation() { + try { + Definition def = wsdlRegistry.loadDefinition(NS + ' ' + exampleWsdl, cl); + Assert.assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } catch (WSDLException e) { + Assert.fail(e.getMessage()); + } + } + + public void testLoadFromRelativeWSDLLocation() { + try { + Definition def = wsdlRegistry.loadDefinition(NS + " org/apache/tuscany/idl/wsdl/example.wsdl", cl); + Assert.assertNotNull(def.getPortType(new QName(NS, "HelloWorld"))); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } catch (WSDLException e) { + Assert.fail(e.getMessage()); + } + } + + protected void setUp() throws Exception { + super.setUp(); + wsdlRegistry = new WSDLDefinitionRegistryImpl(); + wsdlRegistry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + wsdlRegistry.setMonitor(NULL_MONITOR); + exampleWsdl = getClass().getResource("example.wsdl"); + cl = getClass().getClassLoader(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java new file mode 100644 index 0000000000..c05cf9770f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLLoaderImplTestCase.java @@ -0,0 +1,53 @@ +/* + * 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.idl.wsdl; + +import java.net.URI; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class WSDLLoaderImplTestCase extends TestCase { + private WSDLLoaderImpl loader; + private URI exampleURI; + private QName exampleName; + + public void testGetNamespace() throws UnresolveableResourceException { + assertEquals("http://example.org/TicketAgent.wsdl20", loader.getNamespace(exampleURI)); + } + + public void testGetInterfaceNameFromFragment() throws UnresolveableResourceException, InvalidFragmentException { + assertEquals("TicketAgent", loader.getInterfaceName("wsdl.interface(TicketAgent)")); + } + + public void testGetInterfaceNameFromURI() throws UnresolveableResourceException, InvalidFragmentException { + assertEquals(exampleName, loader.getInterfaceName(exampleURI)); + } + + protected void setUp() throws Exception { + super.setUp(); + loader = new WSDLLoaderImpl(); + exampleURI = URI.create("http://example.org/TicketAgent.wsdl20#wsdl.interface(TicketAgent)"); + exampleName = new QName("http://example.org/TicketAgent.wsdl20", "TicketAgent"); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java new file mode 100644 index 0000000000..cdb4c529ef --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WSDLOperationTestCase.java @@ -0,0 +1,119 @@ +/* + * 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.idl.wsdl; + +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.ElementInfo; +import org.apache.tuscany.spi.model.DataType; + +/** + * Test case for WSDLOperation + */ +public class WSDLOperationTestCase extends TestCase { + private static final QName PORTTYPE_NAME = + new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + } + + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + + DataType<List<DataType<QName>>> inputType = op.getInputType(); + Assert.assertEquals(1, inputType.getLogical().size()); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePrice"), inputType + .getLogical().get(0).getLogical()); + + DataType<QName> outputType = op.getOutputType(); + Assert.assertEquals(new QName("http://example.com/stockquote.xsd", "getLastTradePriceResponse"), + outputType.getLogical()); + Assert.assertTrue(op.isWrapperStyle()); + + DataType<List<DataType<QName>>> unwrappedInputType = op.getWrapper().getUnwrappedInputType(); + List<DataType<QName>> childTypes = unwrappedInputType.getLogical(); + Assert.assertEquals(1, childTypes.size()); + DataType<QName> childType = childTypes.get(0); + Assert.assertEquals(new QName(null, "tickerSymbol"), childType.getLogical()); + ElementInfo element = (ElementInfo)childType.getMetadata(ElementInfo.class.getName()); + Assert.assertNotNull(element); + + childType = op.getWrapper().getUnwrappedOutputType(); + Assert.assertEquals(new QName(null, "price"), childType.getLogical()); + element = (ElementInfo)childType.getMetadata(ElementInfo.class.getName()); + Assert.assertNotNull(element); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("unwrapped-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(1, op.getInputType().getLogical().size()); + + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + Assert.assertEquals(2, op.getInputType().getLogical().size()); + } + + public final void testInvalidWSDL() throws Exception { + URL url = getClass().getResource("invalid-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + + try { + op.isWrapperStyle(); + fail("InvalidWSDLException should have been thrown"); + } catch (InvalidWSDLException e) { + // Expected + } + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.java new file mode 100644 index 0000000000..748c790297 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/WrapperStyleOperationTestCase.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.idl.wsdl; + +import java.net.URL; + +import javax.wsdl.Definition; +import javax.wsdl.Operation; +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Test case for WSDLOperation + */ +public class WrapperStyleOperationTestCase extends TestCase { + private static final QName PORTTYPE_NAME = new QName("http://example.com/stockquote.wsdl", "StockQuotePortType"); + + private WSDLDefinitionRegistryImpl registry; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + registry = new WSDLDefinitionRegistryImpl(); + registry.setSchemaRegistry(new XMLSchemaRegistryImpl()); + } + + public final void testWrappedOperation() throws Exception { + URL url = getClass().getResource("stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertTrue(op.isWrapperStyle()); + Assert.assertEquals(1, op.getWrapper().getInputChildElements().size()); + Assert.assertEquals(1, op.getWrapper().getOutputChildElements().size()); + } + + public final void testUnwrappedOperation() throws Exception { + URL url = getClass().getResource("unwrapped-stockquote.wsdl"); + Definition definition = registry.loadDefinition(null, url); + PortType portType = definition.getPortType(PORTTYPE_NAME); + Operation operation = portType.getOperation("getLastTradePrice1", null, null); + WSDLOperation op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + operation = portType.getOperation("getLastTradePrice2", null, null); + op = new WSDLOperation(operation, "org.w3c.dom.Node", registry.getSchemaRegistry()); + Assert.assertFalse(op.isWrapperStyle()); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java new file mode 100644 index 0000000000..60433d3bc1 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/java/org/apache/tuscany/idl/wsdl/XMLSchemaRegistryImplTestCase.java @@ -0,0 +1,105 @@ +/* + * 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.idl.wsdl; + +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaComplexType; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.apache.ws.commons.schema.XmlSchemaException; +import org.apache.ws.commons.schema.XmlSchemaObjectCollection; +import org.apache.ws.commons.schema.XmlSchemaSequence; +import org.apache.ws.commons.schema.XmlSchemaType; + +/** + * Verifies the default XSD registry implementation + * + * @version $Rev$ $Date$ + */ +public class XMLSchemaRegistryImplTestCase extends TestCase { + private static final QName PO_ELEMENT_NAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private static final QName PO_TYPE_NAME = new QName("http://www.example.com/IPO", "PurchaseOrderType"); + + private static final String NS = "http://example.com/stockquote.xsd"; + private static final QName GET_LAST_TRADE_PRICE_ELEMENT_NAME = new QName(NS, "getLastTradePrice"); + + private XMLSchemaRegistryImpl xsdRegistry; + + private WSDLDefinitionRegistryImpl wsdlRegistry; + + private ClassLoader cl; + + private URL wsdl; + + public void testLoadFromAbsoluteWSDLLocation() { + try { + Definition definition = wsdlRegistry.loadDefinition(null, wsdl); + List<XmlSchema> schemas = xsdRegistry.loadSchemas(definition); + Assert.assertTrue(schemas.size() == 1); + XmlSchema schema = schemas.get(0); + XmlSchemaElement element = schema.getElementByName(GET_LAST_TRADE_PRICE_ELEMENT_NAME); + Assert.assertNotNull(element); + XmlSchemaType type = element.getSchemaType(); + XmlSchemaComplexType complexType = (XmlSchemaComplexType) type; + XmlSchemaSequence sequence = (XmlSchemaSequence) complexType.getParticle(); + XmlSchemaObjectCollection items = sequence.getItems(); + Assert.assertTrue(items.getItem(0) instanceof XmlSchemaElement); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + public void testSchemaLocation() throws IOException { + String schemaLocation = "http://www.example.com/IPO org/apache/tuscany/idl/wsdl/ipo.xsd"; + XmlSchema schema = xsdRegistry.loadSchema(schemaLocation, cl); + Assert.assertNotNull(schema); + Assert.assertNotNull(schema.getElementByName(PO_ELEMENT_NAME)); + Assert.assertNotNull(xsdRegistry.getElement(PO_ELEMENT_NAME)); + Assert.assertNotNull(schema.getTypeByName(PO_TYPE_NAME)); + Assert.assertNotNull(xsdRegistry.getType(PO_TYPE_NAME)); + + + schemaLocation = "http://www.example.com/IPO1 org/apache/tuscany/idl/wsdl/ipo.xsd"; + try { + schema = xsdRegistry.loadSchema(schemaLocation, cl); + Assert.fail(""); + } catch (XmlSchemaException e) { + Assert.assertTrue(e.getMessage().contains("http://www.example.com/IPO1 !=")); + } + } + + protected void setUp() throws Exception { + super.setUp(); + xsdRegistry = new XMLSchemaRegistryImpl(); + wsdlRegistry = new WSDLDefinitionRegistryImpl(); + wsdlRegistry.setSchemaRegistry(xsdRegistry); + wsdl = getClass().getResource("stockquote.wsdl"); + cl = getClass().getClassLoader(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl new file mode 100644 index 0000000000..5e8e5dad0d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/example.wsdl @@ -0,0 +1,26 @@ +<?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. +--> +<wsdl:definitions targetNamespace="http://www.example.org" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + name="example"> + + <wsdl:portType name="HelloWorld"> + </wsdl:portType> +</wsdl:definitions> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl new file mode 100644 index 0000000000..38f9cb05d2 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/invalid-stockquote.wsdl @@ -0,0 +1,40 @@ +<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
+ xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
+ <element name="getLastTradePrice1">
+ <complexType>
+ <sequence>
+ <element name="tickerSymbol" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getLastTradePriceResponse">
+ <complexType>
+ <sequence>
+ <element name="price" type="float" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="GetLastTradePriceInput">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <portType name="StockQuotePortType">
+ <operation name="getLastTradePrice">
+ <input message="tns:GetLastTradePriceInput" />
+ <output message="tns:GetLastTradePriceOutput" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd new file mode 100644 index 0000000000..5468542693 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/ipo.xsd @@ -0,0 +1,118 @@ +<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-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl new file mode 100644 index 0000000000..7be1c896a3 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/stockquote.wsdl @@ -0,0 +1,40 @@ +<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
+ xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
+ <element name="getLastTradePrice">
+ <complexType>
+ <sequence>
+ <element name="tickerSymbol" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getLastTradePriceResponse">
+ <complexType>
+ <sequence>
+ <element name="price" type="float" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="GetLastTradePriceInput">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <portType name="StockQuotePortType">
+ <operation name="getLastTradePrice">
+ <input message="tns:GetLastTradePriceInput" />
+ <output message="tns:GetLastTradePriceOutput" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl new file mode 100644 index 0000000000..2fade0036c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/idl/wsdl/src/test/resources/org/apache/tuscany/idl/wsdl/unwrapped-stockquote.wsdl @@ -0,0 +1,58 @@ +<?xml version="1.0"?>
+<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
+ xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/2001/XMLSchema">
+ <element name="getLastTradePrice">
+ <complexType>
+ <sequence>
+ <element name="tickerSymbol" type="string" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getLastTradePriceResponse">
+ <complexType>
+ <sequence>
+ <element name="price" type="float" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+
+ <message name="GetLastTradePriceInput1">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ </message>
+
+ <message name="GetLastTradePriceOutput1">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <message name="GetLastTradePriceInput2">
+ <part name="body" element="xsd1:getLastTradePrice" />
+ <part name="other" type="xsd:string"/>
+ </message>
+
+ <message name="GetLastTradePriceOutput2">
+ <part name="body" element="xsd1:getLastTradePriceResponse" />
+ </message>
+
+ <portType name="StockQuotePortType">
+ <operation name="getLastTradePrice">
+ <input message="tns:GetLastTradePriceInput1" />
+ <output message="tns:GetLastTradePriceOutput1" />
+ </operation>
+ <operation name="getLastTradePrice1">
+ <input message="tns:GetLastTradePriceInput1" />
+ <output message="tns:GetLastTradePriceOutput1" />
+ </operation>
+ <operation name="getLastTradePrice2">
+ <input message="tns:GetLastTradePriceInput2" />
+ <output message="tns:GetLastTradePriceOutput2" />
+ </operation>
+ </portType>
+
+</definitions>
\ No newline at end of file diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/LICENSE.txt new file mode 100644 index 0000000000..0084319535 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/LICENSE.txt @@ -0,0 +1,202 @@ + + 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, serviceDefinition marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/pom.xml new file mode 100644 index 0000000000..ef6a4313b3 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + + <parent> + <groupId>org.apache.tuscany.sca.services.management</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>management-jmx</artifactId> + <packaging>jar</packaging> + <name>Apache Tuscany JMX Management</name> + <description>Apache Tuscany JMX Management</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java new file mode 100644 index 0000000000..5b50affdf2 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxException.java @@ -0,0 +1,39 @@ +/* + * 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.service.management.jmx; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Maps JMX exceptions to runtime exceptions. + * + * @version $Revision$ $Date$ + */ +@SuppressWarnings("serial") +public class JmxException extends TuscanyRuntimeException { + + /** + * Initializes the root cause. + * @param cause Initializes the root cause. + */ + public JmxException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java new file mode 100644 index 0000000000..2905a50c54 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/JmxManagementService.java @@ -0,0 +1,74 @@ +/* + * 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.service.management.jmx; + +import javax.management.JMException; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.tuscany.service.management.jmx.instrument.InstrumentedComponent; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.services.management.TuscanyManagementService; + +/** + * JMX implementation of the management service. + * + * @version $Revision$ $Date$ + */ +public class JmxManagementService implements TuscanyManagementService { + + /** + * MBean server used by the JMX management service. + */ + private final MBeanServer mBeanServer; + + /** + * Management domain used by the runtime. + */ + private final String managementDomain; + + + /** + * Constructor that initializes the MBeanServer and domain to use for registering components. + * + * @param mBeanServer the MBeanServer components should be registered with + * @param managementDomain the JMX domain to use when generating ObjectNames + */ + public JmxManagementService(MBeanServer mBeanServer, String managementDomain) { + this.mBeanServer = mBeanServer; + this.managementDomain = managementDomain; + } + + /** + * @throws JmxException In case of an unexpected JMX exception. + * @see org.apache.tuscany.spi.services.management.TuscanyManagementService#registerComponent( + *java.lang.String,org.apache.tuscany.spi.component.Component) + */ + public final void registerComponent(String name, Component component) throws JmxException { + + try { + ObjectName on = new ObjectName(managementDomain + ":" + "type=component,name=" + name); + InstrumentedComponent mbean = new InstrumentedComponent(component); + mBeanServer.registerMBean(mbean, on); + } catch (JMException ex) { + throw new JmxException(ex); + } + + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java new file mode 100644 index 0000000000..0172b15d8c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/AbstractAgent.java @@ -0,0 +1,154 @@ +/* + * 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.service.management.jmx.agent; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.management.MBeanServer; +import javax.management.MBeanServerFactory; +import javax.management.ObjectName; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXServiceURL; + +/** + * Abstract super class for all the agents. + * @version $Revison$ $Date$ + * + */ +public abstract class AbstractAgent implements Agent { + + /** Root domain */ + private static final String DOMAIN = "tuscany"; + + /** MBean server to use. */ + private MBeanServer mBeanServer; + + /** Start flag. */ + private AtomicBoolean started = new AtomicBoolean(); + + /** RMI connector adaptor. */ + private JMXConnectorServer connectorServer; + + /** + * Initialies the server. + * @throws ManagementException If unable to start the agent. + */ + protected AbstractAgent() throws ManagementException { + mBeanServer = MBeanServerFactory.createMBeanServer(DOMAIN); + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.Agent#getMBeanServer() + */ + public MBeanServer getMBeanServer() { + return mBeanServer; + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.Agent#register(java.lang.Object, java.lang.String) + */ + public final void register(Object instance, String name) throws ManagementException { + + try { + mBeanServer.registerMBean(instance, new ObjectName(name)); + } catch (Exception ex) { + throw new ManagementException(ex); + } + + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.Agent#start() + */ + public final void start() throws ManagementException { + + try { + + if(started.get()) { + throw new IllegalArgumentException("Agent already started"); + } + + preStart(); + + JMXServiceURL url = getAdaptorUrl(); + connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer); + + connectorServer.start(); + + started.set(true); + + } catch (MalformedURLException ex) { + throw new ManagementException(ex); + } catch (IOException ex) { + throw new ManagementException(ex); + } + + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.Agent#shutdown() + */ + public final void shutdown() throws ManagementException { + + try { + + if(!started.get()) { + throw new IllegalArgumentException("Agent not started"); + } + + connectorServer.stop(); + postStop(); + started.set(false); + + } catch (IOException ex) { + throw new ManagementException(ex); + } + + } + + /** + * Gets the underlying MBean server. + * @return A reference to the mbean server. + */ + protected MBeanServer getMbeanServer() { + return mBeanServer; + } + + /** + * Gets the adaptor URL. + * @return Adaptor URL. + */ + protected abstract JMXServiceURL getAdaptorUrl(); + + /** + * Any initialiation required for protocol specific agent. + * + */ + protected abstract void preStart(); + + /** + * Any initialiation required for protocol specific agent. + * + */ + protected abstract void postStop(); + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java new file mode 100644 index 0000000000..30727e21bf --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/Agent.java @@ -0,0 +1,56 @@ +/* + * 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.service.management.jmx.agent; + +import javax.management.MBeanServer; + +/** + * Interface to a JMX agent. + * @version $Revision$ $Date$ + * + */ +public interface Agent { + + /** + * Registers a managed bean. + * @param instance Instance to be registered. + * @param name Object name of the instance. + * @throws ManagementException If unable to register the object. + */ + void register(Object instance, String name) throws ManagementException; + + /** + * Starts the JMX server. + * @throws ManagementException If unable to start the server. + */ + void start() throws ManagementException; + + /** + * Shuts down the JMX server. + * @throws ManagementException If unable to shutdown the server. + */ + void shutdown() throws ManagementException; + + /** + * Gets the MBean server used by the agent. + * @return MBean server used by the agent. + */ + MBeanServer getMBeanServer(); + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java new file mode 100644 index 0000000000..6ff8c14ac6 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/ManagementException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.service.management.jmx.agent; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * @version $Revision$ $Date$ + * + */ +@SuppressWarnings("serial") +public class ManagementException extends TuscanyRuntimeException { + + /** + * Initializes the root cause. + * @param th Root cause. + */ + public ManagementException(Throwable th) { + super(th); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java new file mode 100644 index 0000000000..593f6fec90 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/agent/RmiAgent.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.service.management.jmx.agent; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; + +import javax.management.remote.JMXServiceURL; + +/** + * Utility for starting the JMX server with an RMI agent. + * + * @version $Revsion$ $Date$ + * + */ +public class RmiAgent extends AbstractAgent { + + /** Administration port system property. */ + private static final String ADMIN_PORT_PROPERTY = "tuscany.adminPort"; + + /** Default admin port. */ + private static final int DEFAULT_ADMIN_PORT = 1099; + + /** Instance */ + private static final Agent INSTANCE = new RmiAgent(); + + /** RMI registry. */ + private Registry registry; + + /** Listen port */ + private int port = DEFAULT_ADMIN_PORT; + + /** + * Gets the adaptor URL. + * @return Adaptor URL used by the agent. + * @throws ManagementException If unable to start the agent. + */ + protected JMXServiceURL getAdaptorUrl() throws ManagementException { + + try { + + String portValue = System.getProperty(ADMIN_PORT_PROPERTY); + if(portValue != null) { + port = Integer.parseInt(portValue); + } + + // service:jmx:rmi:///jndi/rmi://localhost:1099/server + return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/server"); + + + } catch (MalformedURLException ex) { + throw new ManagementException(ex); + } + + } + + /** + * Returns the singleton agent instance. + * @return Agent instance. + * @throws ManagementException If unable to start the agent. + */ + public static Agent getInstance() throws ManagementException { + return INSTANCE; + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.AbstractAgent#preStart() + */ + @Override + public void preStart() throws ManagementException { + + try { + registry = LocateRegistry.createRegistry(port); + } catch (RemoteException ex) { + throw new ManagementException(ex); + } + + } + + /** + * @see org.apache.tuscany.service.management.jmx.agent.AbstractAgent#postStop() + */ + @Override + public void postStop() throws ManagementException { + + try { + UnicastRemoteObject.unexportObject(registry, true); + } catch (IOException ex) { + throw new ManagementException(ex); + } + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.java new file mode 100644 index 0000000000..3d16ff6a2a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/AnnotationDrivenDynamicMBean.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.service.management.jmx.instrument; + +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; +import javax.management.InvalidAttributeValueException; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.ReflectionException; + +/** + * Dynamic MBean based on management annotations. + * + * @version $Revision$ $Date$ + */ +public class AnnotationDrivenDynamicMBean implements DynamicMBean { + + /** + * @see javax.management.DynamicMBean#getAttribute(java.lang.String) + */ + public Object getAttribute(String attribute) + throws AttributeNotFoundException, MBeanException, ReflectionException { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.management.DynamicMBean#getAttributes(java.lang.String[]) + */ + public AttributeList getAttributes(String[] attributes) { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.management.DynamicMBean#getMBeanInfo() + */ + public MBeanInfo getMBeanInfo() { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[]) + */ + public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, + ReflectionException { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute) + */ + public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, + MBeanException, ReflectionException { + throw new UnsupportedOperationException(); + } + + /** + * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList) + */ + public AttributeList setAttributes(AttributeList attributes) { + throw new UnsupportedOperationException(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java new file mode 100644 index 0000000000..a8ad1666d5 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentationException.java @@ -0,0 +1,48 @@ +/* + * 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.service.management.jmx.instrument; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Excpetion thrown when there is an instrumentation error. + * + * @version $Revison$ $Date$ + * + */ +@SuppressWarnings("serial") +public class InstrumentationException extends TuscanyRuntimeException { + + /** + * Initializes the root cause. + * @param cause Initializes the root cause. + */ + public InstrumentationException(Throwable cause) { + super(cause); + } + + /** + * Initializes the message. + * @param message Initializes the message. + */ + public InstrumentationException(String message) { + super(message); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java new file mode 100644 index 0000000000..1ef33c8bc9 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/InstrumentedComponent.java @@ -0,0 +1,134 @@ +/* + * 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.service.management.jmx.instrument; + +import java.util.Map; +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanConstructorInfo; +import javax.management.MBeanInfo; +import javax.management.MBeanNotificationInfo; +import javax.management.MBeanOperationInfo; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.model.PropertyValue; + +/** + * This is Ruscany component exposed as a dynamic MBean. Currently it only supports a read-only vew of all the + * properties on the component. + * + * @version $Revision$ $Date$ + */ +public class InstrumentedComponent implements DynamicMBean { + + /** + * Properties available on the component. + */ + private final Map<String, PropertyValue<?>> properties; + + /** + * Name of the component. + */ + private String componentName; + + /** + * Initializes the property values. + * + * @param component Component that is being managed. + */ + @SuppressWarnings("unchecked") + public InstrumentedComponent(final Component component) { + this.properties = component.getDefaultPropertyValues(); + this.componentName = component.getName(); + } + + /** + * @see javax.management.DynamicMBean#getAttribute(java.lang.String) + */ + public final Object getAttribute(final String attribute) throws AttributeNotFoundException { + PropertyValue<?> propertyValue = properties.get(attribute); + if (propertyValue != null) { + return propertyValue.getValueFactory().getInstance(); + } + throw new AttributeNotFoundException(attribute + " not found."); + } + + /** + * @see javax.management.DynamicMBean#getAttributes(java.lang.String[]) + */ + public final AttributeList getAttributes(final String[] attributes) { + + AttributeList list = new AttributeList(); + for (String attribute : attributes) { + try { + list.add(new Attribute(attribute, getAttribute(attribute))); + } catch (AttributeNotFoundException ex) { + throw new InstrumentationException(ex); + } + } + return list; + + } + + /** + * @see javax.management.DynamicMBean#getMBeanInfo() + */ + public final MBeanInfo getMBeanInfo() { + + final MBeanConstructorInfo[] constructors = null; + final MBeanOperationInfo[] operations = null; + final MBeanNotificationInfo[] notifications = null; + + final MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[properties.size()]; + + int i = 0; + for (PropertyValue<?> propertyValue : properties.values()) { + attributes[i++] = + new MBeanAttributeInfo(propertyValue.getName(), String.class.getName(), null, true, false, false); + } + + return new MBeanInfo(componentName, null, attributes, constructors, operations, notifications); + + } + + /** + * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[]) + */ + public final Object invoke(final String actionName, final Object[] params, final String[] signature) { + throw new UnsupportedOperationException("Managed ops not supported"); + } + + /** + * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute) + */ + public final void setAttribute(final Attribute attribute) { + throw new UnsupportedOperationException("Mutable props not supported"); + } + + /** + * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList) + */ + public final AttributeList setAttributes(final AttributeList attributes) { + throw new UnsupportedOperationException("Mutable props not supported"); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java new file mode 100644 index 0000000000..b07787208c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/jmx/src/main/java/org/apache/tuscany/service/management/jmx/instrument/ReflectedDynamicMBean.java @@ -0,0 +1,353 @@ +/* + * 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.service.management.jmx.instrument; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.MethodDescriptor; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.AttributeNotFoundException; +import javax.management.DynamicMBean; +import javax.management.InvalidAttributeValueException; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanOperationInfo; +import javax.management.ReflectionException; + +/** + * Uses JMX dynamic MBean to expose management information of a delegate instance using reflection. Currently + * constructor and notification metadata are not supported. Any attribute or operation that needs to be excluded from + * the management information can be specified optionally in the factory method. + * <p/> + * All the methods and properties on <code>java.lang.Object</code> are excluded by default. Also only public and + * non-static members are made available for management. + * <p/> + * TODO Find a homw other than server.start for this class. TODO Tidy up, unit tests + * + * @version $Revsion$ $Date$ + */ +public class ReflectedDynamicMBean implements DynamicMBean { + + /** + * Excluded methods. + */ + private static final List<String> DEFAULT_EXCLUDED_METHODS = + Arrays.asList(new String[]{"wait", "toString", "hashCode", "notify", "equals", "notifyAll", "getClass"}); + + /** + * Excluded properties. + */ + private static final List<String> DEFAULT_EXCLUDED_PROPERTIES = Arrays.asList(new String[]{"class"}); + + /** + * Proxied object that is managed. + */ + private Object delegate; + + /** + * Runtime type of the managed object. + */ + private Class delegateClass; + + /** + * Delegate class name. + */ + private String delegateClassName; + + /** + * Cache of property write methods. + */ + private Map<String, Method> propertyWriteMethods = new HashMap<String, Method>(); + + /** + * Cache of property read methods. + */ + private Map<String, Method> propertyReadMethods = new HashMap<String, Method>(); + + /** + * Managed operation cache. + */ + private Map<String, Method> methods = new HashMap<String, Method>(); + + /** + * Property descriptor cache. + */ + private Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>(); + + /** + * Excluded methods. + */ + private final List<String> excludedMethods = new ArrayList<String>(); + + /** + * Excluded properties. + */ + private final List<String> excludedProperties = new ArrayList<String>(); + + /** + * Introspects the bean and populate meta information. + * + * @param delegate Proxied managed instance. + */ + private ReflectedDynamicMBean(Object delegate) { + this(delegate, new ArrayList<String>(), new ArrayList<String>()); + } + + /** + * Introspects the bean and populate meta information. + * + * @param delegate Proxied managed instance. + * @param excludedMethods Operations excluded from managed view. + * @param excludedProperties Properties excluded from managed view. + */ + private ReflectedDynamicMBean(Object delegate, List<String> excludedMethods, List<String> excludedProperties) { + + this.delegate = delegate; + this.delegateClass = delegate.getClass(); + this.delegateClassName = delegateClass.getName(); + + this.excludedMethods.addAll(excludedMethods); + this.excludedMethods.addAll(DEFAULT_EXCLUDED_METHODS); + this.excludedProperties.addAll(excludedProperties); + this.excludedProperties.addAll(DEFAULT_EXCLUDED_PROPERTIES); + + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(delegateClass); + } catch (IntrospectionException ex) { + throw new InstrumentationException(ex); + } + + cacheProperties(beanInfo); + + cacheMethods(beanInfo); + } + + /** + * Factory method for creating the management view. + * + * @param delegate Proxied managed instance. + * @param excludedMethods Operations excluded from managed view. + * @param excludedProperties Properties excluded from managed view. + * @return Proxy for the managed instance. + */ + public static ReflectedDynamicMBean newInstance(Object delegate, List<String> excludedMethods, + List<String> excludedProperties) { + return new ReflectedDynamicMBean(delegate, excludedMethods, excludedProperties); + } + + /** + * Factory method for creating the management view. + * + * @param delegate Proxied managed instance. + * @return Proxy for the managed instance. + */ + public static ReflectedDynamicMBean newInstance(Object delegate) { + return new ReflectedDynamicMBean(delegate); + } + + /** + * @see javax.management.DynamicMBean#getAttribute(java.lang.String) + */ + public Object getAttribute(String attribute) + throws AttributeNotFoundException, MBeanException, ReflectionException { + + Method readMethod = propertyReadMethods.get(attribute); + if (readMethod == null) { + throw new AttributeNotFoundException(attribute + " not found"); + } + try { + return readMethod.invoke(delegate); + } catch (IllegalAccessException ex) { + throw new ReflectionException(ex); + } catch (InvocationTargetException ex) { + throw new ReflectionException(ex); + } + + } + + /** + * @see javax.management.DynamicMBean#getAttributes(java.lang.String[]) + */ + public AttributeList getAttributes(String[] attributes) { + + AttributeList list = new AttributeList(); + for (String attribute : attributes) { + try { + list.add(new Attribute(attribute, getAttribute(attribute))); + } catch (AttributeNotFoundException ex) { + throw new InstrumentationException(ex); + } catch (MBeanException ex) { + throw new InstrumentationException(ex); + } catch (ReflectionException ex) { + throw new InstrumentationException(ex); + } + } + return list; + + } + + /** + * @see javax.management.DynamicMBean#getMBeanInfo() + */ + public MBeanInfo getMBeanInfo() { + + try { + + MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[properties.keySet().size()]; + int count = 0; + for (String property : properties.keySet()) { + Method readMethod = propertyReadMethods.get(property); + Method writeMethod = propertyWriteMethods.get(property); + attrs[count++] = new MBeanAttributeInfo(property, "", readMethod, writeMethod); + } + + MBeanOperationInfo[] ops = new MBeanOperationInfo[methods.keySet().size()]; + count = 0; + for (Method method : methods.values()) { + ops[count++] = new MBeanOperationInfo("", method); + } + + MBeanInfo mBeanInfo = new MBeanInfo(delegateClassName, "", attrs, null, ops, null); + return mBeanInfo; + + } catch (javax.management.IntrospectionException ex) { + throw new InstrumentationException(ex); + } + + } + + /** + * @see javax.management.DynamicMBean#invoke(java.lang.String,java.lang.Object[],java.lang.String[]) + */ + public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, + ReflectionException { + + Method method = methods.get(actionName); + if (method == null) { + throw new InstrumentationException("Operation not found: " + actionName); + } + try { + return method.invoke(delegate, params); + } catch (IllegalAccessException ex) { + throw new ReflectionException(ex); + } catch (InvocationTargetException ex) { + throw new ReflectionException(ex); + } + + } + + /** + * @see javax.management.DynamicMBean#setAttribute(javax.management.Attribute) + */ + public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, + MBeanException, ReflectionException { + + Method writeMethod = propertyWriteMethods.get(attribute.getName()); + if (writeMethod == null) { + throw new AttributeNotFoundException(attribute + " not found"); + } + try { + writeMethod.invoke(delegate, attribute.getValue()); + } catch (IllegalAccessException ex) { + throw new ReflectionException(ex); + } catch (InvocationTargetException ex) { + throw new ReflectionException(ex); + } + + } + + /** + * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList) + */ + public AttributeList setAttributes(AttributeList attributes) { + throw new UnsupportedOperationException(); + } + + /** + * Caches managed operations. + * + * @param beanInfo Bean info for the managed instance. + */ + private void cacheMethods(BeanInfo beanInfo) { + + for (MethodDescriptor methodDescriptor : beanInfo.getMethodDescriptors()) { + + Method method = methodDescriptor.getMethod(); + String name = method.getName(); + + if (excludedMethods.contains(name)) { + continue; + } + int modifiers = method.getModifiers(); + if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) { + continue; + } + if (propertyReadMethods.values().contains(method) || propertyWriteMethods.values().contains(method)) { + continue; + } + + // TODO Add support for overloaded methods + methods.put(name, method); + + } + + } + + /** + * Caches managed properties. + * + * @param beanInfo Bean info for the managed instance. + */ + private void cacheProperties(BeanInfo beanInfo) { + for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { + + String name = propertyDescriptor.getName(); + + if (excludedProperties.contains(name)) { + continue; + } + properties.put(name, propertyDescriptor); + + Method readMethod = propertyDescriptor.getReadMethod(); + if (readMethod != null && Modifier.isPublic(readMethod.getModifiers())) { + propertyReadMethods.put(name, readMethod); + } + + Method writeMethod = propertyDescriptor.getWriteMethod(); + if (writeMethod != null && Modifier.isPublic(writeMethod.getModifiers())) { + propertyWriteMethods.put(name, writeMethod); + } + + } + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/management/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/management/pom.xml new file mode 100644 index 0000000000..d652189c7e --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/management/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.services.management</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <name>Tuscany SCA Management Services</name> + + <modules> + <module>jmx</module> + </modules> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/maven/LICENSE.txt new file mode 100644 index 0000000000..75b52484ea --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/LICENSE.txt @@ -0,0 +1,202 @@ +
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/maven/NOTICE.txt new file mode 100644 index 0000000000..ecc68a9614 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/maven/pom.xml new file mode 100644 index 0000000000..eafc73e392 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/pom.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.services</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>maven</artifactId> + <name>Apache Tuscany Maven Service</name> + <description>Tuscany Maven Service</description> + + <dependencies> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-spi</artifactId> + <version>${sca.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>tuscany-api</artifactId> + <version>${pom.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-embedder</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + </dependency> + </dependencies> + +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java new file mode 100644 index 0000000000..394ccae97c --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java @@ -0,0 +1,101 @@ +/* + * 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.services.maven; + +import java.util.Collection; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Property; + +import org.apache.tuscany.spi.annotation.Autowire; +import org.apache.tuscany.spi.services.artifact.Artifact; +import org.apache.tuscany.spi.services.artifact.ArtifactRepository; + +import org.apache.tuscany.host.RuntimeInfo; + +/** + * Artifact repository used for resolving artifacts. + * <p/> + * This is used by the composite loader for resolving artifacts transitively. The repository uses the Maven API for + * resolving dependencies and hence expects the artifacts to be stored in a structure similar to the Maven repository + * layout. The repository first looks within the deployed unit (WAR for example), before resorting to a local and set of + * remote Maven repositories. + * + * @version $Rev$ $Date$ + */ +public class MavenArtifactRepository implements ArtifactRepository { + + /** + * Maven helper + */ + private MavenHelper mavenHelper; + + /** + * WAR repository helper + */ + private WarRepositoryHelper warRepositoryHelper; + + /** + * Conctructs a new artifact repository. + */ + public MavenArtifactRepository(@Property(name = "remoteRepoUrl") + String remoteRepoUrl, @Autowire + RuntimeInfo runtimeInfo) { + mavenHelper = new MavenHelper(remoteRepoUrl, runtimeInfo.isOnline()); + warRepositoryHelper = new WarRepositoryHelper(runtimeInfo.getBaseURL()); + mavenHelper.start(); + } + + /** + * Resolve an artifact. This ensures that the information associated with an artifact is fully populated; + * Specifically, after this operation the URL should contain a location where the artifact can be obtained. + * + * @param rootArtifact the artifact to be resolved + */ + public void resolve(Artifact rootArtifact) { + if (warRepositoryHelper.resolveTransitively(rootArtifact)) { + return; + } + if (mavenHelper.resolveTransitively(rootArtifact)) { + return; + } + throw new TuscanyDependencyException("Unable to resolve artifact", rootArtifact.toString()); + } + + /** + * Resolve a collection of Artifacts. + * + * @param artifacts a collection of artifacts to be resolved + * @see #resolve(Artifact) + */ + public void resolve(Collection<? extends Artifact> artifacts) { + for (Artifact artifact : artifacts) { + resolve(artifact); + } + } + + /** + * Destroy method. + */ + @Destroy + public void destroy() { + mavenHelper.stop(); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java new file mode 100644 index 0000000000..f82756afbd --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java @@ -0,0 +1,296 @@ +/* + * 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.services.maven; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.settings.MavenSettingsBuilder; +import org.apache.maven.settings.Settings; +import org.apache.tuscany.spi.services.artifact.Artifact; +import org.codehaus.classworlds.ClassWorld; +import org.codehaus.classworlds.DefaultClassRealm; +import org.codehaus.classworlds.DuplicateRealmException; +import org.codehaus.plexus.PlexusContainerException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.embed.Embedder; + +/** + * Utility class for embedding Maven. + * + * @version $Rev$ $Date$ + */ +public class MavenHelper { + + /** Local repository */ +// private static final File LOCAL_REPO = new File(System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository"); + + /** Remote repository URLs */ + private final String[] remoteRepositoryUrls; + + /** Maven metadata source */ + private ArtifactMetadataSource metadataSource; + + /** Artifact factory */ + private ArtifactFactory artifactFactory; + + /** Local artifact repository */ + private ArtifactRepository localRepository; + + /** Remote artifact repositories */ + private List<ArtifactRepository> remoteRepositories = new LinkedList<ArtifactRepository>(); + + /** Artifact resolver */ + private ArtifactResolver artifactResolver; + + /** Online */ + private boolean online; + + /** + * Initialize the remote repository URLs. + * + * @param remoteRepositoryUrls + * Remote repository URLS. + * @param runtimeInfo + * Runtime information. + */ + public MavenHelper(String remoteRepositoryUrl, boolean online) { + this.remoteRepositoryUrls = remoteRepositoryUrl.split(","); + this.online = online; + } + + /** + * Starts the embedder. + * + * @throws TuscanyDependencyException + * If unable to start the embedder. + */ + public void start() throws TuscanyDependencyException { + + try { + + Embedder embedder = new Embedder(); + ClassWorld classWorld = new ClassWorld(); + + classWorld.newRealm("plexus.core", getClass().getClassLoader()); + + // Evil hack for Tomcat classloader issue - starts + Field realmsField = ClassWorld.class.getDeclaredField("realms"); + realmsField.setAccessible(true); + Map realms = (Map) realmsField.get(classWorld); + DefaultClassRealm realm = (DefaultClassRealm) realms.get("plexus.core"); + + Class clazz = Class.forName("org.codehaus.classworlds.RealmClassLoader"); + Constructor ctr = clazz.getDeclaredConstructor(new Class[] { DefaultClassRealm.class, ClassLoader.class }); + ctr.setAccessible(true); + Object realmClassLoader = ctr.newInstance(realm, getClass().getClassLoader()); + + Field realmClassLoaderField = DefaultClassRealm.class.getDeclaredField("classLoader"); + realmClassLoaderField.setAccessible(true); + realmClassLoaderField.set(realm, realmClassLoader); + // Evil hack for Tomcat classloader issue - ends + + embedder.start(classWorld); + + metadataSource = (ArtifactMetadataSource) embedder.lookup(ArtifactMetadataSource.ROLE); + artifactFactory = (ArtifactFactory) embedder.lookup(ArtifactFactory.ROLE); + artifactResolver = (ArtifactResolver) embedder.lookup(ArtifactResolver.ROLE); + + setUpRepositories(embedder); + + embedder.stop(); + + } catch (DuplicateRealmException ex) { + throw new TuscanyDependencyException(ex); + } catch (PlexusContainerException ex) { + throw new TuscanyDependencyException(ex); + } catch (ComponentLookupException ex) { + throw new TuscanyDependencyException(ex); + } catch (NoSuchFieldException ex) { + throw new TuscanyDependencyException(ex); + } catch (IllegalAccessException ex) { + throw new TuscanyDependencyException(ex); + } catch (ClassNotFoundException ex) { + throw new TuscanyDependencyException(ex); + } catch (NoSuchMethodException ex) { + throw new TuscanyDependencyException(ex); + } catch (InstantiationException ex) { + throw new TuscanyDependencyException(ex); + } catch (InvocationTargetException ex) { + throw new TuscanyDependencyException(ex); + } + + } + + /** + * Stops the embedder. + * + * @throws TuscanyDependencyException + * If unable to stop the embedder. + */ + public void stop() throws TuscanyDependencyException { + } + + /** + * Resolves the dependencies transitively. + * + * @param artifact + * Artifact whose dependencies need to be resolved. + * @throws TuscanyDependencyException + * If unable to resolve the dependencies. + */ + public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException { + + org.apache.maven.artifact.Artifact mavenRootArtifact = artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(), + rootArtifact.getVersion(), org.apache.maven.artifact.Artifact.SCOPE_RUNTIME, rootArtifact.getType()); + + try { + + if (resolve(mavenRootArtifact)) { + rootArtifact.setUrl(mavenRootArtifact.getFile().toURL()); + if (resolveDependencies(rootArtifact, mavenRootArtifact)) { + return true; + } else { + return false; + } + } else { + return false; + } + } catch (MalformedURLException ex) { + throw new TuscanyDependencyException(ex); + } + + } + + /* + * Resolves the artifact. + */ + private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) { + + try { + artifactResolver.resolve(mavenRootArtifact, remoteRepositories, localRepository); + return true; + } catch (ArtifactResolutionException ex) { + return false; + } catch (ArtifactNotFoundException ex) { + return false; + } + + } + + /* + * Sets up local and remote repositories. + */ + private void setUpRepositories(Embedder embedder) { + + try { + + ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE); + + ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder.lookup(ArtifactRepositoryLayout.ROLE, "default"); + + String updatePolicy = online ? ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS : ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER; + ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); + ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); + + MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder)embedder.lookup(MavenSettingsBuilder.ROLE); + Settings settings = settingsBuilder.buildSettings(); + String localRepo = settings.getLocalRepository(); + + localRepository = artifactRepositoryFactory.createArtifactRepository("local", new File(localRepo).toURL().toString(), layout, + snapshotsPolicy, releasesPolicy); + + if (!online) { + return; + } + + for (String remoteRepositoryUrl : remoteRepositoryUrls) { + String repoid = remoteRepositoryUrl.replace(':', '_'); + repoid = repoid.replace('/', '_'); + repoid = repoid.replace('\\', '_'); + remoteRepositories.add(artifactRepositoryFactory.createArtifactRepository(repoid, remoteRepositoryUrl, layout, snapshotsPolicy, + releasesPolicy)); + } + + } catch (Exception ex) { + throw new TuscanyDependencyException(ex); + } + + } + + /* + * Resolves transitive dependencies. + */ + private boolean resolveDependencies(Artifact rootArtifact, org.apache.maven.artifact.Artifact mavenRootArtifact) { + + try { + + ResolutionGroup resolutionGroup = null; + ArtifactResolutionResult result = null; + + resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository, remoteRepositories); + result = artifactResolver.resolveTransitively(resolutionGroup.getArtifacts(), mavenRootArtifact, remoteRepositories, localRepository, + metadataSource); + + // Add the artifacts to the deployment unit + for (Object obj : result.getArtifacts()) { + org.apache.maven.artifact.Artifact depArtifact = (org.apache.maven.artifact.Artifact) obj; + Artifact artifact = new Artifact(); + artifact.setName(depArtifact.getArtifactId()); + artifact.setGroup(depArtifact.getGroupId()); + artifact.setType(depArtifact.getType()); + artifact.setVersion(depArtifact.getVersion()); + artifact.setClassifier(depArtifact.getClassifier()); + artifact.setUrl(depArtifact.getFile().toURL()); + rootArtifact.addDependency(artifact); + } + + } catch (ArtifactMetadataRetrievalException ex) { + return false; + } catch (MalformedURLException ex) { + throw new TuscanyDependencyException(ex); + } catch (ArtifactResolutionException ex) { + return false; + } catch (ArtifactNotFoundException ex) { + return false; + } + + return true; + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java new file mode 100644 index 0000000000..a7817ff3be --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.services.maven; + +import org.apache.tuscany.api.TuscanyRuntimeException; + +/** + * Exception thrown in case of an artifact error. + * + * @version $Rev$ $Date$ + */ +public class TuscanyDependencyException extends TuscanyRuntimeException { + + /** + * Initializes the cause. + * + * @param cause Cause of the exception. + */ + public TuscanyDependencyException(Throwable cause) { + super(cause); + } + + /** + * Initializes the message. + * + * @param message Message of the exception. + */ + public TuscanyDependencyException(String message) { + super(message); + } + + + /** + * Initializes the message. + * + * @param message Message of the exception. + * @param identifier an identifier for the exeption. + */ + public TuscanyDependencyException(String message, String identifier) { + super(message, identifier); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java new file mode 100644 index 0000000000..6b3ba3ed10 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java @@ -0,0 +1,116 @@ +/* + * 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.services.maven; + +import java.beans.XMLDecoder; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.spi.services.artifact.Artifact; +import org.codehaus.plexus.util.IOUtil; + +/** + * Helper class for resolving dependencies from WAR files. + * + * @author Administrator + * + */ +public class WarRepositoryHelper { + + /** WAR Repository URL */ + private URL reporsitoryUrl; + + /** Dependency metadata */ + private Map<String, Set<String>> transDependencyMap = new HashMap<String, Set<String>>(); + + /** + * Initializes the repository URL. + * @param baseUrl Base URL. + */ + @SuppressWarnings("unchecked") + public WarRepositoryHelper(URL baseUrl) { + + + InputStream transDepMapInputStream = null; + try { + + reporsitoryUrl = new URL(baseUrl, "repository/"); + URL transDependencyMapUrl = new URL(baseUrl, "repository/dependency.metadata"); + transDepMapInputStream = transDependencyMapUrl.openStream(); + + XMLDecoder decoder = new XMLDecoder(transDepMapInputStream); + transDependencyMap = (Map<String, Set<String>>)decoder.readObject(); + decoder.close(); + + } catch (MalformedURLException ex) { + // throw new TuscanyDependencyException(ex); + } catch (IOException ex) { + // throw new TuscanyDependencyException(ex); + } finally { + IOUtil.close(transDepMapInputStream); + } + + } + + /** + * Resolves the dependencies transitively. + * + * @param artifact + * Artifact whose dependencies need to be resolved. + * @throws TuscanyDependencyException + * If unable to resolve the dependencies. + */ + public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException { + + String artKey = rootArtifact.getGroup() + "/" + rootArtifact.getName() + "/" + rootArtifact.getVersion() + "/"; + if(!transDependencyMap.containsKey(artKey)) { + return false; + } + + + for(String dep : transDependencyMap.get(artKey)) { + + String[] tokens = dep.split("/"); + String artName = tokens[1]; + + try { + if(artName.equals(rootArtifact.getName())) { + rootArtifact.setUrl(new URL(reporsitoryUrl, dep)); + } else { + Artifact depArtifact = new Artifact(); + depArtifact.setGroup(tokens[0]); + depArtifact.setName(tokens[1]); + depArtifact.setVersion(tokens[2]); + depArtifact.setUrl(new URL(reporsitoryUrl, dep)); + rootArtifact.addDependency(depArtifact); + + } + } catch (MalformedURLException ex) { + throw new TuscanyDependencyException(ex); + } + } + return rootArtifact.getUrl()!=null; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java new file mode 100644 index 0000000000..b4e9babd05 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java @@ -0,0 +1,96 @@ +/* + * 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.services.maven; + +import java.io.File; +import java.net.URL; +import java.net.URI; +import java.util.Set; + +import junit.framework.TestCase; + +import org.apache.tuscany.host.RuntimeInfo; +import org.apache.tuscany.spi.services.artifact.Artifact; + +/** + * @version $Rev$ $Date$ + */ +public class MavenArtifactRepositoryTestCase extends TestCase { + + public MavenArtifactRepositoryTestCase(String arg0) { + super(arg0); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /* + * Test method for 'org.apache.tuscany.serviceBindings.maven.MavenArtifactRepository.resolve(Artifact)' + */ + public void testResolveArtifact() throws Exception { + + final URL BASE_URL = new File(System.getProperty("user.home") + File.separator + ".m2").toURL(); + String remoteRepoUrl = "http://repo1.maven.org/maven2/"; + MavenArtifactRepository repository = new MavenArtifactRepository(remoteRepoUrl, new RuntimeInfo() { + public File getApplicationRootDirectory() { + return null; + } + + public URL getBaseURL() { + return BASE_URL; + } + + public File getInstallDirectory() { + return null; + } + + public boolean isOnline() { + return false; + } + + public URI getDomain() { + throw new UnsupportedOperationException(); + } + + public String getRuntimeId() { + throw new UnsupportedOperationException(); + } + }); + Artifact artifact = new Artifact(); + artifact.setGroup("junit"); + artifact.setName("junit"); + artifact.setVersion("3.8.1"); + artifact.setType("jar"); + + repository.resolve(artifact); + + Set<URL> urls = artifact.getUrls(); + + System.err.println(urls); + + assertEquals(1, urls.size()); + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java new file mode 100644 index 0000000000..3a79599fa7 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.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.services.maven; + +import java.net.URL; +import java.net.URLClassLoader; + +import org.apache.tuscany.spi.services.artifact.Artifact; + +import junit.framework.TestCase; + +/** + * @author Administrator + * + */ +public class WarRepositoryHelperTestCase extends TestCase { + + /** + * @param arg0 + */ + public WarRepositoryHelperTestCase(String arg0) { + super(arg0); + } + + /** + * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}. + */ + public void testWarRepositoryHelper() { + + URL warUrl = getClass().getClassLoader().getResource("webapp.war"); + URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl}); + + URL repoUrl = urlc.getResource("WEB-INF/tuscany/"); + System.err.println(repoUrl); + + WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl); + assertNotNull(warRepositoryHelper); + + } + + /** + * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}. + */ + public void testResolveTransitively() { + + URL warUrl = getClass().getClassLoader().getResource("webapp.war"); + URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl}); + + URL repoUrl = urlc.getResource("WEB-INF/tuscany/"); + WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl); + + Artifact artifact = new Artifact(); + artifact.setGroup("commons-httpclient"); + artifact.setName("commons-httpclient"); + artifact.setVersion("3.0"); + + warRepositoryHelper.resolveTransitively(artifact); + assertEquals(4, artifact.getUrls().size()); + + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war Binary files differnew file mode 100644 index 0000000000..4448aca8ff --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/LICENSE.txt b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/LICENSE.txt new file mode 100644 index 0000000000..9601ead3f6 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/LICENSE.txt @@ -0,0 +1,1407 @@ + + 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. + + +APACHE TUSCANY SUBCOMPONENTS: + +The Apache Tuscany distribution includes a number of subcomponents with +separate copyright notices and license terms. Your use of the source +code for the these subcomponents is subject to the terms and +conditions of the following licenses. + +=============================================================================== + +For the Eclipse Modeling Framework component and the Celtix binding: + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF +THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and +documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: + +i) changes to the Program, and + +ii) additions to the Program; + +where such changes and/or additions to the Program originate from and +are distributed by that particular Contributor. A Contribution +'originates' from a Contributor if it was added to the Program by such +Contributor itself or anyone acting on such Contributor's behalf. +Contributions do not include additions to the Program which: (i) are +separate modules of software distributed in conjunction with the +Program under their own license agreement, and (ii) are not derivative +works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor +which are necessarily infringed by the use or sale of its Contribution +alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this +Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free copyright +license to reproduce, prepare derivative works of, publicly display, +publicly perform, distribute and sublicense the Contribution of such +Contributor, if any, and such derivative works, in source code and +object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby +grants Recipient a non-exclusive, worldwide, royalty-free patent +license under Licensed Patents to make, use, sell, offer to sell, +import and otherwise transfer the Contribution of such Contributor, if +any, in source code and object code form. This patent license shall +apply to the combination of the Contribution and the Program if, at +the time the Contribution is added by the Contributor, such addition +of the Contribution causes such combination to be covered by the +Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder. + +c) Recipient understands that although each Contributor grants the +licenses to its Contributions set forth herein, no assurances are +provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility +to secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow +Recipient to distribute the Program, it is Recipient's responsibility +to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient +copyright rights in its Contribution, if any, to grant the copyright +license set forth in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form +under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and + +b) its license agreement: + +i) effectively disclaims on behalf of all Contributors all warranties +and conditions, express and implied, including warranties or +conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose; + +ii) effectively excludes on behalf of all Contributors all liability +for damages, including direct, indirect, special, incidental and +consequential damages, such as lost profits; + +iii) states that any provisions which differ from this Agreement are +offered by that Contributor alone and not by any other party; and + +iv) states that source code for the Program is available from such +Contributor, and informs licensees how to obtain it in a reasonable +manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and + +b) a copy of this Agreement must be included with each copy of the +Program. + +Contributors may not remove or alter any copyright notices contained +within the Program. + +Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use +of the Program, the Contributor who includes the Program in a +commercial product offering should do so in a manner which does not +create potential liability for other Contributors. Therefore, if a +Contributor includes the Program in a commercial product offering, +such Contributor ("Commercial Contributor") hereby agrees to defend +and indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") arising +from claims, lawsuits and other legal actions brought by a third party +against the Indemnified Contributor to the extent caused by the acts +or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. +In order to qualify, an Indemnified Contributor must: a) promptly +notify the Commercial Contributor in writing of such claim, and b) +allow the Commercial Contributor to control, and cooperate with the +Commercial Contributor in, the defense and any related settlement +negotiations. The Indemnified Contributor may participate in any such +claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED 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. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable +laws, damage to or loss of data, programs or equipment, and +unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR +ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that +the Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of +the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and +survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign +the responsibility to serve as the Agreement Steward to a suitable +separate entity. Each new version of the Agreement will be given a +distinguishing version number. The Program (including Contributions) +may always be distributed subject to the version of the Agreement +under which it was received. In addition, after a new version of the +Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor +under this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No +party to this Agreement will bring a legal action under this Agreement +more than one year after the cause of action arose. Each party waives +its rights to a jury trial in any resulting litigation. + +=============================================================================== + +For the Rhino JavaScript container component: + +Netscape Public License V1.1 + + AMENDMENTS + + The Netscape Public License Version 1.1 ("NPL") consists of the + Mozilla Public License Version 1.1 with the following Amendments, + including Exhibit A-Netscape Public License. Files identified with + "Exhibit A-Netscape Public License" are governed by the Netscape + Public License Version 1.1. + + Additional Terms applicable to the Netscape Public License. + I. Effect. + These additional terms described in this Netscape Public + License -- Amendments shall apply to the Mozilla Communicator + client code and to all Covered Code under this License. + + II. "Netscape's Branded Code" means Covered Code that Netscape + distributes and/or permits others to distribute under one or more + trademark(s) which are controlled by Netscape but which are not + licensed for use under this License. + + III. Netscape and logo. + This License does not grant any rights to use the trademarks + "Netscape", the "Netscape N and horizon" logo or the "Netscape + lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript", + "Smart Browsing" even if such marks are included in the Original + Code or Modifications. + + IV. Inability to Comply Due to Contractual Obligation. + Prior to licensing the Original Code under this License, Netscape + has licensed third party code for use in Netscape's Branded Code. + To the extent that Netscape is limited contractually from making + such third party code available under this License, Netscape may + choose to reintegrate such code into Covered Code without being + required to distribute such code in Source Code form, even if + such code would otherwise be considered "Modifications" under + this License. + + V. Use of Modifications and Covered Code by Initial Developer. + V.1. In General. + The obligations of Section 3 apply to Netscape, except to + the extent specified in this Amendment, Section V.2 and V.3. + + V.2. Other Products. + Netscape may include Covered Code in products other than the + Netscape's Branded Code which are released by Netscape + during the two (2) years following the release date of the + Original Code, without such additional products becoming + subject to the terms of this License, and may license such + additional products on different terms from those contained + in this License. + + V.3. Alternative Licensing. + Netscape may license the Source Code of Netscape's Branded + Code, including Modifications incorporated therein, without + such Netscape Branded Code becoming subject to the terms of + this License, and may license such Netscape Branded Code on + different terms from those contained in this License. + + VI. Litigation. + Notwithstanding the limitations of Section 11 above, the + provisions regarding litigation in Section 11(a), (b) and (c) of + the License shall apply to all disputes relating to this License. + + EXHIBIT A-Netscape Public License. + + "The contents of this file are subject to the Netscape Public + License Version 1.1 (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.mozilla.org/NPL/ + + Software distributed under the License is distributed on an "AS + IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + implied. See the License for the specific language governing + rights and limitations under the License. + + The Original Code is Mozilla Communicator client code, released + March 31, 1998. + + The Initial Developer of the Original Code is Netscape + Communications Corporation. Portions created by Netscape are + Copyright (C) 1998-1999 Netscape Communications Corporation. All + Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the + terms of the _____ license (the "[___] License"), in which case + the provisions of [______] License are applicable instead of + those above. If you wish to allow use of your version of this + file only under the terms of the [____] License and not to allow + others to use your version of this file under the NPL, indicate + your decision by deleting the provisions above and replace them + with the notice and other provisions required by the [___] + License. If you do not delete the provisions above, a recipient + may use your version of this file under either the NPL or the + [___] License." + + ---------------------------------------------------------------------- + + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``The contents of this file are subject to the Mozilla Public License + Version 1.1 (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.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] + + +=============================================================================== + +For the JAX-WS Reference Implementation component: + +COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 + + + 1. Definitions. + + 1.1. "Contributor" means each individual or entity that + creates or contributes to the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the + Original Software, prior Modifications used by a + Contributor (if any), and the Modifications made by that + particular Contributor. + + 1.3. "Covered Software" means (a) the Original Software, or + (b) Modifications, or (c) the combination of files + containing Original Software with files containing + Modifications, in each case including portions thereof. + + 1.4. "Executable" means the Covered Software in any form + other than Source Code. + + 1.5. "Initial Developer" means the individual or entity + that first makes Original Software available under this + License. + + 1.6. "Larger Work" means a work which combines Covered + Software or portions thereof with code not governed by the + terms of this License. + + 1.7. "License" means this document. + + 1.8. "Licensable" means having the right to grant, to the + maximum extent possible, whether at the time of the initial + grant or subsequently acquired, any and all of the rights + conveyed herein. + + 1.9. "Modifications" means the Source Code and Executable + form of any of the following: + + A. Any file that results from an addition to, + deletion from or modification of the contents of a + file containing Original Software or previous + Modifications; + + B. Any new file that contains any part of the + Original Software or previous Modification; or + + C. Any new file that is contributed or otherwise made + available under the terms of this License. + + 1.10. "Original Software" means the Source Code and + Executable form of computer software code that is + originally released under this License. + + 1.11. "Patent Claims" means any patent claim(s), now owned + or hereafter acquired, including without limitation, + method, process, and apparatus claims, in any patent + Licensable by grantor. + + 1.12. "Source Code" means (a) the common form of computer + software code in which modifications are made and (b) + associated documentation included in or with such code. + + 1.13. "You" (or "Your") means an individual or a legal + entity exercising rights under, and complying with all of + the terms of, this License. For legal entities, "You" + includes any entity which controls, is controlled by, or is + under common control with You. For purposes of this + definition, "control" means (a) the power, direct or + indirect, to cause the direction or management of such + entity, whether by contract or otherwise, or (b) ownership + of more than fifty percent (50%) of the outstanding shares + or beneficial ownership of such entity. + + 2. License Grants. + + 2.1. The Initial Developer Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, the + Initial Developer hereby grants You a world-wide, + royalty-free, non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Initial Developer, + to use, reproduce, modify, display, perform, + sublicense and distribute the Original Software (or + portions thereof), with or without Modifications, + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, + using or selling of Original Software, to make, have + made, use, practice, sell, and offer for sale, and/or + otherwise dispose of the Original Software (or + portions thereof). + + (c) The licenses granted in Sections 2.1(a) and (b) + are effective on the date Initial Developer first + distributes or otherwise makes the Original Software + available to a third party under the terms of this + License. + + (d) Notwithstanding Section 2.1(b) above, no patent + license is granted: (1) for code that You delete from + the Original Software, or (2) for infringements + caused by: (i) the modification of the Original + Software, or (ii) the combination of the Original + Software with other software or devices. + + 2.2. Contributor Grant. + + Conditioned upon Your compliance with Section 3.1 below and + subject to third party intellectual property claims, each + Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + (a) under intellectual property rights (other than + patent or trademark) Licensable by Contributor to + use, reproduce, modify, display, perform, sublicense + and distribute the Modifications created by such + Contributor (or portions thereof), either on an + unmodified basis, with other Modifications, as + Covered Software and/or as part of a Larger Work; and + + + (b) under Patent Claims infringed by the making, + using, or selling of Modifications made by that + Contributor either alone and/or in combination with + its Contributor Version (or portions of such + combination), to make, use, sell, offer for sale, + have made, and/or otherwise dispose of: (1) + Modifications made by that Contributor (or portions + thereof); and (2) the combination of Modifications + made by that Contributor with its Contributor Version + (or portions of such combination). + + (c) The licenses granted in Sections 2.2(a) and + 2.2(b) are effective on the date Contributor first + distributes or otherwise makes the Modifications + available to a third party. + + (d) Notwithstanding Section 2.2(b) above, no patent + license is granted: (1) for any code that Contributor + has deleted from the Contributor Version; (2) for + infringements caused by: (i) third party + modifications of Contributor Version, or (ii) the + combination of Modifications made by that Contributor + with other software (except as part of the + Contributor Version) or other devices; or (3) under + Patent Claims infringed by Covered Software in the + absence of Modifications made by that Contributor. + + 3. Distribution Obligations. + + 3.1. Availability of Source Code. + + Any Covered Software that You distribute or otherwise make + available in Executable form must also be made available in + Source Code form and that Source Code form must be + distributed only under the terms of this License. You must + include a copy of this License with every copy of the + Source Code form of the Covered Software You distribute or + otherwise make available. You must inform recipients of any + such Covered Software in Executable form as to how they can + obtain such Covered Software in Source Code form in a + reasonable manner on or through a medium customarily used + for software exchange. + + 3.2. Modifications. + + The Modifications that You create or to which You + contribute are governed by the terms of this License. You + represent that You believe Your Modifications are Your + original creation(s) and/or You have sufficient rights to + grant the rights conveyed by this License. + + 3.3. Required Notices. + + You must include a notice in each of Your Modifications + that identifies You as the Contributor of the Modification. + You may not remove or alter any copyright, patent or + trademark notices contained within the Covered Software, or + any notices of licensing or any descriptive text giving + attribution to any Contributor or the Initial Developer. + + 3.4. Application of Additional Terms. + + You may not offer or impose any terms on any Covered + Software in Source Code form that alters or restricts the + applicable version of this License or the recipients' + rights hereunder. You may choose to offer, and to charge a + fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Software. + However, you may do so only on Your own behalf, and not on + behalf of the Initial Developer or any Contributor. You + must make it absolutely clear that any such warranty, + support, indemnity or liability obligation is offered by + You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred + by the Initial Developer or such Contributor as a result of + warranty, support, indemnity or liability terms You offer. + + + 3.5. Distribution of Executable Versions. + + You may distribute the Executable form of the Covered + Software under the terms of this License or under the terms + of a license of Your choice, which may contain terms + different from this License, provided that You are in + compliance with the terms of this License and that the + license for the Executable form does not attempt to limit + or alter the recipient's rights in the Source Code form + from the rights set forth in this License. If You + distribute the Covered Software in Executable form under a + different license, You must make it absolutely clear that + any terms which differ from this License are offered by You + alone, not by the Initial Developer or Contributor. You + hereby agree to indemnify the Initial Developer and every + Contributor for any liability incurred by the Initial + Developer or such Contributor as a result of any such terms + You offer. + + 3.6. Larger Works. + + You may create a Larger Work by combining Covered Software + with other code not governed by the terms of this License + and distribute the Larger Work as a single product. In such + a case, You must make sure the requirements of this License + are fulfilled for the Covered Software. + + 4. Versions of the License. + + 4.1. New Versions. + + Sun Microsystems, Inc. is the initial license steward and + may publish revised and/or new versions of this License + from time to time. Each version will be given a + distinguishing version number. Except as provided in + Section 4.3, no one other than the license steward has the + right to modify this License. + + 4.2. Effect of New Versions. + + You may always continue to use, distribute or otherwise + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. If the Initial Developer includes a + notice in the Original Software prohibiting it from being + distributed or otherwise made available under any + subsequent version of the License, You must distribute and + make the Covered Software available under the terms of the + version of the License under which You originally received + the Covered Software. Otherwise, You may also choose to + use, distribute or otherwise make the Covered Software + available under the terms of any subsequent version of the + License published by the license steward. + + 4.3. Modified Versions. + + When You are an Initial Developer and You want to create a + new license for Your Original Software, You may create and + use a modified version of this License if You: (a) rename + the license and remove any references to the name of the + license steward (except to note that the license differs + from this License); and (b) otherwise make it clear that + the license contains terms which differ from this License. + + + 5. DISCLAIMER OF WARRANTY. + + COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" + BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, + INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED + SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR + PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND + PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY + COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE + INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF + ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF + WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS + DISCLAIMER. + + 6. TERMINATION. + + 6.1. This License and the rights granted hereunder will + terminate automatically if You fail to comply with terms + herein and fail to cure such breach within 30 days of + becoming aware of the breach. Provisions which, by their + nature, must remain in effect beyond the termination of + this License shall survive. + + 6.2. If You assert a patent infringement claim (excluding + declaratory judgment actions) against Initial Developer or + a Contributor (the Initial Developer or Contributor against + whom You assert such claim is referred to as "Participant") + alleging that the Participant Software (meaning the + Contributor Version where the Participant is a Contributor + or the Original Software where the Participant is the + Initial Developer) directly or indirectly infringes any + patent, then any and all rights granted directly or + indirectly to You by such Participant, the Initial + Developer (if the Initial Developer is not the Participant) + and all Contributors under Sections 2.1 and/or 2.2 of this + License shall, upon 60 days notice from Participant + terminate prospectively and automatically at the expiration + of such 60 day notice period, unless if within such 60 day + period You withdraw Your claim with respect to the + Participant Software against such Participant either + unilaterally or pursuant to a written agreement with + Participant. + + 6.3. In the event of termination under Sections 6.1 or 6.2 + above, all end user licenses that have been validly granted + by You or any distributor hereunder prior to termination + (excluding licenses granted to You by any distributor) + shall survive termination. + + 7. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE + INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF + COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE + LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR + CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT + LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK + STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL + INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT + APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO + NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR + CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT + APPLY TO YOU. + + 8. U.S. GOVERNMENT END USERS. + + The Covered Software is a "commercial item," as that term is + defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial + computer software" (as that term is defined at 48 C.F.R. + 252.227-7014(a)(1)) and "commercial computer software + documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. + 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 + through 227.7202-4 (June 1995), all U.S. Government End Users + acquire Covered Software with only those rights set forth herein. + This U.S. Government Rights clause is in lieu of, and supersedes, + any other FAR, DFAR, or other clause or provision that addresses + Government rights in computer software under this License. + + 9. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the + extent necessary to make it enforceable. This License shall be + governed by the law of the jurisdiction specified in a notice + contained within the Original Software (except to the extent + applicable law, if any, provides otherwise), excluding such + jurisdiction's conflict-of-law provisions. Any litigation + relating to this License shall be subject to the jurisdiction of + the courts located in the jurisdiction and venue specified in a + notice contained within the Original Software, with the losing + party responsible for costs, including, without limitation, court + costs and reasonable attorneys' fees and expenses. The + application of the United Nations Convention on Contracts for the + International Sale of Goods is expressly excluded. Any law or + regulation which provides that the language of a contract shall + be construed against the drafter shall not apply to this License. + You agree that You alone are responsible for compliance with the + United States export administration regulations (and the export + control laws and regulation of any other countries) when You use, + distribute or otherwise make available any Covered Software. + + 10. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or + indirectly, out of its utilization of rights under this License + and You agree to work with Initial Developer and Contributors to + distribute such responsibility on an equitable basis. Nothing + herein is intended or shall be deemed to constitute any admission + of liability. + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/NOTICE.txt b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/pom.xml new file mode 100644 index 0000000000..d6c2c35617 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/pom.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca.plugins</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>tuscany-itest-plugin</artifactId> + <packaging>maven-plugin</packaging> + <name>Apache Tuscany Integration Test Plugin</name> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>2.0.4</version> + </dependency> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven.surefire</groupId> + <artifactId>surefire-junit</artifactId> + <version>2.0</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca.kernel</groupId> + <artifactId>core</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </dependency> + <!-- [rfeng] A big hack to resolve servlet-api --> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.4</version> + <scope>runtime</scope> + </dependency> + </dependencies> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java new file mode 100644 index 0000000000..8f8934488a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.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.plugin.itest; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; + + +/** + * Represents a configured tuscany dependency for boot and extension libraries. + * + * @version $Rev$ $Date$ + */ +public class Dependency { + + /** + * JAR type artifact. + */ + private static final String TYPE_JAR = "jar"; + + /** + * Group Id that is injected in from configuration. + */ + private String groupId; + + /** + * Artifact Id that is injected in from configuration. + */ + private String artifactId; + + /** + * Version that is injected in from configuration. + */ + private String version; + + /** + * Default constructor. + */ + public Dependency() { + } + + /** + * Initializes the field. + * + * @param groupId Group id. + * @param artifactId Artifact id. + * @param version Artifact version. + */ + public Dependency(String groupId, String artifactId, String version) { + super(); + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + } + + /** + * Gets the artifact using the specified artifact factory. + * + * @param artifactFactory Artifact factory to use. + * @return Artifact identified by the dependency. + */ + public Artifact getArtifact(ArtifactFactory artifactFactory) { + return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, TYPE_JAR); + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java new file mode 100644 index 0000000000..fda97c8a64 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java @@ -0,0 +1,139 @@ +/* + * 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.plugin.itest; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.osoa.sca.CompositeContext; + +import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation; +import org.apache.tuscany.core.launcher.CompositeContextImpl; +import org.apache.tuscany.core.runtime.AbstractRuntime; +import org.apache.tuscany.host.runtime.InitializationException; +import org.apache.tuscany.sca.plugin.itest.TuscanyStartMojo.MavenEmbeddedArtifactRepository; +import org.apache.tuscany.spi.builder.BuilderException; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentException; +import org.apache.tuscany.spi.component.ComponentRegistrationException; +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.deployer.CompositeClassLoader; +import org.apache.tuscany.spi.deployer.Deployer; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.services.artifact.ArtifactRepository; + +/** + * @version $Rev$ $Date$ + */ +public class MavenEmbeddedRuntime extends AbstractRuntime { + private CompositeContextImpl context; + private CompositeComponent application; + + private ArtifactRepository artifactRepository; + // leave untyped b/c of QDox error + private Map extensions = new HashMap(); + + public void addExtension(String extensionName, URL extentionSCDL) { + extensions.put(extensionName, extentionSCDL); + } + + protected void registerSystemComponents() throws InitializationException { + super.registerSystemComponents(); + try { + getSystemComponent().registerJavaObject(MavenRuntimeInfo.COMPONENT_NAME, + MavenRuntimeInfo.class, + (MavenRuntimeInfo) getRuntimeInfo()); + + getSystemComponent().registerJavaObject(MavenEmbeddedArtifactRepository.COMPONENT_NAME, + ArtifactRepository.class, + artifactRepository); + } catch (ComponentRegistrationException e) { + throw new InitializationException(e); + } + } + + public void initialize() throws InitializationException { + super.initialize(); + + try { + for (Object extensionName : extensions.keySet()) { + deployExtension(getTuscanySystem(), getDeployer(), (String) extensionName, (URL) extensions.get(extensionName)); + } + + application = deployApplicationScdl(getDeployer(), + getRuntime().getRootComponent(), + getApplicationName(), + getApplicationScdl(), + getApplicationClassLoader()); + application.start(); + + context = new CompositeContextImpl(application, getWireService()); + } catch (LoaderException e) { + throw new InitializationException(e); + } catch (BuilderException e) { + throw new InitializationException(e); + } catch (TargetResolutionException e) { + throw new InitializationException(e); + } catch (ComponentException e) { + throw new InitializationException(e); + } + } + + protected void deployExtension(CompositeComponent composite, Deployer deployer, String extensionName, URL url) + throws LoaderException, BuilderException, ComponentException { + SystemCompositeImplementation implementation = new SystemCompositeImplementation(); + URL scdlLocation; + try { + scdlLocation = new URL("jar:" + url.toExternalForm() + "!/META-INF/sca/default.scdl"); + } catch (MalformedURLException e) { + throw new IllegalArgumentException(e); + } + + implementation.setScdlLocation(scdlLocation); + implementation.setClassLoader(new CompositeClassLoader(new URL[]{url}, getClass().getClassLoader())); + + ComponentDefinition<SystemCompositeImplementation> definition = + new ComponentDefinition<SystemCompositeImplementation>(extensionName, implementation); + + Component component = deployer.deploy(composite, definition); + component.start(); + } + + public void destroy() { + context = null; + if (application != null) { + application.stop(); + application = null; + } + super.destroy(); + } + + public CompositeContext getContext() { + return context; + } + + public void setArtifactRepository(ArtifactRepository artifactRepository) { + this.artifactRepository = artifactRepository; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java new file mode 100644 index 0000000000..60dfeb604d --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenRuntimeInfo.java @@ -0,0 +1,56 @@ +/* + * 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.plugin.itest; + +import java.io.File; +import java.net.URL; +import java.net.URI; + +import org.apache.tuscany.host.RuntimeInfo; + +/** + * @version $Rev$ $Date$ + */ +public class MavenRuntimeInfo implements RuntimeInfo { + public static final String COMPONENT_NAME = "MavenRuntimeInfo"; + + public File getInstallDirectory() { + throw new UnsupportedOperationException(); + } + + public File getApplicationRootDirectory() { + throw new UnsupportedOperationException(); + } + + public URL getBaseURL() { + throw new UnsupportedOperationException(); + } + + public boolean isOnline() { + throw new UnsupportedOperationException(); + } + + public URI getDomain() { + throw new UnsupportedOperationException(); + } + + public String getRuntimeId() { + throw new UnsupportedOperationException(); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java new file mode 100644 index 0000000000..935dd95d2f --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.plugin.itest; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.surefire.junit.JUnitDirectoryTestSuite; +import org.apache.maven.surefire.report.BriefFileReporter; +import org.apache.maven.surefire.report.ReporterException; +import org.apache.maven.surefire.report.ReporterManager; +import org.apache.maven.surefire.suite.SurefireTestSuite; +import org.apache.maven.surefire.testset.TestSetFailedException; + +/** + * @version $Rev$ $Date$ + * @goal test + * @phase integration-test + */ +public class TuscanyITestMojo extends AbstractMojo { + /** + * @parameter expression="${project.build.directory}/surefire-reports" + */ + private File reportsDirectory; + + /** + * Whether to trim the stack trace in the reports to just the lines within + * the test, or show the full trace. + * + * @parameter expression="${trimStackTrace}" default-value="true" + */ + private boolean trimStackTrace; + + /** + * The directory containing generated test classes of the project being + * tested. + * + * @parameter expression="${project.build.testOutputDirectory}" + * @required + */ + private File testClassesDirectory; + + /** + * @parameter + */ + private List includes = new ArrayList(); + + /** + * @parameter + */ + private List excludes = new ArrayList(); + + public void execute() throws MojoExecutionException, MojoFailureException { + getLog().info("Executing tests..."); + + boolean success = runSurefire(); + if (!success) { + String msg = "There were test failures"; + throw new MojoFailureException(msg); + } + } + + public boolean runSurefire() throws MojoExecutionException { + ClassLoader testsClassLoader = TuscanyStartMojo.foo.get(); + try { + Properties status = new Properties(); + boolean success = run(testsClassLoader, status); + getLog().info("Test results: "+status); + return success; + } catch (ReporterException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (TestSetFailedException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } + + public boolean run(ClassLoader testsClassLoader, Properties status) throws ReporterException, + TestSetFailedException { + List reports = new ArrayList(); + reports.add(new BriefFileReporter(reportsDirectory, trimStackTrace)); + ReporterManager reporterManager = new ReporterManager(reports); + reporterManager.initResultsFromProperties(status); + + List suites = new ArrayList(); + + int totalTests = 0; + SurefireTestSuite suite = + new JUnitDirectoryTestSuite(testClassesDirectory, (ArrayList)includes, (ArrayList)excludes); + suite.locateTestSets(testsClassLoader); + + int testCount = suite.getNumTests(); + if (testCount > 0) { + suites.add(suite); + totalTests += testCount; + } + reporterManager.runStarting(totalTests); + + if (totalTests == 0) { + reporterManager.writeMessage("There are no tests to run."); + } else { + suite.execute(reporterManager, testsClassLoader); + } + + reporterManager.runCompleted(); + reporterManager.updateResultsProperties(status); + return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures() == 0; + } + +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java new file mode 100644 index 0000000000..178561b870 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java @@ -0,0 +1,323 @@ +/* + * 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.plugin.itest; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.tuscany.host.runtime.InitializationException; + +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +/** + * @version $Rev$ $Date$ + * @goal start + * @phase pre-integration-test + */ +public class TuscanyStartMojo extends AbstractMojo { + + public class MavenEmbeddedArtifactRepository implements org.apache.tuscany.spi.services.artifact.ArtifactRepository { + public static final String COMPONENT_NAME = "MavenEmbeddedArtifactRepository"; + + public void resolve(org.apache.tuscany.spi.services.artifact.Artifact artifact) { + resolveTransitively(artifact); + } + + public void resolve(Collection artifacts) { + for (Object a : artifacts) { + resolve((Artifact)a); + } + } + + /** + * Resolves the dependencies transitively. + * + * @param rootArtifact Artifact whose dependencies need to be resolved. + */ + public boolean resolveTransitively(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact) { + + org.apache.maven.artifact.Artifact mavenRootArtifact = + artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(), rootArtifact + .getVersion(), org.apache.maven.artifact.Artifact.SCOPE_RUNTIME, rootArtifact.getType()); + + try { + + if (resolve(mavenRootArtifact)) { + rootArtifact.setUrl(mavenRootArtifact.getFile().toURL()); + if (resolveDependencies(rootArtifact, mavenRootArtifact)) { + return true; + } else { + return false; + } + } else { + return false; + } + } catch (MalformedURLException ex) { + throw new IllegalArgumentException(ex); + } + + } + + /* + * Resolves the artifact. + */ + private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) { + + try { + resolver.resolve(mavenRootArtifact, remoteRepositories, localRepository); + return true; + } catch (ArtifactResolutionException ex) { + return false; + } catch (ArtifactNotFoundException ex) { + return false; + } + + } + + /* + * Resolves transitive dependencies. + */ + private boolean resolveDependencies(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact, + org.apache.maven.artifact.Artifact mavenRootArtifact) { + + try { + + ResolutionGroup resolutionGroup = null; + ArtifactResolutionResult result = null; + + resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository, remoteRepositories); + result = + resolver.resolveTransitively(resolutionGroup.getArtifacts(), + mavenRootArtifact, + remoteRepositories, + localRepository, + metadataSource); + + // Add the artifacts to the deployment unit + for (Object obj : result.getArtifacts()) { + org.apache.maven.artifact.Artifact depArtifact = (org.apache.maven.artifact.Artifact)obj; + org.apache.tuscany.spi.services.artifact.Artifact artifact = + new org.apache.tuscany.spi.services.artifact.Artifact(); + artifact.setName(depArtifact.getArtifactId()); + artifact.setGroup(depArtifact.getGroupId()); + artifact.setType(depArtifact.getType()); + artifact.setClassifier(depArtifact.getClassifier()); + artifact.setUrl(depArtifact.getFile().toURL()); + artifact.setVersion(depArtifact.getVersion()); + rootArtifact.addDependency(artifact); + } + + } catch (ArtifactMetadataRetrievalException ex) { + return false; + } catch (MalformedURLException ex) { + throw new IllegalArgumentException(ex); + } catch (ArtifactResolutionException ex) { + return false; + } catch (ArtifactNotFoundException ex) { + return false; + } + + return true; + + } + + } + + /** + * @parameter + */ + private URL systemScdl; + + /** + * @parameter + */ + private URL applicationScdl; + + /** + * @parameter expression="${project.testClasspathElements}" + * @required + * @readonly + */ + private List testClassPath; + + /** + * Extensions + * + * @parameter + */ + private Dependency[] extensions = new Dependency[0]; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}" + * @required + * @readonly + */ + private ArtifactResolver resolver; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}" + * @required + * @readonly + */ + private ArtifactMetadataSource metadataSource; + + /** + * Location of the local repository. + * + * @parameter expression="${localRepository}" + * @readonly + * @required + */ + private ArtifactRepository localRepository; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @readonly + * @required + */ + private List remoteRepositories; + + /** + * Used to look up Artifacts in the remote repository. + * + * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}" + * @required + * @readonly + */ + private ArtifactFactory artifactFactory; + + static ThreadLocal<ClassLoader> foo = new ThreadLocal<ClassLoader>(); + + public void execute() throws MojoExecutionException, MojoFailureException { + getLog().info("Starting Tuscany..."); + + ClassLoader hostClassLoader = getClass().getClassLoader(); + if (systemScdl == null) { + systemScdl = hostClassLoader.getResource("META-INF/tuscany/embeddedMaven.scdl"); + } + + MavenRuntimeInfo runtimeInfo = new MavenRuntimeInfo(); + MavenEmbeddedRuntime runtime = new MavenEmbeddedRuntime(); + runtime.setArtifactRepository(new MavenEmbeddedArtifactRepository()); + + for (Dependency d : extensions) { + try { + Artifact artifact = d.getArtifact(artifactFactory); + resolver.resolve(artifact, remoteRepositories, localRepository); + URL url = artifact.getFile().toURL(); + getLog().info(url.toString()); + runtime.addExtension(artifact.getGroupId() + ":" + artifact.getArtifactId(), url); + } catch (Exception e) { + throw new MojoExecutionException("Fail to resolve an extension", e); + } + } + + runtime.setSystemScdl(systemScdl); + runtime.setHostClassLoader(hostClassLoader); + + ClassLoader applicationClassLoader = createApplicationClassLoader(hostClassLoader); + if (applicationScdl == null) { + Enumeration resources; + try { + resources = applicationClassLoader.getResources("META-INF/sca/default.scdl"); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + if (!resources.hasMoreElements()) { + throw new MojoExecutionException("No SCDL found on test classpath"); + } + applicationScdl = (URL)resources.nextElement(); + if (resources.hasMoreElements()) { + StringBuffer msg = new StringBuffer(); + msg.append("Multiple SCDL files found on test classpath:\n"); + msg.append(" ").append(applicationScdl).append('\n'); + do { + msg.append(" ").append(resources.nextElement()).append('\n'); + } while (resources.hasMoreElements()); + throw new MojoExecutionException(msg.toString()); + } + } else { + if (applicationScdl.getProtocol() == null) { + String resource = applicationScdl.getPath(); + applicationScdl = applicationClassLoader.getResource(resource); + if (applicationScdl == null) { + throw new MojoExecutionException("Application SCDL cannot be resolved: " + resource); + } + } + } + runtime.setApplicationName("application"); + runtime.setApplicationScdl(applicationScdl); + runtime.setApplicationClassLoader(applicationClassLoader); + runtime.setRuntimeInfo(runtimeInfo); + try { + runtime.initialize(); + } catch (InitializationException e) { + throw new MojoExecutionException("Error initializing", e); + } + CompositeContext context = runtime.getContext(); + CurrentCompositeContext.setContext(context); + + foo.set(applicationClassLoader); + } + + public ClassLoader createApplicationClassLoader(ClassLoader parent) { + URL[] urls = new URL[testClassPath.size()]; + int idx = 0; + for (Iterator i = testClassPath.iterator(); i.hasNext();) { + File pathElement = new File((String)i.next()); + try { + URL url = pathElement.toURI().toURL(); + getLog().debug("Adding application URL: " + url); + urls[idx++] = url; + } catch (MalformedURLException e) { + // toURI should have encoded the URL + throw new AssertionError(); + } + + } + return new URLClassLoader(urls, parent); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStopMojo.java b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStopMojo.java new file mode 100644 index 0000000000..46bde33d5a --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStopMojo.java @@ -0,0 +1,34 @@ +/* + * 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.plugin.itest; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * @goal stop + * @phase post-integration-test + * @version $Rev$ $Date$ + */ +public class TuscanyStopMojo extends AbstractMojo { + public void execute() throws MojoExecutionException, MojoFailureException { + getLog().info("Stopping Tuscany..."); + } +} diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl new file mode 100644 index 0000000000..5b3eeca646 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl @@ -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. +--> +<!-- + Default system configuration for the launcher environment. + + $Rev$ $Date$ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT" + name="org.apache.tuscany.sca.plugins.itest.EmbeddedMaven"> + + <!-- Component that provides the Deployer service --> + <component name="deployer"> + <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/> + </component> + + <!-- Work management --> + <component name="workContext"> + <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/> + </component> + + <!-- Wire service --> + <component name="wireService"> + <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKWireService"/> + </component> + + <!-- Scope infrastructure --> + <component name="scopeRegistry"> + <system:implementation.system class="org.apache.tuscany.core.component.scope.ScopeRegistryImpl"/> + </component> + + <!-- Builder and BuilderRegistry --> + <component name="builder"> + <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/> + </component> + + <!-- Loader and LoaderRegistry --> + <component name="loader"> + <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/> + </component> + + <!-- Introspector and IntrospectionRegistry --> + <component name="interfaceProcessorRegistry"> + <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/> + </component> + + <!-- Connector infrastructure --> + <component name="connector"> + <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/> + </component> + + <component name="wirePostProcessorRegistry"> + <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/> + </component> + + <!-- Resource host registry --> + <component name="resourceHostRegistry"> + <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/> + </component> + + <!-- Default scopes --> + <component name="scope.module"> + <system:implementation.system class="org.apache.tuscany.core.component.scope.CompositeScopeObjectFactory"/> + </component> + <component name="scope.stateless"> + <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeObjectFactory"/> + </component> + <component name="scope.request"> + <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeObjectFactory"/> + </component> + + <component name="scope.conversational"> + <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeObjectFactory"/> + </component> + + <!-- include loader configuration --> + <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl"/> + + <!-- include databinding configuration --> + <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl"/> + + <!-- include implementation processor configuration --> + <include name="org.apache.tuscany.core.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl"/> + + <!-- Java interface definition language --> + <include name="org.apache.tuscany.core.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl"/> + + <!-- include omposite implementation type --> + <include name="org.apache.tuscany.core.Composite" scdlResource="org/apache/tuscany/core/composite.scdl"/> + + <!-- System implementation type --> + <include name="org.apache.tuscany.core.SystemImplementation" scdlResource="org/apache/tuscany/core/systemImplementation.scdl"/> + + <!-- Java implementation type --> + <include name="org.apache.tuscany.core.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/> + + <!-- WorkScheduler service --> + <component name="workManager"> + <system:implementation.system + class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/> + <property name="poolSize">10</property> + </component> + + <component name="workScheduler"> + <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/> + </component> + + <component name="policyBuilderRegistry"> + <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/> + </component> + + <component name="propertyFactory"> + <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/> + </component> + + <!-- Store infrastructure --> + <component name="store"> + <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/> + </component> + + <!-- the local binding --> + <component name="localBindingLoader"> + <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader"/> + </component> + + <component name="localBindingBuilder"> + <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder"/> + </component> + + +</composite> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/plugins/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/plugins/pom.xml new file mode 100644 index 0000000000..a1e32c4000 --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/plugins/pom.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.plugins</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <name>Tuscany SCA Maven Plugins</name> + + <!-- definition of repositories where the parent pom can be found --> + <repositories> + <repository> + <id>apache.snapshots</id> + <name>Apache Snapshot Repository</name> + <url>http://people.apache.org/repo/m2-snapshot-repository</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + <repository> + <id>apache.incubator</id> + <name>Apache Incubator Repository</name> + <url>http://people.apache.org/repo/m2-incubating-repository/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <modules> + <module>plugin.itest</module> + </modules> +</project> diff --git a/sca-java-1.x/branches/pre-spec-changes/services/pom.xml b/sca-java-1.x/branches/pre-spec-changes/services/pom.xml new file mode 100644 index 0000000000..b95f7d4dda --- /dev/null +++ b/sca-java-1.x/branches/pre-spec-changes/services/pom.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<project> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>parent</artifactId> + <version>0.1-pre-spec-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.tuscany.sca.services</groupId> + <artifactId>parent</artifactId> + <packaging>pom</packaging> + <name>Tuscany SCA Services</name> + + <!-- definition of repositories where the parent pom can be found --> + <repositories> + <repository> + <id>apache.snapshots</id> + <name>Apache Snapshot Repository</name> + <url>http://people.apache.org/repo/m2-snapshot-repository</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + <repository> + <id>apache.incubator</id> + <name>Apache Incubator Repository</name> + <url>http://people.apache.org/repo/m2-incubating-repository/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + + <modules> + <module>idl</module> + <module>maven</module> + <module>management</module> + <module>plugins</module> + <module>databinding</module> + </modules> +</project> |