creating tag for the 1.3 release
git-svn-id: https://svn.apache.org/repos/asf/webservices/commons/tags/XmlSchema/1.3@528042 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/XmlSchema/LICENSE.txt b/XmlSchema/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/XmlSchema/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ 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/XmlSchema/NOTICE.txt b/XmlSchema/NOTICE.txt
new file mode 100644
index 0000000..5d98c39
--- /dev/null
+++ b/XmlSchema/NOTICE.txt
@@ -0,0 +1,13 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache XmlSchema distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
+
+ Portions Copyright 2006 International Business Machines Corp.
diff --git a/XmlSchema/README.txt b/XmlSchema/README.txt
new file mode 100644
index 0000000..4cd786a
--- /dev/null
+++ b/XmlSchema/README.txt
@@ -0,0 +1,36 @@
+====================================
+ XMLSchema Release Notes
+====================================
+
+XMLSchema is a lightweight schema object model that can be used to manipulate and
+generate XML schema representations. It has very few external dependancies and can
+be easily integrated into an existing project.
+
+You are welcome to kick the tires and get XMLSchema on the move. If you like to
+help us shape XMLSchema any contribution in the form of coding, testing,
+submitting improvements to the documentation, and reporting bugs are always
+welcome.
+
+Thanks for your interest in XMLSchema!
+
+-The XMLSchema Development Team
+http://ws.apache.org/commons/XmlSchema/
+
+===================
+ Documentation
+===================
+
+Documentation can be found in the 'binary' distribution of this release and in
+the main site.
+
+===================
+ Support
+===================
+
+Any problem with this release can be reported to ws-commons mailing list. If you
+are sending an email to the mailing list make sure to add the [XMLSchema] prefix
+to the subject.
+
+To the subscribe to the mailing list send an empty email to:
+
+ commons-dev-subscribe@ws.apache.org
diff --git a/XmlSchema/RELEASE-NOTE.txt b/XmlSchema/RELEASE-NOTE.txt
new file mode 100644
index 0000000..0d0ee74
--- /dev/null
+++ b/XmlSchema/RELEASE-NOTE.txt
@@ -0,0 +1,20 @@
+ ====================================
+ XMLSchema 1.3 Release Notes
+ ====================================
+
+This is the release of XMLSchema 1.3 of Apache WS-Commons. This release includes
+numerous bug fixes and a new feature addition that enables users to register
+extension types with the schema parser.
+
+XMLSchema is a lightweight schema object model that can be used to manipulate
+and generate XML schema representations. It has no external dependancies
+and can be easily integrated into an existing project.
+
+You are welcome to kick the tires and get XMLSchema on the move. If you like
+to help us shape XMLSchema any contribution in the form of coding, testing,
+submitting improvements to the documentation, and reporting bugs are always
+welcome.
+
+Thanks for your interest in XMLSchema!
+
+- The XMLSchema Development Team
diff --git a/XmlSchema/build.xml b/XmlSchema/build.xml
new file mode 100644
index 0000000..df48d73
--- /dev/null
+++ b/XmlSchema/build.xml
@@ -0,0 +1,167 @@
+<?xml version="1.0"?>
+<project name="XmlSchema" basedir="." default="jar">
+
+ <property name="src.dir" value="${basedir}/src/main/java"/>
+ <property name="project.name" value="XmlSchema"/>
+ <property name="output.jar" value="${project.name}.jar"/>
+ <property name="build.dir" value="${basedir}/build"/>
+ <property name="build_classes.dir" value="${build.dir}/classes"/>
+ <property name="build_lib.dir" value="${build.dir}/lib"/>
+ <property name="build_doc.dir" value="${build.dir}/apidoc"/>
+ <property name="dist.dir" value="${build.dir}/dist"/>
+ <property name="dist.zip" value="${project.name}.zip"/>
+ <property name="srcdist.zip" value="${project.name}-src.zip"/>
+ <property name="test.dir" value="${basedir}/src/test/java"/>
+ <property name="test_classes.dir" value="${build.dir}/test-classes"/>
+ <property name="test_reports.dir" value="${build.dir}/test-reports"/>
+ <property name="test_reports_w3c.dir" value="${build.dir}/test-reports-w3c"/>
+
+ <target name="setproxy" if="http.proxyhost">
+ <setproxy proxyhost="${http.proxyHost}" proxyport="${http.proxyPort}"/>
+ </target>
+
+ <target name="prepare" depends="setproxy">
+ <mkdir dir="${build_classes.dir}"/>
+ <mkdir dir="${build_lib.dir}"/>
+
+ <condition property="downloadLibs">
+ <not>
+ <available file="${build_lib.dir}/xmlunit-1.0.jar"/>
+ </not>
+ </condition>
+
+ <antcall target="get-deps"/>
+ </target>
+
+ <target name="get-deps" if="downloadLibs">
+ <get src="http://www.ibiblio.org/maven2/xmlunit/xmlunit/1.0/xmlunit-1.0.jar"
+ dest="${build_lib.dir}/xmlunit-1.0.jar"/>
+ </target>
+
+ <target name="prepare-tests">
+ <mkdir dir="${test_classes.dir}"/>
+ <mkdir dir="${test_reports.dir}"/>
+ <mkdir dir="${test_reports_w3c.dir}"/>
+
+ <antcall target="prepareNistTest"/>
+ </target>
+
+ <target name="prepareNistTest" unless="maven.test.skip">
+ <condition property="needsTestsDownload">
+ <not>
+ <available file="${build.dir}/xmlschema2002-01-16"/>
+ </not>
+ </condition>
+ <antcall target="get-xml-schema-tests"/>
+ </target>
+
+ <target name="get-xml-schema-tests" if="needsTestsDownload">
+ <echo>Downloading 6MB XML Schema test suite. This make take a few minutes...</echo>
+ <get dest="${build.dir}/xsts-2002-01-16.tar.gz"
+ src="http://www.w3.org/XML/2004/xml-schema-test-suite/xmlschema2002-01-16/xsts-2002-01-16.tar.gz"/>
+ <untar src="${build.dir}/xsts-2002-01-16.tar.gz" compression="gzip" dest="${build.dir}"/>
+ </target>
+
+ <target name="compile" depends="prepare" description="compiles the src and puts it in build/classes">
+ <javac srcdir="${src.dir}" destdir="${build_classes.dir}" debug="true"
+ source="1.2" target="1.2"
+ deprecation="true">
+ <include name="**/*.java" />
+ </javac>
+ </target>
+
+ <target name="compile-tests" depends="prepare-tests, compile" description="compiles the tests and puts them in build/test-classes">
+ <javac srcdir="${test.dir}" destdir="${test_classes.dir}" debug="true"
+ deprecation="true">
+ <classpath>
+ <pathelement location="${build_classes.dir}"/>
+ <fileset dir="${build_lib.dir}">
+ <include name="*.jar" />
+ </fileset>
+ </classpath>
+ <include name="**/*.java" />
+ </javac>
+ </target>
+
+ <target name="test" depends="compile-tests" description="Runs the unit tests">
+ <junit printsummary="yes" haltonfailure="yes">
+ <classpath>
+ <pathelement location="${build_classes.dir}"/>
+ <pathelement location="${test_classes.dir}"/>
+ <fileset dir="${build_lib.dir}">
+ <include name="*.jar" />
+ </fileset>
+ </classpath>
+ <formatter type="plain"/>
+ <batchtest todir="${test_reports.dir}">
+ <fileset dir="${test.dir}">
+ <include name="tests/*Test*.java"/>
+ <include name="tests/w3c/TestW3CSchemaTestSet.java"/>
+ </fileset>
+ </batchtest>
+
+ <sysproperty key="nistTestLocation"
+ value="${build.dir}/xmlschema2002-01-16/nisttest/NISTTestsAll"/>
+
+ </junit>
+ </target>
+
+ <target name="testw3c" depends="compile-tests" description="Runs the full bucket of W3C unit tests">
+ <junit printsummary="yes" haltonfailure="no">
+ <classpath>
+ <pathelement location="${build_classes.dir}"/>
+ <pathelement location="${test_classes.dir}"/>
+ <fileset dir="${build_lib.dir}">
+ <include name="*.jar" />
+ </fileset>
+ </classpath>
+ <formatter type="plain"/>
+ <batchtest todir="${test_reports_w3c.dir}">
+ <fileset dir="${test.dir}">
+ <include name="tests/w3c/TestW3CSchemaBucket.java"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="jar" depends="compile, test" description="compiles the src and creates XmlSchema.jar in build/lib">
+ <jar jarfile="${build_lib.dir}/${output.jar}" compress="true" basedir="${build_classes.dir}"/>
+ </target>
+
+ <target name="javadoc" depends="compile" description="Javadoc for Xml Schema API.">
+ <mkdir dir="${build_doc.dir}"/>
+ <javadoc packagenames="org.apache.axis.xsd.*"
+ destdir="${build.dir}/apidoc"
+ windowtitle="${project.name} API"
+ doctitle="${project.name}"
+ bottom="Copyright © Apache XML Schema Project. All Rights Reserved.">
+ <classpath>
+ <pathelement location="${build_classes.dir}"/>
+ </classpath>
+ <sourcepath>
+ <pathelement location="${src.dir}"/>
+ </sourcepath>
+ </javadoc>
+ </target>
+
+ <target name="clean" description="Clean all build products.">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <target name="dist" depends="jar,javadoc" description="Creates a binary distribution(XmlSchema.zip) in build/dist">
+ <mkdir dir="${dist.dir}"/>
+ <zip zipfile="${dist.dir}/${dist.zip}">
+ <zipfileset dir="${build_lib.dir}" prefix="${project.name}/lib"/>
+ <zipfileset dir="${build_doc.dir}" prefix="${project.name}/doc"/>
+ </zip>
+ </target>
+
+ <target name="srcdist" depends="compile" description="Creates a source distribution(XmlSchema-src.zip) in build/dist">
+ <mkdir dir="${dist.dir}"/>
+ <zip zipfile="${dist.dir}/${srcdist.zip}">
+ <zipfileset dir="${basedir}" includes="build.xml" prefix="${project.name}"/>
+ <zipfileset dir="${src.dir}" prefix="${project.name}/src"/>
+ </zip>
+ </target>
+
+</project>
diff --git a/XmlSchema/legal/stax-api-LICENSE.txt b/XmlSchema/legal/stax-api-LICENSE.txt
new file mode 100644
index 0000000..57bc88a
--- /dev/null
+++ b/XmlSchema/legal/stax-api-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/XmlSchema/pom.xml b/XmlSchema/pom.xml
new file mode 100644
index 0000000..68a70ab
--- /dev/null
+++ b/XmlSchema/pom.xml
@@ -0,0 +1,404 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ws.commons.schema</groupId>
+ <artifactId>XmlSchema</artifactId>
+ <name>XmlSchema</name>
+ <version>1.3</version>
+ <description>Commons XMLSchema is a light weight schema object model that can be used to manipualte or
+ generate a schema. It has a clean, easy to use API and can easily be integrated into an existing project
+ since it has almost no dependancies on third party libraries.</description>
+ <url>http://ws.apache.org/commons/XmlSchema</url>
+ <issueManagement>
+ <system>JIRA</system>
+ <url>http://issues.apache.org/jira/browse/WSCOMMONS</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Continuum</system>
+ <url>unknown</url>
+ <notifiers>
+ <notifier>
+ <sendOnError>false</sendOnError>
+ <sendOnFailure>false</sendOnFailure>
+ <sendOnSuccess>false</sendOnSuccess>
+ <sendOnWarning>false</sendOnWarning>
+ <configuration>
+ <address>commons-dev@ws.apache.org</address>
+ </configuration>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+ <mailingLists>
+ <mailingList>
+ <name>WS Commons Developers</name>
+ <subscribe>commons-dev-subscribe@ws.apache.org</subscribe>
+ <unsubscribe>commons-dev-unsubscribe@ws.apache.org</unsubscribe>
+ <post>commons-dev@ws.apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/ws-commons-dev/</archive>
+ </mailingList>
+ </mailingLists>
+ <inceptionYear>2004</inceptionYear>
+ <developers>
+ <developer>
+ <id>dims</id>
+ <name>Davanum Srinivas</name>
+ <email>dims AT wso2.com</email>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>sanjiva</id>
+ <name>Sanjiva Weerawarana</name>
+ <email>sanjiva AT wso2.com</email>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>gdaniels</id>
+ <name>Glen Daniels</name>
+ <email>gdaniels AT apache.org</email>
+ <organization>Sonic Software</organization>
+ </developer>
+ <developer>
+ <id>alek</id>
+ <name>Aleksander Slominski</name>
+ <email>aslom AT cs.indiana.edu</email>
+ <organization>Indiana University Extreme! Computing Lab</organization>
+ </developer>
+ <developer>
+ <id>hemapani</id>
+ <name>Srinath Perera</name>
+ <email>hemapani AT apache.org</email>
+ <url>http://www.apache.org/~hemapani</url>
+ <organization>Lanka Software Foundation</organization>
+ </developer>
+ <developer>
+ <id>chinthaka</id>
+ <name>Eran Chinthaka</name>
+ <email>chinthaka AT wso2.com</email>
+ <url>http://www.apache.org/~chinthaka</url>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>dasarath</id>
+ <name>Dasarath Weerathunga</name>
+ <email>dasarath AT opensource.lk</email>
+ <organization>Lanka Software Foundation</organization>
+ </developer>
+ <developer>
+ <id>jaliya</id>
+ <name>Jaliya Ekanayake</name>
+ <email>jaliya AT opensource.lk</email>
+ <url>http://www.apache.org/~jaliya</url>
+ <organization>Virtusa / Lanka Software Foundation</organization>
+ </developer>
+ <developer>
+ <id>chathura</id>
+ <name>Chathura Herath</name>
+ <email>chathura AT opensource.lk</email>
+ <url>www.apache.org/~chathura</url>
+ <organization>LSF/MIT</organization>
+ </developer>
+ <developer>
+ <id>deepal</id>
+ <name>Deepal Jayasinghe</name>
+ <email>deepal AT wso2.com</email>
+ <url>http://www.apache.org/~deepal</url>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>ajith</id>
+ <name>Ajith Ranabahu</name>
+ <email>ajith AT apache.org</email>
+ <url>http://www.apache.org/~ajith</url>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>venkat</id>
+ <name>Venkat Reddy</name>
+ <email>vreddyp AT gmail.com</email>
+ <organization>Computer Associates</organization>
+ </developer>
+ <developer>
+ <id>ashu</id>
+ <name>Ashutosh Shahi</name>
+ <email>Ashutosh.Shahi AT ca.com</email>
+ <organization>Computer Associates</organization>
+ </developer>
+ <developer>
+ <id>jaya</id>
+ <name>Jayachandra Sekhara Rao Sunkara</name>
+ <email>jayachandra AT gmail.com</email>
+ <organization>Computer Associates</organization>
+ </developer>
+ <developer>
+ <id>thilina</id>
+ <name>Thilina Gunarathne</name>
+ <email>thilina AT wso2.com</email>
+ <url>http://www.apache.org/~thilina</url>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>ruchith</id>
+ <name>Ruchith Fernando</name>
+ <email>ruchith AT wso2.com</email>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>saminda</id>
+ <name>Saminda Abeyruwan</name>
+ <email>saminda AT wso2.com</email>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>chamil</id>
+ <name>Chamil Thanthrimudalige</name>
+ <email>chamil AT wso2.com</email>
+ <organization>WSO2</organization>
+ </developer>
+ <developer>
+ <id>dandiep</id>
+ <name>Dan Diephouse</name>
+ <email>dandiep AT apache.org</email>
+ <organization>Envoi Solutions</organization>
+ </developer>
+ </developers>
+ <licenses>
+ <license>
+ <name>The Apache Software License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/XmlSchema</connection>
+ <developerConnection>
+ scm:svn:https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/XmlSchema</developerConnection>
+ <url>http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema</url>
+ </scm>
+ <organization>
+ <name>Apache Software Foundation</name>
+ <url>http://www.apache.org/</url>
+ </organization>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <id>prepareNistTest</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <ant inheritRefs="true" antfile="${basedir}/build.xml">
+ <property value="${basedir}/target" name="build.dir"></property>
+ <property value="${maven.test.skip}" name="maven.test.skip"></property>
+ <target name="prepareNistTest"></target>
+ </ant>
+ </tasks>
+ </configuration>
+ </execution>
+ <execution>
+ <id>prepareLicenseFiles</id>
+ <phase>generate-resources</phase>
+ <configuration>
+ <tasks>
+ <copy todir="${project.build.outputDirectory}/META-INF">
+ <fileset dir="${basedir}">
+ <include name="LICENSE.txt"/>
+ <include name="NOTICE.txt"/>
+ </fileset>
+ </copy>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-one-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>install-maven-one-repository</goal>
+ <goal>deploy-maven-one-repository</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <remoteRepositoryId>apache</remoteRepositoryId>
+ <remoteRepositoryUrl>scpexe://people.apache.org/www/people.apache.org/repo/m1-snapshot-repository</remoteRepositoryUrl>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <tagBase>https://svn.apache.org/repos/asf/webservices/commons/tags/XmlSchema</tagBase>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.3</source>
+ <target>1.3</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <!--
+ Required to run the TestW3CSchemaBucket test
+ <version>2.3-SNAPSHOT</version>
+ -->
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ <!-- Fails in about half of the tests
+ <include>tests/w3c/TestW3CSchemaBucket.java</include>
+ -->
+ </includes>
+ <excludes>
+ <exclude>tests/w3c/SchemaTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/bin.xml</descriptor>
+ <descriptor>src/main/assembly/src.xml</descriptor>
+ </descriptors>
+ <tarLongFileMode>gnu</tarLongFileMode>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <attach>true</attach>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>release</id>
+ <activation>
+ <property>
+ <name>release</name>
+ <value></value>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <attach>true</attach>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>snapshot</id>
+ <name>Snapshot repository</name>
+ <url>http://snapshots.maven.codehaus.org/maven2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </pluginRepository>
+ <pluginRepository>
+ <id>snapshot-apache</id>
+ <name>Apache Snapshot repository</name>
+ <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons</groupId>
+ <artifactId>ws-commons-java5</artifactId>
+ <version>1.0.1</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+ <reporting>
+ <plugins>
+ <!--plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin-->
+ <plugin>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jdepend-maven-plugin</artifactId>
+ <version>2.0-beta-1-SNAPSHOT</version>
+ </plugin>
+ <!--plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jxr-maven-plugin</artifactId>
+ <version>2.0-beta-2-SNAPSHOT</version>
+ </plugin-->
+ </plugins>
+ </reporting>
+ <distributionManagement>
+ <repository>
+ <id>apache-repo</id>
+ <name>Maven Central Repository</name>
+ <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-ibiblio-rsync-repository</url>
+ </repository>
+ <snapshotRepository>
+ <id>apache-snapshots</id>
+ <name>Apache Development Repository</name>
+ <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+ </snapshotRepository>
+ <site>
+ <id>website</id>
+ <url>scpexe://people.apache.org/www/ws.apache.org/commons/XmlSchema</url>
+ </site>
+ </distributionManagement>
+</project>
diff --git a/XmlSchema/src/main/assembly/bin.xml b/XmlSchema/src/main/assembly/bin.xml
new file mode 100644
index 0000000..37f40fa
--- /dev/null
+++ b/XmlSchema/src/main/assembly/bin.xml
@@ -0,0 +1,33 @@
+<assembly>
+ <id>bin</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeSiteDirectory>true</includeSiteDirectory>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>*.txt</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target</directory>
+ <outputDirectory></outputDirectory>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ <!-- exclude sources -->
+ <excludes>
+ <exclude>*-sources.jar</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/lib</outputDirectory>
+ <!--<includes>-->
+ <!--<include>org.apache.ws.commons:ws-commons-java5</include>-->
+ <!--</includes>-->
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/XmlSchema/src/main/assembly/src.xml b/XmlSchema/src/main/assembly/src.xml
new file mode 100644
index 0000000..e8313d4
--- /dev/null
+++ b/XmlSchema/src/main/assembly/src.xml
@@ -0,0 +1,23 @@
+<assembly>
+ <id>src</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>*.txt</include>
+ <include>*.xml</include>
+ <include>*.properties</include>
+ <!--<include>.classpath</include>-->
+ <!--<include>.project</include>-->
+ </includes>
+ </fileSet>
+ <!--<fileSet>-->
+ <!--<directory>.settings</directory>-->
+ <!--</fileSet>-->
+ <fileSet>
+ <directory>src</directory>
+ </fileSet>
+ </fileSets>
+</assembly>
\ No newline at end of file
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
new file mode 100644
index 0000000..11a3fd8
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/SchemaBuilder.java
@@ -0,0 +1,1917 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.XmlSchemaCollection.SchemaKey;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+import org.apache.ws.commons.schema.utils.NodeNamespaceContext;
+import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
+import org.apache.ws.commons.schema.utils.XDOMUtil;
+import org.w3c.dom.*;
+import org.xml.sax.InputSource;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class SchemaBuilder {
+ Document doc;
+ XmlSchema schema;
+ XmlSchemaCollection collection;
+ private final TargetNamespaceValidator validator;
+ DocumentBuilderFactory docFac;
+
+ /**
+ * The extension registry to be used while building the
+ * schema model
+ */
+ private ExtensionRegistry extReg = null;
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+ /**
+ * Schema builder constructor
+ * @param collection
+ */
+ SchemaBuilder(XmlSchemaCollection collection, TargetNamespaceValidator validator) {
+ this.collection = collection;
+ this.validator = validator;
+
+ if (collection.getExtReg()!=null){
+ this.extReg = collection.getExtReg();
+ }
+
+ schema = new XmlSchema(collection);
+ }
+
+ /**
+ * build method taking in a document and a validation handler
+ * @param doc
+ * @param uri
+ * @param veh
+ */
+ XmlSchema build(Document doc, String uri, ValidationEventHandler veh) {
+ Element schemaEl = doc.getDocumentElement();
+ return handleXmlSchemaElement(schemaEl, uri);
+ }
+
+ /**
+ * handles the schema element
+ * @param schemaEl
+ * @param uri
+ */
+ XmlSchema handleXmlSchemaElement(Element schemaEl, String uri) {
+ // get all the attributes along with the namespace declns
+ schema.setNamespaceContext(new NodeNamespaceContext(schemaEl));
+ setNamespaceAttributes(schema, schemaEl);
+
+ XmlSchemaCollection.SchemaKey schemaKey = new XmlSchemaCollection.SchemaKey(schema.logicalTargetNamespace, uri);
+ if (!collection.containsSchema(schemaKey)) {
+ collection.addSchema(schemaKey, schema);
+ }
+
+ schema.setElementFormDefault(this.getFormDefault(schemaEl,
+ "elementFormDefault"));
+ schema.setAttributeFormDefault(this.getFormDefault(schemaEl,
+ "attributeFormDefault"));
+ schema.setBlockDefault(this.getDerivation(schemaEl, "blockDefault"));
+ schema.setFinalDefault(this.getDerivation(schemaEl, "finalDefault"));
+ /* set id attribute */
+ if (schemaEl.hasAttribute("id")) {
+ schema.id = schemaEl.getAttribute("id");
+ }
+
+ schema.setSourceURI(uri);
+
+ /***********
+ * for ( each childElement)
+ * if( simpleTypeElement)
+ * handleSimpleType
+ * else if( complexType)
+ * handleComplexType
+ * else if( element)
+ * handleElement
+ * else if( include)
+ * handleInclude
+ * else if( import)
+ * handleImport
+ * else if (group)
+ * handleGroup
+ * else if (attributeGroup)
+ * handleattributeGroup
+ * else if( attribute)
+ * handleattribute
+ * else if (redefine)
+ * handleRedefine
+ * else if(notation)
+ * handleNotation
+ * else if (annotation)
+ * handleAnnotation
+ */
+
+ Element el = XDOMUtil.getFirstChildElementNS(schemaEl, XmlSchema.SCHEMA_NS);
+ if (el == null && XDOMUtil.getFirstChildElementNS(schemaEl, "http://www.w3.org/1999/XMLSchema") != null) {
+ throw new XmlSchemaException("Schema defined using \"http://www.w3.org/1999/XMLSchema\" is not supported. " +
+ "Please update the schema to the \"" + XmlSchema.SCHEMA_NS + "\" namespace");
+ }
+ for (; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ // String elPrefix = el.getPrefix() == null ? "" : el.getPrefix();
+ //if(elPrefix.equals(schema.schema_ns_prefix)) {
+ if (el.getLocalName().equals("simpleType")) {
+ XmlSchemaType type = handleSimpleType(schema, el, schemaEl);
+ schema.addType(type);
+ schema.items.add(type);
+ collection.resolveType(type.getQName(), type);
+ } else if (el.getLocalName().equals("complexType")) {
+ XmlSchemaType type = handleComplexType(schema, el, schemaEl);
+ schema.addType(type);
+ schema.items.add(type);
+ collection.resolveType(type.getQName(), type);
+ } else if (el.getLocalName().equals("element")) {
+ XmlSchemaElement element = handleElement(schema, el, schemaEl, true);
+ if (element.qualifiedName != null)
+ schema.elements.collection.put(element.qualifiedName, element);
+ else if (element.refName != null)
+ schema.elements.collection.put(element.refName, element);
+ schema.items.add(element);
+ } else if (el.getLocalName().equals("include")) {
+ XmlSchemaInclude include = handleInclude(schema,
+ el, schemaEl);
+ schema.includes.add(include);
+ schema.items.add(include);
+
+ } else if (el.getLocalName().equals("import")) {
+ XmlSchemaImport schemaImport = handleImport(schema,
+ el, schemaEl);
+ schema.includes.add(schemaImport);
+ schema.items.add(schemaImport);
+
+ } else if (el.getLocalName().equals("group")) {
+ XmlSchemaGroup group = handleGroup(schema, el, schemaEl);
+ schema.groups.collection.put(
+ new QName(schema.getTargetNamespace(), group.name), group);
+ schema.items.add(group);
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ XmlSchemaAttributeGroup group = handleAttributeGroup(schema,
+ el, schemaEl);
+ schema.attributeGroups.collection.put(
+ new QName(schema.getTargetNamespace(), group.name), group);
+ schema.items.add(group);
+ } else if (el.getLocalName().equals("attribute")) {
+ XmlSchemaAttribute attr = handleAttribute(schema,
+ el, schemaEl);
+ schema.attributes.collection.put(attr.qualifiedName, attr);
+ schema.items.add(attr);
+ } else if (el.getLocalName().equals("redefine")) {
+ XmlSchemaRedefine redefine = handleRedefine(schema,
+ el, schemaEl);
+ schema.includes.add(redefine);
+ } else if (el.getLocalName().equals("notation")) {
+ XmlSchemaNotation notation = handleNotation(el);
+ schema.notations.collection.put(
+ new QName(schema.getTargetNamespace(), notation.name), notation);
+ schema.items.add(notation);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
+ schema.setAnnotation(annotation);
+ }
+ }
+
+ //add the extesibility components
+ processExtensibilityComponents(schema,schemaEl);
+
+ return schema;
+ }
+
+ private XmlSchemaNotation handleNotation(
+ Element notationEl
+ ) {
+
+ XmlSchemaNotation notation = new XmlSchemaNotation();
+
+ if (notationEl.hasAttribute("id")) {
+ notation.id = notationEl.getAttribute("id");
+ }
+
+ if (notationEl.hasAttribute("name")) {
+ notation.name = notationEl.getAttribute("name");
+ }
+
+ if (notationEl.hasAttribute("public")) {
+ notation.publicNotation = notationEl.getAttribute("public");
+ }
+
+ if (notationEl.hasAttribute("system")) {
+ notation.system = notationEl.getAttribute("system");
+ }
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(notationEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation = handleAnnotation(annotationEl);
+ notation.setAnnotation(annotation);
+ }
+
+ return notation;
+ }
+
+ private XmlSchemaRedefine handleRedefine(XmlSchema schema,
+ Element redefineEl, Element schemaEl) {
+
+ XmlSchemaRedefine redefine = new XmlSchemaRedefine();
+ redefine.schemaLocation =
+ redefineEl.getAttribute("schemaLocation");
+ final TargetNamespaceValidator validator = newIncludeValidator(schema);
+ redefine.schema =
+ resolveXmlSchema(schema.logicalTargetNamespace, redefine.schemaLocation, validator);
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(redefineEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("simpleType")) {
+ XmlSchemaType type =
+ handleSimpleType(schema, el, schemaEl);
+
+ redefine.schemaTypes.collection.put(type.getQName(),
+ type);
+ redefine.items.add(type);
+ } else if (el.getLocalName().equals("complexType")) {
+
+ XmlSchemaType type = handleComplexType(schema, el,
+ schemaEl);
+
+ redefine.schemaTypes.collection.put(type.getQName(),
+ type);
+ redefine.items.add(type);
+ } else if (el.getLocalName().equals("group")) {
+ XmlSchemaGroup group = handleGroup(schema, el,
+ schemaEl);
+ redefine.groups.collection.put(group.name, group);
+ redefine.items.add(group);
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ XmlSchemaAttributeGroup group =
+ handleAttributeGroup(schema, el, schemaEl);
+
+ redefine.attributeGroups.collection.put(group.name, group);
+ redefine.items.add(group);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
+ redefine.setAnnotation(annotation);
+ }
+ // }
+ }
+ return redefine;
+ }
+
+ void setNamespaceAttributes(XmlSchema schema, Element schemaEl) {
+ //no targetnamespace found !
+ if (schemaEl.getAttributeNode("targetNamespace") != null) {
+ String contain = schemaEl.getAttribute("targetNamespace");
+ schema.setTargetNamespace(contain);
+ } else {
+ //do nothing here
+ }
+ if (validator != null) {
+ validator.validate(schema);
+ }
+ }
+
+ /**
+ * Handles simple types
+ * @param schema
+ * @param simpleEl
+ * @param schemaEl
+ */
+ XmlSchemaSimpleType handleSimpleType(XmlSchema schema,
+ Element simpleEl, Element schemaEl) {
+ XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(schema);
+ if (simpleEl.hasAttribute("name")) {
+ simpleType.name = simpleEl.getAttribute("name");
+ }
+
+ if (simpleEl.hasAttribute("final")) {
+ String finalstr = simpleEl.getAttribute("final");
+
+ if (finalstr.equalsIgnoreCase("all") |
+ finalstr.equalsIgnoreCase("#all"))
+
+ simpleType.setFinal(new XmlSchemaDerivationMethod(Constants.BlockConstants.ALL));
+ else
+ simpleType.setFinal(new XmlSchemaDerivationMethod(finalstr));
+ }
+
+ Element simpleTypeAnnotationEl =
+ XDOMUtil.getFirstChildElementNS(simpleEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (simpleTypeAnnotationEl != null) {
+ XmlSchemaAnnotation simpleTypeAnnotation =
+ handleAnnotation(simpleTypeAnnotationEl);
+
+ simpleType.setAnnotation(simpleTypeAnnotation);
+ }
+
+ Element unionEl, listEl, restrictionEl;
+
+ if ((restrictionEl =
+ XDOMUtil.getFirstChildElementNS(simpleEl, XmlSchema.SCHEMA_NS, "restriction")) != null) {
+
+ XmlSchemaSimpleTypeRestriction restriction =
+ new XmlSchemaSimpleTypeRestriction();
+
+ Element restAnnotationEl =
+ XDOMUtil.getFirstChildElementNS(restrictionEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (restAnnotationEl != null) {
+ XmlSchemaAnnotation restAnnotation =
+ handleAnnotation(restAnnotationEl);
+ restriction.setAnnotation(restAnnotation);
+ }
+ /** if (restriction has a base attribute )
+ * set the baseTypeName and look up the base type
+ * else if( restricion has a SimpleType Element as child)
+ * get that element and do a handleSimpleType;
+ * get the children of restriction other than annotation
+ * and simpleTypes and construct facets from it;
+ *
+ * set the restriction has the content of the simpleType
+ *
+ **/
+
+ Element inlineSimpleType =
+ XDOMUtil.getFirstChildElementNS(restrictionEl,
+ XmlSchema.SCHEMA_NS, "simpleType");
+
+ if (restrictionEl.hasAttribute("base")) {
+ NamespaceContext ctx = new NodeNamespaceContext(restrictionEl);
+ restriction.baseTypeName = getRefQName(restrictionEl.getAttribute("base"), ctx);
+ } else if (inlineSimpleType != null) {
+
+ restriction.baseType = handleSimpleType(schema, inlineSimpleType, schemaEl);
+ }
+ for (Element el = XDOMUtil.getFirstChildElementNS(restrictionEl, XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (!el.getLocalName().equals("annotation")
+ &&
+ !el.getLocalName().equals("simpleType")) {
+
+ XmlSchemaFacet facet = XmlSchemaFacet.construct(el);
+ Element annotation =
+ XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS,
+ "annotation");
+
+ if (annotation != null) {
+ XmlSchemaAnnotation facetAnnotation =
+ handleAnnotation(annotation);
+ facet.setAnnotation(facetAnnotation);
+ }
+ restriction.facets.add(facet);
+ }
+
+ }
+ simpleType.content = restriction;
+
+ } else if ((listEl = XDOMUtil.getFirstChildElementNS(simpleEl,
+ XmlSchema.SCHEMA_NS, "list")) != null) {
+
+ XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
+
+ /******
+ * if( list has an itemType attribute )
+ * set the baseTypeName and look up the base type
+ * else if( list has a SimpleTypeElement as child)
+ * get that element and do a handleSimpleType
+ *
+ * set the list has the content of the simpleType
+ */
+ Element inlineListType, listAnnotationEl;
+ if (listEl.hasAttribute("itemType")) {
+ String name = listEl.getAttribute("itemType");
+ list.itemTypeName = getRefQName(name, listEl);
+ } else if ((inlineListType =
+ XDOMUtil.getFirstChildElementNS(listEl, XmlSchema.SCHEMA_NS,
+ "simpleType")) != null) {
+
+ list.itemType = handleSimpleType(schema, inlineListType, schemaEl);
+ }
+
+ if ((listAnnotationEl =
+ XDOMUtil.getFirstChildElementNS(listEl, XmlSchema.SCHEMA_NS,
+ "annotation")) != null) {
+
+ XmlSchemaAnnotation listAnnotation =
+ handleAnnotation(listAnnotationEl);
+
+ list.setAnnotation(listAnnotation);
+ }
+ simpleType.content = list;
+
+ } else if ((unionEl =
+ XDOMUtil.getFirstChildElementNS(simpleEl, XmlSchema.SCHEMA_NS,
+ "union")) != null) {
+
+ XmlSchemaSimpleTypeUnion union =
+ new XmlSchemaSimpleTypeUnion();
+
+ /******
+ * if( union has a memberTypes attribute )
+ * add the memberTypeSources string
+ * for (each memberType in the list )
+ * lookup(memberType)
+ * for( all SimpleType child Elements)
+ * add the simpleTypeName (if any) to the memberType Sources
+ * do a handleSimpleType with the simpleTypeElement
+ */
+ if (unionEl.hasAttribute("memberTypes")) {
+ String memberTypes = unionEl.getAttribute("memberTypes");
+ union.memberTypesSource = memberTypes;
+ Vector v = new Vector();
+ StringTokenizer tokenizer = new StringTokenizer(memberTypes, " ");
+ while (tokenizer.hasMoreTokens()) {
+ String member = tokenizer.nextToken();
+ v.add(getRefQName(member, unionEl));
+ }
+ union.memberTypesQNames = new QName[v.size()];
+ v.copyInto(union.memberTypesQNames);
+ }
+
+ Element inlineUnionType =
+ XDOMUtil.getFirstChildElementNS(unionEl, XmlSchema.SCHEMA_NS,
+ "simpleType");
+ while (inlineUnionType != null) {
+
+ XmlSchemaSimpleType unionSimpleType =
+ handleSimpleType(schema, inlineUnionType,
+ schemaEl);
+
+ union.baseTypes.add(unionSimpleType);
+
+ if(unionSimpleType.name != null) {
+ union.memberTypesSource += " " + unionSimpleType.name;
+ }
+
+ inlineUnionType =
+ XDOMUtil.getNextSiblingElementNS(inlineUnionType,
+ XmlSchema.SCHEMA_NS,
+ "simpleType");
+ }
+
+ //NodeList annotations = unionEl.getElementsByTagNameNS(
+ //XmlSchema.SCHEMA_NS, "annotation");
+ Element unionAnnotationEl =
+ XDOMUtil.getFirstChildElementNS(unionEl, XmlSchema.SCHEMA_NS,
+ "annotation");
+
+ if (unionAnnotationEl != null) {
+ XmlSchemaAnnotation unionAnnotation =
+ handleAnnotation(unionAnnotationEl);
+
+ union.setAnnotation(unionAnnotation);
+ }
+ simpleType.content = union;
+ }
+
+ //process extra attributes and elements
+ processExtensibilityComponents(simpleType,simpleEl);
+
+ return simpleType;
+ }
+
+ private QName getRefQName(String pName, Node pNode) {
+ return getRefQName(pName, new NodeNamespaceContext(pNode));
+ }
+
+ private QName getRefQName(String pName, NamespaceContext pContext) {
+ final int offset = pName.indexOf(':');
+ String uri;
+ final String localName;
+ final String prefix;
+ if (offset == -1) {
+ uri = pContext.getNamespaceURI(Constants.DEFAULT_NS_PREFIX);
+ if (Constants.NULL_NS_URI.equals(uri)) {
+ return new QName(schema.logicalTargetNamespace, pName);
+ }
+ localName = pName;
+ prefix = Constants.DEFAULT_NS_PREFIX;
+ } else {
+ prefix = pName.substring(0, offset);
+ uri = pContext.getNamespaceURI(prefix);
+ if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
+ if(schema.parent != null && schema.parent.getNamespaceContext() != null) {
+ uri = schema.parent.getNamespaceContext().getNamespaceURI(prefix);
+ }
+ }
+
+ if (uri == null || Constants.NULL_NS_URI.equals(uri)) {
+ throw new IllegalStateException("The prefix " + prefix + " is not bound.");
+ }
+ localName = pName.substring(offset+1);
+ }
+ return new QName(uri, localName, prefix);
+ }
+
+ /**
+ * Handle complex types
+ * @param schema
+ * @param complexEl
+ * @param schemaEl
+ */
+ XmlSchemaComplexType handleComplexType(XmlSchema schema,
+ Element complexEl, Element schemaEl) {
+
+ /******
+ * set the complexTypeName if any
+ * for( eachChildNode)
+ * if ( simpleContent)
+ * if( restrcition)
+ * handle_simple_content_restriction
+ * else if( extension)
+ * handle_simple_content_extension
+ * break; // it has to be the only child
+ * else if( complexContent)
+ * if( restriction)
+ * handle_complex_content_restriction
+ * else if( extension)
+ * handle_complex_content_extension
+ * break; // it has to be the only child
+ * else if( group)
+ * if( group has ref)
+ * store the group name
+ * else
+ * handleGroup
+ * else if( sequence )
+ * handleSequence
+ * else if( all )
+ * handleAll
+ * else if(choice)
+ * handleChoice
+ * else if(attribute)
+ * handleAttribute
+ * else if(attributeGroup)
+ * handleAttributeGroup
+ * else if(anyAttribute)
+ * handleAnyAttribute
+ */
+
+ XmlSchemaComplexType ct = new XmlSchemaComplexType(schema);
+
+ if (complexEl.hasAttribute("name")) {
+
+ //String namespace = (schema.targetNamespace==null)?
+ // "":schema.targetNamespace;
+
+ ct.name = complexEl.getAttribute("name");
+ }
+ for (Element el = XDOMUtil.getFirstChildElementNS(complexEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ //String elPrefix = el.getPrefix() == null ? "" :
+ //el.getPrefix();
+ //if(elPrefix.equals(schema.schema_ns_prefix)) {
+ if (el.getLocalName().equals("sequence")) {
+ ct.particle = handleSequence(schema,
+ el, schemaEl);
+ } else if (el.getLocalName().equals("choice")) {
+ ct.particle = handleChoice(schema,
+ el, schemaEl);
+ } else if (el.getLocalName().equals("all")) {
+ ct.particle = handleAll(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("attribute")) {
+ ct.attributes.add(handleAttribute(schema,
+ el, schemaEl));
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ ct.attributes.add(handleAttributeGroupRef(el));
+ } else if (el.getLocalName().equals("group")) {
+ XmlSchemaGroupRef group =
+ handleGroupRef(schema, el, schemaEl);
+ ct.particle = (group.particle == null) ?
+ (XmlSchemaParticle) group : group.particle;
+ } else if (el.getLocalName().equals("simpleContent")) {
+ ct.contentModel = handleSimpleContent(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("complexContent")) {
+ ct.contentModel = handleComplexContent(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ ct.setAnnotation(handleAnnotation(el));
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ ct.setAnyAttribute(handleAnyAttribute(schema,el,schemaEl));
+ }
+ //}
+ }
+ if (complexEl.hasAttribute("block")) {
+ String blockStr = complexEl.getAttribute("block");
+ if (blockStr.equalsIgnoreCase("all") |
+ blockStr.equalsIgnoreCase("#all")) {
+
+ ct.setBlock(new XmlSchemaDerivationMethod(Constants.BlockConstants.ALL));
+ } else
+ ct.setBlock(new XmlSchemaDerivationMethod(blockStr));
+ //ct.setBlock(new XmlSchemaDerivationMethod(block));
+ }
+ if (complexEl.hasAttribute("final")) {
+ String finalstr = complexEl.getAttribute("final");
+ if (finalstr.equalsIgnoreCase("all") |
+ finalstr.equalsIgnoreCase("#all")) {
+
+ ct.setFinal(new XmlSchemaDerivationMethod(Constants.BlockConstants.ALL));
+ } else
+ ct.setFinal(new XmlSchemaDerivationMethod(finalstr));
+ }
+ if (complexEl.hasAttribute("abstract")) {
+ String abs = complexEl.getAttribute("abstract");
+ if (abs.equalsIgnoreCase("true"))
+ ct.setAbstract(true);
+ else
+ ct.setAbstract(false);
+ }
+ if (complexEl.hasAttribute("mixed")) {
+ String mixed = complexEl.getAttribute("mixed");
+ if (mixed.equalsIgnoreCase("true"))
+ ct.setMixed(true);
+ else
+ ct.setMixed(false);
+ }
+
+ //process extra attributes and elements
+ processExtensibilityComponents(ct,complexEl);
+
+ return ct;
+ }
+
+ private XmlSchemaSimpleContent
+ handleSimpleContent(XmlSchema schema, Element simpleEl,
+ Element schemaEl) {
+
+ XmlSchemaSimpleContent simpleContent =
+ new XmlSchemaSimpleContent();
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(simpleEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("restriction")) {
+ simpleContent.content = handleSimpleContentRestriction(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("extension")) {
+ simpleContent.content = handleSimpleContentExtension(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ simpleContent.setAnnotation(handleAnnotation(el));
+ }
+ }
+ return simpleContent;
+ }
+
+ private XmlSchemaComplexContent handleComplexContent(XmlSchema schema,
+ Element complexEl,
+ Element schemaEl) {
+
+ XmlSchemaComplexContent complexContent =
+ new XmlSchemaComplexContent();
+
+ for (Element el =
+ XDOMUtil.getFirstChildElementNS(complexEl, XmlSchema.SCHEMA_NS);
+ el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("restriction")) {
+ complexContent.content = handleComplexContentRestriction(schema, el,
+ schemaEl);
+ } else if (el.getLocalName().equals("extension")) {
+ complexContent.content = handleComplexContentExtension(schema, el,
+ schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ complexContent.setAnnotation(handleAnnotation(el));
+ }
+ }
+ return complexContent;
+ }
+
+ private XmlSchemaSimpleContentRestriction
+ handleSimpleContentRestriction(XmlSchema schema,
+ Element restrictionEl, Element schemaEl) {
+
+ XmlSchemaSimpleContentRestriction restriction =
+ new XmlSchemaSimpleContentRestriction();
+
+ if (restrictionEl.hasAttribute("base")) {
+ String name = restrictionEl.getAttribute("base");
+ restriction.baseTypeName = getRefQName(name, restrictionEl);
+ }
+
+ if (restrictionEl.hasAttribute("id"))
+ restriction.id = restrictionEl.getAttribute("id");
+
+ // check back simpleContent tag children to add attributes and simpleType if any occur
+ for (
+ Element el = XDOMUtil.getFirstChildElementNS(restrictionEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("attribute")) {
+ XmlSchemaAttribute attr =
+ handleAttribute(schema, el, schemaEl);
+ restriction.attributes.add(attr);
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ XmlSchemaAttributeGroupRef attrGroup =
+ handleAttributeGroupRef(el);
+ restriction.attributes.add(attrGroup);
+ } else if (el.getLocalName().equals("simpleType")) {
+ restriction.baseType = handleSimpleType(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ restriction.anyAttribute =
+ handleAnyAttribute(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ restriction.setAnnotation(handleAnnotation(el));
+ } else {
+ XmlSchemaFacet facet = XmlSchemaFacet.construct(el);
+ NodeList annotations =
+ el.getElementsByTagNameNS(XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotations.getLength() > 0) {
+ XmlSchemaAnnotation facetAnnotation =
+ handleAnnotation(el);
+ facet.setAnnotation(facetAnnotation);
+ }
+ restriction.facets.add(facet);
+ }
+ }
+ return restriction;
+ }
+
+ private XmlSchemaSimpleContentExtension
+ handleSimpleContentExtension(XmlSchema schema, Element extEl,
+ Element schemaEl) {
+
+ XmlSchemaSimpleContentExtension ext =
+ new XmlSchemaSimpleContentExtension();
+
+ if (extEl.hasAttribute("base")) {
+ String name = extEl.getAttribute("base");
+ ext.baseTypeName = getRefQName(name, extEl);
+ }
+
+ for (
+ Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("attribute")) {
+ XmlSchemaAttribute attr =
+ handleAttribute(schema, el, schemaEl);
+ ext.attributes.add(attr);
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ XmlSchemaAttributeGroupRef attrGroup =
+ handleAttributeGroupRef(el);
+ ext.attributes.add(attrGroup);
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ ext.anyAttribute =
+ handleAnyAttribute(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation ann = handleAnnotation(el);
+ ext.setAnnotation(ann);
+ }
+ }
+ return ext;
+ }
+
+ private XmlSchemaComplexContentRestriction
+ handleComplexContentRestriction(XmlSchema schema,
+ Element restrictionEl, Element schemaEl) {
+
+ XmlSchemaComplexContentRestriction restriction =
+ new XmlSchemaComplexContentRestriction();
+
+ if (restrictionEl.hasAttribute("base")) {
+ String name = restrictionEl.getAttribute("base");
+ restriction.baseTypeName = getRefQName(name, restrictionEl);
+ }
+ for (Element el = XDOMUtil.getFirstChildElementNS(restrictionEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("sequence")) {
+ restriction.particle = handleSequence(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("choice")) {
+ restriction.particle = handleChoice(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("all")) {
+ restriction.particle = handleAll(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("attribute")) {
+ restriction.attributes.add(handleAttribute(schema, el, schemaEl));
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ restriction.attributes.add(handleAttributeGroupRef(el));
+ } else if (el.getLocalName().equals("group")) {
+ restriction.particle = handleGroupRef(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ restriction.anyAttribute =
+ handleAnyAttribute(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ restriction.setAnnotation(handleAnnotation(el));
+ }
+ }
+ return restriction;
+ }
+
+ private XmlSchemaComplexContentExtension
+ handleComplexContentExtension(XmlSchema schema,
+ Element extEl, Element schemaEl) {
+
+ XmlSchemaComplexContentExtension ext =
+ new XmlSchemaComplexContentExtension();
+
+ if (extEl.hasAttribute("base")) {
+ String name = extEl.getAttribute("base");
+ ext.baseTypeName = getRefQName(name, extEl);
+ }
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(extEl, XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("sequence")) {
+ ext.particle = handleSequence(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("choice")) {
+ ext.particle = handleChoice(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("all")) {
+ ext.particle = handleAll(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("attribute")) {
+ ext.attributes.add(handleAttribute(schema, el, schemaEl));
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ ext.attributes.add(handleAttributeGroupRef(el));
+ } else if (el.getLocalName().equals("group")) {
+ ext.particle = handleGroupRef(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ ext.anyAttribute =
+ handleAnyAttribute(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ ext.setAnnotation(handleAnnotation(el));
+ }
+ }
+ return ext;
+ }
+
+ private XmlSchemaAttributeGroupRef
+ handleAttributeGroupRef(Element attrGroupEl
+ ) {
+
+ XmlSchemaAttributeGroupRef attrGroup =
+ new XmlSchemaAttributeGroupRef();
+
+ if (attrGroupEl.hasAttribute("ref")) {
+ String ref = attrGroupEl.getAttribute("ref");
+ attrGroup.refName = getRefQName(ref, attrGroupEl);
+ }
+
+ if (attrGroupEl.hasAttribute("id"))
+ attrGroup.id = attrGroupEl.getAttribute("id");
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(attrGroupEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation = handleAnnotation(annotationEl);
+ attrGroup.setAnnotation(annotation);
+ }
+ return attrGroup;
+ }
+
+ private XmlSchemaSequence handleSequence(XmlSchema schema,
+ Element sequenceEl,
+ Element schemaEl) {
+
+ XmlSchemaSequence sequence = new XmlSchemaSequence();
+ for (Element el = XDOMUtil.getFirstChildElementNS(sequenceEl, XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("sequence")) {
+ XmlSchemaSequence seq = handleSequence(schema, el,
+ schemaEl);
+ sequence.items.add(seq);
+ } else if (el.getLocalName().equals("element")) {
+ XmlSchemaElement element = handleElement(schema, el,
+ schemaEl, false);
+ sequence.items.add(element);
+ } else if (el.getLocalName().equals("group")) {
+ XmlSchemaGroupRef group = handleGroupRef(schema, el,
+ schemaEl);
+ sequence.items.add(group);
+ } else if (el.getLocalName().equals("choice")) {
+ XmlSchemaChoice choice = handleChoice(schema, el,
+ schemaEl);
+ sequence.items.add(choice);
+ } else if (el.getLocalName().equals("any")) {
+ XmlSchemaAny any = handleAny(schema, el, schemaEl);
+ sequence.items.add(any);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
+ sequence.setAnnotation(annotation);
+ }
+ }
+ return sequence;
+ }
+
+ /** @noinspection UnusedParameters*/
+ private XmlSchemaAny handleAny(XmlSchema schema,
+ Element anyEl,
+ Element schemaEl) {
+
+ XmlSchemaAny any = new XmlSchemaAny();
+
+ if (anyEl.hasAttribute("namespace"))
+ any.namespace = anyEl.getAttribute("namespace");
+
+ if (anyEl.hasAttribute("processContents")) {
+ String processContent = getEnumString(anyEl,
+ "processContents");
+
+ any.processContent =
+ new XmlSchemaContentProcessing(processContent);
+ }
+
+ Element annotationEl = XDOMUtil.getFirstChildElementNS(anyEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+ any.setAnnotation(annotation);
+ }
+ any.minOccurs = getMinOccurs(anyEl);
+ any.maxOccurs = getMaxOccurs(anyEl);
+
+ return any;
+ }
+
+ private XmlSchemaChoice handleChoice(XmlSchema schema, Element choiceEl,
+ Element schemaEl) {
+ XmlSchemaChoice choice = new XmlSchemaChoice();
+
+ if (choiceEl.hasAttribute("id"))
+ choice.id = choiceEl.getAttribute("id");
+
+ choice.minOccurs = getMinOccurs(choiceEl);
+ choice.maxOccurs = getMaxOccurs(choiceEl);
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(choiceEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("sequence")) {
+ XmlSchemaSequence seq =
+ handleSequence(schema, el, schemaEl);
+ choice.items.add(seq);
+ } else if (el.getLocalName().equals("element")) {
+ XmlSchemaElement element =
+ handleElement(schema, el, schemaEl, false);
+ choice.items.add(element);
+ } else if (el.getLocalName().equals("group")) {
+ XmlSchemaGroupRef group =
+ handleGroupRef(schema, el, schemaEl);
+ choice.items.add(group);
+ } else if (el.getLocalName().equals("choice")) {
+ XmlSchemaChoice choiceItem =
+ handleChoice(schema, el, schemaEl);
+ choice.items.add(choiceItem);
+ } else if (el.getLocalName().equals("any")) {
+ XmlSchemaAny any = handleAny(schema, el, schemaEl);
+ choice.items.add(any);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
+ choice.setAnnotation(annotation);
+ }
+ }
+ return choice;
+ }
+
+ private XmlSchemaAll handleAll(XmlSchema schema, Element allEl,
+ Element schemaEl) {
+
+ XmlSchemaAll all = new XmlSchemaAll();
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(allEl, XmlSchema.SCHEMA_NS);
+ el != null; el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("element")) {
+ XmlSchemaElement element = handleElement(schema, el, schemaEl, false);
+ all.items.add(element);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation annotation = handleAnnotation(el);
+ all.setAnnotation(annotation);
+ }
+ }
+ return all;
+ }
+
+ private XmlSchemaGroup handleGroup(XmlSchema schema, Element groupEl,
+ Element schemaEl) {
+
+ XmlSchemaGroup group = new XmlSchemaGroup();
+ group.name = groupEl.getAttribute("name");
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(groupEl,
+ XmlSchema.SCHEMA_NS);
+ el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("all")) {
+ group.particle = handleAll(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("sequence")) {
+ group.particle = handleSequence(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("choice")) {
+ group.particle = handleChoice(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation groupAnnotation =
+ handleAnnotation(el);
+ group.setAnnotation(groupAnnotation);
+ }
+ }
+ return group;
+ }
+
+ private XmlSchemaAttributeGroup handleAttributeGroup(XmlSchema schema,
+ Element groupEl,
+ Element schemaEl) {
+ XmlSchemaAttributeGroup attrGroup =
+ new XmlSchemaAttributeGroup();
+
+ if (groupEl.hasAttribute("name"))
+ attrGroup.name = groupEl.getAttribute("name");
+ if (groupEl.hasAttribute("id"))
+ attrGroup.id = groupEl.getAttribute("id");
+
+ for (Element el = XDOMUtil.getFirstChildElementNS(groupEl,
+ XmlSchema.SCHEMA_NS);
+ el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ if (el.getLocalName().equals("attribute")) {
+ XmlSchemaAttribute attr =
+ handleAttribute(schema, el, schemaEl);
+ attrGroup.attributes.add(attr);
+ } else if (el.getLocalName().equals("attributeGroup")) {
+ XmlSchemaAttributeGroupRef attrGroupRef =
+ handleAttributeGroupRef(el);
+ attrGroup.attributes.add(attrGroupRef);
+ } else if (el.getLocalName().equals("anyAttribute")) {
+ attrGroup.anyAttribute = handleAnyAttribute(schema,
+ el, schemaEl);
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation ann = handleAnnotation(el);
+ attrGroup.setAnnotation(ann);
+ }
+ }
+ return attrGroup;
+ }
+
+ /** @noinspection UnusedParameters*/
+ private XmlSchemaAnyAttribute handleAnyAttribute(XmlSchema schema,
+ Element anyAttrEl,
+ Element schemaEl) {
+
+ XmlSchemaAnyAttribute anyAttr = new XmlSchemaAnyAttribute();
+
+ if (anyAttrEl.hasAttribute("namespace"))
+ anyAttr.namespace = anyAttrEl.getAttribute("namespace");
+
+ if (anyAttrEl.hasAttribute("processContents")) {
+
+ String contentProcessing = getEnumString(anyAttrEl,
+ "processContents");
+
+ anyAttr.processContent = new XmlSchemaContentProcessing(contentProcessing);
+ }
+ if (anyAttrEl.hasAttribute("id"))
+ anyAttr.id = anyAttrEl.getAttribute("id");
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(anyAttrEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ anyAttr.setAnnotation(annotation);
+ }
+ return anyAttr;
+ }
+
+ private XmlSchemaGroupRef handleGroupRef(XmlSchema schema,
+ Element groupEl, Element schemaEl) {
+
+ XmlSchemaGroupRef group = new XmlSchemaGroupRef();
+
+ Element annotationEl = XDOMUtil.getFirstChildElementNS(groupEl,
+ XmlSchema.SCHEMA_NS,
+ "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ group.setAnnotation(annotation);
+ }
+
+ if (groupEl.hasAttribute("ref")) {
+ String ref = groupEl.getAttribute("ref");
+ group.refName = getRefQName(ref, groupEl);
+ return group;
+ }
+ for (Element el = XDOMUtil.getFirstChildElementNS(groupEl,
+ XmlSchema.SCHEMA_NS)
+ ; el != null;
+ el = XDOMUtil.getNextSiblingElement(el)) {
+
+ if (el.getLocalName().equals("sequence")) {
+ group.particle = handleSequence(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("all")) {
+ group.particle = handleAll(schema, el, schemaEl);
+ } else if (el.getLocalName().equals("choice")) {
+ group.particle = handleChoice(schema, el,
+ schemaEl);
+ }
+ }
+ return group;
+ }
+
+ private QName newLocalQName(String pLocalName) {
+ String uri = schema.logicalTargetNamespace;
+ if (uri == null) {
+ uri = Constants.NULL_NS_URI;
+ }
+ return new QName(uri, pLocalName);
+ }
+
+
+ private XmlSchemaAttribute handleAttribute(XmlSchema schema,
+ Element attrEl, Element schemaEl) {
+ //todo: need to implement different rule of attribute such as
+ //restriction between ref and name. This can be implemented
+ //in the compile function
+ XmlSchemaAttribute attr = new XmlSchemaAttribute();
+
+ if (attrEl.hasAttribute("name")) {
+ String name = attrEl.getAttribute("name");
+ //String namespace = (schema.targetNamespace==null)?
+ // "" :schema.targetNamespace;
+
+ attr.name = name;
+ }
+
+ boolean isQualified = schema.getAttributeFormDefault().getValue().equals(XmlSchemaForm.QUALIFIED);
+ if (attr.name != null) {
+ final String name = attr.name;
+ attr.qualifiedName = (isQualified) ? newLocalQName(name) : new QName(name);
+ }
+
+ if (attrEl.hasAttribute("type")) {
+ String name = attrEl.getAttribute("type");
+ attr.schemaTypeName = getRefQName(name, attrEl);
+ }
+
+ if (attrEl.hasAttribute("default"))
+ attr.defaultValue = attrEl.getAttribute("default");
+
+ if (attrEl.hasAttribute("fixed"))
+ attr.fixedValue = attrEl.getAttribute("fixed");
+
+ if (attrEl.hasAttribute("form")) {
+ String formValue = getEnumString(attrEl, "form");
+ attr.form = new XmlSchemaForm(formValue);
+ }
+ if (attrEl.hasAttribute("id"))
+ attr.id = attrEl.getAttribute("id");
+
+
+ if (attrEl.hasAttribute("use")) {
+ String useType = getEnumString(attrEl, "use");
+ attr.use = new XmlSchemaUse(useType);
+ }
+ if (attrEl.hasAttribute("ref")) {
+ String name = attrEl.getAttribute("ref");
+ attr.refName = getRefQName(name, attrEl);
+ attr.name = name;
+ }
+
+ Element simpleTypeEl =
+ XDOMUtil.getFirstChildElementNS(attrEl,
+ XmlSchema.SCHEMA_NS, "simpleType");
+
+ if (simpleTypeEl != null) {
+ attr.schemaType = handleSimpleType(schema, simpleTypeEl,
+ schemaEl);
+ }
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(attrEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ attr.setAnnotation(annotation);
+ }
+
+ NamedNodeMap attrNodes = attrEl.getAttributes();
+ Vector attrs = new Vector();
+ NodeNamespaceContext ctx = null;
+ for (int i = 0; i < attrNodes.getLength(); i++) {
+ Attr att = (Attr) attrNodes.item(i);
+ String attName = att.getName();
+ if (!attName.equals("name") &&
+ !attName.equals("type") &&
+ !attName.equals("default") &&
+ !attName.equals("fixed") &&
+ !attName.equals("form") &&
+ !attName.equals("id") &&
+ !attName.equals("use") &&
+ !attName.equals("ref")) {
+
+
+ attrs.add(att);
+ String value = att.getValue();
+
+ if (value.indexOf(":") > -1) {
+ // there is a possiblily of some namespace mapping
+ String prefix = value.substring(0, value.indexOf(":"));
+ if (ctx == null) {
+ ctx = new NodeNamespaceContext(attrEl);
+ }
+ String namespace = ctx.getNamespaceURI(prefix);
+ if (!Constants.NULL_NS_URI.equals(namespace)) {
+ Attr nsAttr = attrEl.getOwnerDocument().createAttribute("xmlns:" + prefix);
+ nsAttr.setValue(namespace);
+ attrs.add(nsAttr);
+ }
+ }
+ }
+ }
+
+ if (attrs.size() > 0)
+ attr.setUnhandledAttributes((Attr[]) attrs.toArray(new Attr[0]));
+ return attr;
+ }
+
+ /*
+ * handle_simple_content_restriction
+ *
+ * if( restriction has base attribute )
+ * set the baseType
+ * else if( restriciton has an inline simpleType )
+ * handleSimpleType
+ * add facets if any to the restriction
+ */
+
+ /*
+ * handle_simple_content_extension
+ *
+ * extension should have a base name and cannot have any inline defn
+ * for( each childNode )
+ * if( attribute)
+ * handleAttribute
+ * else if( attributeGroup)
+ * handleAttributeGroup
+ * else if( anyAttribute)
+ * handleAnyAttribute
+ */
+
+ /*
+ * ********
+ * handle_complex_content_restriction
+ */
+ /**
+ * handle elements
+ * @param schema
+ * @param el
+ * @param schemaEl
+ * @param isGlobal
+ */
+ XmlSchemaElement handleElement(XmlSchema schema,
+ Element el,
+ Element schemaEl,
+ boolean isGlobal) {
+
+ XmlSchemaElement element = new XmlSchemaElement();
+
+ if (el.getAttributeNode("name") != null)
+ element.name = el.getAttribute("name");
+
+ // String namespace = (schema.targetNamespace==null)?
+ // "" : schema.targetNamespace;
+
+ boolean isQualified = schema.getElementFormDefault().getValue().equals(XmlSchemaForm.QUALIFIED);
+ if (el.hasAttribute("form")) {
+ String formDef = el.getAttribute("form");
+ element.form = new XmlSchemaForm(formDef);
+ isQualified = formDef.equals(XmlSchemaForm.QUALIFIED);
+ }
+
+ if (element.name != null) {
+ final String name = element.name;
+ element.qualifiedName = (isQualified || isGlobal) ? newLocalQName(name) : new QName(Constants.NULL_NS_URI, name);
+ }
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(el,
+ XmlSchema.SCHEMA_NS,
+ "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ element.setAnnotation(annotation);
+ }
+ if (el.getAttributeNode("type") != null) {
+ String typeName = el.getAttribute("type");
+ QName typeQName = element.schemaTypeName = getRefQName(typeName, el);
+
+ XmlSchemaType type = collection.getTypeByQName(typeQName);
+ if (type == null) {
+ // Could be a forward reference...
+ collection.addUnresolvedType(typeQName, element);
+ }
+ element.schemaType = type;
+ } else if (el.getAttributeNode("ref") != null) {
+ String refName = el.getAttribute("ref");
+ QName refQName = getRefQName(refName, el);
+ element.setRefName(refQName);
+ element.name = refQName.getLocalPart();
+ }
+
+ Element simpleTypeEl, complexTypeEl, keyEl, keyrefEl, uniqueEl;
+
+ if ((simpleTypeEl = XDOMUtil.getFirstChildElementNS(el,
+ XmlSchema.SCHEMA_NS, "simpleType")) != null) {
+
+ XmlSchemaSimpleType simpleType =
+ handleSimpleType(schema, simpleTypeEl, schemaEl);
+ element.schemaType = simpleType;
+ element.schemaTypeName = simpleType.getQName();
+ } else if ((complexTypeEl =
+ XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS,
+ "complexType")) != null) {
+
+ element.schemaType = handleComplexType(schema, complexTypeEl, schemaEl);
+ }
+
+ if ((keyEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "key")) != null) {
+ while(keyEl != null) {
+ element.constraints.add(handleConstraint(keyEl, "Key"));
+ keyEl = XDOMUtil.getNextSiblingElement(keyEl, "key");
+ }
+ }
+
+ if ((keyrefEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "keyref")) != null) {
+ while(keyrefEl != null) {
+ XmlSchemaKeyref keyRef = (XmlSchemaKeyref) handleConstraint(keyrefEl, "Keyref");
+ if(keyrefEl.hasAttribute("refer")) {
+ String name = keyrefEl.getAttribute("refer");
+ keyRef.refer = getRefQName(name, el);
+ }
+ element.constraints.add(keyRef);
+ keyrefEl = XDOMUtil.getNextSiblingElement(keyrefEl, "keyref");
+ }
+ }
+
+ if ((uniqueEl = XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS, "unique")) != null) {
+ while(uniqueEl != null) {
+ element.constraints.add(handleConstraint(uniqueEl, "Unique"));
+ uniqueEl = XDOMUtil.getNextSiblingElement(uniqueEl, "unique");
+ }
+ }
+
+ if (el.hasAttribute("abstract")) {
+ element.isAbstract =
+ Boolean.valueOf(el.getAttribute("abstract")).booleanValue();
+ }
+
+ if (el.hasAttribute("block"))
+ element.block = getDerivation(el, "block");
+
+ if (el.hasAttribute("default"))
+ element.defaultValue = el.getAttribute("default");
+
+ if (el.hasAttribute("final"))
+ element.finalDerivation = getDerivation(el, "final");
+
+ if (el.hasAttribute("fixed"))
+ element.fixedValue = el.getAttribute("fixed");
+
+ if (el.hasAttribute("id"))
+ element.id = el.getAttribute("id");
+
+ if (el.hasAttribute("nillable"))
+ element.isNillable =
+ Boolean.valueOf(el.getAttribute("nillable")).booleanValue();
+
+ if (el.hasAttribute("substitutionGroup")) {
+ String substitutionGroup = el.getAttribute("substitutionGroup");
+ element.setSubstitutionGroup(getRefQName(substitutionGroup, el));
+ }
+
+ element.minOccurs = getMinOccurs(el);
+ element.maxOccurs = getMaxOccurs(el);
+
+ //process extra attributes and elements
+ processExtensibilityComponents(element,el);
+
+ return element;
+ }
+
+ private XmlSchemaIdentityConstraint handleConstraint(
+ Element constraintEl, String type) {
+
+ try {
+ XmlSchemaIdentityConstraint constraint =
+ (XmlSchemaIdentityConstraint) Class.forName("org.apache.ws.commons.schema.XmlSchema" + type).newInstance();
+
+ if (constraintEl.hasAttribute("name"))
+ constraint.name = constraintEl.getAttribute("name");
+
+ if (constraintEl.hasAttribute("refer")) {
+ String name = constraintEl.getAttribute("refer");
+ ((XmlSchemaKeyref) constraint).refer = getRefQName(name, constraintEl);
+ }
+ for (Element el = XDOMUtil.getFirstChildElementNS(constraintEl,
+ XmlSchema.SCHEMA_NS);
+ el != null;
+ el = XDOMUtil.getNextSiblingElementNS(el, XmlSchema.SCHEMA_NS)) {
+
+ // String elPrefix = el.getPrefix() == null ? ""
+ // : el.getPrefix();
+ //if(elPrefix.equals(schema.schema_ns_prefix)) {
+ if (el.getLocalName().equals("selector")) {
+ XmlSchemaXPath selectorXPath =
+ new XmlSchemaXPath();
+ selectorXPath.xpath = el.getAttribute("xpath");
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS,
+ "annotation");
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ selectorXPath.setAnnotation(annotation);
+ }
+ constraint.selector = selectorXPath;
+ } else if (el.getLocalName().equals("field")) {
+ XmlSchemaXPath fieldXPath = new XmlSchemaXPath();
+ fieldXPath.xpath = el.getAttribute("xpath");
+ constraint.fields.add(fieldXPath);
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(el, XmlSchema.SCHEMA_NS,
+ "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation annotation =
+ handleAnnotation(annotationEl);
+
+ fieldXPath.setAnnotation(annotation);
+ }
+ } else if (el.getLocalName().equals("annotation")) {
+ XmlSchemaAnnotation constraintAnnotation =
+ handleAnnotation(el);
+ constraint.setAnnotation(constraintAnnotation);
+ }
+ }
+ return constraint;
+ } catch (ClassNotFoundException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (InstantiationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (IllegalAccessException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ /**
+ * Hanlde the import
+ * @param schema
+ * @param importEl
+ * @param schemaEl
+ * @return XmlSchemaObject
+ */
+ XmlSchemaImport handleImport(XmlSchema schema, Element importEl,
+ Element schemaEl) {
+
+ XmlSchemaImport schemaImport = new XmlSchemaImport();
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(importEl, XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation importAnnotation =
+ handleAnnotation(annotationEl);
+ schemaImport.setAnnotation(importAnnotation);
+ }
+
+ final String uri = schemaImport.namespace = importEl.getAttribute("namespace");
+ schemaImport.schemaLocation =
+ importEl.getAttribute("schemaLocation");
+
+ TargetNamespaceValidator validator = new TargetNamespaceValidator(){
+ private boolean isEmpty(String pValue) {
+ return pValue == null || Constants.NULL_NS_URI.equals(pValue);
+ }
+ public void validate(XmlSchema pSchema) {
+ final boolean valid;
+ if (isEmpty(uri)) {
+ valid = isEmpty(pSchema.syntacticalTargetNamespace);
+ } else {
+ valid = pSchema.syntacticalTargetNamespace.equals(uri);
+ }
+ if (!valid) {
+ throw new XmlSchemaException("An imported schema was announced to have the namespace "
+ + uri + ", but has the namespace " +
+ pSchema.syntacticalTargetNamespace);
+ }
+ }
+ };
+ if ((schemaImport.schemaLocation != null) && (!schemaImport.schemaLocation.equals(""))) {
+ if(schema.getSourceURI()!=null) {
+ schemaImport.schema =
+ resolveXmlSchema(
+ uri,
+ schemaImport.schemaLocation,
+ schema.getSourceURI(),
+ validator);
+ } else {
+ schemaImport.schema =
+ resolveXmlSchema(
+ schemaImport.namespace,
+ schemaImport.schemaLocation,
+ validator);
+ }
+ }
+ return schemaImport;
+ }
+
+ /**
+ * Handles the include
+ * @param schema
+ * @param includeEl
+ * @param schemaEl
+ */
+ XmlSchemaInclude handleInclude(final XmlSchema schema,
+ Element includeEl, Element schemaEl) {
+
+ XmlSchemaInclude include = new XmlSchemaInclude();
+
+ Element annotationEl =
+ XDOMUtil.getFirstChildElementNS(includeEl,
+ XmlSchema.SCHEMA_NS, "annotation");
+
+ if (annotationEl != null) {
+ XmlSchemaAnnotation includeAnnotation =
+ handleAnnotation(annotationEl);
+ include.setAnnotation(includeAnnotation);
+ }
+
+ include.schemaLocation =
+ includeEl.getAttribute("schemaLocation");
+
+ //includes are not supposed to have a target namespace
+ // we should be passing in a null in place of the target
+ //namespace
+
+ final TargetNamespaceValidator validator = newIncludeValidator(schema);
+ if(schema.getSourceURI()!=null) {
+ include.schema =
+ resolveXmlSchema(
+ schema.logicalTargetNamespace,
+ include.schemaLocation,
+ schema.getSourceURI(),
+ validator);
+ } else {
+ include.schema =
+ resolveXmlSchema(
+ schema.logicalTargetNamespace,
+ include.schemaLocation,
+ validator);
+ }
+
+ //process extra attributes and elements
+ processExtensibilityComponents(include,includeEl);
+ return include;
+ }
+
+ private TargetNamespaceValidator newIncludeValidator(final XmlSchema schema) {
+ return new TargetNamespaceValidator(){
+ private boolean isEmpty(String pValue) {
+ return pValue == null || Constants.NULL_NS_URI.equals(pValue);
+ }
+ public void validate(XmlSchema pSchema) {
+ if (isEmpty(pSchema.syntacticalTargetNamespace)) {
+ pSchema.logicalTargetNamespace = schema.logicalTargetNamespace;
+ } else {
+ if (!pSchema.syntacticalTargetNamespace.equals(schema.logicalTargetNamespace)) {
+ String msg = "An included schema was announced to have the default target namespace";
+ if (!isEmpty(schema.logicalTargetNamespace)) {
+ msg += " or the target namespace " + schema.logicalTargetNamespace;
+ }
+ throw new XmlSchemaException(msg + ", but has the target namespace "
+ + pSchema.logicalTargetNamespace);
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * Handles the annotation
+ * Traversing if encounter appinfo or documentation
+ * add it to annotation collection
+ *
+ */
+ XmlSchemaAnnotation handleAnnotation(Element annotEl) {
+ XmlSchemaObjectCollection content = new XmlSchemaObjectCollection();
+ XmlSchemaAppInfo appInfoObj;
+ XmlSchemaDocumentation docsObj;
+
+ for (Element appinfo = XDOMUtil.getFirstChildElementNS(annotEl,
+ XmlSchema.SCHEMA_NS, "appinfo");
+ appinfo != null;
+ appinfo = XDOMUtil.getNextSiblingElementNS(appinfo, XmlSchema.SCHEMA_NS, "appinfo")) {
+
+ appInfoObj = handleAppInfo(appinfo);
+ if (appInfoObj != null) {
+ content.add(appInfoObj);
+ }
+ }
+ for (Element documentation = XDOMUtil.getFirstChildElementNS(annotEl,
+ XmlSchema.SCHEMA_NS, "documentation");
+ documentation != null;
+ documentation = XDOMUtil.getNextSiblingElementNS(documentation,
+
+
+ XmlSchema.SCHEMA_NS, "documentation")) {
+
+ docsObj = handleDocumentation(documentation);
+ if (docsObj != null) {
+ content.add(docsObj);
+ }
+ }
+
+ XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
+ annotation.items = content;
+
+ //process extra attributes and elements
+ processExtensibilityComponents(annotation,annotEl);
+ return annotation;
+ }
+
+
+
+ /**
+ * create new XmlSchemaAppinfo and add value goten from element
+ * to this obj
+ * @param content
+ */
+ XmlSchemaAppInfo handleAppInfo(Element content) {
+ XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
+ NodeList markup = getChild(content);
+
+ if (!content.hasAttribute("source") &&
+ (markup == null || markup.getLength() <= 0)) {
+ return null;
+ }
+ appInfo.setSource(getAttribute(content, "source"));
+ appInfo.setMarkup(markup);
+ return appInfo;
+ }
+
+ //iterate each documentation element, create new XmlSchemaAppinfo and add to collection
+ XmlSchemaDocumentation handleDocumentation(Element content) {
+ XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
+ NodeList markup = getChild(content);
+
+ if (!content.hasAttribute("source") &&
+ !content.hasAttribute("xml:lang") &&
+ (markup == null || markup.getLength() <= 0))
+ return null;
+
+ documentation.setSource(getAttribute(content, "source"));
+ documentation.setLanguage(getAttribute(content, "xml:lang"));
+ documentation.setMarkup(getChild(content));
+
+ return documentation;
+ }
+
+ private String getAttribute(Element content, String attrName) {
+ if (content.hasAttribute(attrName))
+ return content.getAttribute(attrName);
+ return null;
+ }
+
+ private NodeList getChild(Element content) {
+ NodeList childs = content.getChildNodes();
+ if (childs.getLength() > 0)
+ return childs;
+ return null;
+ }
+
+ long getMinOccurs(Element el) {
+ try {
+ if (el.getAttributeNode("minOccurs") != null) {
+ String value = el.getAttribute("minOccurs");
+ if (value.equals("unbounded"))
+ return Long.MAX_VALUE;
+ else
+ return Long.parseLong(value);
+ }
+ return 1;
+ } catch (java.lang.NumberFormatException e) {
+ return 1;
+ }
+ }
+
+ long getMaxOccurs(Element el) {
+ try {
+ if (el.getAttributeNode("maxOccurs") != null) {
+ String value = el.getAttribute("maxOccurs");
+ if (value.equals("unbounded"))
+ return Long.MAX_VALUE;
+ else
+ return Long.parseLong(value);
+ }
+ return 1;
+ } catch (java.lang.NumberFormatException e) {
+ return 1;
+ }
+ }
+
+ XmlSchemaForm getFormDefault(Element el, String attrName) {
+ if (el.getAttributeNode(attrName) != null) {
+ String value = el.getAttribute(attrName);
+ return new XmlSchemaForm(value);
+ } else
+ return new XmlSchemaForm("unqualified");
+ }
+
+ //Check value entered by user and change according to .net spec,
+ //according to w3c spec have to be "#all"
+ //but in .net the valid enum value is "all".
+ XmlSchemaDerivationMethod getDerivation(Element el, String attrName) {
+ if (el.hasAttribute(attrName) && !el.getAttribute(attrName).equals("")) {
+ //#all | List of (extension | restriction | substitution
+ String derivationMethod = el.getAttribute(attrName).trim();
+ if (derivationMethod.equals("#all"))
+ return new XmlSchemaDerivationMethod(Constants.BlockConstants.ALL);
+ else
+ return new XmlSchemaDerivationMethod(derivationMethod);
+ }
+ return new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ }
+
+ //Check value entered by user and change according to .net spec, user
+ String getEnumString(Element el, String attrName) {
+ if (el.hasAttribute(attrName)) {
+ return el.getAttribute(attrName).trim();
+ }
+ return Constants.BlockConstants.NONE;
+ }
+
+ /**
+ * Resolve the schemas
+ * @param targetNamespace
+ * @param schemaLocation
+ */
+ XmlSchema resolveXmlSchema(String targetNamespace,
+ String schemaLocation,
+ String baseUri,
+ TargetNamespaceValidator validator) {
+ //use the entity resolver provided
+ InputSource source = collection.schemaResolver.
+ resolveEntity(targetNamespace,schemaLocation,baseUri);
+
+ final String systemId = source.getSystemId() == null ? schemaLocation : source.getSystemId();
+ final SchemaKey key = new XmlSchemaCollection.SchemaKey(targetNamespace, systemId);
+ XmlSchema schema = collection.getSchema(key);
+ if (schema != null) {
+ return schema;
+ }
+ if (collection.check(key)) {
+ collection.push(key);
+ try {
+ return collection.read(source, null, validator);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ collection.pop();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Resolve the schemas
+ * @param targetNamespace
+ * @param schemaLocation
+ */
+ XmlSchema resolveXmlSchema(String targetNamespace,
+ String schemaLocation,
+ TargetNamespaceValidator validator) {
+ return resolveXmlSchema(targetNamespace, schemaLocation,
+ collection.baseUri, validator);
+
+ }
+
+ /**
+ * A generic method to process the extra attributes and the the extra
+ * elements present within the schema.
+ * What are considered extensions are child elements with non schema namespace
+ * and child attributes with any namespace
+ * @param schemaObject
+ * @param parentElement
+ */
+ private void processExtensibilityComponents(XmlSchemaObject schemaObject,Element parentElement){
+
+ if (extReg!=null){
+ //process attributes
+ NamedNodeMap attributes = parentElement.getAttributes();
+ for (int i=0 ;i < attributes.getLength();i++){
+ Attr attribute = (Attr)attributes.item(i);
+
+ String namespaceURI = attribute.getNamespaceURI();
+ String name = attribute.getLocalName();
+
+ if (namespaceURI!= null &&
+ !"".equals(namespaceURI) && //ignore unqualified attributes
+ !name.startsWith(Constants.XMLNS_ATTRIBUTE) && //ignore namespaces
+ !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI))
+ //does not belong to the schema namespace by any chance!
+ {
+ QName qName = new QName(namespaceURI,name);
+ extReg.deserializeExtension(schemaObject,qName,attribute);
+
+
+ }
+ }
+
+ //process elements
+ NodeList allChildren = parentElement.getChildNodes();
+ for (int i=0 ;i < allChildren.getLength();i++){
+ if (allChildren.item(i).getNodeType()==Node.ELEMENT_NODE){
+
+ Element extElement = (Element)allChildren.item(i);
+
+ String namespaceURI = extElement.getNamespaceURI();
+ String name = extElement.getLocalName();
+
+ if (namespaceURI!= null &&
+ !Constants.URI_2001_SCHEMA_XSD.equals(namespaceURI))
+ //does not belong to the schema namespace
+ {
+ QName qName = new QName(namespaceURI,name);
+ extReg.deserializeExtension(schemaObject,qName,extElement);
+
+ }
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/TypeReceiver.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/TypeReceiver.java
new file mode 100644
index 0000000..adaa538
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/TypeReceiver.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * A TypeReceiver is something that can have its type set. This gets used
+ * to resolve forward references.
+ */
+public interface TypeReceiver {
+ void setType(XmlSchemaType type);
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEvent.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEvent.java
new file mode 100644
index 0000000..fa3ee68
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEvent.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import java.util.EventObject;
+
+public class ValidationEvent extends EventObject {
+
+ /**
+ * Creates new ValidationEvent
+ */
+ public ValidationEvent(Object source) {
+ super(source);
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEventHandler.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEventHandler.java
new file mode 100644
index 0000000..243bc59
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/ValidationEventHandler.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+public class ValidationEventHandler {
+
+ /**
+ * Creates new ValidationEventHandler
+ */
+ public ValidationEventHandler() {
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
new file mode 100644
index 0000000..4ef56f2
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchema.java
@@ -0,0 +1,300 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.utils.NamespaceContextOwner;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.w3c.dom.Document;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+
+/**
+ * Contains the definition of a schema. All XML Schema definition language (XSD)
+ * elements are children of the schema element. Represents the World Wide Web
+ * Consortium (W3C) schema element
+ */
+
+// Oct 15th - momo - initial impl
+// Oct 17th - vidyanand - add SimpleType + element
+// Oct 18th - momo - add ComplexType
+// Oct 19th - vidyanand - handle external
+// Dec 6th - Vidyanand - changed RuntimeExceptions thrown to XmlSchemaExceptions
+// Jan 15th - Vidyanand - made changes to SchemaBuilder.handleElement to look for an element ref.
+// Feb 20th - Joni - Change the getXmlSchemaFromLocation schema
+// variable to name s.
+// Feb 21th - Joni - Port to XMLDomUtil and Tranformation.
+
+public class XmlSchema extends XmlSchemaAnnotated implements NamespaceContextOwner {
+ static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
+ XmlSchemaForm attributeFormDefault, elementFormDefault;
+
+ XmlSchemaObjectTable attributeGroups,
+ attributes, elements, groups,
+ notations, schemaTypes;
+ XmlSchemaDerivationMethod blockDefault, finalDefault;
+ XmlSchemaObjectCollection includes, items;
+ boolean isCompiled;
+ String syntacticalTargetNamespace, logicalTargetNamespace, version;
+ String schema_ns_prefix = "";
+ XmlSchemaCollection parent;
+ private NamespacePrefixList namespaceContext;
+
+ /**
+ * Creates new XmlSchema
+ */
+ public XmlSchema(XmlSchemaCollection parent) {
+ this.parent = parent;
+ attributeFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
+ elementFormDefault = new XmlSchemaForm(XmlSchemaForm.UNQUALIFIED);
+ blockDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ finalDefault = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ items = new XmlSchemaObjectCollection();
+ includes = new XmlSchemaObjectCollection();
+ elements = new XmlSchemaObjectTable();
+ attributeGroups = new XmlSchemaObjectTable();
+ attributes = new XmlSchemaObjectTable();
+ groups = new XmlSchemaObjectTable();
+ notations = new XmlSchemaObjectTable();
+ schemaTypes = new XmlSchemaObjectTable();
+ }
+
+ public XmlSchema(String namespace, XmlSchemaCollection parent) {
+ this(parent);
+ syntacticalTargetNamespace = logicalTargetNamespace = namespace;
+ }
+
+ public XmlSchemaForm getAttributeFormDefault() {
+ return attributeFormDefault;
+ }
+
+ public void setAttributeFormDefault(XmlSchemaForm value) {
+ attributeFormDefault = value;
+ }
+
+ public XmlSchemaObjectTable getAttributeGroups() {
+ return attributeGroups;
+ }
+
+ public XmlSchemaObjectTable getAttributes() {
+ return attributes;
+ }
+
+ public XmlSchemaDerivationMethod getBlockDefault() {
+ return blockDefault;
+ }
+
+ public void setBlockDefault(XmlSchemaDerivationMethod blockDefault) {
+ this.blockDefault = blockDefault;
+ }
+
+ public XmlSchemaForm getElementFormDefault() {
+ return elementFormDefault;
+ }
+
+ public void setElementFormDefault(XmlSchemaForm elementFormDefault) {
+ this.elementFormDefault = elementFormDefault;
+ }
+
+ public XmlSchemaObjectTable getElements() {
+ return elements;
+ }
+
+ public XmlSchemaElement getElementByName(QName name) {
+ return (XmlSchemaElement)elements.getItem(name);
+ }
+
+ public XmlSchemaType getTypeByName(QName name) {
+ return (XmlSchemaType)schemaTypes.getItem(name);
+ }
+
+ public XmlSchemaDerivationMethod getFinalDefault() {
+ return finalDefault;
+ }
+
+ public void setFinalDefault(XmlSchemaDerivationMethod finalDefault) {
+ this.finalDefault = finalDefault;
+ }
+
+ public XmlSchemaObjectTable getGroups() {
+ return groups;
+ }
+
+ public XmlSchemaObjectCollection getIncludes() {
+ return includes;
+ }
+
+ public boolean isCompiled() {
+ return isCompiled;
+ }
+
+ public XmlSchemaObjectCollection getItems() {
+ return items;
+ }
+
+ public XmlSchemaObjectTable getNotations() {
+ return notations;
+ }
+
+ public XmlSchemaObjectTable getSchemaTypes() {
+ return schemaTypes;
+ }
+
+ public String getTargetNamespace() {
+ return syntacticalTargetNamespace;
+ }
+
+ public void setTargetNamespace(String targetNamespace) {
+ if (!targetNamespace.equals("")) {
+ syntacticalTargetNamespace = logicalTargetNamespace = targetNamespace;
+ }
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void compile(ValidationEventHandler eh) {
+
+ }
+
+ public void write(OutputStream out) {
+ write(new OutputStreamWriter(out));
+ }
+
+ public void write(Writer writer) {
+ serialize_internal(this, writer);
+ }
+
+ public Document[] getAllSchemas() {
+ try {
+
+ XmlSchemaSerializer xser = new XmlSchemaSerializer();
+ xser.setExtReg(this.parent.getExtReg());
+ return xser.serializeSchema(this, true);
+
+ } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ private void serialize_internal(XmlSchema schema, Writer out) {
+ try {
+ XmlSchemaSerializer xser = new XmlSchemaSerializer();
+ xser.setExtReg(this.parent.getExtReg());
+ Document[] serializedSchemas = xser.serializeSchema(schema, false);
+ TransformerFactory trFac = TransformerFactory.newInstance();
+ Source source = new DOMSource(serializedSchemas[0]);
+ Result result = new StreamResult(out);
+ javax.xml.transform.Transformer tr = trFac.newTransformer();
+ tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ tr.setOutputProperty(OutputKeys.INDENT, "yes");
+ tr.transform(source, result);
+ out.flush();
+ } catch (TransformerConfigurationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (TransformerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (XmlSchemaSerializer.XmlSchemaSerializerException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (IOException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ public void addType(XmlSchemaType type) {
+ QName qname = type.getQName();
+ if (schemaTypes.contains(qname)) {
+ throw new RuntimeException("Schema for namespace '" +
+ syntacticalTargetNamespace + "' already contains type '" +
+ qname.getLocalPart());
+ }
+ schemaTypes.add(qname, type);
+ }
+
+ public NamespacePrefixList getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ /**
+ * Sets the schema elements namespace context. This may be used for schema
+ * serialization, until a better mechanism was found.
+ */
+ public void setNamespaceContext(NamespacePrefixList namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+
+ /**
+ * Override the equals(Object) method with equivalence checking
+ * that is specific to this class.
+ */
+ public boolean equals(Object what) {
+
+ //Note: this method may no longer be required when line number/position are used correctly in XmlSchemaObject.
+ //Currently they are simply initialized to zero, but they are used in XmlSchemaObject.equals
+ //which can result in a false positive (e.g. if a WSDL contains 2 inlined schemas).
+
+ if (what == this) {
+ return true;
+ }
+
+ //If the inherited behaviour determines that the objects are NOT equal, return false.
+ //Otherwise, do some further equivalence checking.
+
+ if(!super.equals(what)) {
+ return false;
+ }
+
+ if (!(what instanceof XmlSchema)) {
+ return false;
+ }
+
+ XmlSchema xs = (XmlSchema) what;
+
+ if (this.id != null) {
+ if (!this.id.equals(xs.id)) {
+ return false;
+ }
+ } else {
+ if (xs.id != null) {
+ return false;
+ }
+ }
+
+ if (this.syntacticalTargetNamespace != null) {
+ if (!this.syntacticalTargetNamespace.equals(xs.syntacticalTargetNamespace)) {
+ return false;
+ }
+ } else {
+ if (xs.syntacticalTargetNamespace != null) {
+ return false;
+ }
+ }
+
+ //TODO decide if further schema content should be checked for equivalence.
+
+ return true;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAll.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAll.java
new file mode 100644
index 0000000..66415d3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAll.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Permits the elements in the group to appear (or not appear)
+ * in any order in the containing element. Represents the World
+ * Wide Web Consortium (W3C) all element (compositor).
+ */
+public class XmlSchemaAll extends XmlSchemaGroupBase {
+
+ /**
+ * Creates new XmlSchemaAll
+ */
+ public XmlSchemaAll() {
+ }
+
+ public XmlSchemaObjectCollection getItems() {
+ return this.items;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java
new file mode 100644
index 0000000..6107f66
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotated.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.w3c.dom.Attr;
+
+/**
+ * The base class for any element that can contain annotation elements.
+ */
+
+public class XmlSchemaAnnotated extends XmlSchemaObject {
+ /**
+ * Defines an annotation.
+ * Creates an annotation element.
+ * Represents the W3C annotation element.
+ */
+ XmlSchemaAnnotation annotation;
+ String id;
+
+ // Stores qualified attributes that do not belong to the schema target namespace.
+ public Attr[] unhandledAttributes;
+
+
+ /**
+ * Creates new XmlSchemaAnnotated
+ */
+ public XmlSchemaAnnotated() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public XmlSchemaAnnotation getAnnotation() {
+ return annotation;
+ }
+
+ public void setAnnotation(XmlSchemaAnnotation annotation) {
+ this.annotation = annotation;
+ }
+
+ public Attr[] getUnhandledAttributes() {
+ return unhandledAttributes;
+ }
+
+ public void setUnhandledAttributes(Attr[] unhandledAttributes) {
+ this.unhandledAttributes = unhandledAttributes;
+ }
+
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java
new file mode 100644
index 0000000..6fbb41a
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnnotation.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+
+/**
+ * Defines an annotation. Represents the World Wide Web Consortium (W3C)
+ * annotation element.
+ */
+
+public class XmlSchemaAnnotation extends XmlSchemaObject {
+ XmlSchemaObjectCollection items;
+
+ /**
+ * Creates new XmlSchemaAnnotation
+ */
+ public XmlSchemaAnnotation() {
+ items = new XmlSchemaObjectCollection();
+ }
+
+ public XmlSchemaObjectCollection getItems() {
+ return items;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAny.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAny.java
new file mode 100644
index 0000000..027d4f8
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAny.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Enables any element from the specified namespace or namespaces
+ * to appear in the containing complexType element. Represents the
+ * World Wide Web Consortium (W3C) any element.
+ */
+
+public class XmlSchemaAny extends XmlSchemaParticle {
+
+ /**
+ * Creates new XmlSchemaAny
+ */
+ public XmlSchemaAny() {
+ processContent = new XmlSchemaContentProcessing(Constants.BlockConstants.NONE);
+ }
+
+ /**
+ * Namespaces containing the elements that can be used.
+ */
+ String namespace;
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ XmlSchemaContentProcessing processContent;
+
+ public XmlSchemaContentProcessing getProcessContent() {
+ return processContent;
+ }
+
+ public void setProcessContent(XmlSchemaContentProcessing processContent) {
+ this.processContent = processContent;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnyAttribute.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnyAttribute.java
new file mode 100644
index 0000000..c999481
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAnyAttribute.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Enables any attribute from the specified namespace or namespaces
+ * to appear in the containing complexType element. Represents the
+ * World Wide Web Consortium (W3C) anyAttribute element.
+ */
+public class XmlSchemaAnyAttribute extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaAnyAttribute
+ */
+ public XmlSchemaAnyAttribute() {
+ processContent = new XmlSchemaContentProcessing(
+ Constants.BlockConstants.NONE);
+ }
+
+ String namespace;
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ XmlSchemaContentProcessing processContent;
+
+ public XmlSchemaContentProcessing getProcessContent() {
+ return processContent;
+ }
+
+ public void setProcessContent(XmlSchemaContentProcessing processContent) {
+ this.processContent = processContent;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java
new file mode 100644
index 0000000..89ad6cc
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAppInfo.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.w3c.dom.NodeList;
+
+/**
+ * Defines application specific information within an annotation.
+ * Represents the World Wide Web Consortium (W3C) appinfo element.
+ */
+
+// Jan 24 2002 - Joni - Change the Node into NodeList
+
+
+public class XmlSchemaAppInfo extends XmlSchemaObject {
+
+ /**
+ * Provides the source of the application information.
+ */
+ String source;
+
+ /**
+ * Returns an array of XmlNode that represents the document text markup.
+ */
+ NodeList markup;
+
+ /**
+ * Creates new XmlSchemaAppInfo
+ * The default constructor initializes all fields to their default values.
+ */
+ public XmlSchemaAppInfo() {
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public NodeList getMarkup() {
+ return markup;
+ }
+
+ public void setMarkup(NodeList markup) {
+ this.markup = markup;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java
new file mode 100644
index 0000000..6c1de8d
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttribute.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Class for attribute types. Represents the World Wide Web Consortium
+ * (W3C) attribute element.
+ */
+
+// October 15th - momo - initial implementation
+
+public class XmlSchemaAttribute extends XmlSchemaAnnotated {
+
+ Object attributeType;
+ String defaultValue, fixedValue, name;
+ XmlSchemaForm form;
+ XmlSchemaSimpleType schemaType;
+ QName schemaTypeName, qualifiedName, refName;
+ XmlSchemaUse use;
+
+ /**
+ * Creates new XmlSchemaAttribute
+ */
+ public XmlSchemaAttribute() {
+ form = new XmlSchemaForm(XmlSchemaForm.NONE);
+ use = new XmlSchemaUse(Constants.BlockConstants.NONE);
+ }
+
+ public Object getAttributeType() {
+ return attributeType;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public String getFixedValue() {
+ return fixedValue;
+ }
+
+ public void setFixedValue(String fixedValue) {
+ this.fixedValue = fixedValue;
+ }
+
+ public XmlSchemaForm getForm() {
+ return form;
+ }
+
+ public void setSchemaForm(XmlSchemaForm form) {
+ this.form = form;
+ }
+
+ public QName getQName() {
+ return qualifiedName;
+ }
+
+ public void setQName(QName qualifiedName) {
+ this.qualifiedName = qualifiedName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public QName getRefName() {
+ return refName;
+ }
+
+ public void setRefName(QName refName) {
+ this.refName = refName;
+ }
+
+ public XmlSchemaSimpleType getSchemaType() {
+ return schemaType;
+ }
+
+ public void setSchemaType(XmlSchemaSimpleType schemaType) {
+ this.schemaType = schemaType;
+ }
+
+ public QName getSchemaTypeName() {
+ return schemaTypeName;
+ }
+
+ public void setSchemaTypeName(QName schemaTypeName) {
+ this.schemaTypeName = schemaTypeName;
+ }
+
+ public XmlSchemaUse getUse() {
+ return use;
+ }
+
+ public void setUse(XmlSchemaUse use) {
+ this.use = use;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "<" + prefix + "attribute name=\"" + name + "\" type=\"" + schemaTypeName + "\"/>\n";
+
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java
new file mode 100644
index 0000000..dc9e3f9
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroup.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for attribute groups. Groups a set of attribute declarations
+ * so that they can be incorporated as a group into complex type
+ * definitions. Represents the World Wide Web Consortium (W3C)
+ * attributeGroup element.
+ */
+
+public class XmlSchemaAttributeGroup extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaAttributeGroup
+ */
+ public XmlSchemaAttributeGroup() {
+ attributes = new XmlSchemaObjectCollection();
+ }
+
+ XmlSchemaAnyAttribute anyAttribute;
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return this.anyAttribute;
+ }
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ XmlSchemaObjectCollection attributes;
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return this.attributes;
+ }
+
+ public void setAttributes(XmlSchemaObjectCollection attributes) {
+ this.attributes = attributes;
+ }
+
+ String name;
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java
new file mode 100644
index 0000000..adbf239
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaAttributeGroupRef.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for the attribute group reference. Represents the World Wide
+ * Web Consortium (W3C) attributeGroup element with the ref attribute.
+ */
+public class XmlSchemaAttributeGroupRef extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaAttributeGroupRef
+ */
+ public XmlSchemaAttributeGroupRef() {
+ }
+
+ QName refName;
+
+ public QName getRefName() {
+ return this.refName;
+ }
+
+ public void setRefName(QName refName) {
+ this.refName = refName;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaChoice.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaChoice.java
new file mode 100644
index 0000000..7903779
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaChoice.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Allows only one of its children to appear in an instance. Represents
+ * the World Wide Web Consortium (W3C) choice (compositor) element.
+ */
+public class XmlSchemaChoice extends XmlSchemaGroupBase {
+
+ /**
+ * Creates new XmlSchemaChoice
+ */
+ public XmlSchemaChoice() {
+ }
+
+ public XmlSchemaObjectCollection getItems() {
+ return this.items;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
new file mode 100644
index 0000000..0f1568f
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
@@ -0,0 +1,468 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+import org.apache.ws.commons.schema.resolver.DefaultURIResolver;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.apache.ws.commons.schema.utils.TargetNamespaceValidator;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.*;
+
+/**
+ * Contains a cache of XML Schema definition language (XSD).
+ *
+ */
+public final class XmlSchemaCollection {
+
+ // the default extension registry
+ private ExtensionRegistry extReg = new ExtensionRegistry();
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+
+ static class SchemaKey {
+ private final String namespace;
+ private final String systemId;
+ SchemaKey(String pNamespace, String pSystemId) {
+ namespace = pNamespace == null ? Constants.NULL_NS_URI : pNamespace;
+ systemId = pSystemId == null ? "" : pSystemId;
+ }
+ String getNamespace() { return namespace; }
+ String getSystemId() { return systemId; }
+ public int hashCode() {
+ final int PRIME = 31;
+ return (PRIME + namespace.hashCode()) * PRIME + systemId.hashCode();
+ }
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final SchemaKey other = (SchemaKey) obj;
+ return namespace.equals(other.namespace) && systemId.equals(other.systemId);
+ }
+ public String toString() {
+ return Constants.NULL_NS_URI.equals(namespace) ?
+ systemId : ("{" + namespace + "}" + systemId);
+ }
+ }
+
+ /**
+ * Map of included schemas.
+ */
+ private Map schemas = new HashMap();
+
+
+ /**
+ * base URI is used as the base for loading the
+ * imports
+ */
+ String baseUri = null;
+ /**
+ * In-scope namespaces for XML processing
+ */
+ private NamespacePrefixList namespaceContext;
+
+ /**
+ * An org.xml.sax.EntityResolver that is used to
+ * resolve the imports/includes
+ */
+ URIResolver schemaResolver = new DefaultURIResolver();
+
+ XmlSchema xsd = new XmlSchema(XmlSchema.SCHEMA_NS, this);
+
+ /**
+ * stack to track imports (to prevent recursion)
+ */
+ Stack stack = new Stack();
+
+ /**
+ * Set the base URI. This is used when schemas need to be
+ * loaded from relative locations
+ * @param baseUri
+ */
+ public void setBaseUri(String baseUri){
+ this.baseUri = baseUri;
+ }
+
+ /**
+ * Register a custom URI resolver
+ * @param schemaResolver
+ */
+ public void setSchemaResolver(URIResolver schemaResolver) {
+ this.schemaResolver = schemaResolver;
+ }
+
+ /**
+ * This section should comply to the XMLSchema specification; see
+ * <a href="http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes">
+ * http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes</a>.
+ * This needs to be inspected by another pair of eyes
+ */
+ public void init() {
+ /*
+ Primitive types
+
+ 3.2.1 string
+ 3.2.2 boolean
+ 3.2.3 decimal
+ 3.2.4 float
+ 3.2.5 double
+ 3.2.6 duration
+ 3.2.7 dateTime
+ 3.2.8 time
+ 3.2.9 date
+ 3.2.10 gYearMonth
+ 3.2.11 gYear
+ 3.2.12 gMonthDay
+ 3.2.13 gDay
+ 3.2.14 gMonth
+ 3.2.15 hexBinary
+ 3.2.16 base64Binary
+ 3.2.17 anyURI
+ 3.2.18 QName
+ 3.2.19 NOTATION
+ */
+ addSimpleType(xsd, Constants.XSD_STRING.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BOOLEAN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_FLOAT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DOUBLE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_QNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DECIMAL.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DURATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_TIME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATETIME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTHDAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEAR.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEARMONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NOTATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_HEXBIN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BASE64.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ANYURI.getLocalPart());
+
+
+ /*
+ 3.3.1 normalizedString
+ 3.3.2 token
+ 3.3.3 language
+ 3.3.4 NMTOKEN
+ 3.3.5 NMTOKENS
+ 3.3.6 Name
+ 3.3.7 NCName
+ 3.3.8 ID
+ 3.3.9 IDREF
+ 3.3.10 IDREFS
+ 3.3.11 ENTITY
+ 3.3.12 ENTITIES
+ 3.3.13 integer
+ 3.3.14 nonPositiveInteger
+ 3.3.15 negativeInteger
+ 3.3.16 long
+ 3.3.17 int
+ 3.3.18 short
+ 3.3.19 byte
+ 3.3.20 nonNegativeInteger
+ 3.3.21 unsignedLong
+ 3.3.22 unsignedInt
+ 3.3.23 unsignedShort
+ 3.3.24 unsignedByte
+ 3.3.25 positiveInteger
+ */
+
+ //derived types from decimal
+ addSimpleType(xsd, Constants.XSD_LONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_SHORT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_POSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONPOSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONNEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDBYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDINT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDLONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDSHORT.getLocalPart());
+
+ //derived types from string
+ addSimpleType(xsd, Constants.XSD_NAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NORMALIZEDSTRING.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NCNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKEN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKENS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITIES.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ID.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREF.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREFS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_LANGUAGE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_TOKEN.getLocalPart());
+
+ SchemaKey key = new SchemaKey(XmlSchema.SCHEMA_NS, null);
+ addSchema(key, xsd);
+
+ // look for a system property to see whether we have a registered
+ // extension registry class. if so we'll instantiate a new one
+ // and set it as the extension registry
+ //if there is an error, we'll just print out a message and move on.
+
+ if (System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY)!= null){
+ try {
+ Class clazz = Class.forName(System.getProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY));
+ this.extReg = (ExtensionRegistry)clazz.newInstance();
+ } catch (ClassNotFoundException e) {
+ System.err.println("The specified extension registry class cannot be found!");
+ } catch (InstantiationException e) {
+ System.err.println("The specified extension registry class cannot be instantiated!");
+ } catch (IllegalAccessException e) {
+ System.err.println("The specified extension registry class cannot be accessed!");
+ }
+ }
+ }
+
+ boolean containsSchema(SchemaKey pKey) {
+ return schemas.containsKey(pKey);
+ }
+
+ XmlSchema getSchema(SchemaKey pKey) {
+ return (XmlSchema) schemas.get(pKey);
+ }
+
+ void addSchema(SchemaKey pKey, XmlSchema pSchema) {
+ if (schemas.containsKey(pKey)) {
+ throw new IllegalStateException("A schema with target namespace "
+ + pKey.getNamespace() + " and system ID " + pKey.getSystemId()
+ + " is already present.");
+ }
+ schemas.put(pKey, pSchema);
+ }
+
+ private void addSimpleType(XmlSchema schema,String typeName){
+ XmlSchemaSimpleType type;
+ type = new XmlSchemaSimpleType(schema);
+ type.setName(typeName);
+ schema.addType(type);
+ }
+ public XmlSchema read(Reader r, ValidationEventHandler veh) {
+ return read(new InputSource(r), veh);
+ }
+
+ XmlSchema read(InputSource inputSource, ValidationEventHandler veh,
+ TargetNamespaceValidator namespaceValidator) {
+ try {
+ DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
+ docFac.setNamespaceAware(true);
+ DocumentBuilder builder = docFac.newDocumentBuilder();
+ Document doc = builder.parse(inputSource);
+ return read(doc, inputSource.getSystemId(), veh, namespaceValidator);
+ } catch (ParserConfigurationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (IOException e) {
+ throw new XmlSchemaException(e.getMessage());
+ } catch (SAXException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+ }
+
+ public XmlSchema read(InputSource inputSource, ValidationEventHandler veh) {
+ return read(inputSource, veh, null);
+ }
+
+ public XmlSchema read(Source source, ValidationEventHandler veh) {
+ if (source instanceof SAXSource) {
+ return read(((SAXSource) source).getInputSource(), veh);
+ } else if (source instanceof DOMSource) {
+ Node node = ((DOMSource) source).getNode();
+ if (node instanceof Document) {
+ node = ((Document) node).getDocumentElement();
+ }
+ return read((Document) node, veh);
+ } else if (source instanceof StreamSource) {
+ StreamSource ss = (StreamSource) source;
+ InputSource isource = new InputSource(ss.getSystemId());
+ isource.setByteStream(ss.getInputStream());
+ isource.setCharacterStream(ss.getReader());
+ isource.setPublicId(ss.getPublicId());
+ return read(isource, veh);
+ } else {
+ InputSource isource = new InputSource(source.getSystemId());
+ return read(isource, veh);
+ }
+ }
+
+ public XmlSchema read(Document doc, ValidationEventHandler veh) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ return builder.build(doc, null, veh);
+ }
+
+ public XmlSchema read(Element elem) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ return builder.handleXmlSchemaElement(elem, null);
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh) {
+ return read(doc, uri, veh, null);
+ }
+
+ public XmlSchema read(Document doc, String uri, ValidationEventHandler veh,
+ TargetNamespaceValidator validator) {
+ SchemaBuilder builder = new SchemaBuilder(this, validator);
+ return builder.build(doc, uri, veh);
+ }
+
+ public XmlSchema read(Element elem, String uri) {
+ SchemaBuilder builder = new SchemaBuilder(this, null);
+ return builder.handleXmlSchemaElement(elem, uri);
+ }
+
+ /**
+ * Creates new XmlSchemaCollection
+ */
+ public XmlSchemaCollection() {
+ init();
+ }
+
+ /**
+ * Retrieve a set of XmlSchema instances with the given its system ID.
+ * In general, this will return a single instance, or none. However,
+ * if the schema has no targetNamespace attribute and was included
+ * from schemata with different target namespaces, then it may
+ * occur, that multiple schema instances with different logical
+ * target namespaces may be returned.
+ * @param systemId
+ */
+ public XmlSchema[] getXmlSchema(String systemId) {
+ if (systemId == null) {
+ systemId = "";
+ }
+ final List result = new ArrayList();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getSystemId().equals(systemId)) {
+ result.add(entry.getValue());
+ }
+ }
+ return (XmlSchema[]) result.toArray(new XmlSchema[result.size()]);
+ }
+
+ /**
+ * Returns an array of all the XmlSchemas in this collection.
+ */
+ public XmlSchema[] getXmlSchemas() {
+ Collection c = schemas.values();
+ return (XmlSchema[]) c.toArray(new XmlSchema[c.size()]);
+ }
+
+ public XmlSchemaElement getElementByQName(QName qname) {
+ String uri = qname.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaElement element = ((XmlSchema) entry.getValue()).getElementByName(qname);
+ if (element != null) {
+ return element;
+ }
+ }
+ }
+ return null;
+ }
+
+ public XmlSchemaType getTypeByQName(QName schemaTypeName) {
+ String uri = schemaTypeName.getNamespaceURI();
+ for (Iterator iter = schemas.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (((SchemaKey) entry.getKey()).getNamespace().equals(uri)) {
+ XmlSchemaType type = ((XmlSchema) entry.getValue()).getTypeByName(schemaTypeName);
+ if (type != null) {
+ return type;
+ }
+ }
+ }
+ return null;
+ }
+
+ Map unresolvedTypes = new HashMap();
+
+ void addUnresolvedType(QName type, TypeReceiver receiver) {
+ ArrayList receivers = (ArrayList)unresolvedTypes.get(type);
+ if (receivers == null) {
+ receivers = new ArrayList();
+ unresolvedTypes.put(type, receivers);
+ }
+ receivers.add(receiver);
+ }
+
+ void resolveType(QName typeName, XmlSchemaType type) {
+ ArrayList receivers = (ArrayList)unresolvedTypes.get(typeName);
+ if (receivers == null)
+ return;
+ for (Iterator i = receivers.iterator(); i.hasNext();) {
+ TypeReceiver receiver = (TypeReceiver) i.next();
+ receiver.setType(type);
+ }
+ unresolvedTypes.remove(typeName);
+ }
+
+ public NamespacePrefixList getNamespaceContext() {
+ return namespaceContext;
+ }
+
+ public void setNamespaceContext(NamespacePrefixList namespaceContext) {
+ this.namespaceContext = namespaceContext;
+ }
+
+ public void push(SchemaKey pKey){
+ stack.push(pKey);
+ }
+
+ public void pop(){
+ stack.pop();
+ }
+
+ public boolean check(SchemaKey pKey){
+ return (stack.indexOf(pKey)==-1);
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollectionEnumerator.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollectionEnumerator.java
new file mode 100644
index 0000000..04b98f1
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollectionEnumerator.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Supports a simple iteration over a collection. This class cannot be inherited.
+ */
+public final class XmlSchemaCollectionEnumerator {
+
+ /**
+ * Creates new XmlSchemaCollectionEnumerator
+ */
+ public XmlSchemaCollectionEnumerator() {
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContent.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContent.java
new file mode 100644
index 0000000..7cb2662
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContent.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class that represents the complex content model for complex types.
+ * Contains extensions or restrictions on a complex type that has mixed
+ * content or elements only. Represents the World Wide Web Consortium (W3C)
+ * complexContent element.
+ */
+
+// Vidyanand - 16th Oct - initial implementation
+
+public class XmlSchemaComplexContent extends XmlSchemaContentModel {
+
+ /**
+ * Creates new XmlSchemaComplexContent
+ */
+ public XmlSchemaComplexContent() {
+ }
+
+ /* One of either the XmlSchemaComplexContentRestriction or
+ * XmlSchemaComplexContentExtension classes.
+ */
+ XmlSchemaContent content;
+
+ public XmlSchemaContent getContent() {
+ return this.content;
+ }
+
+ public void setContent(XmlSchemaContent content) {
+ this.content = content;
+ }
+
+ /* Indicates that this type has a mixed content model. Character data
+ * is allowed to appear between the child elements of the complex type.
+ */
+ public boolean mixed;
+
+ public boolean isMixed() {
+ return this.mixed;
+ }
+
+ public void setMixed(boolean mixed) {
+ this.mixed = mixed;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ xml += "<" + prefix + "complexContent>\n";
+
+ xml += content.toString(prefix, (tab + 1));
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+ xml += "<" + prefix + "complexContent>\n";
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentExtension.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentExtension.java
new file mode 100644
index 0000000..8f8cfab
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentExtension.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for complex types with a complex content model derived by extension.
+ * Extends the complex type by adding attributes or elements. Represents the
+ * World Wide Web Consortium (W3C) extension element for complex content.
+ */
+
+public class XmlSchemaComplexContentExtension extends XmlSchemaContent {
+
+ /**
+ * Creates new XmlSchemaComplexContentExtension
+ */
+ public XmlSchemaComplexContentExtension() {
+ attributes = new XmlSchemaObjectCollection();
+
+ }
+
+ /* Allows an XmlSchemaAnyAttribute to be used for the attribute value.*/
+ XmlSchemaAnyAttribute anyAttribute;
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return this.anyAttribute;
+ }
+
+ /* Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef. Collection of attributes for the simple type.*/
+ XmlSchemaObjectCollection attributes;
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return this.attributes;
+ }
+
+ /* Name of the built-in data type, simple type, or complex type.*/
+ QName baseTypeName;
+
+ public void setBaseTypeName(QName baseTypeName) {
+ this.baseTypeName = baseTypeName;
+ }
+
+ public QName getBaseTypeName() {
+ return this.baseTypeName;
+ }
+
+ /*One of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence classes.*/
+ XmlSchemaParticle particle;
+
+ public XmlSchemaParticle getParticle() {
+ return this.particle;
+ }
+
+ public void setParticle(XmlSchemaParticle particle) {
+ this.particle = particle;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ xml += "<" + prefix + "extension>\n";
+
+ if (particle != null)
+ xml += particle.toString(prefix, (tab + 1));
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "extension>\n";
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentRestriction.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentRestriction.java
new file mode 100644
index 0000000..83b4ea6
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexContentRestriction.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for complex types with a complex content model that are derived
+ * by restriction. Restricts the contents of the complex type to a subset
+ * of the inherited complex type. Represents the World Wide Web Consortium
+ * (W3C) restriction element for complex content.
+ */
+
+public class XmlSchemaComplexContentRestriction extends XmlSchemaContent {
+
+ /**
+ * Creates new XmlSchemaComplexContentRestriction
+ */
+ public XmlSchemaComplexContentRestriction() {
+ attributes = new XmlSchemaObjectCollection();
+ }
+
+ /* Allows an XmlSchemaAnyAttribute to be used for the attribute value.*/
+ XmlSchemaAnyAttribute anyAttribute;
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return this.anyAttribute;
+ }
+
+ /* Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef.
+ * Collection of attributes for the simple type.
+ */
+ XmlSchemaObjectCollection attributes;
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return this.attributes;
+ }
+
+ /* Name of the built-in data type, simple type, or complex type.*/
+ QName baseTypeName;
+
+ public void setBaseTypeName(QName baseTypeName) {
+ this.baseTypeName = baseTypeName;
+ }
+
+ public QName getBaseTypeName() {
+ return this.baseTypeName;
+ }
+
+ /*One of the XmlSchemaGroupRef, XmlSchemaChoice, XmlSchemaAll,
+ * or XmlSchemaSequence classes.
+ */
+ XmlSchemaParticle particle;
+
+ public XmlSchemaParticle getParticle() {
+ return this.particle;
+ }
+
+ public void setParticle(XmlSchemaParticle particle) {
+ this.particle = particle;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ xml += "<" + prefix + "restriction>\n";
+
+ if (particle != null)
+ xml += particle.toString(prefix, (tab + 1));
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "restriction>\n";
+ return xml;
+ }
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java
new file mode 100644
index 0000000..d56ea43
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaComplexType.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Class for complex types. Defines a complex type that determines the
+ * set of attributes and content of an element. Represents the World Wide
+ * Web Consortium (W3C) complexType element.
+ */
+
+public class XmlSchemaComplexType extends XmlSchemaType {
+ XmlSchemaAnyAttribute anyAttribute, attributeWildcard;
+ XmlSchemaObjectCollection attributes;
+ XmlSchemaObjectTable attributeUses;
+ XmlSchemaDerivationMethod block, blockResolved;
+ XmlSchemaContentModel contentModel;
+ XmlSchemaContentType contentType;
+ XmlSchemaParticle particleType, particle;
+ boolean isAbstract, isMixed;
+
+ /**
+ * Creates new XmlSchemaComplexType
+ */
+ public XmlSchemaComplexType(XmlSchema schema) {
+ super(schema);
+ attributes = new XmlSchemaObjectCollection();
+ block = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ isAbstract = false;
+ isMixed = false;
+ }
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return anyAttribute;
+ }
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return attributes;
+ }
+
+ public XmlSchemaObjectTable getAttributeUses() {
+ return attributeUses;
+ }
+
+ public XmlSchemaAnyAttribute getAttributeWildcard() {
+ return attributeWildcard;
+ }
+
+ public XmlSchemaDerivationMethod getBlock() {
+ return block;
+ }
+
+ public void setBlock(XmlSchemaDerivationMethod block) {
+ this.block = block;
+ }
+
+ public XmlSchemaDerivationMethod getBlockResolved() {
+ return blockResolved;
+ }
+
+ public XmlSchemaContentModel getContentModel() {
+ return contentModel;
+ }
+
+ public void setContentModel(XmlSchemaContentModel contentModel) {
+ this.contentModel = contentModel;
+ }
+
+ public XmlSchemaContentType getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(XmlSchemaContentType contentType) {
+ this.contentType = contentType;
+ }
+
+ public XmlSchemaParticle getContentTypeParticle() {
+ return particleType;
+ }
+
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ public void setAbstract(boolean b) {
+ isAbstract = b;
+ }
+
+ public boolean isMixed() {
+ return isMixed;
+ }
+
+ public void setMixed(boolean b) {
+ isMixed = b;
+ }
+
+ public XmlSchemaParticle getParticle() {
+ return particle;
+ }
+
+ public void setParticle(XmlSchemaParticle particle) {
+ this.particle = particle;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ String typeName = name != null ? name : "";
+
+ xml += "<" + prefix + "complexType name=\"" + typeName + "\">\n";
+
+ if (particle != null)
+ xml += particle.toString(prefix, (tab + 1));
+
+ if (contentModel != null)
+ xml += contentModel.toString(prefix, (tab + 1));
+
+ for (int i = 0; i < attributes.getCount(); i++) {
+ xml += attributes.getItem(i).toString(prefix, (tab + 1));
+ }
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "complexType>\n";
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContent.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContent.java
new file mode 100644
index 0000000..7e39614
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContent.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * An abstract class for schema content.
+ *
+ */
+
+public abstract class XmlSchemaContent extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaContent
+ */
+ protected XmlSchemaContent() {
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentModel.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentModel.java
new file mode 100644
index 0000000..84a703d
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentModel.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * An abstract class for the schema content model.
+ */
+
+public abstract class XmlSchemaContentModel extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaContentModel
+ */
+ protected XmlSchemaContentModel() {
+ }
+
+ public abstract void setContent(XmlSchemaContent content);
+
+ public abstract XmlSchemaContent getContent();
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentProcessing.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentProcessing.java
new file mode 100644
index 0000000..5979e7a
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentProcessing.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Provides information about the validation mode of any
+ * and anyAttribute element replacements.
+ */
+
+public class XmlSchemaContentProcessing extends org.apache.ws.commons.schema.constants.Enum {
+
+ static String[] members = new String[]{
+ Constants.BlockConstants.LAX,
+ Constants.BlockConstants.NONE,
+ Constants.BlockConstants.SKIP,
+ Constants.BlockConstants.STRICT
+ };
+
+ /**
+ * Creates new XmlSeverityType
+ */
+ public XmlSchemaContentProcessing() {
+ super();
+ }
+
+ public XmlSchemaContentProcessing(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentType.java
new file mode 100644
index 0000000..bd24aae
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaContentType.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.constants.Enum;
+
+/**
+ * Enumerations for the content model of the complex type. This
+ * represents the content in the post-schema-validation infoset.
+ */
+
+public class XmlSchemaContentType extends Enum {
+
+ static String[] members = new String[]{
+ Constants.BlockConstants.ELEMENT_ONLY,
+ Constants.BlockConstants.EMPTY,
+ Constants.BlockConstants.MIXED,
+ Constants.BlockConstants.TEXT_ONLY};
+
+ /**
+ * Creates new XmlSchemaContentType
+ */
+ public XmlSchemaContentType() {
+ super();
+ }
+
+ public XmlSchemaContentType(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDatatype.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDatatype.java
new file mode 100644
index 0000000..76fcb76
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDatatype.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+public abstract class XmlSchemaDatatype {
+
+ /**
+ * Creates new XmlSchemaDatatype
+ */
+ public XmlSchemaDatatype() {
+ }
+
+ public abstract Object parseValue(Object input);
+
+ public abstract Class valueType();
+
+ public abstract XmlTokenizedType tokenizedType();
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDerivationMethod.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDerivationMethod.java
new file mode 100644
index 0000000..faad9a6
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDerivationMethod.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Provides different methods for preventing derivation.
+ */
+public class XmlSchemaDerivationMethod extends org.apache.ws.commons.schema.constants.Enum {
+ static String[] members = new String[]{
+ Constants.BlockConstants.ALL,
+ Constants.BlockConstants.EMPTY,
+ Constants.BlockConstants.EXTENSION,
+ Constants.BlockConstants.LIST,
+ Constants.BlockConstants.NONE,
+ Constants.BlockConstants.RESTRICTION,
+ Constants.BlockConstants.SUBSITUTION,
+ Constants.BlockConstants.UNION};
+
+ /**
+ * Creates new XmlSeverityType
+ */
+ public XmlSchemaDerivationMethod() {
+ super();
+ }
+
+ public XmlSchemaDerivationMethod(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java
new file mode 100644
index 0000000..9a5f845
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaDocumentation.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.w3c.dom.NodeList;
+
+/**
+ * Class that specifies information to be read or used by humans
+ * within an annotation. Represents the World Wide Web Consortium
+ * (W3C) documentation element.
+ */
+
+public class XmlSchemaDocumentation extends XmlSchemaObject {
+
+ /**
+ * Creates new XmlSchemaDocumentation
+ */
+ public XmlSchemaDocumentation() {
+ }
+
+ /**
+ * Provides the source of the application information.
+ */
+ String source;
+ String language;
+
+ /**
+ * Returns an array of XmlNode that represents the document text markup.
+ */
+ NodeList markup;
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public NodeList getMarkup() {
+ return markup;
+ }
+
+ public void setMarkup(NodeList markup) {
+ this.markup = markup;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java
new file mode 100644
index 0000000..c6e5ab9
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaElement.java
@@ -0,0 +1,265 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for elements. Represents the World Wide Web Consortium (W3C) element element.
+ */
+
+public class XmlSchemaElement extends XmlSchemaParticle implements TypeReceiver {
+
+ /**
+ * Attribute used to block a type derivation.
+ */
+ XmlSchemaDerivationMethod block;
+
+ /**
+ * The value after an element has been compiled to post-schema infoset.
+ * This value is either from the type itself or, if not defined on the type, taken from the schema element.
+ */
+ XmlSchemaDerivationMethod blockResolved;
+ XmlSchemaObjectCollection constraints;
+
+ /**
+ * Provides the default value of the element if its content
+ * is a simple type or the element's content is textOnly.
+ */
+ String defaultValue;
+ String fixedValue;
+
+ /**
+ * Returns the correct common runtime library
+ * object based upon the SchemaType for the element.
+ */
+ Object elementType;
+
+ XmlSchemaDerivationMethod finalDerivation;
+ XmlSchemaDerivationMethod finalDerivationResolved;
+
+ /**
+ * The default value is the value of the elementFormDefault attribute for the schema element containing the attribute.
+ * The default is Unqualified.
+ */
+ XmlSchemaForm form;
+ boolean isAbstract;
+ boolean isNillable;
+ String name;
+ QName qualifiedName;
+ QName refName;
+
+ /**
+ * Returns the type of the element.
+ * This can either be a complex type or a simple type.
+ */
+ XmlSchemaType schemaType;
+
+ /**
+ * QName of a built-in data type defined in this schema or another
+ * schema indicated by the specified namespace.
+ */
+ QName schemaTypeName;
+
+ /**
+ * QName of an element that can be a substitute for this element.
+ */
+ QName substitutionGroup;
+
+ /**
+ * Creates new XmlSchemaElement
+ */
+ public XmlSchemaElement() {
+ constraints = new XmlSchemaObjectCollection();
+ isAbstract = false;
+ isNillable = false;
+ form = new XmlSchemaForm(XmlSchemaForm.NONE);
+ finalDerivation = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ block = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ }
+
+ /**
+ * Returns a collection of constraints on the element.
+ */
+ public XmlSchemaObjectCollection getConstraints() {
+ return constraints;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public XmlSchemaDerivationMethod getBlock() {
+ return block;
+ }
+
+ public void setBlock(XmlSchemaDerivationMethod block) {
+ this.block = block;
+ }
+
+ public XmlSchemaDerivationMethod getFinal() {
+ return finalDerivation;
+ }
+
+ public void setFinal(XmlSchemaDerivationMethod finalDerivation) {
+ this.finalDerivation = finalDerivation;
+ }
+
+ public XmlSchemaDerivationMethod getBlockResolved() {
+ return blockResolved;
+ }
+
+ public String getFixedValue() {
+ return fixedValue;
+ }
+
+ public void setFixedValue(String fixedValue) {
+ this.fixedValue = fixedValue;
+ }
+
+ public Object getElementType() {
+ return elementType;
+ }
+
+ public XmlSchemaForm getForm() {
+ return form;
+ }
+
+ public void setForm(XmlSchemaForm form) {
+ this.form = form;
+ }
+
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ public void setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
+ }
+
+ public boolean isNillable() {
+ return isNillable;
+ }
+
+ public void setNillable(boolean isNillable) {
+ this.isNillable = isNillable;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public QName getRefName() {
+ return refName;
+ }
+
+ public void setRefName(QName refName) {
+ this.refName = refName;
+ }
+
+ public QName getQName() {
+ return qualifiedName;
+ }
+
+ public void setQName(QName qualifiedName) {
+ this.qualifiedName = qualifiedName;
+ }
+
+ public XmlSchemaType getSchemaType() {
+ return schemaType;
+ }
+
+ public void setSchemaType(XmlSchemaType schemaType) {
+ this.schemaType = schemaType;
+ }
+
+ public QName getSchemaTypeName() {
+ return schemaTypeName;
+ }
+
+ public void setSchemaTypeName(QName schemaTypeName) {
+ this.schemaTypeName = schemaTypeName;
+ }
+
+ public QName getSubstitutionGroup() {
+ return substitutionGroup;
+ }
+
+ public void setSubstitutionGroup(QName substitutionGroup) {
+ this.substitutionGroup = substitutionGroup;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "<" + prefix + "element ";
+
+ if (!name.equals(""))
+ xml += "name=\"" + name + "\" ";
+
+ if (schemaTypeName != null)
+ xml += "type=\"" + schemaTypeName + "\"";
+
+ if (refName != null)
+ xml += "ref=\"" + refName + "\" ";
+
+ if (minOccurs != 1)
+ xml += "minOccurs=\"" + minOccurs + "\" ";
+
+ if (maxOccurs != 1)
+ xml += "maxOccurs=\"" + maxOccurs + "\" ";
+
+ if (isNillable)
+ xml += "nillable=\"" + isNillable + "\" ";
+
+ xml += ">\n";
+
+ if (constraints != null)
+ xml += constraints.toString(prefix, (tab + 1));
+
+ if (schemaType != null) {
+ xml += schemaType.toString(prefix, (tab + 1));
+ }
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "element>\n";
+
+ return xml;
+ }
+
+ public void setType(XmlSchemaType type) {
+ this.schemaType = type;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaEnumerationFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaEnumerationFacet.java
new file mode 100644
index 0000000..a600135
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaEnumerationFacet.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining enumeration facets. Represents the World Wide
+ * Web Consortium (W3C) enumeration facet.
+ */
+
+public class XmlSchemaEnumerationFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaEnumerationFacet
+ */
+ public XmlSchemaEnumerationFacet() {
+ }
+
+ public XmlSchemaEnumerationFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<enumeration value=\"");
+ xml.append(super.getValue());
+ xml.append("\" ");
+
+ xml.append("fixed=\"");
+ xml.append(super.isFixed());
+ xml.append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java
new file mode 100644
index 0000000..d779968
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaException.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+
+/**
+ * Returns detailed information about the schema exception.
+ */
+
+public class XmlSchemaException extends RuntimeException {
+
+ /**
+ * Creates new XmlSchemaException
+ */
+ public XmlSchemaException() {
+ }
+
+ public XmlSchemaException(String message) {
+ super(message);
+ }
+
+ public XmlSchemaException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ // TODO :implement
+ public int getLineNumer() {
+ return 1;
+ }
+
+ public int getLinePosition() {
+ return 1;
+ }
+
+ public XmlSchemaObject getSourceSchemaObject() {
+ return null;
+ }
+
+ public String getSourceUri() {
+ return null;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaExternal.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaExternal.java
new file mode 100644
index 0000000..1ae278e
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaExternal.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * An abstract class. Provides information about the included schema.
+ */
+
+public abstract class XmlSchemaExternal extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaExternal
+ */
+ protected XmlSchemaExternal() {
+ }
+
+ XmlSchema schema;
+
+ public XmlSchema getSchema() {
+ return schema;
+ }
+
+ public void setSchema(XmlSchema schema) {
+ this.schema = schema;
+ }
+
+ String schemaLocation;
+
+ public String getSchemaLocation() {
+ return schemaLocation;
+ }
+
+ public void setSchemaLocation(String schemaLocation) {
+ this.schemaLocation = schemaLocation;
+ }
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java
new file mode 100644
index 0000000..e1fe238
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFacet.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.w3c.dom.Element;
+
+/**
+ * Abstract class for all facets that are used when simple types are
+ * derived by restriction.
+ */
+
+public abstract class XmlSchemaFacet extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaFacet
+ */
+
+
+ protected XmlSchemaFacet() {
+ }
+
+ protected XmlSchemaFacet(Object value, boolean fixed) {
+ this.value = value;
+ this.fixed = fixed;
+ }
+
+ boolean fixed;
+
+ Object value;
+
+ public boolean isFixed() {
+ return fixed;
+ }
+
+ public void setFixed(boolean fixed) {
+ this.fixed = fixed;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public static XmlSchemaFacet construct(Element el) {
+ String name = el.getLocalName();
+ boolean fixed = false;
+ if (el.getAttribute("fixed").equals("true")) {
+ fixed = true;
+ }
+ XmlSchemaFacet facet;
+ if (name.equals("enumeration")) {
+ facet = new XmlSchemaEnumerationFacet();
+ } else if (name.equals("fractionDigits")) {
+ facet = new XmlSchemaFractionDigitsFacet();
+ } else if (name.equals("length")) {
+ facet = new XmlSchemaLengthFacet();
+ } else if (name.equals("maxExclusive")) {
+ facet = new XmlSchemaMaxExclusiveFacet();
+ } else if (name.equals("maxInclusive")) {
+ facet = new XmlSchemaMaxInclusiveFacet();
+ } else if (name.equals("maxLength")) {
+ facet = new XmlSchemaMaxLengthFacet();
+ } else if (name.equals("minLength")) {
+ facet = new XmlSchemaMinLengthFacet();
+ } else if (name.equals("minExclusive")) {
+ facet = new XmlSchemaMinExclusiveFacet();
+ } else if (name.equals("minInclusive")) {
+ facet = new XmlSchemaMinInclusiveFacet();
+ } else if (name.equals("pattern")) {
+ facet = new XmlSchemaPatternFacet();
+ } else if (name.equals("totalDigits")) {
+ facet = new XmlSchemaTotalDigitsFacet();
+ } else if (name.equals("whiteSpace")) {
+ facet = new XmlSchemaWhiteSpaceFacet();
+ } else {
+ throw new XmlSchemaException("Incorrect facet with name \""
+ + name + "\" found.");
+ }
+ if (el.hasAttribute("id"))facet.setId(el.getAttribute("id"));
+ facet.setFixed(fixed);
+ facet.setValue(el.getAttribute("value"));
+ return facet;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaForm.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaForm.java
new file mode 100644
index 0000000..91df070
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaForm.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Enum;
+
+/**
+ * Indicates if attributes or elements need to be qualified or left unqualified.
+ */
+
+public class XmlSchemaForm extends Enum {
+
+ public static final String QUALIFIED = "qualified";
+ public static final String UNQUALIFIED = "unqualified";
+ public static final String NONE = "none";
+
+ static String[] members = new String[]{NONE, QUALIFIED, UNQUALIFIED};
+
+ /**
+ * Creates new XmlSchemaForm
+ */
+ public XmlSchemaForm() {
+ super();
+ }
+
+ public XmlSchemaForm(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFractionDigitsFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFractionDigitsFacet.java
new file mode 100644
index 0000000..a129dc6
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaFractionDigitsFacet.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining fractionDigits facets. Represents the World Wide
+ * Web Consortium (W3C) fractionDigits facet.
+ */
+
+public class XmlSchemaFractionDigitsFacet extends XmlSchemaNumericFacet {
+
+ /**
+ * Creates new XmlSchemaFractionDigitsFacet
+ */
+ public XmlSchemaFractionDigitsFacet() {
+ }
+
+ public XmlSchemaFractionDigitsFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<fractionDigits value=\"");
+ xml.append(super.getValue());
+ xml.append("\" ");
+
+ xml.append("fixed=\"");
+ xml.append(super.isFixed());
+ xml.append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroup.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroup.java
new file mode 100644
index 0000000..2b47ae1
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroup.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class that defines groups at the schema level that are referenced
+ * from the complex types. Groups a set of element declarations so that
+ * they can be incorporated as a group into complex type definitions.
+ * Represents the World Wide Web Consortium (W3C) group element.
+ */
+
+public class XmlSchemaGroup extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaGroup
+ */
+ public XmlSchemaGroup() {
+ }
+
+ String name;
+ XmlSchemaGroupBase particle;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public XmlSchemaGroupBase getParticle() {
+ return particle;
+ }
+
+ public void setParticle(XmlSchemaGroupBase particle) {
+ this.particle = particle;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupBase.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupBase.java
new file mode 100644
index 0000000..191a2c3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupBase.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * An abstract class for XmlSchemaChoice, XmlSchemaAll, or XmlSchemaSequence.
+ */
+
+public abstract class XmlSchemaGroupBase extends XmlSchemaParticle {
+ XmlSchemaObjectCollection items;
+
+ /**
+ * Creates new XmlSchemaGroupBase
+ */
+ public XmlSchemaGroupBase() {
+ items = new XmlSchemaObjectCollection();
+ }
+
+ public abstract XmlSchemaObjectCollection getItems();
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupRef.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupRef.java
new file mode 100644
index 0000000..901c23d
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaGroupRef.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class used within complex types that defines the reference to
+ * groups defined at the schema level. Represents the World Wide
+ * Web Consortium (W3C) group element with ref attribute.
+ */
+
+public class XmlSchemaGroupRef extends XmlSchemaParticle {
+
+ /**
+ * Creates new XmlSchemaGroupRef
+ */
+ public XmlSchemaGroupRef() {
+ }
+
+ XmlSchemaGroupBase particle;
+
+ public XmlSchemaGroupBase getParticle() {
+ return this.particle;
+ }
+
+ QName refName;
+
+ public QName getRefName() {
+ return this.refName;
+ }
+
+ public void setRefName(QName refName) {
+ this.refName = refName;
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java
new file mode 100644
index 0000000..715bef9
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaIdentityConstraint.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for the identity constraints: key, keyref, and unique elements.
+ */
+
+public class XmlSchemaIdentityConstraint extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaIdentityConstraint
+ */
+ public XmlSchemaIdentityConstraint() {
+ fields = new XmlSchemaObjectCollection();
+ }
+
+ XmlSchemaObjectCollection fields;
+
+ public XmlSchemaObjectCollection getFields() {
+ return fields;
+ }
+
+ String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ XmlSchemaXPath selector;
+
+ public XmlSchemaXPath getSelector() {
+ return selector;
+ }
+
+ public void setSelector(XmlSchemaXPath selector) {
+ this.selector = selector;
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaImport.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaImport.java
new file mode 100644
index 0000000..2cf7f49
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaImport.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * The class to import schema components from any schema.
+ * Represents the World Wide Web Consortium (W3C) import element.
+ */
+
+public class XmlSchemaImport extends XmlSchemaExternal {
+
+ /**
+ * Creates new XmlSchemaImport
+ */
+ public XmlSchemaImport() {
+ super();
+ }
+
+ String namespace;
+
+ public String getNamespace() {
+ return this.namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaInclude.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaInclude.java
new file mode 100644
index 0000000..c61e7ff
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaInclude.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class to include declarations and definitions from an external schema.
+ * Allows them to be available for processing in the containing schema.
+ * Represents the World Wide Web Consortium (W3C) include element.
+ */
+
+public class XmlSchemaInclude extends XmlSchemaExternal {
+
+ /**
+ * Creates new XmlSchemaInclude
+ */
+ public XmlSchemaInclude() {
+ super();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKey.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKey.java
new file mode 100644
index 0000000..324e866
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKey.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Identifies a key constraint. Represents the World Wide Web Consortium
+ * (W3C) key element.
+ */
+
+public class XmlSchemaKey extends XmlSchemaIdentityConstraint {
+
+ /**
+ * Creates new XmlSchemaKey
+ */
+ public XmlSchemaKey() {
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKeyref.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKeyref.java
new file mode 100644
index 0000000..61c81bb
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaKeyref.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Identifies a keyref constraint. Represents the World Wide Web
+ * Consortium (W3C) keyref element.
+ */
+
+public class XmlSchemaKeyref extends XmlSchemaIdentityConstraint {
+
+ /**
+ * Creates new XmlSchemaKeyref
+ */
+ public XmlSchemaKeyref() {
+ }
+
+ QName refer;
+
+ public QName getRefer() {
+ return refer;
+ }
+
+ public void setRefer(QName refer) {
+ this.refer = refer;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaLengthFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaLengthFacet.java
new file mode 100644
index 0000000..f46e97c
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaLengthFacet.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining length facets. Represents the World Wide Web
+ * Consortium (W3C) length facet.
+ */
+
+public class XmlSchemaLengthFacet extends XmlSchemaNumericFacet {
+
+ /**
+ * Creates new XmlSchemaLengthFacet
+ */
+ public XmlSchemaLengthFacet() {
+ }
+
+ public XmlSchemaLengthFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<length value=\"");
+ xml.append(super.getValue());
+ xml.append("\" ");
+ xml.append("fixed=\"");
+ xml.append(super.isFixed());
+ xml.append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxExclusiveFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxExclusiveFacet.java
new file mode 100644
index 0000000..314d9ca
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxExclusiveFacet.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining maxExclusive facets. Represents the World Wide
+ * Web Consortium (W3C) maxExclusive facet.
+ */
+
+public class XmlSchemaMaxExclusiveFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaMaxExclusiveFacet
+ */
+ public XmlSchemaMaxExclusiveFacet() {
+ }
+
+ public XmlSchemaMaxExclusiveFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<maxExclusive value=\"");
+ xml.append(super.getValue());
+ xml.append("\" ");
+ xml.append("fixed=\"");
+ xml.append(super.isFixed());
+ xml.append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxInclusiveFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxInclusiveFacet.java
new file mode 100644
index 0000000..780c220
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxInclusiveFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining maxInclusive facets. Represents the World
+ * Wide Web Consortium (W3C) maxInclusive facet.
+ */
+
+public class XmlSchemaMaxInclusiveFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaMaxInclusiveFacet
+ */
+ public XmlSchemaMaxInclusiveFacet() {
+ }
+
+ public XmlSchemaMaxInclusiveFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<maxInclusive value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"" + super.isFixed() + "\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxLengthFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxLengthFacet.java
new file mode 100644
index 0000000..b0a6db3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMaxLengthFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining maxLength facets. Represents the World Wide
+ * Web Consortium (W3C) maxLength facet.
+ */
+
+public class XmlSchemaMaxLengthFacet extends XmlSchemaNumericFacet {
+
+ /**
+ * Creates new XmlSchemaMaxLengthFacet
+ */
+ public XmlSchemaMaxLengthFacet() {
+ }
+
+ public XmlSchemaMaxLengthFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<maxLength value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"" + super.isFixed() + "\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinExclusiveFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinExclusiveFacet.java
new file mode 100644
index 0000000..67e24a5
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinExclusiveFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining minExclusive facets. Represents the World
+ * Wide Web Consortium (W3C) minExclusive facet.
+ */
+
+public class XmlSchemaMinExclusiveFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaMinExclusive
+ */
+ public XmlSchemaMinExclusiveFacet() {
+ }
+
+ public XmlSchemaMinExclusiveFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<minExclusive value=\"").append((String) super.getValue()).append("\" ");
+ xml.append("fixed=\"" + super.isFixed() + "\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinInclusiveFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinInclusiveFacet.java
new file mode 100644
index 0000000..f204c25
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinInclusiveFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining minInclusive facets. Represents the World Wide
+ * Web Consortium (W3C) minInclusive facet.
+ */
+
+public class XmlSchemaMinInclusiveFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaMinInclusive
+ */
+ public XmlSchemaMinInclusiveFacet() {
+ }
+
+ public XmlSchemaMinInclusiveFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<minInclusive value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"" + super.isFixed() + "\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinLengthFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinLengthFacet.java
new file mode 100644
index 0000000..dfb438f
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaMinLengthFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining minLength facets. Represents the World Wide
+ * Web Consortium (W3C) minLength facet.
+ */
+
+public class XmlSchemaMinLengthFacet extends XmlSchemaNumericFacet {
+
+ /**
+ * Creates new XmlSchemaMinLengthFacet
+ */
+ public XmlSchemaMinLengthFacet() {
+ }
+
+ public XmlSchemaMinLengthFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<minLength value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"").append(super.isFixed()).append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNotation.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNotation.java
new file mode 100644
index 0000000..d701df6
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNotation.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class represents a notation. An XML Schema definition language (XSD)
+ * notation declaration is a reconstruction of XML 1.0 NOTATION
+ * declarations. The purpose of notations is to describe the format of
+ * non-XML data within an XML document. Represents the World Wide Web Consortium
+ * (W3C) notation element.
+ */
+
+public class XmlSchemaNotation extends XmlSchemaAnnotated {
+
+ String name, system, publicNotation;
+
+ /**
+ * Creates new XmlSchemaNotation
+ */
+ public XmlSchemaNotation() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setString(String name) {
+ this.name = name;
+ }
+
+ public String getPublic() {
+ return publicNotation;
+ }
+
+ public void setPublic(String publicNotation) {
+ this.publicNotation = publicNotation;
+ }
+
+ public String getSystem() {
+ return system;
+ }
+
+ public void setSystem(String system) {
+ this.system = system;
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNumericFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNumericFacet.java
new file mode 100644
index 0000000..ac6315b
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaNumericFacet.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Abstract class for defining numeric facets.
+ */
+
+public abstract class XmlSchemaNumericFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaNumericFacet
+ */
+ protected XmlSchemaNumericFacet() {
+ }
+
+ protected XmlSchemaNumericFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java
new file mode 100644
index 0000000..37e83ac
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObject.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public abstract class XmlSchemaObject {
+ int lineNumber;
+ int linePosition;
+ String sourceURI;
+
+ /**
+ * a map for holding meta information
+ * Initially set to null to gain some improvement
+ * in memory. will be initialized only if a
+ * user attempts
+ */
+ private Map metaInfoMap = null;
+
+ /**
+ * returns the metainfo map. may be null
+ * if not utilized
+ */
+ public Map getMetaInfoMap() {
+ return metaInfoMap;
+ }
+
+ /**
+ * Directly set the meta info map into the schema element
+ * @param metaInfoMap
+ */
+ public void setMetaInfoMap(Map metaInfoMap) {
+ this.metaInfoMap = metaInfoMap;
+ }
+
+ /**
+ * Add a value to the meta info map
+ * will be initialized if not used
+ * previously
+ * @param key
+ * @param value
+ */
+ public void addMetaInfo(Object key,Object value){
+ if (metaInfoMap==null){
+ metaInfoMap = new LinkedHashMap();
+ }
+
+ metaInfoMap.put(key,value);
+ }
+
+
+ /**
+ * Creates new XmlSchemaObject
+ */
+ protected XmlSchemaObject() {
+ }
+
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ public void setLineNumber(int lineNumber) {
+ this.lineNumber = lineNumber;
+ }
+
+ public int getLinePosition() {
+ return linePosition;
+ }
+
+ public void setLinePosition(int linePosition) {
+ this.linePosition = linePosition;
+ }
+
+ public String getSourceURI() {
+ return sourceURI;
+ }
+
+ public void setSourceURI(String sourceURI) {
+ this.sourceURI = sourceURI;
+ }
+
+ public boolean equals(Object what) {
+ if (what == this) {
+ return true;
+ }
+
+ // note: instanceof returns false if its first operand is null
+ if (!(what instanceof XmlSchemaObject)) {
+ return false;
+ }
+
+ XmlSchemaObject xso = (XmlSchemaObject) what;
+
+ if (this.lineNumber != xso.lineNumber) {
+ return false;
+ }
+
+ if (this.linePosition != xso.linePosition) {
+ return false;
+ }
+
+ if (this.sourceURI != null) {
+ if (!this.sourceURI.equals(xso.sourceURI)) {
+ return false;
+ }
+ } else {
+ if (xso.sourceURI != null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += this.getClass().toString() + "\n";
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java
new file mode 100644
index 0000000..3abba91
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectCollection.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * An object collection class to handle XmlSchemaObjects when collections
+ * are returned from method calls.
+ */
+public class XmlSchemaObjectCollection {
+
+ Vector objects;
+
+ /**
+ * Creates new XmlSchemaObjectCollection
+ */
+ public XmlSchemaObjectCollection() {
+ objects = new Vector();
+ }
+
+ public int getCount() {
+ return objects.size();
+ }
+
+ public XmlSchemaObject getItem(int i) {
+ return (XmlSchemaObject) objects.elementAt(i);
+ }
+
+ public void setItem(int i, XmlSchemaObject item) {
+ objects.insertElementAt(item, i);
+ }
+
+ public void add(XmlSchemaObject item) {
+ objects.addElement(item);
+ }
+
+ public boolean contains(XmlSchemaObject item) {
+ return objects.contains(item);
+ }
+
+ public int indexOf(XmlSchemaObject item) {
+ return objects.indexOf(item);
+ }
+
+ public void remove(XmlSchemaObject item) {
+ objects.remove(item);
+ }
+
+ public void removeAt(int index) {
+ objects.removeElementAt(index);
+ }
+
+ public Iterator getIterator() {
+ return objects.iterator();
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ for (int i = 0; i < getCount(); i++) {
+ xml += getItem(i).toString(prefix, tab);
+ }
+
+
+ return xml;
+
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectEnumerator.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectEnumerator.java
new file mode 100644
index 0000000..e81b4ba
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectEnumerator.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * An enumerator class to walk the XmlSchemaObjectCollection collections.
+ */
+public class XmlSchemaObjectEnumerator {
+
+ /**
+ * Creates new XmlSchemaObjectEnumerator
+ */
+ public XmlSchemaObjectEnumerator() {
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectTable.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectTable.java
new file mode 100644
index 0000000..4d22c6e
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaObjectTable.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * A collection class that provides read-only helpers for XmlSchemaObject
+ * objects. This class is used to provide the collections for contained
+ * elements that are within the schema as collections that are accessed
+ * from the XmlSchema class (for example, Attributes, AttributeGroups,
+ * Elements, and so on).
+ */
+
+public class XmlSchemaObjectTable {
+
+ HashMap collection;
+
+ /**
+ * Creates new XmlSchemaObjectTable
+ */
+ public XmlSchemaObjectTable() {
+ this.collection = new HashMap();
+ }
+
+ public int getCount() {
+ return this.collection.size();
+ }
+
+ public XmlSchemaObject getItem(QName name) {
+ return (XmlSchemaObject) collection.get(name);
+ }
+
+ public Iterator getNames() {
+ return collection.keySet().iterator();
+ }
+
+ public Iterator getValues() {
+ return collection.values().iterator();
+ }
+
+ public boolean contains(QName name) {
+ return collection.containsKey(name);
+ }
+
+ public void add(QName name, XmlSchemaObject value) {
+ collection.put(name, value);
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java
new file mode 100644
index 0000000..e52b72c
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaParticle.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Base class for all particle types.
+ */
+
+public class XmlSchemaParticle extends XmlSchemaAnnotated {
+
+ long maxOccurs = 1;
+ String maxOccursString;
+ long minOccurs = 1;
+ String minOccursString;
+
+ /**
+ * Creates new XmlSchemaParticle
+ * Particle types are usually interchangeable.
+ * A local element declaration or reference to a global element
+ * declaration (element), a compositor ( sequence, choice, or all),
+ * a reference to a named content model group (group), or an element wildcard (any).
+ */
+ public XmlSchemaParticle() {
+ }
+
+ public void setMaxOccurs(long maxOccurs) {
+ this.maxOccurs = maxOccurs;
+ }
+
+ public long getMaxOccurs() {
+ return maxOccurs;
+ }
+
+ public void setMinOccurs(long minOccurs) {
+ this.minOccurs = minOccurs;
+ }
+
+ public long getMinOccurs() {
+ return minOccurs;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaPatternFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaPatternFacet.java
new file mode 100644
index 0000000..56a4515
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaPatternFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining pattern facets. Represents the World Wide
+ * Web Consortium (W3C) pattern facet.
+ */
+
+public class XmlSchemaPatternFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaPatternFacet
+ */
+ public XmlSchemaPatternFacet() {
+ }
+
+ public XmlSchemaPatternFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<pattern value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"").append(super.isFixed()).append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaRedefine.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaRedefine.java
new file mode 100644
index 0000000..569d2d0
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaRedefine.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Allows simple and complex types, groups, and attribute groups from
+ * external schema files to be redefined in the current schema. This
+ * class provides versioning for the schema elements. Represents the
+ * World Wide Web Consortium (W3C) redefine element.
+ */
+
+public class XmlSchemaRedefine extends XmlSchemaExternal {
+
+ /**
+ * Creates new XmlSchemaRedefine
+ */
+ public XmlSchemaRedefine() {
+ items = new XmlSchemaObjectCollection();
+ schemaTypes = new XmlSchemaObjectTable();
+ groups = new XmlSchemaObjectTable();
+ attributeGroups = new XmlSchemaObjectTable();
+ }
+
+ XmlSchemaObjectTable attributeGroups, groups, schemaTypes;
+
+ public XmlSchemaObjectTable getAttributeGroup() {
+ return attributeGroups;
+ }
+
+ public XmlSchemaObjectTable getGroup() {
+ return groups;
+ }
+
+ XmlSchemaObjectCollection items;
+
+ public XmlSchemaObjectCollection getItems() {
+ return items;
+ }
+
+ public XmlSchemaObjectTable getSchemaTypes() {
+ return schemaTypes;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSequence.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSequence.java
new file mode 100644
index 0000000..3df1820
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSequence.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Requires the elements in the group to appear in the specified sequence
+ * within the containing element. Represents the World Wide Web Consortium
+ * (W3C) sequence (compositor) element.
+ */
+
+public class XmlSchemaSequence extends XmlSchemaGroupBase {
+
+ /**
+ * Creates new XmlSchemaSequence
+ */
+ public XmlSchemaSequence() {
+ }
+
+ /**
+ * The elements contained within the compositor.
+ * Collection of XmlSchemaElement, XmlSchemaGroupRef,
+ * XmlSchemaChoice, XmlSchemaSequence, or XmlSchemaAny.
+ */
+ public XmlSchemaObjectCollection getItems() {
+ return items;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ xml += "<" + prefix + "sequence>\n";
+ for (int i = 0; i < items.getCount(); i++) {
+ xml += items.getItem(i).toString(prefix, (tab + 1));
+ }
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "sequence>\n";
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
new file mode 100644
index 0000000..1604561
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
@@ -0,0 +1,2729 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+import org.apache.ws.commons.schema.utils.NamespacePrefixList;
+import org.w3c.dom.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.util.*;
+public class XmlSchemaSerializer {
+
+ /**
+ * Extension registry for the serializer
+ * */
+
+ private ExtensionRegistry extReg;
+
+ public ExtensionRegistry getExtReg() {
+ return extReg;
+ }
+
+ public void setExtReg(ExtensionRegistry extReg) {
+ this.extReg = extReg;
+ }
+
+
+ private Hashtable schema_ns;
+
+ static String xsdPrefix = "xs";
+ public static final String xsdNamespace = "http://www.w3.org/2001/XMLSchema";
+ ArrayList docs;
+ Element schemaElement;
+
+ private static final String XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
+
+ XmlSchemaSerializer() {
+ docs = new ArrayList();
+ schema_ns = new Hashtable();
+ }
+
+ /**
+ * *********************************************************************
+ * Document[] serializeSchema(XmlSchema schemaObj,
+ * boolean serializeIncluded)
+ * <p/>
+ * Serialize XmlSchema object pass back the document containing a schema
+ * element as its root.
+ * <p/>
+ * Parameter:
+ * schemaObj - Schema object to serialize.
+ * serialzeIncluded - whether to serialize the included(imported)
+ * schema or not. pass true for serialize all included
+ * schema.
+ * <p/>
+ * Return:
+ * Array of Documents that include/imported.
+ * **********************************************************************
+ */
+ public Document[] serializeSchema(XmlSchema schemaObj,
+ boolean serializeIncluded) throws XmlSchemaSerializerException {
+ return serializeSchemaElement(schemaObj, serializeIncluded);
+ }
+
+ Document[] serializeSchemaElement(XmlSchema schemaObj,
+ boolean serializeIncluded) throws XmlSchemaSerializerException {
+
+ XmlSchemaObjectCollection items = schemaObj.getItems();
+ Document serializedSchemaDocs;
+ try {
+ DocumentBuilderFactory docFac = DocumentBuilderFactory.newInstance();
+ docFac.setNamespaceAware(true);
+ DocumentBuilder builder = docFac.newDocumentBuilder();
+ serializedSchemaDocs = builder.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new XmlSchemaException(e.getMessage());
+ }
+
+ Element serializedSchema;
+
+ serializedSchema = setupNamespaces(serializedSchemaDocs, schemaObj);
+ schemaElement = serializedSchema;
+
+ if (schemaObj.syntacticalTargetNamespace != null) {
+ serializedSchema.setAttribute("targetNamespace", schemaObj.syntacticalTargetNamespace);
+
+ Object targetNS =
+ schema_ns.get(schemaObj.syntacticalTargetNamespace);
+
+ //if the namespace is not entered then add
+ //the targetNamespace as its
+ if (targetNS == null) {
+ if(!Constants.XMLNS_URI.equals(schemaObj.syntacticalTargetNamespace)){
+ serializedSchema.setAttributeNS(XMLNS_NAMESPACE_URI,
+ "xmlns", schemaObj.syntacticalTargetNamespace);
+ }
+ String prefix = null;
+ if(schemaObj.getNamespaceContext() != null) {
+ prefix = schemaObj.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
+ }
+ if(prefix == null && schemaObj.parent != null && schemaObj.parent.getNamespaceContext() != null) {
+ prefix = schemaObj.parent.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);
+ }
+ if(prefix == null) {
+ prefix = "";
+ }
+ schema_ns.put(schemaObj.syntacticalTargetNamespace, prefix);
+ }
+ }
+
+
+ //todo: implement xml:lang,
+ if (schemaObj.attributeFormDefault != null) {
+ String formQualified = schemaObj.attributeFormDefault.getValue();
+
+ if (!formQualified.equals(XmlSchemaForm.NONE))
+ serializedSchema.setAttribute("attributeFormDefault", convertString(formQualified));
+ }
+
+ if (schemaObj.elementFormDefault != null) {
+ String formQualified = schemaObj.elementFormDefault.getValue();
+
+ if (!formQualified.equals(XmlSchemaForm.NONE))
+ serializedSchema.setAttribute("elementFormDefault", convertString(formQualified));
+ }
+
+
+ if (schemaObj.annotation != null) {
+ Element annotation = serializeAnnotation(serializedSchemaDocs,
+ schemaObj.annotation, schemaObj);
+ serializedSchema.appendChild(annotation);
+ }
+ if (schemaObj.id != null) {
+ serializedSchema.setAttribute("id",
+ schemaObj.id);
+ }
+ if (schemaObj.blockDefault != null) {
+ String blockDefault = schemaObj.blockDefault.getValue();
+ if (!blockDefault.equals(Constants.BlockConstants.NONE)) {
+ blockDefault = convertString(blockDefault);
+ serializedSchema.setAttribute("blockDefault", blockDefault);
+ }
+ }
+ if (schemaObj.finalDefault != null) {
+ String finalDefault = schemaObj.finalDefault.getValue();
+ if (!finalDefault.equals(Constants.BlockConstants.NONE)) {
+ finalDefault = convertString(finalDefault);
+ serializedSchema.setAttribute("finalDefault", finalDefault);
+ }
+ }
+
+ if (schemaObj.version != null) {
+ serializedSchema.setAttribute("version", schemaObj.version);
+ }
+
+ //add the extra namespace decalarations if any are available
+ NamespacePrefixList ctx = schemaObj.getNamespaceContext();
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int i = 0; i < prefixes.length; i++) {
+ String prefix = prefixes[i];
+ String uri = ctx.getNamespaceURI(prefix);
+ if (!Constants.DEFAULT_NS_PREFIX.equals(prefix)) {
+ serializedSchema.setAttributeNS(Constants.XMLNS_ATTRIBUTE_NS_URI,
+ Constants.XMLNS_ATTRIBUTE + ":" + prefix, uri);
+ }
+ }
+
+ //after serialize the schema add into documentation
+ //and add to document collection array which at the end
+ //returned
+ serializeSchemaChild(items, serializedSchema, serializedSchemaDocs,
+ schemaObj, serializeIncluded);
+
+ //process extension elements/attributes
+ processExtensibilityComponents(schemaObj,serializedSchema);
+
+
+ serializedSchemaDocs.appendChild(serializedSchema);
+ docs.add(serializedSchemaDocs);
+
+
+ Document[] serializedDocs = new Document[docs.size()];
+ docs.toArray(serializedDocs);
+
+ return serializedDocs;
+ }
+
+ private void serializeSchemaChild(XmlSchemaObjectCollection items,
+ Element serializedSchema, Document serializedSchemaDocs,
+ XmlSchema schemaObj, boolean serializeIncluded)
+ throws XmlSchemaSerializerException {
+
+ int itemsLength = items.getCount();
+ /**
+ * For each of the items that belong to this schema,
+ * serialize each member found.
+ * Permittable member is: element, simpleType, complexType,
+ * group, attrributeGroup, Attribute, include, import and redefine.
+ * if any of the member found then serialize the component.
+ */
+
+ // Since imports and includes need to be the first items of the
+ // serialized schema. So this loop does the serialization of the
+ // imports and includes
+
+ for (int i = 0; i < itemsLength; i++) {
+ XmlSchemaObject obj = items.getItem(i);
+ if (obj instanceof XmlSchemaInclude) {
+ Element e = serializeInclude(serializedSchemaDocs,
+ (XmlSchemaInclude) obj, schemaObj, serializeIncluded);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaImport) {
+ Element e = serializeImport(serializedSchemaDocs,
+ (XmlSchemaImport) obj, schemaObj, serializeIncluded);
+ serializedSchema.appendChild(e);
+ }
+ }
+
+ // reloop to serialize the others
+ for (int i = 0; i < itemsLength; i++) {
+ XmlSchemaObject obj = items.getItem(i);
+
+ if (obj instanceof XmlSchemaElement) {
+ Element e = serializeElement(serializedSchemaDocs,
+ (XmlSchemaElement) obj, schemaObj);
+ serializedSchema.appendChild(e);
+
+ } else if (obj instanceof XmlSchemaSimpleType) {
+ Element e = serializeSimpleType(serializedSchemaDocs,
+ (XmlSchemaSimpleType) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaComplexType) {
+ Element e = serializeComplexType(serializedSchemaDocs,
+ (XmlSchemaComplexType) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaGroup) {
+ Element e = serializeGroup(serializedSchemaDocs,
+ (XmlSchemaGroup) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaAttributeGroup) {
+ Element e = serializeAttributeGroup(serializedSchemaDocs,
+ (XmlSchemaAttributeGroup) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaAttribute) {
+ Element e = serializeAttribute(serializedSchemaDocs,
+ (XmlSchemaAttribute) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ } else if (obj instanceof XmlSchemaRedefine) {
+ Element e = serializeRedefine(serializedSchemaDocs,
+ (XmlSchemaRedefine) obj, schemaObj);
+ serializedSchema.appendChild(e);
+ }
+ }
+ }
+
+ /**
+ * Set up <schema> namespaces appropriately and append that attr
+ * into specified element
+ */
+ private Element setupNamespaces(Document schemaDocs, XmlSchema schemaObj) {
+ NamespacePrefixList ctx = schemaObj.getNamespaceContext();
+ schemaObj.schema_ns_prefix = xsdPrefix = ctx.getPrefix(xsdNamespace);
+ if(xsdPrefix == null) {
+ schemaObj.schema_ns_prefix = xsdPrefix = "";
+ }
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int i = 0; i < prefixes.length; i++) {
+ String prefix = prefixes[i];
+ String uri = ctx.getNamespaceURI(prefix);
+ schema_ns.put(uri, prefix);
+ }
+ //for schema that not set the xmlns attrib member
+ if (schema_ns.get(xsdNamespace) == null) {
+ schema_ns.put(xsdNamespace, xsdPrefix);
+ schemaObj.schema_ns_prefix = xsdPrefix;
+ }
+
+ Element schemaEl = createNewElement(schemaDocs, "schema",
+ schemaObj.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ Iterator entries = schema_ns.entrySet().iterator();
+
+ while (entries.hasNext()) {
+ //let it crash for null pointer because then either the schema
+ //is wrong(namespace not set properly or bug in setting ns)
+ Map.Entry entry = (Map.Entry) entries.next();
+ String key = entry.getKey().toString();
+ String value = entry.getValue().toString();
+ value = (value.length() > 0) ? "xmlns:" + value : "xmlns";
+ schemaEl.setAttributeNS(XMLNS_NAMESPACE_URI,
+ value, key);
+ }
+ return schemaEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeInclude(Document doc, XmlSchemaInclude includeObj,
+ * XmlSchema schema)throws XmlSchemaSerializerException
+ * <p/>
+ * set appropriate attribute as per this object attribute availability.
+ * Call included schema to append to this schema document collection.
+ * Then add the document created into document pool.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * includeObj - XmlSchemaInclude that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element object representation of XmlSchemaInclude
+ * **********************************************************************
+ */
+ Element serializeInclude(Document doc, XmlSchemaInclude includeObj,
+ XmlSchema schema, boolean serializeIncluded)
+ throws XmlSchemaSerializerException {
+
+ Element includeEl = createNewElement(doc, "include",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (includeObj.schemaLocation != null) {
+ includeEl.setAttribute("schemaLocation",
+ includeObj.schemaLocation);
+ }
+
+ if (includeObj.id != null)
+ includeEl.setAttribute("id", includeObj.id);
+
+ if (includeObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ includeObj.annotation, schema);
+ includeEl.appendChild(annotation);
+ }
+
+ //Get the XmlSchema obj and append that to the content
+ XmlSchema includedSchemaObj = includeObj.getSchema();
+ if (includedSchemaObj != null && serializeIncluded) {
+ XmlSchemaSerializer includeSeri = new XmlSchemaSerializer();
+ includeSeri.serializeSchemaElement(includedSchemaObj, true);
+// XmlSchemaObjectCollection ii = includedSchemaObj.getItems();
+ docs.addAll(includeSeri.docs);
+ }
+
+ //process includes
+ processExtensibilityComponents(includeObj,includeEl);
+
+ return includeEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeImport(Document doc, XmlSchemaImport importObj,
+ * XmlSchema schema)throws XmlSchemaSerializerException
+ * <p/>
+ * Add each of the attribute of XmlSchemaImport obj into import Element
+ * Then serialize schema that is included by this import. Include the
+ * serialized schema into document pool.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * includeObj - XmlSchemaInclude that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element object representation of XmlSchemaImport
+ * **********************************************************************
+ */
+ Element serializeImport(Document doc, XmlSchemaImport importObj,
+ XmlSchema schema, boolean serializeIncluded)
+ throws XmlSchemaSerializerException {
+
+ Element importEl = createNewElement(doc, "import",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (importObj.namespace != null)
+ importEl.setAttribute("namespace",
+ importObj.namespace);
+
+ if (importObj.schemaLocation != null && !importObj.schemaLocation.trim().equals(""))
+ importEl.setAttribute("schemaLocation",
+ importObj.schemaLocation);
+
+ if (importObj.id != null)
+ importEl.setAttribute("id", importObj.id);
+
+ if (importObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ importObj.annotation, schema);
+
+ importEl.appendChild(annotation);
+ }
+
+ if (importObj.schema != null && serializeIncluded) {
+
+
+ XmlSchemaSerializer importSeri = new XmlSchemaSerializer();
+ importSeri.serializeSchemaElement(importObj.schema, serializeIncluded);
+ docs.addAll(importSeri.docs);
+ }
+
+ //process extension
+ processExtensibilityComponents(importObj,importEl);
+
+ return importEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeRedefine(Document doc, XmlSchemaRedefine redefineObj,
+ * XmlSchema schema)throws XmlSchemaSerializerException
+ * <p/>
+ * Add each of the attribute of XmlSchemaImport obj into import Element
+ * Then serialize schema that is included by this import. Include the
+ * serialized schema into document pool.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * redefineObj - XmlSchemaInclude that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element object representation of XmlSchemaRedefine
+ * **********************************************************************
+ */
+ Element serializeRedefine(Document doc, XmlSchemaRedefine redefineObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element redefine = createNewElement(doc, "redefine",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (redefineObj.schemaLocation != null)
+ redefine.setAttribute("schemaLocation",
+ redefineObj.schemaLocation);
+ else
+ throw new XmlSchemaSerializerException("redefine must have "
+ + "schemaLocation fields fill");
+
+ if (redefineObj.id != null)
+ redefine.setAttribute("id", redefineObj.id);
+
+ if (redefineObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ redefineObj.annotation, schema);
+ redefine.appendChild(annotation);
+ }
+ int itemsLength = redefineObj.items.getCount();
+ for (int i = 0; i < itemsLength; i++) {
+ XmlSchemaObject obj = redefineObj.items.getItem(i);
+ if (obj instanceof XmlSchemaSimpleType) {
+ Element simpleType = serializeSimpleType(doc,
+ (XmlSchemaSimpleType) obj, schema);
+ redefine.appendChild(simpleType);
+ } else if (obj instanceof XmlSchemaComplexType) {
+ Element complexType = serializeComplexType(doc,
+ (XmlSchemaComplexType) obj, schema);
+ redefine.appendChild(complexType);
+ } else if (obj instanceof XmlSchemaGroupRef) {
+ Element groupRef = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) obj, schema);
+ redefine.appendChild(groupRef);
+ } else if (obj instanceof XmlSchemaGroup) {
+ Element group = serializeGroup(doc,
+ (XmlSchemaGroup) obj, schema);
+ redefine.appendChild(group);
+ } else if (obj instanceof XmlSchemaAttributeGroup) {
+ Element attributeGroup = serializeAttributeGroup(doc,
+ (XmlSchemaAttributeGroup) obj, schema);
+ redefine.appendChild(attributeGroup);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attributeGroupRef = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ redefine.appendChild(attributeGroupRef);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(redefineObj,redefine);
+
+ return redefine;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeElement(Document doc, XmlSchemaElement elementObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException
+ * <p/>
+ * Each member of Element will be appended and pass the element
+ * created. Element processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * elementObj - XmlSchemaInclude that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element object of element.
+ * **********************************************************************
+ */
+ Element serializeElement(Document doc, XmlSchemaElement elementObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+ Element serializedEl = createNewElement(doc, "element",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+
+ if (elementObj.refName != null) {
+
+ String resolvedName = resolveQName(elementObj.refName, schema);
+ serializedEl.setAttribute("ref", resolvedName);
+ } else if (elementObj.name != null && elementObj.name.length() > 0) {
+ serializedEl.setAttribute("name",
+ elementObj.name);
+ }
+
+ if (elementObj.isAbstract)
+ serializedEl.setAttribute("abstract", "true");
+
+ String block = elementObj.block.getValue();
+ if (!block.equals(Constants.BlockConstants.NONE)) {
+ block = convertString(block);
+ serializedEl.setAttribute("block", block);
+ }
+ if (elementObj.defaultValue != null)
+ serializedEl.setAttribute("default",
+ elementObj.defaultValue);
+
+ String finalDerivation = elementObj.finalDerivation.getValue();
+ if (!finalDerivation.equals(Constants.BlockConstants.NONE)) {
+ finalDerivation = convertString(finalDerivation);
+ serializedEl.setAttribute("final",
+ finalDerivation);
+ }
+ if (elementObj.fixedValue != null)
+ serializedEl.setAttribute("fixed",
+ elementObj.fixedValue);
+
+ String formDef = elementObj.form.getValue();
+ if (!formDef.equals(XmlSchemaForm.NONE)) {
+ formDef = convertString(formDef);
+ serializedEl.setAttribute("form", formDef);
+ }
+ if (elementObj.id != null)
+ serializedEl.setAttribute("id", elementObj.id);
+
+ if (elementObj.maxOccurs < Long.MAX_VALUE && elementObj.maxOccurs > 1)
+ serializedEl.setAttribute("maxOccurs",
+ elementObj.maxOccurs + "");
+ else if (elementObj.maxOccurs == Long.MAX_VALUE)
+ serializedEl.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+ /*if(elementObj.minOccurs >1)
+ serializedEl.setAttribute("minOccurs",
+ elementObj.minOccurs + "");*/
+
+ //Change - SK and Ragu cos it wasnt picking up
+ // minOccurs = 0
+ if (elementObj.minOccurs < Long.MAX_VALUE && elementObj.minOccurs != 1)
+ serializedEl.setAttribute("minOccurs",
+ elementObj.minOccurs + "");
+ else if (elementObj.minOccurs == Long.MAX_VALUE)
+ serializedEl.setAttribute("minOccurs",
+ "unbounded");
+
+ /*
+ if(elementObj.maxOccursString != null)
+ serializedEl.setAttribute("maxOccurs",
+ elementObj.maxOccursString);
+ else if(elementObj.maxOccurs > 1)
+ serializedEl.setAttribute("maxOccurs",
+ elementObj.maxOccurs + "");
+
+ if(elementObj.minOccurs > 1)
+ serializedEl.setAttribute("minOccurs",
+ elementObj.minOccurs + "");
+ */
+ if (elementObj.substitutionGroup != null) {
+ String resolvedQName = resolveQName(elementObj.substitutionGroup, schema);
+ serializedEl.setAttribute("substitutionGroup",
+ resolvedQName);
+ }
+ if (elementObj.schemaTypeName != null) {
+ String resolvedName = resolveQName(elementObj.schemaTypeName, schema);
+ serializedEl.setAttribute("type", resolvedName);
+ }
+ if (elementObj.annotation != null) {
+ Element annotationEl = serializeAnnotation(doc,
+ elementObj.annotation, schema);
+ serializedEl.appendChild(annotationEl);
+ }
+ if (elementObj.schemaType != null && elementObj.schemaTypeName == null) {
+ if (elementObj.schemaType instanceof XmlSchemaComplexType) {
+
+ Element complexType = serializeComplexType(doc,
+ (XmlSchemaComplexType) elementObj.schemaType, schema);
+ serializedEl.appendChild(complexType);
+ } else if (elementObj.schemaType instanceof XmlSchemaSimpleType) {
+ Element simpleType = serializeSimpleType(doc,
+ (XmlSchemaSimpleType) elementObj.schemaType, schema);
+ serializedEl.appendChild(simpleType);
+ }
+ }
+ if (elementObj.constraints.getCount() > 0) {
+ for (int i = 0; i < elementObj.constraints.getCount(); i++) {
+ Element constraint = serializeIdentityConstraint(doc,
+ (XmlSchemaIdentityConstraint) elementObj.constraints.getItem(i),
+ schema);
+ serializedEl.appendChild(constraint);
+ }
+ }
+ if (elementObj.isNillable) {
+ serializedEl.setAttribute("nillable", "true");
+ }
+
+ //process extension
+ processExtensibilityComponents(elementObj,serializedEl);
+
+ return serializedEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleType(Document doc,
+ * XmlSchemaSimpleType simpleTypeObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of simple type will be appended and pass the element
+ * created. Simple type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * simpleTypeObj - XmlSchemaSimpleType that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element object of SimpleType
+ * **********************************************************************
+ */
+ Element serializeSimpleType(Document doc, XmlSchemaSimpleType simpleTypeObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element serializedSimpleType = createNewElement(doc, "simpleType",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+
+ String tmp;
+ tmp = simpleTypeObj.finalDerivation.getValue();
+ if (!tmp.equals(Constants.BlockConstants.NONE)) {
+
+ tmp = convertString(tmp);
+ serializedSimpleType.setAttribute("final", tmp);
+ }
+ if (simpleTypeObj.id != null)
+ serializedSimpleType.setAttribute("id",
+ simpleTypeObj.id);
+ if ((simpleTypeObj.name != null) && (!simpleTypeObj.name.equals("")))
+ serializedSimpleType.setAttribute("name",
+ simpleTypeObj.name);
+ if (simpleTypeObj.annotation != null) {
+ Element annotationEl = serializeAnnotation(doc,
+ simpleTypeObj.annotation, schema);
+ serializedSimpleType.appendChild(annotationEl);
+ }
+ if (simpleTypeObj.content != null) {
+ if (simpleTypeObj.content instanceof XmlSchemaSimpleTypeRestriction) {
+ Element restEl = serializeSimpleTypeRestriction(doc,
+ (XmlSchemaSimpleTypeRestriction) simpleTypeObj.content,
+ schema);
+ serializedSimpleType.appendChild(restEl);
+ } else if (simpleTypeObj.content instanceof XmlSchemaSimpleTypeList) {
+ Element listEl = serializeSimpleTypeList(doc,
+ (XmlSchemaSimpleTypeList) simpleTypeObj.content, schema);
+ serializedSimpleType.appendChild(listEl);
+ } else if (simpleTypeObj.content instanceof XmlSchemaSimpleTypeUnion) {
+ Element unionEl = serializeSimpleTypeUnion(doc,
+ (XmlSchemaSimpleTypeUnion) simpleTypeObj.content, schema);
+ serializedSimpleType.appendChild(unionEl);
+ }/*else
+ throw new XmlSchemaSerializerException("Invalid type inserted "
+ + "in simpleType content, the content is: "
+ + simpleTypeObj.content.getClass().getName()
+ + " valid content should be XmlSchemaSimpleTypeunion, "
+ + "XmlSchemaSimpleTyperestriction or list");*/
+ }/*else
+ throw new XmlSchemaSerializerException("simple type must be set "
+ + "with content, either union, restriction or list");*/
+
+ //process extension
+ processExtensibilityComponents(simpleTypeObj,serializedSimpleType);
+
+ return serializedSimpleType;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleTypeRestriction(Document doc,
+ * XmlSchemaSimpleTypeRestriction restrictionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of simple type will be appended and pass the element
+ * created. Simple type's <restriction> processed according to w3c
+ * Recommendation May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * restrictionObj - XmlSchemaRestriction that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple type restriction and its child.
+ * **********************************************************************
+ */
+ Element serializeSimpleTypeRestriction(Document doc,
+ XmlSchemaSimpleTypeRestriction restrictionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+ //todo: need to implement any attribute that related to non schema namespace
+ Element serializedRestriction = createNewElement(doc, "restriction",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (schema.schema_ns_prefix.length() > 0)
+ serializedRestriction.setPrefix(schema.schema_ns_prefix);
+ if (restrictionObj.baseTypeName != null) {
+ String baseType = resolveQName(restrictionObj.baseTypeName, schema);
+ serializedRestriction.setAttribute("base", baseType);
+ } else if (restrictionObj.baseType != null && restrictionObj.baseType
+ instanceof XmlSchemaSimpleType) {
+ Element inlineSimpleType = serializeSimpleType(doc,
+ restrictionObj.baseType, schema);
+ serializedRestriction.appendChild(inlineSimpleType);
+ } else
+ throw new XmlSchemaSerializerException("restriction must be define "
+ + "with specifying base or inline simpleType");
+
+ if (restrictionObj.id != null)
+ serializedRestriction.setAttribute("id",
+ restrictionObj.id);
+
+ if (restrictionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ restrictionObj.annotation, schema);
+ serializedRestriction.appendChild(annotation);
+ }
+ if (restrictionObj.facets.getCount() > 0) {
+ int facetsNum = restrictionObj.facets.getCount();
+ for (int i = 0; i < facetsNum; i++) {
+ Element facetEl = serializeFacet(doc,
+ (XmlSchemaFacet) restrictionObj.facets.getItem(i), schema);
+ serializedRestriction.appendChild(facetEl);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(restrictionObj,serializedRestriction);
+
+ return serializedRestriction;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeFacet(Document doc, XmlSchemaFacet facetObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * detect what type of facet and cass appropriatelly,
+ * construct the element and pass it.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * facetObj - XmlSchemaFacet that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple type with facet.
+ * **********************************************************************
+ */
+ Element serializeFacet(Document doc, XmlSchemaFacet facetObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element serializedFacet;
+
+ if (facetObj instanceof XmlSchemaMinExclusiveFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "minExclusive");
+ else if (facetObj instanceof XmlSchemaMinInclusiveFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "minInclusive");
+ else if (facetObj instanceof XmlSchemaMaxExclusiveFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "maxExclusive");
+ else if (facetObj instanceof XmlSchemaMaxInclusiveFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "maxInclusive");
+ else if (facetObj instanceof XmlSchemaTotalDigitsFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "totalDigits");
+ else if (facetObj instanceof XmlSchemaFractionDigitsFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "fractionDigits");
+ else if (facetObj instanceof XmlSchemaLengthFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "length");
+ else if (facetObj instanceof XmlSchemaMinLengthFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "minLength");
+ else if (facetObj instanceof XmlSchemaMaxLengthFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "maxLength");
+ else if (facetObj instanceof XmlSchemaEnumerationFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "enumeration");
+ else if (facetObj instanceof XmlSchemaWhiteSpaceFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "whiteSpace");
+ else if (facetObj instanceof XmlSchemaPatternFacet)
+ serializedFacet = constructFacet(facetObj, doc, schema,
+ "pattern");
+ else
+ throw new XmlSchemaSerializerException("facet not exist "
+ + facetObj.getClass().getName());
+
+ if (facetObj.id != null)
+ serializedFacet.setAttribute("id", facetObj.id);
+// if (facetObj.annotation != null) {
+// Element annotation = serializeAnnotation(doc, facetObj.annotation,
+// schema);
+// serializedFacet.appendChild(annotation);
+// }
+
+ //process extension
+ processExtensibilityComponents(facetObj,serializedFacet);
+
+ return serializedFacet;
+ }
+
+ private Element constructFacet(XmlSchemaFacet facetObj, Document doc,
+ XmlSchema schema, String tagName) {
+
+ Element facetEl = createNewElement(doc, tagName,
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ facetEl.setAttribute("value",
+ facetObj.value.toString());
+ if (facetObj.fixed)
+ facetEl.setAttribute("fixed", "true");
+
+ if (facetObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ facetObj.annotation, schema);
+ facetEl.appendChild(annotation);
+ }
+ return facetEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeComplexType(Document doc,
+ * XmlSchemaComplexType complexTypeObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * complexTypeObj - XmlSchemaFacet that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of complexType.
+ * **********************************************************************
+ */
+ Element serializeComplexType(Document doc,
+ XmlSchemaComplexType complexTypeObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ //todo: need to implement abstract, id, mixed
+ Element serializedComplexType = createNewElement(doc,
+ "complexType", schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if ((complexTypeObj.name != null) && (!complexTypeObj.name.equals("")))
+ serializedComplexType.setAttribute("name",
+ complexTypeObj.name);
+ /*if(complexTypeObj.annotation != null){
+ Element annotationEl = serializeAnnotation(doc,
+ complexTypeObj.annotation, schema);
+ serializedComplexType.appendChild(annotationEl);
+ }*/
+
+ if (complexTypeObj.isMixed)
+ serializedComplexType.setAttribute("mixed", "true");
+ if (complexTypeObj.isAbstract)
+ serializedComplexType.setAttribute(
+ "abstract", "true");
+ if (complexTypeObj.id != null)
+ serializedComplexType.setAttribute("id",
+ complexTypeObj.id);
+
+ if (complexTypeObj.contentModel instanceof XmlSchemaSimpleContent) {
+ Element simpleContent = serializeSimpleContent(doc,
+ (XmlSchemaSimpleContent) complexTypeObj.contentModel, schema);
+ serializedComplexType.appendChild(simpleContent);
+ } else if (complexTypeObj.contentModel instanceof
+ XmlSchemaComplexContent) {
+
+ Element complexContent = serializeComplexContent(doc,
+ (XmlSchemaComplexContent) complexTypeObj.contentModel, schema);
+ serializedComplexType.appendChild(complexContent);
+ }
+
+ if (complexTypeObj.particle instanceof XmlSchemaSequence) {
+ Element sequence = serializeSequence(doc,
+ (XmlSchemaSequence) complexTypeObj.particle, schema);
+ serializedComplexType.appendChild(sequence);
+ } else if (complexTypeObj.particle instanceof XmlSchemaChoice) {
+ Element choice = serializeChoice(doc,
+ (XmlSchemaChoice) complexTypeObj.particle, schema);
+ serializedComplexType.appendChild(choice);
+ } else if (complexTypeObj.particle instanceof XmlSchemaAll) {
+ Element all = serializeAll(doc,
+ (XmlSchemaAll) complexTypeObj.particle, schema);
+ serializedComplexType.appendChild(all);
+ } else if (complexTypeObj.particle instanceof XmlSchemaGroupRef) {
+ Element group = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) complexTypeObj.particle, schema);
+ serializedComplexType.appendChild(group);
+ }
+
+ String block = complexTypeObj.block.getValue();
+ if (!block.equals(Constants.BlockConstants.NONE)) {
+ block = convertString(block);
+ serializedComplexType.setAttribute(
+ "block", block);
+ }
+ String finalDerivation = complexTypeObj.finalDerivation.getValue();
+ if (!finalDerivation.equals(Constants.BlockConstants.NONE)) {
+ finalDerivation = convertString(finalDerivation);
+ serializedComplexType.setAttribute("final",
+ finalDerivation);
+ }
+
+ XmlSchemaObjectCollection attrColl = complexTypeObj.attributes;
+ if (attrColl.getCount() > 0)
+ setupAttr(doc, attrColl, schema, serializedComplexType);
+
+ //process extension
+ processExtensibilityComponents(complexTypeObj,serializedComplexType);
+
+ return serializedComplexType;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSequence(Document doc, XmlSchemaSequence sequenceObj,
+ * XmlSchema schema)throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. `Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * sequenceObj - XmlSchemaFacet that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of sequence particle.
+ * **********************************************************************
+ */
+ Element serializeSequence(Document doc, XmlSchemaSequence sequenceObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element sequence = createNewElement(doc, "sequence",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+
+ if (sequenceObj.id != null)
+ sequence.setAttribute("id", sequenceObj.id);
+
+
+ if (sequenceObj.maxOccurs < Long.MAX_VALUE && sequenceObj.maxOccurs > 1)
+ sequence.setAttribute("maxOccurs",
+ sequenceObj.maxOccurs + "");
+ else if (sequenceObj.maxOccurs == Long.MAX_VALUE)
+ sequence.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+
+ if (sequenceObj.minOccurs > 1)
+ sequence.setAttribute("minOccurs",
+ sequenceObj.minOccurs + "");
+
+ XmlSchemaObjectCollection seqColl = sequenceObj.items;
+ int containLength = seqColl.getCount();
+ for (int i = 0; i < containLength; i++) {
+ XmlSchemaObject obj = seqColl.getItem(i);
+ if (obj instanceof XmlSchemaElement) {
+ Element el = serializeElement(doc,
+ (XmlSchemaElement) obj, schema);
+ sequence.appendChild(el);
+ } else if (obj instanceof XmlSchemaGroupRef) {
+ Element group = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) obj, schema);
+ sequence.appendChild(group);
+ } else if (obj instanceof XmlSchemaChoice) {
+ Element choice = serializeChoice(doc,
+ (XmlSchemaChoice) obj, schema);
+ sequence.appendChild(choice);
+ } else if (obj instanceof XmlSchemaSequence) {
+ Element sequenceChild = serializeSequence(doc,
+ (XmlSchemaSequence) obj, schema);
+ sequence.appendChild(sequenceChild);
+ } else if (obj instanceof XmlSchemaAny) {
+ Element any = serializeAny(doc, (XmlSchemaAny) obj, schema);
+ sequence.appendChild(any);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(sequenceObj,sequence);
+
+ return sequence;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAttribute(Document doc, XmlSchemaAttribute attributeObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. `Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * attributeObj - XmlSchemaAttribute that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of attribute.
+ * **********************************************************************
+ */
+ Element serializeAttribute(Document doc, XmlSchemaAttribute attributeObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element attribute = createNewElement(doc, "attribute",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (attributeObj.refName != null) {
+ String refName =
+ resolveQName(attributeObj.refName, schema);
+ attribute.setAttribute("ref", refName);
+ } else if (attributeObj.name != null)
+ attribute.setAttribute("name",
+ attributeObj.name);
+
+ if (attributeObj.schemaTypeName != null) {
+ String typeName =
+ resolveQName(attributeObj.schemaTypeName, schema);
+ attribute.setAttribute("type", typeName);
+ }
+
+ if (attributeObj.defaultValue != null)
+ attribute.setAttribute("default",
+ attributeObj.defaultValue);
+ if (attributeObj.fixedValue != null)
+ attribute.setAttribute("fixed",
+ attributeObj.fixedValue);
+
+ String formType = attributeObj.form.getValue();
+ if (!formType.equals(XmlSchemaForm.NONE)) {
+ formType = convertString(formType);
+ attribute.setAttribute("form", formType);
+ }
+ if (attributeObj.id != null)
+ attribute.setAttribute("id", attributeObj.id);
+
+ String useType = attributeObj.use.getValue();
+ if (!useType.equals(Constants.BlockConstants.NONE)) {
+ useType = convertString(useType);
+ attribute.setAttribute("use", useType);
+ }
+ if (attributeObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ attributeObj.annotation, schema);
+ attribute.appendChild(annotation);
+ }
+
+
+ if (attributeObj.schemaType != null) {
+ try {
+ XmlSchemaSimpleType simpleType =
+ attributeObj.schemaType;
+ Element simpleTypeEl = serializeSimpleType(doc,
+ simpleType, schema);
+ attribute.appendChild(simpleTypeEl);
+ } catch (ClassCastException e) {
+ throw new XmlSchemaSerializerException("only inline simple type allow as attribute's inline type");
+ }
+ }
+
+ Attr[] unhandled = attributeObj.getUnhandledAttributes();
+
+ Hashtable namespaces = new Hashtable();
+
+ if (unhandled != null) {
+
+ // this is to make the wsdl:arrayType work
+ // since unhandles attributes are not handled this is a special case
+ // but the basic idea is to see if there is any attibute whose value has ":"
+ // if it is present then it is likely that it is a namespace prefix
+ // do what is neccesary to get the real namespace for it and make
+ // required changes to the prefix
+
+ for (int i = 0; i < unhandled.length; i++) {
+ String name = unhandled[i].getNodeName();
+ String value = unhandled[i].getNodeValue();
+ if (name.equals("xmlns")) {
+ namespaces.put("", value);
+ } else if (name.startsWith("xmlns")) {
+ namespaces.put(name.substring(name.indexOf(":") + 1), value);
+ }
+ }
+
+ for (int i = 0; i < unhandled.length; i++) {
+ String value = unhandled[i].getNodeValue();
+ String nodeName = unhandled[i].getNodeName();
+ if (value.indexOf(":") > -1 && !nodeName.startsWith("xmlns")) {
+ String prefix = value.substring(0, value.indexOf(":"));
+ String oldNamespace;
+ if ((oldNamespace = (String) namespaces.get(prefix)) != null) {
+ value = value.substring(value.indexOf(":") + 1);
+ NamespacePrefixList ctx = schema.getNamespaceContext();
+ String[] prefixes = ctx.getDeclaredPrefixes();
+ for (int j = 0; j < prefixes.length; j++) {
+ String pref = prefixes[j];
+ String uri = ctx.getNamespaceURI(pref);
+ if (uri.equals(oldNamespace)) {
+ value = prefix + ":" + value;
+ }
+ }
+ }
+
+ }
+ if (unhandled[i].getNamespaceURI() != null)
+ attribute.setAttributeNS(unhandled[i].getNamespaceURI(), nodeName, value);
+ else
+ attribute.setAttribute(nodeName, value);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(attributeObj,attribute);
+
+ return attribute;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeChoice(Document doc, XmlSchemaChoice choiceObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * choiceObj - XmlSchemaChoice that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of choice schema object.
+ * **********************************************************************
+ */
+ Element serializeChoice(Document doc, XmlSchemaChoice choiceObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+ //todo: handle any non schema attri ?
+
+ Element choice = createNewElement(doc, "choice",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (choiceObj.id != null)
+ if (choiceObj.id.length() > 0)
+ choice.setAttribute("id", choiceObj.id);
+
+
+ if (choiceObj.maxOccurs < Long.MAX_VALUE && choiceObj.maxOccurs != 1)
+ choice.setAttribute("maxOccurs",
+ choiceObj.maxOccurs + "");
+ else if (choiceObj.maxOccurs == Long.MAX_VALUE)
+ choice.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+ if (choiceObj.minOccurs != 1)
+ choice.setAttribute("minOccurs",
+ choiceObj.minOccurs + "");
+
+
+ /*
+ if(choiceObj.maxOccursString != null)
+ choice.setAttribute("maxOccurs",
+ choiceObj.maxOccursString);
+ else if(choiceObj.maxOccurs > 1)
+ choice.setAttribute("maxOccurs",
+ choiceObj.maxOccurs +"");
+ */
+
+
+ if (choiceObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ choiceObj.annotation, schema);
+ choice.appendChild(annotation);
+ }
+
+
+ XmlSchemaObjectCollection itemColl = choiceObj.items;
+
+ if (itemColl != null) {
+ int itemLength = itemColl.getCount();
+
+ for (int i = 0; i < itemLength; i++) {
+ XmlSchemaObject obj = itemColl.getItem(i);
+
+ if (obj instanceof XmlSchemaElement) {
+ Element el = serializeElement(doc,
+ (XmlSchemaElement) obj, schema);
+ choice.appendChild(el);
+ } else if (obj instanceof XmlSchemaGroupRef) {
+ Element group = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) obj, schema);
+ choice.appendChild(group);
+ } else if (obj instanceof XmlSchemaChoice) {
+ Element inlineChoice = serializeChoice(doc,
+ (XmlSchemaChoice) obj, schema);
+ choice.appendChild(inlineChoice);
+ } else if (obj instanceof XmlSchemaSequence) {
+ Element inlineSequence = serializeSequence(doc,
+ (XmlSchemaSequence) obj, schema);
+ choice.appendChild(inlineSequence);
+ } else if (obj instanceof XmlSchemaAny) {
+ Element any = serializeAny(doc, (XmlSchemaAny) obj, schema);
+ choice.appendChild(any);
+ }
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(choiceObj,choice);
+
+ return choice;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAll(Document doc, XmlSchemaAll allObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * allObj - XmlSchemaAll that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of particle all.
+ * **********************************************************************
+ */
+ Element serializeAll(Document doc, XmlSchemaAll allObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+ Element allEl = createNewElement(doc, "all", schema.schema_ns_prefix,
+ XmlSchema.SCHEMA_NS);
+
+ if (allObj.minOccurs == 0)
+ allEl.setAttribute("minOccurs", "0");
+
+
+ if (allObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc, allObj.annotation,
+ schema);
+ allEl.appendChild(annotation);
+ }
+
+ XmlSchemaObjectCollection itemColl = allObj.items;
+
+ if (itemColl != null) {
+ int itemLength = itemColl.getCount();
+
+ for (int i = 0; i < itemLength; i++) {
+ XmlSchemaObject obj = itemColl.getItem(i);
+ if (obj instanceof XmlSchemaElement) {
+ Element el = serializeElement(doc, (XmlSchemaElement) obj,
+ schema);
+ allEl.appendChild(el);
+ } else
+ throw new XmlSchemaSerializerException("Only element "
+ + "allowed as child of all model type");
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(allObj,allEl);
+
+ return allEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleTypeList(Document doc,
+ * XmlSchemaSimpleTypeList listObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * listObj - XmlSchemaSimpleTypeList that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple type with list method.
+ * **********************************************************************
+ */
+ Element serializeSimpleTypeList(Document doc,
+ XmlSchemaSimpleTypeList listObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element list = createNewElement(doc, "list",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (listObj.itemTypeName != null) {
+ String listItemType = resolveQName(listObj.itemTypeName,
+ schema);
+ list.setAttribute("itemType", listItemType);
+ }
+ if (listObj.id != null)
+ list.setAttribute("id", listObj.id);
+
+ else if (listObj.itemType != null) {
+ Element inlineSimpleEl = serializeSimpleType(doc, listObj.itemType,
+ schema);
+ list.appendChild(inlineSimpleEl);
+ }
+ if (listObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc, listObj.annotation, schema);
+ list.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(listObj,list);
+
+ return list;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleTypeUnion(Document doc,
+ * XmlSchemaSimpleTypeUnion unionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * unionObj - XmlSchemaSimpleTypeUnion that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple type with union method.
+ * **********************************************************************
+ */
+ Element serializeSimpleTypeUnion(Document doc,
+ XmlSchemaSimpleTypeUnion unionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+
+ Element union = createNewElement(doc, "union",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (unionObj.id != null)
+ union.setAttribute("id", unionObj.id);
+
+ if (unionObj.memberTypesSource != null)
+ union.setAttribute("memberTypes",
+ unionObj.memberTypesSource);
+ if (unionObj.baseTypes.getCount() > 0) {
+ int baseTypesLength = unionObj.baseTypes.getCount();
+ Element baseType;
+ for (int i = 0; i < baseTypesLength; i++) {
+ try {
+ baseType = serializeSimpleType(doc,
+ (XmlSchemaSimpleType) unionObj.baseTypes.getItem(i),
+ schema);
+ union.appendChild(baseType);
+ } catch (ClassCastException e) {
+ throw new XmlSchemaSerializerException("only inline simple type allow as attribute's "
+ + "inline type");
+ }
+ }
+ }
+ if (unionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc, unionObj.annotation,
+ schema);
+ union.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(unionObj,union);
+
+ return union;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAny(Document doc, XmlSchemaAny anyObj, XmlSchema schema)
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * anyObj - XmlSchemaAny that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of any that is part of its parent.
+ * **********************************************************************
+ */
+ Element serializeAny(Document doc, XmlSchemaAny anyObj, XmlSchema schema) {
+ Element anyEl = createNewElement(doc, "any", schema.schema_ns_prefix,
+ XmlSchema.SCHEMA_NS);
+ if (anyObj.id != null)
+ if (anyObj.id.length() > 0)
+ anyEl.setAttribute("id", anyObj.id);
+
+
+ if (anyObj.maxOccurs < Long.MAX_VALUE && anyObj.maxOccurs > 1)
+ anyEl.setAttribute("maxOccurs",
+ anyObj.maxOccurs + "");
+ else if (anyObj.maxOccurs == Long.MAX_VALUE)
+ anyEl.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+ if (anyObj.minOccurs > 1)
+ anyEl.setAttribute("minOccurs",
+ anyObj.minOccurs + "");
+
+ if (anyObj.namespace != null)
+ anyEl.setAttribute("namespace",
+ anyObj.namespace);
+
+ if (anyObj.processContent != null) {
+ String value = anyObj.processContent.getValue();
+ if (!value.equals(Constants.BlockConstants.NONE)) {
+ String processContent = convertString(value);
+ anyEl.setAttribute("processContents",
+ processContent);
+ }
+ }
+ if (anyObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ anyObj.annotation, schema);
+ anyEl.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(anyObj,anyEl);
+
+ return anyEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeGroup(Document doc, XmlSchemaGroup groupObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * groupObj - XmlSchemaGroup that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of group elements.
+ * **********************************************************************
+ */
+ Element serializeGroup(Document doc, XmlSchemaGroup groupObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element group = createNewElement(doc, "group",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (groupObj.name != null) {
+ if (groupObj.name.length() > 0) {
+ group.setAttribute("name", groupObj.name);
+ }
+ } else
+ throw new XmlSchemaSerializerException("Group must have " +
+ "name or ref");
+
+ /* annotations are supposed to be written first!!!!! */
+ if (groupObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ groupObj.annotation, schema);
+ group.appendChild(annotation);
+ }
+
+ if (groupObj.particle instanceof XmlSchemaSequence) {
+ Element sequence = serializeSequence(doc,
+ (XmlSchemaSequence) groupObj.particle, schema);
+ group.appendChild(sequence);
+ } else if (groupObj.particle instanceof XmlSchemaChoice) {
+ Element choice = serializeChoice(doc,
+ (XmlSchemaChoice) groupObj.particle, schema);
+ group.appendChild(choice);
+ } else if (groupObj.particle instanceof XmlSchemaAll) {
+ Element all = serializeAll(doc,
+ (XmlSchemaAll) groupObj.particle, schema);
+ group.appendChild(all);
+ }
+
+ //process extension
+ processExtensibilityComponents(groupObj,group);
+
+ return group;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeGroupRef(Document doc, XmlSchemaGroupRef groupRefObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * groupRefObj - XmlSchemaGroupRef that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of group elements ref inside its parent.
+ * **********************************************************************
+ */
+ Element serializeGroupRef(Document doc, XmlSchemaGroupRef groupRefObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element groupRef = createNewElement(doc, "group",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (groupRefObj.refName != null) {
+ String groupRefName = resolveQName(groupRefObj.refName,
+ schema);
+ groupRef.setAttribute("ref", groupRefName);
+ } else
+ throw new XmlSchemaSerializerException("Group must have name or ref");
+
+ if (groupRefObj.maxOccurs < Long.MAX_VALUE && groupRefObj.maxOccurs > 1)
+ groupRef.setAttribute("maxOccurs",
+ groupRefObj.maxOccurs + "");
+ else if (groupRefObj.maxOccurs == Long.MAX_VALUE)
+ groupRef.setAttribute("maxOccurs",
+ "unbounded");
+ //else not serialized
+
+ if (groupRefObj.minOccurs > 1)
+ groupRef.setAttribute("minOccurs",
+ groupRefObj.minOccurs + "");
+
+
+
+ if (groupRefObj.particle != null) {
+ if (groupRefObj.particle instanceof XmlSchemaChoice)
+ serializeChoice(doc, (XmlSchemaChoice) groupRefObj.particle, schema);
+ else if (groupRefObj.particle instanceof XmlSchemaSequence)
+ serializeSequence(doc,(XmlSchemaSequence) groupRefObj.particle, schema);
+ else if (groupRefObj.particle instanceof XmlSchemaAll)
+ serializeAll(doc,(XmlSchemaAll) groupRefObj.particle, schema);
+ else
+ throw new XmlSchemaSerializerException("The content of group "
+ + "ref particle should be"
+ + " sequence, choice or all reference: "
+ + "www.w3.org/TR/xmlschema-1#element-group-3.7.2");
+ }
+ if (groupRefObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ groupRefObj.annotation, schema);
+ groupRef.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(groupRefObj,groupRef);
+
+ return groupRef;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleContent(Document doc,
+ * XmlSchemaSimpleContent simpleContentObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * simpleContentObj - XmlSchemaSimpleContent that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of complex type simple content.
+ * **********************************************************************
+ */
+ Element serializeSimpleContent(Document doc,
+ XmlSchemaSimpleContent simpleContentObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+ Element simpleContent = createNewElement(doc, "simpleContent",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ Element content;
+ if (simpleContentObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ simpleContentObj.annotation, schema);
+ simpleContent.appendChild(annotation);
+ }
+ if (simpleContentObj.content instanceof
+ XmlSchemaSimpleContentRestriction)
+ content = serializeSimpleContentRestriction(doc,
+ (XmlSchemaSimpleContentRestriction) simpleContentObj.content,
+ schema);
+ else if (simpleContentObj.content instanceof
+ XmlSchemaSimpleContentExtension)
+ content = serializeSimpleContentExtension(doc,
+ (XmlSchemaSimpleContentExtension) simpleContentObj.content,
+ schema);
+ else
+ throw new XmlSchemaSerializerException("content of simple content "
+ + "must be restriction or extension");
+
+ simpleContent.appendChild(content);
+
+ //process extension
+ processExtensibilityComponents(simpleContentObj,simpleContent);
+
+ return simpleContent;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeComplexContent(Document doc,
+ * XmlSchemaComplexContent complexContentObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * complexContentObj - XmlSchemaComplexContent that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of complex type complex content.
+ * **********************************************************************
+ */
+ Element serializeComplexContent(Document doc,
+ XmlSchemaComplexContent complexContentObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element complexContent = createNewElement(doc, "complexContent",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+
+ if (complexContentObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ complexContentObj.annotation, schema);
+ complexContent.appendChild(annotation);
+ }
+
+ if (complexContentObj.mixed)
+ complexContent.setAttribute("mixed", "true");
+ if (complexContentObj.id != null)
+ complexContent.setAttribute("id",
+ complexContentObj.id);
+
+ Element content;
+ if (complexContentObj.content instanceof
+ XmlSchemaComplexContentRestriction)
+
+ content = serializeComplexContentRestriction(doc,
+ (XmlSchemaComplexContentRestriction) complexContentObj.content,
+ schema);
+ else if (complexContentObj.content instanceof
+ XmlSchemaComplexContentExtension)
+ content = serializeComplexContentExtension(doc,
+ (XmlSchemaComplexContentExtension) complexContentObj.content,
+ schema);
+ else
+ throw new XmlSchemaSerializerException("content of complexContent "
+ + "must be restriction or extension");
+
+ complexContent.appendChild(content);
+
+ //process extension
+ processExtensibilityComponents(complexContentObj,complexContent);
+
+ return complexContent;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeIdentityConstraint(Document doc,
+ * XmlSchemaIdentityConstraint constraintObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * constraintObj - XmlSchemaIdentityConstraint that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of key, keyref or unique that part of its parent.
+ * **********************************************************************
+ */
+ Element serializeIdentityConstraint(Document doc,
+ XmlSchemaIdentityConstraint constraintObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element constraint;
+
+ if (constraintObj instanceof XmlSchemaUnique)
+ constraint = createNewElement(doc, "unique",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ else if (constraintObj instanceof XmlSchemaKey)
+ constraint = createNewElement(doc, "key",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ else if (constraintObj instanceof XmlSchemaKeyref) {
+ constraint = createNewElement(doc, "keyref",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ XmlSchemaKeyref keyref = (XmlSchemaKeyref) constraintObj;
+ if (keyref.refer != null) {
+ String keyrefStr = resolveQName(keyref.refer, schema);
+ constraint.setAttribute(
+ "refer", keyrefStr);
+ }
+ } else
+ throw new XmlSchemaSerializerException("not valid identity "
+ + "constraint");
+
+ if (constraintObj.name != null)
+ constraint.setAttribute("name",
+ constraintObj.name);
+ if (constraintObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ constraintObj.annotation, schema);
+ constraint.appendChild(annotation);
+ }
+
+ if (constraintObj.selector != null) {
+ Element selector = serializeSelector(doc,
+ constraintObj.selector, schema);
+ constraint.appendChild(selector);
+ }
+ XmlSchemaObjectCollection fieldColl = constraintObj.fields;
+ if (fieldColl != null) {
+ int fieldLength = fieldColl.getCount();
+ for (int i = 0; i < fieldLength; i++) {
+ Element field = serializeField(doc,
+ (XmlSchemaXPath) fieldColl.getItem(i), schema);
+ constraint.appendChild(field);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(constraintObj,constraint);
+
+ return constraint;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSelector(Document doc, XmlSchemaXPath selectorObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * selectorObj - XmlSchemaXPath that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of selector with collection of xpath as its attrib. The selector
+ * itself is the part of identity type. eg <key><selector xpath="..."
+ * **********************************************************************
+ */
+ Element serializeSelector(Document doc, XmlSchemaXPath selectorObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element selector = createNewElement(doc, "selector",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (selectorObj.xpath != null)
+ selector.setAttribute("xpath",
+ selectorObj.xpath);
+ else
+ throw new XmlSchemaSerializerException("xpath can't be null");
+
+ if (selectorObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ selectorObj.annotation, schema);
+ selector.appendChild(annotation);
+ }
+ //process extension
+ processExtensibilityComponents(selectorObj,selector);
+ return selector;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeField(Document doc, XmlSchemaXPath fieldObj,
+ * XmlSchema schema) throws XmlSchemaSerializerException
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * fieldObj - XmlSchemaXPath that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * field element that part of constraint.
+ * **********************************************************************
+ */
+ Element serializeField(Document doc, XmlSchemaXPath fieldObj,
+ XmlSchema schema) throws XmlSchemaSerializerException {
+
+ Element field = createNewElement(doc, "field", schema.schema_ns_prefix,
+ XmlSchema.SCHEMA_NS);
+
+ if (fieldObj.xpath != null)
+ field.setAttribute("xpath", fieldObj.xpath);
+ else
+ throw new XmlSchemaSerializerException("xpath can't be null");
+
+ if (fieldObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ fieldObj.annotation, schema);
+ field.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(fieldObj,field);
+
+ return field;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAnnotation(Document doc, XmlSchemaAnnotation
+ * annotationObj, XmlSchema schema)
+ * <p/>
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * annotationObj - XmlSchemaAnnotation that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * annotation element that part of any type. will contain document and
+ * appinfo for child.
+ * **********************************************************************
+ */
+ Element serializeAnnotation(Document doc, XmlSchemaAnnotation annotationObj,
+ XmlSchema schema) {
+
+ Element annotation = createNewElement(doc, "annotation",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ XmlSchemaObjectCollection contents = annotationObj.items;
+ int contentLength = contents.getCount();
+
+ for (int i = 0; i < contentLength; i++) {
+ XmlSchemaObject obj = contents.getItem(i);
+
+ if (obj instanceof XmlSchemaAppInfo) {
+ XmlSchemaAppInfo appinfo = (XmlSchemaAppInfo) obj;
+ Element appInfoEl = serializeAppInfo(doc, appinfo, schema);
+ annotation.appendChild(appInfoEl);
+ } else if (obj instanceof XmlSchemaDocumentation) {
+ XmlSchemaDocumentation documentation =
+ (XmlSchemaDocumentation) obj;
+
+ Element documentationEl = serializeDocumentation(doc,
+ documentation, schema);
+
+
+ annotation.appendChild(documentationEl);
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(annotationObj,annotation);
+
+ return annotation;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAppInfo(Document doc,XmlSchemaAppInfo appInfoObj,
+ * XmlSchema schema)
+ * <p/>
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * appInfoObj - XmlSchemaAppInfo that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * App info element that is part of the annotation.
+ * **********************************************************************
+ */
+ Element serializeAppInfo(Document doc, XmlSchemaAppInfo appInfoObj,
+ XmlSchema schema) {
+
+ Element appInfoEl = createNewElement(doc, "appinfo",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (appInfoObj.source != null)
+ appInfoEl.setAttribute("source",
+ appInfoObj.source);
+
+ if (appInfoObj.markup != null) {
+ int markupLength = appInfoObj.markup.getLength();
+ for (int j = 0; j < markupLength; j++) {
+ Node n = appInfoObj.markup.item(j);
+ switch (n.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ appendElement(doc, appInfoEl, n, schema);
+ break;
+ case Node.TEXT_NODE:
+ Text t = doc.createTextNode(n.getNodeValue());
+ appInfoEl.appendChild(t);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ //process extension
+ processExtensibilityComponents(appInfoObj,appInfoEl);
+
+ return appInfoEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeDocumentation(Document doc,XmlSchemaDocumentation
+ * documentationObj, XmlSchema schema){
+ * <p/>
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * documentationObj - XmlSchemaAppInfo that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element representation of documentation that is part of annotation.
+ * **********************************************************************
+ */
+ Element serializeDocumentation(Document doc, XmlSchemaDocumentation
+ documentationObj, XmlSchema schema) {
+
+
+ Element documentationEl = createNewElement(doc, "documentation",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (documentationObj.source != null)
+ documentationEl.setAttribute("source",
+ documentationObj.source);
+ if (documentationObj.language != null)
+ documentationEl.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang",
+ documentationObj.language);
+
+ if (documentationObj.markup != null) {
+ int markupLength = documentationObj.markup.getLength();
+ for (int j = 0; j < markupLength; j++) {
+ Node n = documentationObj.markup.item(j);
+
+ switch (n.getNodeType()) {
+ case Node.ELEMENT_NODE:
+ appendElement(doc, documentationEl, n, schema);
+ break;
+ case Node.TEXT_NODE:
+ Text t = doc.createTextNode(n.getNodeValue());
+ documentationEl.appendChild(t);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ //process extension
+ processExtensibilityComponents(documentationObj,documentationEl);
+
+ return documentationEl;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleContentRestriction(Document doc,
+ * XmlSchemaSimpleContentRestriction restrictionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * restrictionObj - XmlSchemaSimpleContentRestriction that will be
+ * serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple content restriction.
+ * **********************************************************************
+ */
+ Element serializeSimpleContentRestriction(Document doc,
+ XmlSchemaSimpleContentRestriction restrictionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element restriction = createNewElement(doc, "restriction",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (restrictionObj.baseTypeName != null) {
+ String baseTypeName =
+ resolveQName(restrictionObj.baseTypeName, schema);
+
+ restriction.setAttribute("base", baseTypeName);
+
+ }
+ if (restrictionObj.id != null)
+ restriction.setAttribute("id", restrictionObj.id);
+
+ if (restrictionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ restrictionObj.annotation, schema);
+ restriction.appendChild(annotation);
+ }
+ int attrCollLength = restrictionObj.attributes.getCount();
+ for (int i = 0; i < attrCollLength; i++) {
+ XmlSchemaObject obj = restrictionObj.attributes.getItem(i);
+
+ if (obj instanceof XmlSchemaAttribute) {
+ Element attribute = serializeAttribute(doc,
+ (XmlSchemaAttribute) obj, schema);
+ restriction.appendChild(attribute);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attributeGroup = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ restriction.appendChild(attributeGroup);
+ }
+ }
+ if (restrictionObj.baseType != null) {
+ Element inlineSimpleType = serializeSimpleType(doc,
+ restrictionObj.baseType, schema);
+ restriction.appendChild(inlineSimpleType);
+ }
+ if (restrictionObj.anyAttribute != null) {
+ Element anyAttribute = serializeAnyAttribute(doc,
+ restrictionObj.anyAttribute, schema);
+ restriction.appendChild(anyAttribute);
+ }
+ XmlSchemaObjectCollection facets = restrictionObj.facets;
+ int facetLength = facets.getCount();
+ for (int i = 0; i < facetLength; i++) {
+ Element facet = serializeFacet(doc,
+ (XmlSchemaFacet) facets.getItem(i), schema);
+ restriction.appendChild(facet);
+ }
+
+ //process extension
+ processExtensibilityComponents(restrictionObj,restriction);
+
+ return restriction;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeSimpleContentExtension(Document doc,
+ * XmlSchemaSimpleContentExtension extensionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * extensionObj - XmlSchemaSimpleContentExtension
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple content extension.
+ * **********************************************************************
+ */
+ Element serializeSimpleContentExtension(Document doc,
+ XmlSchemaSimpleContentExtension extensionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element extension = createNewElement(doc, "extension",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (extensionObj.baseTypeName != null) {
+ String baseTypeName =
+ resolveQName(extensionObj.baseTypeName, schema);
+
+ extension.setAttribute("base", baseTypeName);
+ }
+
+ if (extensionObj.id != null)
+ extension.setAttribute("id", extensionObj.id);
+
+ if (extensionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ extensionObj.annotation, schema);
+ extension.appendChild(annotation);
+ }
+
+ XmlSchemaObjectCollection attributes = extensionObj.attributes;
+ int attributeLength = attributes.getCount();
+ for (int i = 0; i < attributeLength; i++) {
+ XmlSchemaObject obj = attributes.getItem(i);
+
+ if (obj instanceof XmlSchemaAttribute) {
+ Element attribute = serializeAttribute(doc,
+ (XmlSchemaAttribute) obj, schema);
+ extension.appendChild(attribute);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attributeGroupRef = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ extension.appendChild(attributeGroupRef);
+ }
+ }
+
+ /*
+ * anyAttribute must come *after* any other attributes
+ */
+ if (extensionObj.anyAttribute != null) {
+ Element anyAttribute = serializeAnyAttribute(doc,
+ extensionObj.anyAttribute, schema);
+ extension.appendChild(anyAttribute);
+ }
+
+ //process extension
+ processExtensibilityComponents(extensionObj,extension);
+
+ return extension;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeComplexContentRestriction(Document doc,
+ * XmlSchemaComplexContentRestriction restrictionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * restrictionObj - XmlSchemaSimpleContentRestriction
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of simple content restriction.
+ * **********************************************************************
+ */
+ Element serializeComplexContentRestriction(Document doc,
+ XmlSchemaComplexContentRestriction restrictionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element restriction = createNewElement(doc, "restriction",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (restrictionObj.baseTypeName != null) {
+ String baseTypeName = resolveQName(restrictionObj.baseTypeName, schema);
+ restriction.setAttribute(
+ "base", baseTypeName);
+ }
+
+ if (restrictionObj.id != null)
+ restriction.setAttribute("id",
+ restrictionObj.id);
+
+ if (restrictionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ restrictionObj.annotation, schema);
+ restriction.appendChild(annotation);
+ }
+
+ if (restrictionObj.particle instanceof XmlSchemaSequence) {
+ Element sequenceParticle = serializeSequence(doc,
+ (XmlSchemaSequence) restrictionObj.particle, schema);
+ restriction.appendChild(sequenceParticle);
+ } else if (restrictionObj.particle instanceof XmlSchemaChoice) {
+ Element choiceParticle = serializeChoice(doc,
+ (XmlSchemaChoice) restrictionObj.particle, schema);
+ restriction.appendChild(choiceParticle);
+ } else if (restrictionObj.particle instanceof XmlSchemaAll) {
+ Element allParticle = serializeAll(doc,
+ (XmlSchemaAll) restrictionObj.particle, schema);
+ restriction.appendChild(allParticle);
+ } else if (restrictionObj.particle instanceof XmlSchemaGroupRef) {
+ Element groupRefParticle = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) restrictionObj.particle, schema);
+ restriction.appendChild(groupRefParticle);
+ }
+
+ int attributesLength = restrictionObj.attributes.getCount();
+ for (int i = 0; i < attributesLength; i++) {
+ XmlSchemaObject obj = restrictionObj.attributes.getItem(i);
+
+ if (obj instanceof XmlSchemaAttribute) {
+ Element attr = serializeAttribute(doc,
+ (XmlSchemaAttribute) obj, schema);
+ restriction.appendChild(attr);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attrGroup = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ restriction.appendChild(attrGroup);
+ }
+ }
+
+ if (restrictionObj.anyAttribute != null) {
+ Element anyAttribute = serializeAnyAttribute(doc,
+ restrictionObj.anyAttribute, schema);
+ restriction.appendChild(anyAttribute);
+ }
+
+ //process extension
+ processExtensibilityComponents(restrictionObj,restriction);
+
+ return restriction;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeComplexContentExtension(Document doc,
+ * XmlSchemaComplexContentExtension extensionObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * extensionObj - XmlSchemaComplexContentRestriction
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of complex content extension.
+ * **********************************************************************
+ */
+ Element serializeComplexContentExtension(Document doc,
+ XmlSchemaComplexContentExtension extensionObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element extension = createNewElement(doc, "extension",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ if (extensionObj.baseTypeName != null) {
+ String baseType = resolveQName(extensionObj.baseTypeName,
+ schema);
+ extension.setAttribute("base", baseType);
+ }
+ if (extensionObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ extensionObj.annotation, schema);
+ extension.appendChild(annotation);
+ }
+
+
+ if (extensionObj.particle instanceof XmlSchemaSequence) {
+ Element sequenceParticle = serializeSequence(doc,
+ (XmlSchemaSequence) extensionObj.particle, schema);
+ extension.appendChild(sequenceParticle);
+ } else if (extensionObj.particle instanceof XmlSchemaChoice) {
+ Element choiceParticle = serializeChoice(doc,
+ (XmlSchemaChoice) extensionObj.particle, schema);
+ extension.appendChild(choiceParticle);
+ } else if (extensionObj.particle instanceof XmlSchemaAll) {
+ Element allParticle = serializeAll(doc,
+ (XmlSchemaAll) extensionObj.particle, schema);
+ extension.appendChild(allParticle);
+ } else if (extensionObj.particle instanceof XmlSchemaGroupRef) {
+ Element groupRefParticle = serializeGroupRef(doc,
+ (XmlSchemaGroupRef) extensionObj.particle, schema);
+ extension.appendChild(groupRefParticle);
+ }
+
+ int attributesLength = extensionObj.attributes.getCount();
+ for (int i = 0; i < attributesLength; i++) {
+ XmlSchemaObject obj = extensionObj.attributes.getItem(i);
+
+ if (obj instanceof XmlSchemaAttribute) {
+ Element attr = serializeAttribute(doc,
+ (XmlSchemaAttribute) obj, schema);
+ extension.appendChild(attr);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attrGroup = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ extension.appendChild(attrGroup);
+ }
+ }
+
+ if (extensionObj.anyAttribute != null) {
+ Element anyAttribute = serializeAnyAttribute(doc,
+ extensionObj.anyAttribute, schema);
+ extension.appendChild(anyAttribute);
+ }
+
+ //process extension
+ processExtensibilityComponents(extensionObj,extension);
+
+ return extension;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAnyAttribute(Document doc,
+ * XmlSchemaAnyAttribute anyAttributeObj, XmlSchema schema)
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * anyAttributeObj - XmlSchemaAnyAttribute
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of any attribute element.
+ * **********************************************************************
+ */
+ Element serializeAnyAttribute(Document doc,
+ XmlSchemaAnyAttribute anyAttributeObj, XmlSchema schema) {
+
+ Element anyAttribute = createNewElement(doc, "anyAttribute",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+
+ if (anyAttributeObj.namespace != null)
+ anyAttribute.setAttribute("namespace",
+ anyAttributeObj.namespace);
+
+ if (anyAttributeObj.id != null)
+ anyAttribute.setAttribute("id",
+ anyAttributeObj.id);
+
+ if (anyAttributeObj.processContent != null) {
+ String processContent = anyAttributeObj.processContent.getValue();
+ processContent = convertString(processContent);
+ anyAttribute.setAttribute("processContents",
+ processContent);
+ }
+ if (anyAttributeObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ anyAttributeObj.annotation, schema);
+ anyAttribute.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(anyAttributeObj,anyAttribute);
+
+ return anyAttribute;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAttributeGroupRef(Document doc,
+ * XmlSchemaAttributeGroupRef attributeGroupObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * attributeGroupObj - XmlSchemaAttributeGroupRef
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of attribute group ref that part of type.
+ * **********************************************************************
+ */
+ Element serializeAttributeGroupRef(Document doc,
+ XmlSchemaAttributeGroupRef attributeGroupObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element attributeGroupRef = createNewElement(doc, "attributeGroup",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (attributeGroupObj.refName != null) {
+ String refName = resolveQName(attributeGroupObj.refName,
+ schema);
+ attributeGroupRef.setAttribute("ref", refName);
+ } else
+ throw new XmlSchemaSerializerException("Attribute group must have "
+ + "ref name set");
+
+ if (attributeGroupObj.id != null)
+ attributeGroupRef.setAttribute("id",
+ attributeGroupObj.id);
+
+ if (attributeGroupObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ attributeGroupObj.annotation, schema);
+ attributeGroupRef.appendChild(annotation);
+ }
+
+ //process extension
+ processExtensibilityComponents(attributeGroupObj,attributeGroupRef);
+
+ return attributeGroupRef;
+ }
+
+ /**
+ * *********************************************************************
+ * Element serializeAttributeGroup(Document doc,
+ * XmlSchemaAttributeGroup attributeGroupObj, XmlSchema schema)
+ * throws XmlSchemaSerializerException{
+ * <p/>
+ * Each member of complex type will be appended and pass the element
+ * created. Complex type processed according to w3c Recommendation
+ * May 2 2001.
+ * <p/>
+ * Parameter:
+ * doc - Document the parent use.
+ * attributeGroupObj - XmlSchemaAttributeGroup
+ * that will be serialized.
+ * schema - Schema Document object of the parent.
+ * <p/>
+ * Return:
+ * Element of attribute group.
+ * **********************************************************************
+ */
+ Element serializeAttributeGroup(Document doc,
+ XmlSchemaAttributeGroup attributeGroupObj, XmlSchema schema)
+ throws XmlSchemaSerializerException {
+
+ Element attributeGroup = createNewElement(doc, "attributeGroup",
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+
+ if (attributeGroupObj.name != null)
+ attributeGroup.setAttribute("name",
+ attributeGroupObj.name);
+ else
+ throw new XmlSchemaSerializerException("Attribute group must"
+ + "have name");
+ if (attributeGroupObj.id != null)
+ attributeGroup.setAttribute("id",
+ attributeGroupObj.id);
+
+ if (attributeGroupObj.annotation != null) {
+ Element annotation = serializeAnnotation(doc,
+ attributeGroupObj.annotation, schema);
+ attributeGroup.appendChild(annotation);
+ }
+ int attributesLength = attributeGroupObj.attributes.getCount();
+ for (int i = 0; i < attributesLength; i++) {
+ XmlSchemaObject obj = attributeGroupObj.attributes.getItem(i);
+
+ if (obj instanceof XmlSchemaAttribute) {
+ Element attr = serializeAttribute(doc, (XmlSchemaAttribute) obj,
+ schema);
+ attributeGroup.appendChild(attr);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ Element attrGroup = serializeAttributeGroupRef(doc,
+ (XmlSchemaAttributeGroupRef) obj, schema);
+ attributeGroup.appendChild(attrGroup);
+ }
+ }
+
+ if (attributeGroupObj.anyAttribute != null) {
+ Element anyAttribute = serializeAnyAttribute(doc,
+ attributeGroupObj.anyAttribute, schema);
+ attributeGroup.appendChild(anyAttribute);
+ }
+
+ //process extension
+ processExtensibilityComponents(attributeGroupObj,attributeGroup);
+
+ return attributeGroup;
+ }
+
+ //recursively add any attribute, text and children append all
+ //found children base on parent as its root.
+ private void appendElement(Document doc, Element parent,
+ Node children, XmlSchema schema) {
+ Element elTmp = (Element) children;
+ Element el = createNewElement(doc, elTmp.getLocalName(),
+ schema.schema_ns_prefix, XmlSchema.SCHEMA_NS);
+ NamedNodeMap attributes = el.getAttributes();
+ //check if child node has attribute
+ //create new element and append it if found
+ int attributeLength = attributes.getLength();
+ for (int i = 0; i < attributeLength; i++) {
+ Node n = attributes.item(i);
+ //assuming attributes got to throw exception if not later
+ el.setAttribute(n.getNodeName(),
+ n.getNodeValue());
+ }
+
+ //check any descendant of this node
+ //if there then append its child
+ NodeList decendants = el.getChildNodes();
+ int decendantLength = decendants.getLength();
+ for (int i = 0; i < decendantLength; i++) {
+ Node n = decendants.item(i);
+ short nodeType = n.getNodeType();
+ if (nodeType == Node.TEXT_NODE) {
+ String nValue = n.getNodeValue();
+ Text t = doc.createTextNode(nValue);
+ el.appendChild(t);
+ } else if (nodeType == Node.ELEMENT_NODE) {
+ appendElement(doc, el, n, schema);
+ }
+ }
+ }
+
+ //break string with prefix into two parts part[0]:prefix , part[1]:namespace
+ private static String[] getParts(String name) {
+ String[] parts = new String[2];
+
+ int index = name.indexOf(":");
+ if (index > -1) {
+ parts[0] = name.substring(0, index);
+ parts[1] = name.substring(index + 1);
+ } else {
+ parts[0] = "";
+ parts[1] = name;
+ }
+ return parts;
+ }
+
+ //Convert given string to lower case or w3c standard
+ private String convertString(String convert) {
+ String input = convert.trim();
+ if (input.equals(Constants.BlockConstants.ALL)) {
+ return "#all";
+ } else
+ return input.toLowerCase();
+ }
+
+ //Create new element with given local name and namespaces check whether
+ //the prefix is there or not.
+ private Element createNewElement(Document docs, String localName,
+ String prefix, String namespace) {
+ String elementName = ((prefix.length() > 0) ? prefix += ":" : "")
+ + localName;
+ return docs.createElementNS(namespace, elementName);
+ }
+
+ /**
+ * will search whether the prefix is available in global hash table, if it
+ * is there than append the prefix to the element name. If not then it will
+ * create new prefix corresponding to that namespace and store that in
+ * hash table. Finally add the new prefix and namespace to <schema>
+ * element
+ * @param names
+ * @param schemaObj
+ * @return resolved QName of the string
+ */
+
+ private String resolveQName(QName names,
+ XmlSchema schemaObj) {
+
+ String namespace = names.getNamespaceURI();
+ String type[] = getParts(names.getLocalPart());
+ String typeName = (type.length > 1) ? type[1] : type[0];
+ String prefixStr;
+
+ // If the namespace is "" then the prefix is also ""
+ Object prefix = ("".equals(namespace)) ? "" : schema_ns.get(namespace);
+
+ if (prefix == null) {
+ if (Constants.XMLNS_URI.equals(namespace)) {
+ prefix = Constants.XMLNS_PREFIX;
+ } else {
+ int magicNumber = 0;
+ Collection prefixes = schema_ns.values();
+ while(prefixes.contains("ns" + magicNumber)){
+ magicNumber++;
+ }
+ prefix = "ns" + magicNumber;
+ schema_ns.put(namespace, prefix);
+
+ //setting xmlns in schema
+ schemaElement.setAttributeNS(XMLNS_NAMESPACE_URI,
+ "xmlns:" + prefix.toString(), namespace);
+ }
+ }
+
+ prefixStr = prefix.toString();
+ prefixStr = (prefixStr.trim().length() > 0) ? prefixStr + ":" : "";
+
+ return prefixStr + typeName;
+ }
+
+ //for each collection if it is an attribute serialize attribute and
+ //append that child to container element.
+ void setupAttr(Document doc, XmlSchemaObjectCollection collectionObj,
+ XmlSchema schema, Element container) throws XmlSchemaSerializerException {
+ int collectionLength = collectionObj.getCount();
+ for (int i = 0; i < collectionLength; i++) {
+ XmlSchemaObject obj = collectionObj.getItem(i);
+ if (obj instanceof XmlSchemaAttribute) {
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
+ Element attrEl = serializeAttribute(doc, attr, schema);
+ container.appendChild(attrEl);
+ } else if (obj instanceof XmlSchemaAttributeGroupRef) {
+ XmlSchemaAttributeGroupRef attr = (XmlSchemaAttributeGroupRef) obj;
+ Element attrEl = serializeAttributeGroupRef(doc, attr, schema);
+ container.appendChild(attrEl);
+ }
+ }
+ }
+
+ public static class XmlSchemaSerializerException extends Exception {
+
+ public XmlSchemaSerializerException(String msg) {
+ super(msg);
+ }
+ }
+
+
+ /**
+ * A generic method to process the extra attributes and the the extra
+ * elements present within the schema.
+ * What are considered extensions are child elements with non schema namespace
+ * and child attributes with any namespace
+ * @param schemaObject
+ * @param parentElement
+ */
+ private void processExtensibilityComponents(XmlSchemaObject schemaObject,Element parentElement){
+
+ if (extReg!=null){
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ if (metaInfoMap!=null && !metaInfoMap.isEmpty()) {
+ //get the extra objects and call the respective deserializers
+ Iterator keysIt = metaInfoMap.keySet().iterator();
+ while (keysIt.hasNext()) {
+ Object key = keysIt.next();
+ extReg.serializeExtension(schemaObject,metaInfoMap.get(key).getClass(),parentElement);
+
+ }
+
+ }
+
+ }
+
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContent.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContent.java
new file mode 100644
index 0000000..601b05b
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContent.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for simple types and complex types with a simple content model.
+ * Represents the World Wide Web Consortium (W3C) simpleContent element.
+ */
+
+public class XmlSchemaSimpleContent extends XmlSchemaContentModel {
+
+ /**
+ * Creates new XmlSchemaSimpleContent
+ */
+ public XmlSchemaSimpleContent() {
+ }
+
+ /* One of XmlSchemaSimpleContentRestriction or XmlSchemaSimpleContentExtension. */
+ XmlSchemaContent content;
+
+ public XmlSchemaContent getContent() {
+ return this.content;
+ }
+
+ public void setContent(XmlSchemaContent content) {
+ this.content = content;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1) {
+ prefix += ":";
+ }
+ return xml;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java
new file mode 100644
index 0000000..fa4efb3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentExtension.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for simple types that are derived by extension. Extends the simple
+ * type content of the element by adding attributes. Represents the World Wide
+ * Web Consortium (W3C) extension element for simple content.
+ */
+
+public class XmlSchemaSimpleContentExtension extends XmlSchemaContent {
+
+ /**
+ * Creates new XmlSchemaSimpleContentExtension
+ */
+ public XmlSchemaSimpleContentExtension() {
+ attributes = new XmlSchemaObjectCollection();
+
+ }
+
+ /* Allows an XmlSchemaAnyAttribute to be used for the attribute value.*/
+ XmlSchemaAnyAttribute anyAttribute;
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return this.anyAttribute;
+ }
+
+ /* Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef. Collection of attributes for the simple type.*/
+ XmlSchemaObjectCollection attributes;
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return this.attributes;
+ }
+
+ /* Name of the built-in data type, simple type, or complex type.*/
+ QName baseTypeName;
+
+ public void setBaseTypeName(QName baseTypeName) {
+ this.baseTypeName = baseTypeName;
+ }
+
+ public QName getBaseTypeName() {
+ return this.baseTypeName;
+ }
+
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentRestriction.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentRestriction.java
new file mode 100644
index 0000000..53fd0de
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleContentRestriction.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for simple types that are derived by restriction. Restricts the
+ * range of values for the element to a subset of the inherited simple types.
+ * Represents the World Wide Web Consortium (W3C) restriction element for simple content.
+ */
+
+public class XmlSchemaSimpleContentRestriction extends XmlSchemaContent {
+
+ /**
+ * Creates new XmlSchemaSimpleContentRestriction
+ */
+ public XmlSchemaSimpleContentRestriction() {
+ facets = new XmlSchemaObjectCollection();
+ attributes = new XmlSchemaObjectCollection();
+ }
+
+ /* Allows an XmlSchemaAnyAttribute to be used for the attribute value.*/
+ XmlSchemaAnyAttribute anyAttribute;
+
+ public void setAnyAttribute(XmlSchemaAnyAttribute anyAttribute) {
+ this.anyAttribute = anyAttribute;
+ }
+
+ public XmlSchemaAnyAttribute getAnyAttribute() {
+ return this.anyAttribute;
+ }
+
+ /* Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef. Collection of attributes for the simple type.*/
+ XmlSchemaObjectCollection attributes;
+
+ public XmlSchemaObjectCollection getAttributes() {
+ return this.attributes;
+ }
+
+ /*Derived from the type specified by the base value.*/
+ XmlSchemaSimpleType baseType;
+
+ public void setBaseType(XmlSchemaSimpleType baseType) {
+ this.baseType = baseType;
+ }
+
+ public XmlSchemaSimpleType getBaseType() {
+ return this.baseType;
+ }
+
+ /* Name of the built-in data type, simple type, or complex type.*/
+ QName baseTypeName;
+
+ public void setBaseTypeName(QName baseTypeName) {
+ this.baseTypeName = baseTypeName;
+ }
+
+ public QName getBaseTypeName() {
+ return this.baseTypeName;
+ }
+
+ /* One or more of the facet classes: */
+ XmlSchemaObjectCollection facets;
+
+ public XmlSchemaObjectCollection getFacets() {
+ return this.facets;
+ }
+
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleType.java
new file mode 100644
index 0000000..5ff5d9b
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleType.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class defines a simple type that determines the information and
+ * constraints for the values of attributes or elements with text-only
+ * content. Represents the World Wide Web Consortium (W3C) simpleType element.
+ */
+
+public class XmlSchemaSimpleType extends XmlSchemaType {
+
+ XmlSchemaSimpleTypeContent content;
+
+ /**
+ * Creates new XmlSchemaSimpleType
+ */
+ public XmlSchemaSimpleType(XmlSchema schema) {
+ super(schema);
+ }
+
+ public XmlSchemaSimpleTypeContent getContent() {
+ return content;
+ }
+
+ public void setContent(XmlSchemaSimpleTypeContent content) {
+ this.content = content;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+
+ xml += "<" + prefix + "simpleType>\n";
+
+ if (content != null)
+ xml += content.toString(prefix, (tab + 1));
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "</" + prefix + "simpleType>\n";
+ return xml;
+ }
+
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeContent.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeContent.java
new file mode 100644
index 0000000..33d9993
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeContent.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Abstract class for simple type content classes.
+ */
+
+public abstract class XmlSchemaSimpleTypeContent extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaSimpleTypeContent
+ */
+ protected XmlSchemaSimpleTypeContent() {
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeList.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeList.java
new file mode 100644
index 0000000..420c866
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeList.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for the list of simpleType elements. Defines a simpleType element
+ * as a list of values of a specified data type. Represents the World Wide
+ * Web Consortium (W3C) list element.
+ */
+public class XmlSchemaSimpleTypeList extends XmlSchemaSimpleTypeContent {
+
+ /**
+ * Creates new XmlSchemaSimpleTypeList
+ */
+ public XmlSchemaSimpleTypeList() {
+ }
+
+ XmlSchemaSimpleType itemType;
+
+ public XmlSchemaSimpleType getItemType() {
+ return this.itemType;
+ }
+
+ public void setItemType(XmlSchemaSimpleType itemType) {
+ this.itemType = itemType;
+ }
+
+ QName itemTypeName;
+
+ public QName getItemTypeName() {
+ return this.itemTypeName;
+ }
+
+ public void setItemTypeName(QName itemTypeName) {
+ this.itemTypeName = itemTypeName;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeRestriction.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeRestriction.java
new file mode 100644
index 0000000..83173da
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeRestriction.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for the restriction of simpleType elements. Represents the World
+ * Wide Web Consortium (W3C) restriction element for simple types.
+ */
+
+public class XmlSchemaSimpleTypeRestriction extends XmlSchemaSimpleTypeContent {
+
+ /**
+ * Creates new XmlSchemaSimpleTypeRestriction
+ */
+ public XmlSchemaSimpleTypeRestriction() {
+ facets = new XmlSchemaObjectCollection();
+ }
+
+ XmlSchemaSimpleType baseType;
+
+ public XmlSchemaSimpleType getBaseType() {
+ return this.baseType;
+ }
+
+ public void setBaseType(XmlSchemaSimpleType baseType) {
+ this.baseType = baseType;
+ }
+
+ QName baseTypeName;
+
+ public QName getBaseTypeName() {
+ return this.baseTypeName;
+ }
+
+ public void setBaseTypeName(QName baseTypeName) {
+ this.baseTypeName = baseTypeName;
+ }
+
+ XmlSchemaObjectCollection facets;// = new XmlSchemaObjectCollection();
+
+ public XmlSchemaObjectCollection getFacets() {
+ return this.facets;
+ }
+
+ public String toString(String prefix, int tab) {
+ String xml = new String();
+
+ if (!prefix.equals("") && prefix.indexOf(":") == -1)
+ prefix += ":";
+
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+
+ xml += "<" + prefix + "restriction ";
+
+ if (baseTypeName != null) {
+ xml += "base =\"" + baseTypeName + "\">\n";
+ } else {
+ xml += ">\n";
+ // inline def
+ xml += baseType.toString(prefix, (tab + 1));
+ }
+
+ xml += facets.toString(prefix, (tab + 1));
+ for (int i = 0; i < tab; i++)
+ xml += "\t";
+ xml += "</" + prefix + "restriction>\n";
+
+
+ return xml;
+
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeUnion.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeUnion.java
new file mode 100644
index 0000000..accb5d7
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSimpleTypeUnion.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * Class for the union of simpleType elements. Defines a simpleType element
+ * as a list of values of a specified data type. Represents the World
+ * Wide Web Consortium (W3C) union element.
+ */
+
+public class XmlSchemaSimpleTypeUnion extends XmlSchemaSimpleTypeContent {
+
+ XmlSchemaObjectCollection baseTypes;
+ String memberTypesSource;
+ QName[] memberTypesQNames;
+
+ public XmlSchemaSimpleTypeUnion() {
+ baseTypes = new XmlSchemaObjectCollection();
+ }
+
+ public XmlSchemaObjectCollection getBaseTypes() {
+ return this.baseTypes;
+ }
+
+ public void setMemberTypesSource(String memberTypesSources) {
+ this.memberTypesSource = memberTypesSources;
+ }
+
+ public String getMemberTypesSource() {
+ return this.memberTypesSource;
+ }
+
+ public QName[] getMemberTypesQNames() {
+ return this.memberTypesQNames;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaTotalDigitsFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaTotalDigitsFacet.java
new file mode 100644
index 0000000..aa26ff4
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaTotalDigitsFacet.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining totalDigits facets. Represents the World Wide
+ * Web Consortium (W3C) totalDigits facet.
+ */
+
+public class XmlSchemaTotalDigitsFacet extends XmlSchemaNumericFacet {
+
+ /**
+ * Creates new XmlSchemaTotalDigitsFacet
+ */
+ public XmlSchemaTotalDigitsFacet() {
+ }
+
+ public XmlSchemaTotalDigitsFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<totalDigits value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"").append(super.isFixed()).append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
new file mode 100644
index 0000000..aa12455
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaType.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+import javax.xml.namespace.QName;
+
+
+/**
+ * The base class for all simple types and complex types.
+ */
+
+public class XmlSchemaType extends XmlSchemaAnnotated {
+
+ Object baseSchemaType;
+ XmlSchemaDatatype dataType;
+ XmlSchemaDerivationMethod deriveBy, finalDerivation, finalResolved;
+ boolean isMixed;
+
+ // name of the type
+ String name;
+
+ XmlSchema schema;
+
+ /**
+ * Creates new XmlSchemaType
+ */
+ public XmlSchemaType(XmlSchema schema) {
+ this.schema = schema;
+ finalDerivation = new XmlSchemaDerivationMethod(Constants.BlockConstants.NONE);
+ }
+
+ public Object getBaseSchemaType() {
+ return baseSchemaType;
+ }
+
+ public XmlSchemaDatatype getDataType() {
+ return dataType;
+ }
+
+ public XmlSchemaDerivationMethod getDeriveBy() {
+ return deriveBy;
+ }
+
+ public XmlSchemaDerivationMethod getFinal() {
+ return finalDerivation;
+ }
+
+ public void setFinal(XmlSchemaDerivationMethod finalDerivation) {
+ this.finalDerivation = finalDerivation;
+ }
+
+ public XmlSchemaDerivationMethod getFinalResolved() {
+ return finalResolved;
+ }
+
+ public boolean isMixed() {
+ return isMixed;
+ }
+
+ public void setMixed(boolean isMixed) {
+ this.isMixed = isMixed;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public QName getQName() {
+ if(name == null) {
+ return null;
+ }
+ return new QName(schema.logicalTargetNamespace, name);
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUnique.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUnique.java
new file mode 100644
index 0000000..aedc88f
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUnique.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Identifies a unique constraint among a set of elements. Represents
+ * the World Wide Web Consortium (W3C) unique element.
+ */
+
+public class XmlSchemaUnique extends XmlSchemaIdentityConstraint {
+
+ /**
+ * Creates new XmlSchemaUnique
+ */
+ public XmlSchemaUnique() {
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUse.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUse.java
new file mode 100644
index 0000000..86c5781
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaUse.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+
+/**
+ * Indicator of how the attribute is used.
+ */
+public class XmlSchemaUse extends org.apache.ws.commons.schema.constants.Enum {
+
+ static String[] members = new String[]{
+ Constants.BlockConstants.NONE,
+ Constants.BlockConstants.OPTIONAL,
+ Constants.BlockConstants.PROHIBITED,
+ Constants.BlockConstants.REQUIRED
+ };
+ /**
+ * Creates new XmlSchemaUse
+ */
+ public XmlSchemaUse() {
+ super();
+ }
+
+ public XmlSchemaUse(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaWhiteSpaceFacet.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaWhiteSpaceFacet.java
new file mode 100644
index 0000000..c0079c9
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaWhiteSpaceFacet.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+/*
+ * XmlSchemaWhiteSpaceFacet.java
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for defining whiteSpace facets. Represents the World Wide
+ * Web Consortium (W3C) whiteSpace facet.
+ */
+
+public class XmlSchemaWhiteSpaceFacet extends XmlSchemaFacet {
+
+ /**
+ * Creates new XmlSchemaWhiteSpaceFacet
+ */
+ public XmlSchemaWhiteSpaceFacet() {
+ }
+
+ public XmlSchemaWhiteSpaceFacet(Object value, boolean fixed) {
+ super(value, fixed);
+ }
+
+ public String toString(String prefix, int tab) {
+ StringBuffer xml = new StringBuffer();
+ for (int i = 0; i < tab; i++) {
+ xml.append("\t");
+ }
+ xml.append("<whiteSpace value=\"").append(super.getValue()).append("\" ");
+ xml.append("fixed=\"").append(super.isFixed()).append("\"/>\n");
+ return xml.toString();
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaXPath.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaXPath.java
new file mode 100644
index 0000000..280519b
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaXPath.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+/**
+ * Class for XML Path Language (XPath) expressions. Represents the
+ * World Wide Web Consortium (W3C) selector element. The World Wide
+ * Web Consortium (W3C) field element is a collection of
+ * XmlSchemaXPath classes.
+ */
+
+public class XmlSchemaXPath extends XmlSchemaAnnotated {
+
+ /**
+ * Creates new XmlSchemaXPath
+ */
+ public XmlSchemaXPath() {
+ }
+
+ String xpath;
+
+ public String getXPath() {
+ return xpath;
+ }
+
+ public void setXPath(String xpath) {
+ this.xpath = xpath;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSeverityType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSeverityType.java
new file mode 100644
index 0000000..3488b2f
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSeverityType.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.apache.ws.commons.schema.constants.Enum;
+
+/**
+ * Represents the severity of the validation event.
+ */
+
+public class XmlSeverityType extends Enum {
+
+ static String[] members = new String[]{
+ Constants.BlockConstants.ERROR,
+ Constants.BlockConstants.WARNING
+ };
+
+ /**
+ * Creates new XmlSeverityType
+ */
+ public XmlSeverityType() {
+ super();
+ }
+
+ public XmlSeverityType(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlTokenizedType.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlTokenizedType.java
new file mode 100644
index 0000000..5070387
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlTokenizedType.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema;
+
+public class XmlTokenizedType extends org.apache.ws.commons.schema.constants.Enum {
+
+ static String[] members = new String[]{"CDATA", "IDREF", "IDREFS",
+ "ENTITY", "ENTITIES", "NMTOKEN",
+ "NMTOKENS", "NOTATION", "ENUMERATION",
+ "QName", "NCName", "None"};
+
+ /**
+ * Creates new XmlSchemaForm
+ */
+ public XmlTokenizedType(String value) {
+ super(value);
+ }
+
+ public String[] getValues() {
+ return members;
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
new file mode 100644
index 0000000..c9b0a66
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Constants.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema.constants;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Constants
+ */
+public class Constants {
+ public static final String XMLNS_URI =
+ "http://www.w3.org/XML/1998/namespace";
+
+ public static final String XMLNS_PREFIX =
+ "xml";
+
+ //
+ // Schema Namespaces
+ //
+ public static final String URI_2001_SCHEMA_XSD =
+ "http://www.w3.org/2001/XMLSchema";
+ public static final String URI_2001_SCHEMA_XSI =
+ "http://www.w3.org/2001/XMLSchema-instance";
+
+ // Define qnames for the all of the XSD and SOAP-ENC encodings
+ public static final QName XSD_STRING = new QName(URI_2001_SCHEMA_XSD, "string");
+ public static final QName XSD_BOOLEAN = new QName(URI_2001_SCHEMA_XSD, "boolean");
+ public static final QName XSD_DOUBLE = new QName(URI_2001_SCHEMA_XSD, "double");
+ public static final QName XSD_FLOAT = new QName(URI_2001_SCHEMA_XSD, "float");
+ public static final QName XSD_INT = new QName(URI_2001_SCHEMA_XSD, "int");
+ public static final QName XSD_INTEGER = new QName(URI_2001_SCHEMA_XSD, "integer");
+ public static final QName XSD_LONG = new QName(URI_2001_SCHEMA_XSD, "long");
+ public static final QName XSD_SHORT = new QName(URI_2001_SCHEMA_XSD, "short");
+ public static final QName XSD_BYTE = new QName(URI_2001_SCHEMA_XSD, "byte");
+ public static final QName XSD_DECIMAL = new QName(URI_2001_SCHEMA_XSD, "decimal");
+ public static final QName XSD_BASE64 = new QName(URI_2001_SCHEMA_XSD, "base64Binary");
+ public static final QName XSD_HEXBIN = new QName(URI_2001_SCHEMA_XSD, "hexBinary");
+ public static final QName XSD_ANYSIMPLETYPE = new QName(URI_2001_SCHEMA_XSD, "anySimpleType");
+ public static final QName XSD_ANYTYPE = new QName(URI_2001_SCHEMA_XSD, "anyType");
+ public static final QName XSD_ANY = new QName(URI_2001_SCHEMA_XSD, "any");
+ public static final QName XSD_QNAME = new QName(URI_2001_SCHEMA_XSD, "QName");
+ public static final QName XSD_DATETIME = new QName(URI_2001_SCHEMA_XSD, "dateTime");
+ public static final QName XSD_DATE = new QName(URI_2001_SCHEMA_XSD, "date");
+ public static final QName XSD_TIME = new QName(URI_2001_SCHEMA_XSD, "time");
+
+ public static final QName XSD_NORMALIZEDSTRING = new QName(URI_2001_SCHEMA_XSD, "normalizedString");
+ public static final QName XSD_TOKEN = new QName(URI_2001_SCHEMA_XSD, "token");
+
+ public static final QName XSD_UNSIGNEDLONG = new QName(URI_2001_SCHEMA_XSD, "unsignedLong");
+ public static final QName XSD_UNSIGNEDINT = new QName(URI_2001_SCHEMA_XSD, "unsignedInt");
+ public static final QName XSD_UNSIGNEDSHORT = new QName(URI_2001_SCHEMA_XSD, "unsignedShort");
+ public static final QName XSD_UNSIGNEDBYTE = new QName(URI_2001_SCHEMA_XSD, "unsignedByte");
+ public static final QName XSD_POSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "positiveInteger");
+ public static final QName XSD_NEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "negativeInteger");
+ public static final QName XSD_NONNEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonNegativeInteger");
+ public static final QName XSD_NONPOSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonPositiveInteger");
+
+ public static final QName XSD_YEARMONTH = new QName(URI_2001_SCHEMA_XSD, "gYearMonth");
+ public static final QName XSD_MONTHDAY = new QName(URI_2001_SCHEMA_XSD, "gMonthDay");
+ public static final QName XSD_YEAR = new QName(URI_2001_SCHEMA_XSD, "gYear");
+ public static final QName XSD_MONTH = new QName(URI_2001_SCHEMA_XSD, "gMonth");
+ public static final QName XSD_DAY = new QName(URI_2001_SCHEMA_XSD, "gDay");
+ public static final QName XSD_DURATION = new QName(URI_2001_SCHEMA_XSD, "duration");
+
+ public static final QName XSD_NAME = new QName(URI_2001_SCHEMA_XSD, "Name");
+ public static final QName XSD_NCNAME = new QName(URI_2001_SCHEMA_XSD, "NCName");
+ public static final QName XSD_NMTOKEN = new QName(URI_2001_SCHEMA_XSD, "NMTOKEN");
+ public static final QName XSD_NMTOKENS = new QName(URI_2001_SCHEMA_XSD, "NMTOKENS");
+ public static final QName XSD_NOTATION = new QName(URI_2001_SCHEMA_XSD, "NOTATION");
+ public static final QName XSD_ENTITY = new QName(URI_2001_SCHEMA_XSD, "ENTITY");
+ public static final QName XSD_ENTITIES = new QName(URI_2001_SCHEMA_XSD, "ENTITIES");
+ public static final QName XSD_IDREF = new QName(URI_2001_SCHEMA_XSD, "IDREF");
+ public static final QName XSD_IDREFS = new QName(URI_2001_SCHEMA_XSD, "IDREFS");
+ public static final QName XSD_ANYURI = new QName(URI_2001_SCHEMA_XSD, "anyURI");
+ public static final QName XSD_LANGUAGE = new QName(URI_2001_SCHEMA_XSD, "language");
+ public static final QName XSD_ID = new QName(URI_2001_SCHEMA_XSD, "ID");
+ public static final QName XSD_SCHEMA = new QName(URI_2001_SCHEMA_XSD, "schema");
+
+ /**
+ * All constants that are relevant to the names of the
+ * schema elements
+ */
+ public static class BlockConstants {
+
+ public static final String ALL = "all";
+ public static final String NONE = "none";
+ public static final String EXTENSION = "extension";
+ public static final String LIST = "list";
+ public static final String RESTRICTION = "restriction";
+ public static final String SUBSITUTION = "substitution";
+ public static final String UNION = "union";
+ public static final String EMPTY = "empty";
+ public static final String ELEMENT_ONLY = "elementOnly";
+ public static final String MIXED = "mixed";
+ public static final String TEXT_ONLY = "textOnly";
+ public static final String LAX = "lax";
+ public static final String SKIP = "skip";
+ public static final String STRICT = "strict";
+ public static final String OPTIONAL = "optional";
+ public static final String PROHIBITED = "prohibited";
+ public static final String REQUIRED = "required";
+ public static final String ERROR = "error";
+ public static final String WARNING = "warning";
+ }
+
+ /**
+ * class holding the the constants for meta data storage
+ */
+ public static class MetaDataConstants{
+ public static final String EXTERNAL_ATTRIBUTES = "EXTERNAL_ATTRIBUTES";
+ public static final String EXTERNAL_ELEMENTS = "EXTERNAL_ELEMENTS";
+ }
+
+ /**
+ * class holding the the constants for meta data storage
+ */
+ public static class SystemConstants{
+ public static final String EXTENSION_REGISTRY_KEY = "org.apache.ws.commons.extensions.ExtensionRegistry";
+ }
+
+ public static final String XMLNS_ATTRIBUTE_NS_URI =
+ "http://www.w3.org/2000/xmlns/";
+
+ public static final String XMLNS_ATTRIBUTE = "xmlns";
+
+ public static final String DEFAULT_NS_PREFIX = "";
+
+ public static final String XML_NS_URI =
+ "http://www.w3.org/XML/1998/namespace";
+
+ public static final String XML_NS_PREFIX = "xml";
+
+ public static final String NULL_NS_URI = "";
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Enum.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Enum.java
new file mode 100644
index 0000000..d8c87b3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/constants/Enum.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema.constants;
+
+public abstract class Enum {
+
+ public static String NULL = "NULL";
+
+ protected Enum(String value) {
+ setValue(value);
+ }
+
+ protected Enum() {
+ this(NULL);
+ }
+
+ protected abstract String[] getValues();
+
+ protected String value = NULL;
+
+ public void setValue(String value) {
+ if (value.equals(Enum.NULL))
+ this.value = Enum.NULL;
+ else {
+ String values[] = getValues();
+ for (int i = 0; i < values.length; i++) {
+ if (values[i].equals(value)) {
+ this.value = value;
+ break;
+ }
+ if (i == values.length - 1)
+ throw new EnumValueException("Bad Enumeration value '" + value + "'");
+ }
+ }
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public String toString() {
+ return value;
+ }
+
+ public boolean equals(Object what) {
+ return what.getClass().equals(this.getClass()) &&
+ ((Enum) what).getValue().equals(this.getValue());
+ }
+
+ public static class EnumValueException extends RuntimeException {
+ public EnumValueException(String mesg) {
+ super(mesg);
+ }
+ }
+
+ protected static final int index(String value, String values[]) {
+ for (int i = 0; i < values.length; i++) {
+ if (value.equals(values[i]))
+ return i;
+ }
+ return -1;
+ }
+}
+
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java
new file mode 100644
index 0000000..5782aad
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionDeserializer.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Default deserializer. The action taken when there is nothing specific
+ * to be done would be to attach the raw element object as it is to the
+ * meta information map for an element or the raw attribute object
+ *
+ */
+public class DefaultExtensionDeserializer implements ExtensionDeserializer {
+
+ /**
+ * deserialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param name - the QName of the element/attribute to be deserialized.
+ * in the case where a deserializer is used to handle multiple elements/attributes
+ * this may be useful to determine the correct deserialization
+ * @param node - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or the extension attribute object if
+ * it is an attribute
+ */
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node node) {
+
+ // we just attach the raw node either to the meta map of
+ // elements or the attributes
+ Map metaInfoMap = new HashMap();
+
+
+
+ if (node.getNodeType()==Node.ATTRIBUTE_NODE){
+
+ Map attribMap;
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
+ attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
+ }else{
+ attribMap = new HashMap();
+ metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES,attribMap);
+ }
+ attribMap.put(name,node);
+
+ }else if (node.getNodeType()==Node.ELEMENT_NODE){
+ Map elementMap;
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
+ elementMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
+ }else{
+ elementMap = new HashMap();
+ metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ELEMENTS,elementMap);
+ }
+ elementMap.put(name,node);
+ }
+
+ //subsequent processing takes place only if this map is not empty
+ if (!metaInfoMap.isEmpty()){
+ Map metaInfoMapFromSchemaElement = schemaObject.getMetaInfoMap();
+ if (metaInfoMapFromSchemaElement==null){
+ schemaObject.setMetaInfoMap(metaInfoMap);
+ }else{
+ metaInfoMapFromSchemaElement.putAll(metaInfoMap);
+ }
+
+ }
+
+
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java
new file mode 100644
index 0000000..c65a8db
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/DefaultExtensionSerializer.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Attr;
+
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+
+ */
+public class DefaultExtensionSerializer implements ExtensionSerializer{
+
+ /**
+ * serialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param classOfType - the class of the object to be serialized
+ * @param node - The DOM Node that is the parent of the serialzation
+ */
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node node) {
+ // serialization is somewhat tricky in most cases hence this default serializer will
+ // do the exact reverse of the deserializer - look for any plain 'as is' items
+ // and attach them to the parent node.
+ // we just attach the raw node either to the meta map of
+ // elements or the attributes
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ Document parentDoc = node.getOwnerDocument();
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES)){
+ Map attribMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
+ for(Iterator it = attribMap.values().iterator();it.hasNext();){
+ if (node.getNodeType()==Node.ELEMENT_NODE){
+ ((Element)node).setAttributeNodeNS((Attr)parentDoc.importNode((Node)it.next(),true));
+ }
+
+ }
+ }
+
+ if (metaInfoMap.containsKey(Constants.MetaDataConstants.EXTERNAL_ELEMENTS)){
+ Map elementMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ELEMENTS);
+ for(Iterator it = elementMap.values().iterator();it.hasNext();){
+ node.appendChild(
+ parentDoc.importNode((Node)it.next(),true));
+ }
+ }
+
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java
new file mode 100644
index 0000000..a9512ac
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionDeserializer.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Interface for the extension deserializer. The purpose of an instance
+ * of this is to deserialize the relevant attribute/element and perhaps generate
+ * a desired custom object. This custom object can be stored in the metadata map
+ * of the parent schema object. When to invoke a given deserializer is a decision
+ * taken by the extension registry
+ */
+public interface ExtensionDeserializer {
+
+ /**
+ * deserialize the given element
+ * @param schemaObject - Parent schema element
+ * @param name - the QName of the element/attribute to be deserialized.
+ * in the case where a deserializer is used to handle multiple elements/attributes
+ * this may be useful to determine the correct deserialization
+ * @param domNode - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or the extension attribute object if
+ * it is an attribute
+ *
+ */
+ public void deserialize(XmlSchemaObject schemaObject,
+ QName name,
+ Node domNode);
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
new file mode 100644
index 0000000..3c17937
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionRegistry.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The task of the extension serializer is to delegate the serilization of
+ * the extensions. The extension serializers/deserializers are retained in seperate
+ * maps and there are also two seperate references to default serializers and deserializers
+ * which would jump into action when there are no specifically attached
+ * serializers/deserializers
+ */
+public class ExtensionRegistry {
+
+ /**
+ * Maps for the storage of extension serializers /deserializers
+ */
+ private Map extensionSerializers = new HashMap();
+ private Map extensionDeserializers = new HashMap();
+
+ /**
+ * Default serializer and serializer
+ */
+ private ExtensionSerializer defaultExtensionSerializer =new DefaultExtensionSerializer();
+ private ExtensionDeserializer defaultExtensionDeserializer = new DefaultExtensionDeserializer();
+
+
+ public ExtensionSerializer getDefaultExtensionSerializer() {
+ return defaultExtensionSerializer;
+ }
+
+ public void setDefaultExtensionSerializer(ExtensionSerializer defaultExtensionSerializer) {
+ this.defaultExtensionSerializer = defaultExtensionSerializer;
+ }
+
+ public ExtensionDeserializer getDefaultExtensionDeserializer() {
+ return defaultExtensionDeserializer;
+ }
+
+ public void setDefaultExtensionDeserializer(ExtensionDeserializer defaultExtensionDeserializer) {
+ this.defaultExtensionDeserializer = defaultExtensionDeserializer;
+ }
+
+ /**
+ * Register a deserializer with a QName
+ * @param name - the QName of the element/attribute
+ * @param deserializer - an instance of the deserializer
+ */
+ public void registerDeserializer(QName name,ExtensionDeserializer deserializer){
+ extensionDeserializers.put(name,deserializer);
+ }
+ /**
+ * Register a serializer with a Class
+ * @param classOfType - the class of the object that would be serialized
+ * @param serializer - an instance of the deserializer
+ */
+ public void registerSerializer(Class classOfType,ExtensionSerializer serializer){
+ extensionSerializers.put(classOfType,serializer);
+ }
+
+
+ /**
+ * remove the registration for a serializer with a QName
+ * @param name - the QName of the element/attribute the
+ * serializer is associated with
+ */
+ public void unregisterSerializer(QName name){
+ extensionSerializers.remove(name);
+ }
+
+ /**
+ * remove the registration for a deserializer with a QName
+ * @param classOfType - the the
+ * deserializer is associated with
+ */
+ public void unregisterDeserializer(Class classOfType){
+ extensionDeserializers.remove(classOfType);
+ }
+
+
+ /**
+ * Serialize a given extension element
+ * @param parentSchemaObject - the parent schema object. This is what
+ * would contain the extension object, probably in side its meta information
+ * map
+ * @param classOfType - The class of type to be serialized
+ * @param node - the parent DOM Node that will ultimately be serialized. The XMLSchema
+ * serialization mechanism is to create a DOM tree first and serialize it
+ */
+ public void serializeExtension(XmlSchemaObject parentSchemaObject,
+ Class classOfType,
+ Node node){
+ Object serializerObject = extensionSerializers.get(classOfType);
+ if (serializerObject!=null){
+ //perform the serialization
+ ExtensionSerializer ser = (ExtensionSerializer)serializerObject;
+ ser.serialize(parentSchemaObject,classOfType,node);
+ }else if (defaultExtensionSerializer!=null) {
+ defaultExtensionSerializer.serialize(parentSchemaObject,classOfType,node);
+ }
+
+
+ }
+
+
+ /**
+ * Deserialize a given extension element
+ * @param parentSchemaObject - the parent schema object. This is anticipated
+ * to be created already and the relevant object would contain the extension
+ * object, probably in side its meta information map
+ * @param name - The qname of the element/attribute to be deserialized. This will be used to
+ * search for the extension as well as by the deserializer if a single deserializer is
+ * registered against a number of qnames
+ * @param rawNode - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or extension attribute itself
+ * in case of an attribute
+ */
+ public void deserializeExtension(XmlSchemaObject parentSchemaObject,
+ QName name,
+ Node rawNode){
+ Object deserializerObject = extensionDeserializers.get(name);
+ if (deserializerObject !=null){
+ //perform the serialization
+ ExtensionDeserializer deser = (ExtensionDeserializer)deserializerObject;
+ deser.deserialize(parentSchemaObject,name,rawNode);
+ } else if (defaultExtensionDeserializer!=null){
+ defaultExtensionDeserializer.deserialize(parentSchemaObject,name,rawNode);
+ }
+ }
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java
new file mode 100644
index 0000000..c4bf894
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/extensions/ExtensionSerializer.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Portions Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ */
+package org.apache.ws.commons.schema.extensions;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.w3c.dom.Node;
+
+
+/**
+ * Interface for the extension serializer. The purpose of an instance
+ * of this is to serialize the relevant custom object
+ * and generate attribute/elementa desired . This custom object
+ * may be stored in the metadata map
+ * of the parent schema object. When to invoke a given serializer is a decision
+ * taken by the extension registry
+ */
+public interface ExtensionSerializer {
+
+ /**
+ * serialize the given element
+ * @param schemaObject - Parent schema object.contains the extension
+ * to be serialized
+ * @param classOfType - The class of type to be serialized
+ * @param domNode - the parent DOM Node that will ultimately be serialized. The XMLSchema
+ * serialization mechanism is to create a DOM tree first and serialize it
+ */
+ public void serialize(XmlSchemaObject schemaObject,
+ Class classOfType,
+ Node domNode);
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
new file mode 100644
index 0000000..06fdaca
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package org.apache.ws.commons.schema.resolver;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+
+/**
+ * This resolver provides the means of resolving the imports and includes of a
+ * given schema document. The system will call this default resolver if there
+ * is no other resolver present in the system
+ */
+public class DefaultURIResolver implements URIResolver {
+
+
+ /**
+ * As for the resolver the publid ID is the target namespace of the
+ * schema and the schemaLocation is the value of the schema location
+ * @param namespace
+ * @param schemaLocation
+ * @param baseUri
+ */
+ public InputSource resolveEntity(String namespace,
+ String schemaLocation,
+ String baseUri){
+
+ if (baseUri!=null)
+ {
+ try
+ {
+ File baseFile = new File(baseUri);
+ if (baseFile.exists()) baseUri = baseFile.toURI().toString();
+
+ String ref = new URI(baseUri).resolve(new URI(schemaLocation)).toString();
+
+ return new InputSource(ref);
+ }
+ catch (URISyntaxException e1)
+ {
+ throw new RuntimeException(e1);
+ }
+
+ }
+ return new InputSource(schemaLocation);
+
+
+
+ }
+
+ /**
+ * Find whether a given uri is relative or not
+ *
+ * @param uri
+ * @return boolean
+ */
+ protected boolean isAbsolute(String uri) {
+ return uri.startsWith("http://");
+ }
+
+ /**
+ * This is essentially a call to "new URL(contextURL, spec)"
+ * with extra handling in case spec is
+ * a file.
+ *
+ * @param contextURL
+ * @param spec
+ * @throws java.io.IOException
+ */
+ protected URL getURL(URL contextURL, String spec) throws IOException {
+
+ // First, fix the slashes as windows filenames may have backslashes
+ // in them, but the URL class wont do the right thing when we later
+ // process this URL as the contextURL.
+ String path = spec.replace('\\', '/');
+
+ // See if we have a good URL.
+ URL url;
+
+ try {
+
+ // first, try to treat spec as a full URL
+ url = new URL(contextURL, path);
+
+ // if we are deail with files in both cases, create a url
+ // by using the directory of the context URL.
+ if ((contextURL != null) && url.getProtocol().equals("file")
+ && contextURL.getProtocol().equals("file")) {
+ url = getFileURL(contextURL, path);
+ }
+ } catch (MalformedURLException me) {
+
+ // try treating is as a file pathname
+ url = getFileURL(contextURL, path);
+ }
+
+ // Everything is OK with this URL, although a file url constructed
+ // above may not exist. This will be caught later when the URL is
+ // accessed.
+ return url;
+ } // getURL
+
+ /**
+ * Method getFileURL
+ *
+ * @param contextURL
+ * @param path
+ * @throws IOException
+ */
+ protected URL getFileURL(URL contextURL, String path)
+ throws IOException {
+
+ if (contextURL != null) {
+
+ // get the parent directory of the contextURL, and append
+ // the spec string to the end.
+ String contextFileName = contextURL.getFile();
+ URL parent = null;
+ //the logic for finding the parent file is this.
+ //1.if the contextURI represents a file then take the parent file
+ //of it
+ //2. If the contextURI represents a directory, then take that as
+ //the parent
+ File parentFile;
+ File contextFile = new File(contextFileName);
+ if (contextFile.isDirectory()){
+ parentFile = contextFile;
+ }else{
+ parentFile = contextFile.getParentFile();
+ }
+
+ if (parentFile != null) {
+ parent = parentFile.toURL();
+ }
+ if (parent != null) {
+ return new URL(parent, path);
+ }
+ }
+
+ return new URL("file", "", path);
+ } // getFileURL
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/URIResolver.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/URIResolver.java
new file mode 100644
index 0000000..d411966
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/resolver/URIResolver.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package org.apache.ws.commons.schema.resolver;
+
+import org.xml.sax.InputSource;
+
+
+public interface URIResolver {
+ /**
+ * Resolves an interface
+ * @param targetNamespace
+ * @param schemaLocation
+ * @param baseUri
+ */
+ InputSource resolveEntity(String targetNamespace,
+ String schemaLocation,
+ String baseUri
+ );
+
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
new file mode 100644
index 0000000..b1323b9
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/DOMUtil.java
@@ -0,0 +1,584 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+import org.w3c.dom.*;
+
+/**
+ * Some useful utility methods.
+ * This class was modified in Xerces2 with a view to abstracting as
+ * much as possible away from the representation of the underlying
+ * parsed structure (i.e., the DOM). This was done so that, if Xerces
+ * ever adopts an in-memory representation more efficient than the DOM
+ * (such as a DTM), we should easily be able to convert our schema
+ * parsing to utilize it.
+ *
+ * @version $ID DOMUtil
+ */
+public class DOMUtil {
+
+ //
+ // Constructors
+ //
+
+ /**
+ * This class cannot be instantiated.
+ */
+ protected DOMUtil() {
+ }
+
+ //
+ // Public static methods
+ //
+
+ /**
+ * Finds and returns the first child element node.
+ */
+ public static Element getFirstChildElement(Node parent) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element) child;
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElement(Node):Element
+
+ /**
+ * Finds and returns the last child element node.
+ */
+ public static Element getLastChildElement(Node parent) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element) child;
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElement(Node):Element
+
+
+ /**
+ * Finds and returns the next sibling element node.
+ */
+ public static Element getNextSiblingElement(Node node) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ return (Element) sibling;
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingElement(Node):Element
+
+ /**
+ * Finds and returns the first child node with the given name.
+ */
+ public static Element getFirstChildElement(Node parent, String elemName) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ if (child.getNodeName().equals(elemName)) {
+ return (Element) child;
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElement(Node,String):Element
+
+ /**
+ * Finds and returns the last child node with the given name.
+ */
+ public static Element getLastChildElement(Node parent, String elemName) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ if (child.getNodeName().equals(elemName)) {
+ return (Element) child;
+ }
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElement(Node,String):Element
+
+ /**
+ * Finds and returns the next sibling node with the given name.
+ */
+ public static Element getNextSiblingElement(Node node, String elemName) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ if (sibling.getNodeName().equals(elemName)) {
+ return (Element) sibling;
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingdElement(Node,String):Element
+
+ /**
+ * Finds and returns the first child node with the given qualified name.
+ */
+ public static Element getFirstChildElementNS(Node parent,
+ String uri, String localpart) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String childURI = child.getNamespaceURI();
+ if (childURI != null && childURI.equals(uri) &&
+ child.getLocalName().equals(localpart)) {
+ return (Element) child;
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElementNS(Node,String,String):Element
+
+ /**
+ * Finds and returns the last child node with the given qualified name.
+ */
+ public static Element getLastChildElementNS(Node parent,
+ String uri, String localpart) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String childURI = child.getNamespaceURI();
+ if (childURI != null && childURI.equals(uri) &&
+ child.getLocalName().equals(localpart)) {
+ return (Element) child;
+ }
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElementNS(Node,String,String):Element
+
+ /**
+ * Finds and returns the next sibling node with the given qualified name.
+ */
+ public static Element getNextSiblingElementNS(Node node,
+ String uri, String localpart) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ String siblingURI = sibling.getNamespaceURI();
+ if (siblingURI != null && siblingURI.equals(uri) &&
+ sibling.getLocalName().equals(localpart)) {
+ return (Element) sibling;
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingdElementNS(Node,String,String):Element
+
+ /**
+ * Finds and returns the first child node with the given name.
+ */
+ public static Element getFirstChildElement(Node parent, String elemNames[]) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ if (child.getNodeName().equals(elemNames[i])) {
+ return (Element) child;
+ }
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElement(Node,String[]):Element
+
+ /**
+ * Finds and returns the last child node with the given name.
+ */
+ public static Element getLastChildElement(Node parent, String elemNames[]) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ if (child.getNodeName().equals(elemNames[i])) {
+ return (Element) child;
+ }
+ }
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElement(Node,String[]):Element
+
+ /**
+ * Finds and returns the next sibling node with the given name.
+ */
+ public static Element getNextSiblingElement(Node node, String elemNames[]) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ if (sibling.getNodeName().equals(elemNames[i])) {
+ return (Element) sibling;
+ }
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingdElement(Node,String[]):Element
+
+ /**
+ * Finds and returns the first child node with the given qualified name.
+ */
+ public static Element getFirstChildElementNS(Node parent,
+ String[][] elemNames) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ String uri = child.getNamespaceURI();
+ if (uri != null && uri.equals(elemNames[i][0]) &&
+ child.getLocalName().equals(elemNames[i][1])) {
+ return (Element) child;
+ }
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElementNS(Node,String[][]):Element
+
+ /**
+ * Finds and returns the last child node with the given qualified name.
+ */
+ public static Element getLastChildElementNS(Node parent,
+ String[][] elemNames) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ String uri = child.getNamespaceURI();
+ if (uri != null && uri.equals(elemNames[i][0]) &&
+ child.getLocalName().equals(elemNames[i][1])) {
+ return (Element) child;
+ }
+ }
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElementNS(Node,String[][]):Element
+
+ /**
+ * Finds and returns the next sibling node with the given qualified name.
+ */
+ public static Element getNextSiblingElementNS(Node node,
+ String[][] elemNames) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < elemNames.length; i++) {
+ String uri = sibling.getNamespaceURI();
+ if (uri != null && uri.equals(elemNames[i][0]) &&
+ sibling.getLocalName().equals(elemNames[i][1])) {
+ return (Element) sibling;
+ }
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingdElementNS(Node,String[][]):Element
+
+ /**
+ * Finds and returns the first child node with the given name and
+ * attribute name, value pair.
+ */
+ public static Element getFirstChildElement(Node parent,
+ String elemName,
+ String attrName,
+ String attrValue) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) child;
+ if (element.getNodeName().equals(elemName) &&
+ element.getAttribute(attrName).equals(attrValue)) {
+ return element;
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getFirstChildElement(Node,String,String,String):Element
+
+ /**
+ * Finds and returns the last child node with the given name and
+ * attribute name, value pair.
+ */
+ public static Element getLastChildElement(Node parent,
+ String elemName,
+ String attrName,
+ String attrValue) {
+
+ // search for node
+ Node child = parent.getLastChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) child;
+ if (element.getNodeName().equals(elemName) &&
+ element.getAttribute(attrName).equals(attrValue)) {
+ return element;
+ }
+ }
+ child = child.getPreviousSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getLastChildElement(Node,String,String,String):Element
+
+ /**
+ * Finds and returns the next sibling node with the given name and
+ * attribute name, value pair. Since only elements have attributes,
+ * the node returned will be of type Node.ELEMENT_NODE.
+ */
+ public static Element getNextSiblingElement(Node node,
+ String elemName,
+ String attrName,
+ String attrValue) {
+
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) sibling;
+ if (element.getNodeName().equals(elemName) &&
+ element.getAttribute(attrName).equals(attrValue)) {
+ return element;
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ } // getNextSiblingElement(Node,String,String,String):Element
+
+ /**
+ * Returns the concatenated child text of the specified node.
+ * This method only looks at the immediate children of type
+ * <code>Node.TEXT_NODE</code> or the children of any child
+ * node that is of type <code>Node.CDATA_SECTION_NODE</code>
+ * for the concatenation.
+ *
+ * @param node The node to look at.
+ */
+ public static String getChildText(Node node) {
+
+ // is there anything to do?
+ if (node == null) {
+ return null;
+ }
+
+ // concatenate children text
+ StringBuffer str = new StringBuffer();
+ Node child = node.getFirstChild();
+ while (child != null) {
+ short type = child.getNodeType();
+ if (type == Node.TEXT_NODE) {
+ str.append(child.getNodeValue());
+ } else if (type == Node.CDATA_SECTION_NODE) {
+ str.append(getChildText(child));
+ }
+ child = child.getNextSibling();
+ }
+
+ // return text value
+ return str.toString();
+
+ } // getChildText(Node):String
+
+ // return the name of this element
+ public static String getName(Node node) {
+ return node.getNodeName();
+ } // getLocalName(Element): String
+
+ /**
+ * returns local name of this element if not null, otherwise
+ * returns the name of the node
+ */
+ public static String getLocalName(Node node) {
+ String name = node.getLocalName();
+ return (name != null) ? name : node.getNodeName();
+ } // getLocalName(Element): String
+
+ public static Element getParent(Element elem) {
+ Node parent = elem.getParentNode();
+ if (parent instanceof Element)
+ return (Element) parent;
+ return null;
+ } // getParent(Element):Element
+
+ // get the Document of which this Node is a part
+ public static Document getDocument(Node node) {
+ return node.getOwnerDocument();
+ } // getDocument(Node):Document
+
+ // return this Document's root node
+ public static Element getRoot(Document doc) {
+ return doc.getDocumentElement();
+ } // getRoot(Document(: Element
+
+ // some methods for handling attributes:
+
+ // return the right attribute node
+ public static Attr getAttr(Element elem, String name) {
+ return elem.getAttributeNode(name);
+ } // getAttr(Element, String):Attr
+
+ // return the right attribute node
+ public static Attr getAttrNS(Element elem, String nsUri,
+ String localName) {
+ return elem.getAttributeNodeNS(nsUri, localName);
+ } // getAttrNS(Element, String):Attr
+
+ // get all the attributes for an Element
+ public static Attr[] getAttrs(Element elem) {
+ NamedNodeMap attrMap = elem.getAttributes();
+ Attr[] attrArray = new Attr[attrMap.getLength()];
+ for (int i = 0; i < attrMap.getLength(); i++)
+ attrArray[i] = (Attr) attrMap.item(i);
+ return attrArray;
+ } // getAttrs(Element): Attr[]
+
+ // get attribute's value
+ public static String getValue(Attr attribute) {
+ return attribute.getValue();
+ } // getValue(Attr):String
+
+ // It is noteworthy that, because of the way the DOM specs
+ // work, the next two methods return the empty string (not
+ // null!) when the attribute with the specified name does not
+ // exist on an element. Beware!
+
+ // return the value of the attribute of the given element
+ // with the given name
+ public static String getAttrValue(Element elem, String name) {
+ return elem.getAttribute(name);
+ } // getAttr(Element, String):Attr
+
+ // return the value of the attribute of the given element
+ // with the given name
+ public static String getAttrValueNS(Element elem, String nsUri,
+ String localName) {
+ return elem.getAttributeNS(nsUri, localName);
+ } // getAttrValueNS(Element, String):Attr
+
+ // return the namespace URI
+ public static String getNamespaceURI(Node node) {
+ return node.getNamespaceURI();
+ }
+} // class XUtil
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java
new file mode 100644
index 0000000..f1e72db
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceContextOwner.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+/**
+ * Interface of an object, which is able to provide a namespace
+ * context.
+ */
+public interface NamespaceContextOwner {
+ /**
+ * Returns the objects namespace context.
+ */
+ NamespacePrefixList getNamespaceContext();
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java
new file mode 100644
index 0000000..8520366
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespaceMap.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package org.apache.ws.commons.schema.utils;
+
+import java.util.*;
+
+public class NamespaceMap extends HashMap implements NamespacePrefixList {
+
+ public NamespaceMap() {
+ }
+
+ public NamespaceMap(Map map) {
+ super(map);
+ }
+
+ public void add(String prefix, String namespaceURI) {
+ put(prefix, namespaceURI);
+ }
+
+ public String[] getDeclaredPrefixes() {
+ Set keys = keySet();
+ return (String[]) keys.toArray(new String[keys.size()]);
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return get(prefix).toString();
+ }
+
+ public String getPrefix(String namespaceURI) {
+ Iterator iterator = entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (entry.getValue().toString().equals(namespaceURI)) {
+ return (String) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ ArrayList list = new ArrayList();
+ Iterator iterator = entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ if (entry.getValue().toString().equals(namespaceURI)) {
+ list.add(entry.getKey());
+ }
+ }
+ return list.iterator();
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java
new file mode 100644
index 0000000..f15d652
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NamespacePrefixList.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+import javax.xml.namespace.NamespaceContext;
+
+
+/**
+ * Interface of an object, which is able to provide a list of currently
+ * defined namespace prefixes.
+ */
+public interface NamespacePrefixList extends NamespaceContext {
+ /**
+ * Returns the list of currently defined namespace prefixes.
+ */
+ public String[] getDeclaredPrefixes();
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
new file mode 100644
index 0000000..41509f5
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/NodeNamespaceContext.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.NamespaceContext;
+import java.util.*;
+
+/**
+ * Implementation of {@link NamespaceContext}, which is based on a DOM node.
+ */
+public class NodeNamespaceContext implements NamespacePrefixList {
+ private static final Collection XML_NS_PREFIX_COLLECTION = Collections.singletonList(Constants.XML_NS_PREFIX);
+ private static final Collection XMLNS_ATTRIBUTE_COLLECTION = Collections.singletonList(Constants.XMLNS_ATTRIBUTE);
+ private Node node;
+ private Map declarations;
+ private String[] prefixes;
+
+ /**
+ * Creates a new instance with the given nodes context.
+ */
+ public NodeNamespaceContext(Node pNode) {
+ node = pNode;
+ }
+
+ private Map getDeclarations() {
+ if (declarations == null) {
+ declarations = new HashMap();
+ //FIXME: Do we really need to add this mapping? shows up in the serialized schema as xmlns=""
+ //declarations.put(Constants.DEFAULT_NS_PREFIX, Constants.NULL_NS_URI);
+ new PrefixCollector(){
+ protected void declare(String pPrefix, String pNamespaceURI) {
+ declarations.put(pPrefix, pNamespaceURI);
+ }
+ }.searchAllPrefixDeclarations(node);
+ Collection keys = declarations.keySet();
+ prefixes = (String[]) keys.toArray(new String[keys.size()]);
+ }
+ return declarations;
+ }
+
+ public String getNamespaceURI(String pPrefix) {
+ if (pPrefix == null) {
+ throw new IllegalArgumentException("The prefix must not be null.");
+ }
+ if (Constants.XML_NS_PREFIX.equals(pPrefix)) {
+ return Constants.XML_NS_URI;
+ }
+ if (Constants.XMLNS_ATTRIBUTE.equals(pPrefix)) {
+ return Constants.XMLNS_ATTRIBUTE_NS_URI;
+ }
+ final String uri = (String) getDeclarations().get(pPrefix);
+ return uri == null ? Constants.NULL_NS_URI : uri;
+ }
+
+ public String getPrefix(String pNamespaceURI) {
+ if (pNamespaceURI == null) {
+ throw new IllegalArgumentException("The namespace URI must not be null.");
+ }
+ if (Constants.XML_NS_URI.equals(pNamespaceURI)) {
+ return Constants.XML_NS_PREFIX;
+ }
+ if (Constants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)) {
+ return Constants.XMLNS_ATTRIBUTE;
+ }
+ Map decl = getDeclarations();
+ for (Iterator iter = decl.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (pNamespaceURI.equals(entry.getValue())) {
+ return (String) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String pNamespaceURI) {
+ if (pNamespaceURI == null) {
+ throw new IllegalArgumentException("The namespace URI must not be null.");
+ }
+ if (Constants.XML_NS_URI.equals(pNamespaceURI)) {
+ return XML_NS_PREFIX_COLLECTION.iterator();
+ }
+ if (Constants.XMLNS_ATTRIBUTE_NS_URI.equals(pNamespaceURI)) {
+ return XMLNS_ATTRIBUTE_COLLECTION.iterator();
+ }
+ final List list = new ArrayList();
+ for (Iterator iter = getDeclarations().entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (pNamespaceURI.equals(entry.getValue())) {
+ list.add(entry.getKey());
+ }
+ }
+ return list.iterator();
+ }
+
+ public String[] getDeclaredPrefixes() {
+ getDeclarations(); // Make sure, that the prefixes array is valid
+ return prefixes;
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java
new file mode 100644
index 0000000..549db2e
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/PrefixCollector.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Searches for namespace prefix declarations.
+ */
+public abstract class PrefixCollector {
+ /**
+ * Records a single namespace prefix declaration.
+ */
+ protected abstract void declare(String pPrefix, String pNamespaceURI);
+
+ /**
+ * Searches for namespace prefix declarations in the given node.
+ * For any prefix declaration, it invokes {@link #declare(String, String)}.
+ * This method doesn't work recursively: The parent nodes prefix
+ * declarations are ignored.
+ */
+ public void searchLocalPrefixDeclarations(Node pNode) {
+ if (pNode.getNodeType() == Node.ELEMENT_NODE) {
+ NamedNodeMap map = pNode.getAttributes();
+ for (int i = 0; i < map.getLength(); i++) {
+ Node attr = map.item(i);
+ final String uri = attr.getNamespaceURI();
+ if (Constants.XMLNS_ATTRIBUTE_NS_URI.equals(uri)) {
+ String localName = attr.getLocalName();
+ String prefix = Constants.XMLNS_ATTRIBUTE.equals(localName) ? Constants.DEFAULT_NS_PREFIX : localName;
+ declare(prefix, attr.getNodeValue());
+ }
+ }
+ }
+ }
+
+ /**
+ * Searches for namespace prefix declarations in the given node.
+ * For any prefix declaration, it invokes {@link #declare(String, String)}.
+ * This method works recursively: The parent nodes prefix
+ * declarations are collected before the current nodes.
+ */
+ public void searchAllPrefixDeclarations(Node pNode) {
+ Node parent = pNode.getParentNode();
+ if (parent != null) {
+ searchAllPrefixDeclarations(parent);
+ }
+ searchLocalPrefixDeclarations(pNode);
+ }
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java
new file mode 100644
index 0000000..72139b6
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/TargetNamespaceValidator.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 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.
+ */
+package org.apache.ws.commons.schema.utils;
+
+import org.apache.ws.commons.schema.XmlSchema;
+
+/**
+ * Interface of an object, which may validate a schemas target namespace.
+ */
+public interface TargetNamespaceValidator {
+ /**
+ * Called for validating the given schemas target namespace.
+ */
+ void validate(XmlSchema pSchema);
+}
diff --git a/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java
new file mode 100644
index 0000000..5b0dec3
--- /dev/null
+++ b/XmlSchema/src/main/java/org/apache/ws/commons/schema/utils/XDOMUtil.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package org.apache.ws.commons.schema.utils;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class XDOMUtil extends DOMUtil {
+
+ /**
+ * Creates a new instance of XDOMUtil
+ */
+ private XDOMUtil() {
+ }
+
+ public static Element getFirstChildElementNS(Node parent, String uri) {
+
+ // search for node
+ Node child = parent.getFirstChild();
+ while (child != null) {
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ String childURI = child.getNamespaceURI();
+ if (childURI != null && childURI.equals(uri)) {
+ return (Element) child;
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ }
+
+ public static Element getNextSiblingElementNS(Node node, String uri) {
+ // search for node
+ Node sibling = node.getNextSibling();
+ while (sibling != null) {
+ if (sibling.getNodeType() == Node.ELEMENT_NODE) {
+ String siblingURI = sibling.getNamespaceURI();
+ if (siblingURI != null && siblingURI.equals(uri)) {
+ return (Element) sibling;
+ }
+ }
+ sibling = sibling.getNextSibling();
+ }
+
+ // not found
+ return null;
+
+ }
+
+}
diff --git a/XmlSchema/src/site/apt/index.apt b/XmlSchema/src/site/apt/index.apt
new file mode 100644
index 0000000..c6b30ef
--- /dev/null
+++ b/XmlSchema/src/site/apt/index.apt
@@ -0,0 +1,23 @@
+Overview
+
+ XMLSchema is a lightweight schema object model that can be used to manipulate and
+ generate XML schema representations. It has very few external dependancies and can
+ be easily integrated into an existing project.
+
+ For information on how to use the XmlSchema API, please
+ see the {{{apidocs/index.html}javadocs}} or the {{{schematutorial.html}tutorial}}.
+
+ You are welcome to kick the tires and get XMLSchema on the move. If you like to
+ help us shape XMLSchema any contribution in the form of coding, testing,
+ submitting improvements to the documentation, and reporting bugs are always
+ welcome.
+
+
+Downloads
+
+ The latest release is 1.3 and can be found
+ {{{http://ws.apache.org/commons/XmlSchema/download.cgi}here}}.
+
+
+
+ -The XMLSchema Development Team
\ No newline at end of file
diff --git a/XmlSchema/src/site/site.xml b/XmlSchema/src/site/site.xml
new file mode 100644
index 0000000..0a5b6c9
--- /dev/null
+++ b/XmlSchema/src/site/site.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<project name="Apache XmlSchema">
+ <bannerLeft>
+ <name>Apache XmlSchema</name>
+ <src>http://www.apache.org/images/asf-logo.gif</src>
+ <href>http://ws.apache.org/</href>
+ </bannerLeft>
+ <body>
+ <links>
+ <item name="Apache" href="http://www.apache.org/"/>
+ <item name="WebServices" href="http://ws.apache.org/"/>
+ <item name="WS Commons" href="http://ws.apache.org/commons"/>
+ <item name="XmlSchema" href="http://ws.apache.org/commons/XmlSchema/"/>
+ </links>
+ <menu name="XML Schema">
+ <item name="Home" href="index.html"/>
+ <item name="Downloads">
+ <item name="Releases" href="download.cgi"/>
+ <item name="Source Code" href="source-repository.html"/>
+ </item>
+ <item name="Documentation">
+ <item name="Tutorial" href="schematutorial.html"/>
+ <item name="Extensions" href="writingExtensions.html"/>
+ <item name="Javadocs" href="/apidocs/index.html"/>
+ <item name="View Source"
+ href="http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/?root=Apache-SVN"/>
+ </item>
+ <item name="Project Information">
+ <item name="Mailing Lists" href="/mail-lists.html"/>
+ <item name="Project Team" href="/team-list.html"/>
+ <item name="Issue Tracking" href="issue-tracking.html"/>
+ </item>
+ <item name="License" href="/license.html"/>
+ </menu>
+ </body>
+</project>
+
+
+
diff --git a/XmlSchema/src/site/xdoc/download.xml b/XmlSchema/src/site/xdoc/download.xml
new file mode 100644
index 0000000..53104d4
--- /dev/null
+++ b/XmlSchema/src/site/xdoc/download.xml
@@ -0,0 +1,309 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<document>
+ <properties>
+ <title>:: Apache XmlSchema Releases ::</title>
+ </properties>
+
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
+ <meta content="text/html; charset=iso-8859-1"/>
+ </head>
+
+ <body>
+
+ <section>
+ <h2>Releases</h2>
+ <div align="left">
+ <p>XmlSchema is becoming more and more stable and the latest official version available for download is
+ XmlSchema 1.1. All the releases are available for download as source or binary. For more information,
+ please see
+ <a href="http://www.apache.org/dev/release.html">Apache Release FAQ</a>
+ </p>
+ <p>Please select the XmlSchema version you want to download.</p>
+ </div>
+ <div align="center">
+
+ <table class="bodyTable">
+ <tbody>
+ <tr class="a">
+ <td align="center" width="45">Name</td>
+ <td align="center" width="80">Type</td>
+ <td align="center" width="300">Distribution</td>
+ <td align="center" width="100">Date</td>
+ <td align="center" width="200">Description</td>
+ </tr>
+
+
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.2
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip">zip</a>
+
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-src.zip.asc">PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip">zip</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/ws/commons/XmlSchema/1_3/XmlSchema-1.3-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>11 - 04 - 2007</td>
+ <td>1.3 Release (Mirrored)</td>
+ </tr>
+
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.2
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip">zip</a>
+
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-src.zip.asc">PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip">zip</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/ws/commons/XmlSchema/1_2/XmlSchema-1.2-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>13 - 11 - 2006</td>
+ <td>1.2 Release (Mirrored)</td>
+ </tr>
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.1
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip">zip</a>
+
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-src.zip.asc">PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip">zip</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/ws/commons/XmlSchema/1_1/XmlSchema-1.1-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>18 - 09 - 2006</td>
+ <td>1.1 Release (Mirrored)</td>
+ </tr>
+
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.0.3
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip">zip</a>
+
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-src.zip.asc">PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip">zip</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip.md5"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip.md5">MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip.asc"
+ class="externalLink"
+ title="http://www.apache.org/dist/ws/ws/commons/XmlSchema/1_0_3/XmlSchema-1.0.3-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>13- 05 - 2006</td>
+ <td>1.0.3 Release (Archived)
+ </td>
+ </tr>
+
+
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.0.2
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip">zip</a>
+
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip.md5"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip.md5">
+ MD5</a>
+ <a href="http://www.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip.asc"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-src.zip.asc">
+ PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-bin.zip"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-0.95-bin.zip">
+ zip</a>
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-bin.zip.md5"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-bin.zip.md5">
+ MD5</a>
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-bin.zip.asc"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/ws/commons/XmlSchema/1_0_2/XmlSchema-1.0.2-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>30 - 04 - 2006</td>
+ <td>1.0.2 Release (Archived)</td>
+ </tr>
+
+
+ <tr class="b">
+ <td align="center" valign="middle">
+ 1.0.1
+ </td>
+ <td align="center">Release</td>
+ <td>Source Distribution
+ <a href="http://archive.apache.org/dist/ws/XmlSchema/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip">
+ zip</a>
+
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip.md5"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip.md5">
+ MD5</a>
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip.asc"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-src.zip.asc">
+ PGP</a>
+ <br/>
+ Binary Distribution
+ <a href="[preferred]/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip"
+ title="[preferred]/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip">zip</a>
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip.md5"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip.md5">
+ MD5</a>
+ <a href="http://archive.apache.org/dist/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip.asc"
+ class="externalLink"
+ title="http://archive.apache.org/dist/ws/ws/commons/XmlSchema/1_0_1/XmlSchema-1.0.1-bin.zip.asc">
+ PGP</a>
+
+ <br/>
+ </td>
+ <td>13 - 04 - 2006</td>
+ <td>1.0.1 Release (Archived)</td>
+ </tr>
+
+ </tbody>
+ </table>
+ </div>
+ <div align="left">
+ <p>[if-any logo]
+ <a href="[link]">
+ <img align="right" src="[logo]"
+ border="0"/>
+ </a>
+ [end] The currently selected mirror is
+ <b>[preferred]</b>
+ . If
+ you encounter a problem with this mirror, please select another mirror. If
+ all mirrors are failing, there are
+ <i>backup</i>
+ mirrors (at the end of the
+ mirrors list) that should be available.
+ </p>
+
+ <form action="[location]" method="get" id="SelectMirror">
+ Other mirrors:
+ <select name="Preferred">[if-any http][for http]
+ <option value="[http]"
+ selected="selected">[http]</option>
+ [end][end][if-any ftp][for ftp]
+ <option value="[ftp]">[ftp]</option>
+ [end][end][if-any backup][for backup]
+ <option value="[backup]">[backup] (backup)</option>
+ [end][end]
+ </select>
+
+ <input type="submit" value="Change"/>
+ </form>
+
+ <p>You may also consult the
+ <a href="http://www.apache.org/mirrors/">complete
+ list of mirrors</a>
+ .
+ </p>
+
+ <p>
+ <strong>Note:</strong>
+ when downloading from a mirror please check the
+ <a
+ href="http://www.apache.org/dev/release-signing#md5">md5sum</a>
+ and verify
+ the
+ <a href="http://www.apache.org/dev/release-signing#openpgp">OpenPGP</a>
+ compatible signature from the main Apache site. These can be downloaded by
+ following the links above. This
+ <a
+ href="http://www.apache.org/dist/ws/commons/XmlSchema/KEYS">KEYS</a>
+ file contains the
+ public keys used for signing release. It is recommended that (when possible)
+ a
+ <a href="http://www.apache.org/dev/release-signing#web-of-trust">web of
+ trust</a>
+ is used to confirm the identity of these keys.
+ </p>
+ </div>
+
+ </section>
+ </body>
+</document>
diff --git a/XmlSchema/src/site/xdoc/schematutorial.xml b/XmlSchema/src/site/xdoc/schematutorial.xml
new file mode 100644
index 0000000..f2c141e
--- /dev/null
+++ b/XmlSchema/src/site/xdoc/schematutorial.xml
@@ -0,0 +1,103 @@
+<xdoc>
+ <properties>
+ <title>:: Apache XmlSchema Tutorial ::</title>
+ </properties>
+<body>
+<section name="Contents">
+<ul>
+ <li><a href="#intro">Introduction</a></li>
+ <li><a href="#dependencies">Structure and Dependencies</a></li>
+ <li><a href="#reading">Reading a Schema</a></li>
+ <li><a href="#navigating">Navigating the Schema Model</a></li>
+ <li><a href="#printing">Printing the Schema Model</a></li>
+ <li><a href="#conclusion">Conclusion</a></li>
+</ul>
+</section>
+
+<a name="intro"></a>
+<section name="Introduction">
+
+<p>Commons XML Schema model is a general purpose schema model that can be
+used when a Java object tree representation of an Xml schema is required.
+This short tutorial explains how the Commons XML Schema can be utilized.</p>
+<a name="dependencies"></a>
+</section>
+<section name="Structure and Dependencies">
+
+<p>The core commons XML Schema classes have <strong>no</strong> third party
+dependencies. However it depends on the XMLUnit and JUnit libraries for unit
+testing, and the maven build uses the StAX API libraries to access the
+javax.xml.namespace.QName class (which is not part of the JDK). Also the
+serialization mechanism uses the DOM serialization mechanism, hence the JDK
+has to be 1.4 and upwards.</p>
+
+<p>The structure of the commons XMLSchema model is quite straightforward. It
+has a strict specification bound hierarchy of classes that represents each
+and every schema component. It is not based on an interface-implementation
+model which allows extensions and different implementations. However, the
+schema specification is quite stable and complete, hence a change is
+unlikelyl, which makes the commons XmlSchema sufficient for almost all needs
+of schema handling.</p>
+</section>
+
+<section name="Reading a Schema">
+<a name="reading"></a>
+<p>The reader for the XML Schema model is called the SchemaCollection
+(org.apache.ws.commons.schema.XmlSchemaCollection). It has a
+<em>read</em> method that returns a XmlSchema object which represents the
+whole schema. The XmlSchema instance returned can be used to access types and
+elements of the relevant schema by their qualified name.</p>
+
+<p>The <em>read</em> method has a parameter to pass in a validating event
+handler. The validating event handler can be used to pass in the custom
+validating procedures. However, this particular handler has no effect on the
+reading of the schema yet, and it is not a feature in this release of Commons
+XML Schema. The following code fragment shows how a file can be read through
+the SchemaCollection.</p>
+<source><pre>
+InputStream is = new FileInputStream(fileName);
+XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+XmlSchema schema = schemaCol.read(new StreamSource(is), null);</pre></source>
+
+<p>Note that null is passed for the validating handler since it has no effect
+yet.</p>
+</section>
+
+<a name="navigating"></a>
+
+<section name="Navigating the Schema Model">
+
+<p>Navigation of the model once the XmlSchema model is obtained is also quite
+straight forward. All top level elements and types are available through the
+schema object as either
+<code>org.apache.ws.commons.schema.XmlSchemaObjectTable</code> instances or
+can be accessed directly if it can have a QName reference. For example, if
+the qualified name of an element is known, then getElementByName method can
+be used to extract the XmlSchemaElement object directly from the schema
+object. The following code sample shows how such direct methods can be used
+to extract schema objects</p>
+<source><pre>XmlSchemaType schemaType = schema.getTypeByName(TYPE_QNAME);
+XmlSchemaElement elem = schema.getElementByName(ELEMENT_QNAME);</pre></source>
+
+<p>Note that the TYPE_QNAME and ELEMENT_QNAME represents QName objects.</p>
+<a name="printing"></a>
+<h2>Printing the Schema Model</h2>
+
+<p>Printing of the model once the XmlSchema model has been modified or
+constructed in-memory, is also quite straightforward. Schema object has a
+<em>write</em> method that can use an output stream.</p>
+
+<p>The following code fragment shows how to write the schema into the System
+output stream.</p>
+<source><pre>schema.write(System.out);</pre></source>
+</section>
+
+<!--<h2>Advanced Topics</h2>-->
+<a name="conclusion"></a>
+<section name="Conclusion">
+<p>Commons XmlSchema is quite a versatile piece of code that can be used to
+manipulate and generate XML Schemas. It has minimum dependencies and can be
+used inside another project with ease.</p>
+</section>
+</body>
+</xdoc>
diff --git a/XmlSchema/src/site/xdoc/writingExtensions.xml b/XmlSchema/src/site/xdoc/writingExtensions.xml
new file mode 100644
index 0000000..b8f7cec
--- /dev/null
+++ b/XmlSchema/src/site/xdoc/writingExtensions.xml
@@ -0,0 +1,262 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<document>
+ <properties>
+ <title>:: Apache XmlSchema Extension Tutorial ::</title>
+ </properties>
+
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
+ <meta content="text/html; charset=iso-8859-1"/>
+ </head>
+
+ <body>
+ <section name="Contents">
+ <ul>
+ <li><a href="#intro">Introduction</a></li>
+ <li><a href="#example">Example Extension</a></li>
+ <li><a href="#iclasses">Important classes</a></li>
+ <li><a href="#deser">Code for a Deserializer</a></li>
+ <li><a href="#ser">Code for a Serializer</a></li>
+ <li><a href="#reg">Registering types and using a custom extension registry</a></li>
+ <!--<li><a href="#default">Default Behavior</a></li>-->
+ <li><a href="#conclusion">Conclusion</a></li>
+ </ul>
+ </section>
+
+
+ <a name="intro"></a>
+ <section name="Introduction">
+ <p>Usually when parsing a schema document, developers will prefer to make custom
+ objects for attribute and element extensions. XMLSchema supports this through
+ an extension registry mechanism. This document explains how this extension mechanism works by going through
+ two complete examples. These two examples are included as test cases with the source release.</p>
+ </section>
+
+
+ <a name="example"></a>
+ <section name="Example Extension">
+ <p>Following are two example schema documents that contain external attributes/elements</p>
+ <p>This schema demonstrates the use of an extension attribute
+ <pre>
+ <schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:ext="http://customattrib.org"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct" ext:customAttrib="toplevel:type">
+ <sequence>
+ <element name="varString" type="xsd:string" ext:customAttrib="inner:element"/>
+ <element name="varInt" type="xsd:int" ext:customAttrib="inner:element"/>
+ <element name="varFloat" type="xsd:float" ext:customAttrib="inner:element"/>
+ <element name="varStruct" type="tns:Struct" ext:customAttrib="inner:element"/>
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct" ext:customAttrib="toplevel:element"/>
+
+ </schema>
+
+ </pre>
+ </p>
+
+ <p>This schema demonstrates the use of an extension element
+ <pre>
+ <schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:ext="http://customattrib.org"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct">
+ <ext:customElt prefix="ext" suffix="type"/>
+ <sequence>
+ <element name="varString" type="xsd:string"/>
+ <element name="varInt" type="xsd:int" />
+ <element name="varFloat" type="xsd:float" />
+ <element name="varStruct" type="tns:Struct" />
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct" >
+ <ext:customElt prefix="ext" suffix="elt"/>
+ </element>
+
+ </schema>
+ </pre>
+ </p>
+
+ <p>A developer would like the parser to make custom objects when it encounters customAttrib
+ or customElt. This can be achieved by writing a custom extension deserializer and serializer and
+ registering them with the extension registry. The next section briefly explains the important classes
+ involved in this process.</p>
+ </section>
+
+ <a name="iclasses"></a>
+ <section name="Important classes">
+ <p>Following are the important classes in writing an extension</p>
+ <ul>
+ <li><code>org.apache.ws.commons.schema.extensions.ExtensionRegistry</code></li>
+ <li><code>org.apache.ws.commons.schema.extensions.ExtensionDeserializer</code></li>
+ <li><code>org.apache.ws.commons.schema.extensions.ExtensionSerializer</code></li>
+ </ul>
+ <p>Last two classes are interfaces that should be implemented by the respective
+ implementations.</p>
+
+ </section>
+
+ <a name="deser"></a>
+ <section name="Code for a Deserializer">
+ <p>The deserializer needs to implement the
+ <code>org.apache.ws.commons.schema.extensions.ExtensionDeserializer</code> interface.
+ Following is a code fragment of the Extension deserializer that deserializes the extension
+ attribute into a custom object. Note that once the custom object is made it is attached
+ to the meta info map of the relevant XMLSchema object with the QName as the key</p>
+
+ <p>
+ <pre>
+ <code>
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node domNode) {
+ if (CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.equals(name)){
+ Attr attrib = (Attr)domNode;
+ String value = attrib.getValue();
+ //break the attrib into
+ CustomAttribute customAttrib = new CustomAttribute();
+ String[] strings = value.split(":");
+ customAttrib.setPrefix(strings[0]);
+ customAttrib.setSuffix(strings[1]);
+
+ //put this in the schema object meta info map
+ schemaObject.addMetaInfo(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME,customAttrib);
+ }
+ }
+ </code>
+ </pre>
+ </p>
+ <p>Note that prior knowledge is required about the format of the string of the attribute value.
+ The complete custom attribute deserializer is available in
+ <code>tests.customext.attrib.CustomAttributeDeserializer</code></p>
+
+ <p> Following is a code fragment of the Extension deserializer that deserializes the extension
+ element into a custom object. This is similar to the attribute case but now the node
+ passed is the actual extension element itself.</p>
+
+ <p>
+ <pre>
+ <code>
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node domNode) {
+ if (CustomElement.CUSTOM_ELT_QNAME.equals(name)){
+ Element elt = (Element)domNode;
+
+ CustomElement customElement = new CustomElement();
+ customElement.setPrefix(elt.getAttribute("prefix"));
+ customElement.setSuffix(elt.getAttribute("suffix"));
+
+ //put this in the schema object meta info map
+ schemaObject.addMetaInfo(CustomElement.CUSTOM_ELT_QNAME,customElement);
+ }
+ }
+ </code>
+ </pre>
+ </p>
+ <p>The complete custom attribute deserializer is available in
+ <code>tests.customext.elt.CustomElementDeserializer</code></p>
+ </section>
+
+ <a name="ser"></a>
+ <section name="Code for a Serializer">
+ <p>The serializer needs to implement the
+ <code>org.apache.ws.commons.schema.extensions.ExtensionSerializer</code> interface.
+ Following is a code fragment of the Extension serializer that serializes a given custom
+ object into an attributeObject. Note that XMLSchema serialization mechanism is to create
+ a DOM tree and serialize it. Hence the custom serializers needs to create the
+ appropriate DOM node and attach it.</p>
+
+ <p>
+ <pre>
+ <code>
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ CustomAttribute att = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+
+ Element elt = (Element)domNode;
+ Attr att1 = elt.getOwnerDocument().createAttributeNS(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getNamespaceURI(),
+ CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getLocalPart());
+ att1.setValue(att.getPrefix() + ":" + att.getSuffix());
+ elt.setAttributeNodeNS(att1);
+ }
+ </code>
+ </pre>
+ </p>
+ <p>Note that prior knowledge is required about the format of the string of the attribute value. DomNode
+ passed in would be the parent node of the serialized DOM tree.The complete custom attribute serializer is available in
+ <code>tests.customext.attrib.CustomAttributeSerializer</code></p>
+
+ <p> Following is a code fragment of the Extension serializer that serializes the custom object into
+ an extension element. This is similar to the attribute case.</p>
+
+ <p>
+ <pre>
+ <code>
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+
+ Element elt = (Element)domNode;
+ Element extElt = elt.getOwnerDocument().createElementNS(CustomElement.CUSTOM_ELT_QNAME.getNamespaceURI(),
+ CustomElement.CUSTOM_ELT_QNAME.getLocalPart());
+ extElt.setAttribute("prefix",customElt.getPrefix());
+ extElt.setAttribute("suffix",customElt.getSuffix());
+
+ elt.appendChild(extElt);
+
+ }
+ </code>
+ </pre>
+ </p>
+ <p>The complete custom element serializer is available in
+ <code>tests.customext.elt.CustomElementSerializer</code></p>
+ </section>
+
+ <a name="reg"></a>
+ <section name="Registering Types and Using a Custom Extension Registry">
+ <p>Once the serilizers are made they need to be registered with the registry.
+ This can be done by the following way.</p>
+ <p>
+ <pre>
+ <code>
+ //register our custom type
+ registerDeserializer(CustomElement.CUSTOM_ELT_QNAME,new CustomElementDeserializer());
+ registerSerializer(CustomElement.class,new CustomElementSerializer());
+ </code>
+ </pre>
+ </p>
+ <p>It can be a more convenient if the extension types are registered inside a subclass
+ of the <code>org.apache.ws.commons.schema.extensions.ExtensionRegistry</code> to
+ avoid any confusions.</p>
+ <p>If the system property<code>"org.apache.ws.commons.extensions.ExtensionRegistry"</code> is present
+ the extension registry will be instantiated with the class specified. Following is an example of
+ how this can be done</p>
+ <p>
+ <pre>
+ <code>
+ System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+ </code>
+ </pre>
+ </p>
+ <p>This behavior is quite useful when the XMlSchema object models are used internally with
+ no direct access to the extension registry.</p>
+ </section>
+
+ <a name="conclusion"></a>
+ <section name="Conclusion">
+ The extension mechanism of the XMLSchema object model allows the users to add their custom
+ objects to the standard XMLSchema objects.
+ </section>
+ </body>
+
+</document>
diff --git a/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java b/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java
new file mode 100644
index 0000000..58dfc6e
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/AllSimpleTypeTest.java
@@ -0,0 +1,54 @@
+package tests;
+
+import junit.framework.TestCase;
+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.XmlSchemaType;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Iterator;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class AllSimpleTypeTest extends TestCase {
+
+ public void testSimpleTypeSchemaGeneration() throws Exception {
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("allSimpleTypes.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ //loop through the schema elements and inspect the SchemaTypeObject
+ //if the type is registered, then getSchemaType should return a SchemaType
+ //object
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ XmlSchemaType schemaType = elt.getSchemaType();
+ assertNotNull(schemaType);
+
+ }
+
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/AnnotationTest.java b/XmlSchema/src/test/java/tests/AnnotationTest.java
new file mode 100644
index 0000000..4b1bdec
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/AnnotationTest.java
@@ -0,0 +1,335 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class AnnotationTest extends TestCase {
+
+ /**
+ * This method will test for when the appinfo
+ * element of an annotation doesn't include a
+ * source attribute and doesn't contain any
+ * content.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testEmptyAppInfo() throws Exception {
+
+ /*
+ <simpleType name="emptyAppinfo">
+ <annotation>
+ <documentation source="http://test/source/doc" xml:lang="en">testing987</documentation>
+ <appinfo/>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "emptyAppinfo");
+ InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaSimpleType simpleType =
+ (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+ assertNotNull(xsa);
+
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(1, col.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaDocumentation.class.getName());
+ for (int i = 0; i < col.getCount(); i++) {
+ XmlSchemaObject o = col.getItem(i);
+ if (o instanceof XmlSchemaAppInfo) {
+ fail("The appinfo element did not contain a source"
+ + " attribute or any content, so this element"
+ + " was not exptected to be found.");
+ } else if (o instanceof XmlSchemaDocumentation) {
+ assertEquals("en",
+ ((XmlSchemaDocumentation)o).getLanguage());
+ assertEquals("http://test/source/doc",
+ ((XmlSchemaDocumentation)o).getSource());
+ NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing987", n.getNodeValue());
+ }
+ }
+ }
+ assertTrue(s.remove(o.getClass().getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+ }
+
+ /**
+ * This method will test for when the documentation
+ * element of an annotation doesn't include a
+ * source attribute or xml:lang attribute and doesn't
+ * contain any content.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testEmptyDocumentation() throws Exception {
+
+ /*
+ <simpleType name="emptyDocumentation">
+ <annotation>
+ <documentation/>
+ <appinfo source="http://test/source/appinfo">testing123</appinfo>
+ </annotation>
+ <restriction base="string">
+ <length value="2"/>
+ </restriction>
+ </simpleType>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "emptyDocumentation");
+ InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaSimpleType simpleType =
+ (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+ assertNotNull(xsa);
+
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(1, col.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaAppInfo.class.getName());
+ for (int i = 0; i < col.getCount(); i++) {
+ XmlSchemaObject o = col.getItem(i);
+ if (o instanceof XmlSchemaAppInfo) {
+ assertEquals("http://test/source/appinfo",
+ ((XmlSchemaAppInfo)o).getSource());
+ NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing123", n.getNodeValue());
+ }
+ }
+ } else if (o instanceof XmlSchemaDocumentation) {
+ fail("The documentation element did not contain a source"
+ + " attribute or any content, so this element"
+ + " was not exptected to be found.");
+ }
+ assertTrue(s.remove(o.getClass().getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+ }
+
+
+ /**
+ * This method will test for when the documentation
+ * and appinfo elements of an annotation don't include
+ * anything.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testEmptyAppinfoDocumentation() throws Exception {
+
+ /*
+ <simpleType name="emptyAppinfoDocumentation">
+ <annotation>
+ <documentation/>
+ <appinfo/>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "emptyAppinfoDocumentation");
+ InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaSimpleType simpleType =
+ (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+ assertNotNull(xsa);
+
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(0, col.getCount());
+
+ }
+
+ /**
+ * This method will test for when the documentation
+ * and appinfo elements contain all the information.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testFullDocumentationAppinfo() throws Exception {
+
+ /*
+ <simpleType name="annotationTest">
+ <annotation>
+ <documentation source="http://test/source/doc" xml:lang="en">testing987</documentation>
+ <appinfo source="http://test/source/appinfo">testing123</appinfo>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "annotationTest");
+ InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaSimpleType simpleType =
+ (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaAnnotation xsa = simpleType.getAnnotation();
+ assertNotNull(xsa);
+
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(2, col.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaAppInfo.class.getName());
+ s.add(XmlSchemaDocumentation.class.getName());
+ for (int i = 0; i < col.getCount(); i++) {
+ XmlSchemaObject o = col.getItem(i);
+ if (o instanceof XmlSchemaAppInfo) {
+ assertEquals("http://test/source/appinfo",
+ ((XmlSchemaAppInfo)o).getSource());
+ NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing123", n.getNodeValue());
+ }
+ }
+ } else if (o instanceof XmlSchemaDocumentation) {
+ assertEquals("en",
+ ((XmlSchemaDocumentation)o).getLanguage());
+ assertEquals("http://test/source/doc",
+ ((XmlSchemaDocumentation)o).getSource());
+ NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing987", n.getNodeValue());
+ }
+ }
+ }
+ assertTrue(s.remove(o.getClass().getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+ }
+
+ /**
+ * This method will test for when an annotation is added
+ * to the Xml Schema Element.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testXmlSchemaElementAnnotation() throws Exception {
+
+ /*
+ <annotation id="schemaAnnotation">
+ <documentation source="http://test101/source/doc" xml:lang="en">testing101</documentation>
+ <appinfo source="http://test101/source/appinfo">testing101</appinfo>
+ </annotation>
+ */
+
+ InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaAnnotation xsa = schema.getAnnotation();
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(2, col.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaAppInfo.class.getName());
+ s.add(XmlSchemaDocumentation.class.getName());
+ for (int i = 0; i < col.getCount(); i++) {
+ XmlSchemaObject o = col.getItem(i);
+ if (o instanceof XmlSchemaAppInfo) {
+ assertEquals("http://test101/source/appinfo",
+ ((XmlSchemaAppInfo)o).getSource());
+ NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing101", n.getNodeValue());
+ }
+ }
+ } else if (o instanceof XmlSchemaDocumentation) {
+ assertEquals("en",
+ ((XmlSchemaDocumentation)o).getLanguage());
+ assertEquals("http://test101/source/doc",
+ ((XmlSchemaDocumentation)o).getSource());
+ NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("testing101", n.getNodeValue());
+ }
+ }
+ }
+ assertTrue(s.remove(o.getClass().getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/AnyAttTest.java b/XmlSchema/src/test/java/tests/AnyAttTest.java
new file mode 100644
index 0000000..28c429f
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/AnyAttTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+import org.w3c.dom.Document;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+
+public class AnyAttTest extends TestCase {
+
+ protected void setUp() throws Exception {
+
+ }
+
+ public void testAnyAtt() throws Exception{
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("anyAttTest.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema s = schemaCol.read(doc.getDocumentElement());
+
+ //get the element
+ XmlSchemaElement elt = s.getElementByName(new QName("http://unqualified-elements.example.com","AnyAttContainer"));
+ assertNotNull("Element \"AnyAttContainer\" is missing! ",elt);
+
+ XmlSchemaType schemaType = elt.getSchemaType();
+ assertNotNull("Relevant schema type is missing!",schemaType);
+
+ XmlSchemaComplexType xmlSchemaComplexType = ((XmlSchemaComplexType) schemaType);
+ XmlSchemaParticle particle = xmlSchemaComplexType.getParticle();
+ assertNotNull(particle);
+
+ XmlSchemaAnyAttribute anyAttribute = xmlSchemaComplexType.getAnyAttribute();
+ assertNotNull("Any attribute is missing",anyAttribute);
+
+
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/AnyTest.java b/XmlSchema/src/test/java/tests/AnyTest.java
new file mode 100644
index 0000000..ae1156c
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/AnyTest.java
@@ -0,0 +1,114 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class AnyTest extends TestCase {
+
+ /**
+ * This method will test the any.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testAny() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ elementFormDefault="qualified">
+
+ <element name="department">
+ <complexType>
+ <sequence>
+ <element name="id" type="xsd:integer"/>
+ <element name="name" type="xsd:string"/>
+ <any minOccurs="5" maxOccurs="10"/>
+ </sequence>
+ </complexType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "department");
+ InputStream is = new FileInputStream(Resources.asURI("any.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("department", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "department"),
+ elem.getQName());
+
+ XmlSchemaComplexType type =
+ (XmlSchemaComplexType)elem.getSchemaType();
+ assertNotNull(type);
+
+ XmlSchemaSequence xss = (XmlSchemaSequence)type.getParticle();
+ assertNotNull(xss);
+
+ XmlSchemaObjectCollection c = xss.getItems();
+ assertEquals(3, c.getCount());
+
+ Set s = new HashSet();
+ s.add("id");
+ s.add("name");
+ Object o = null;
+ for (int i = 0; i < c.getCount(); i++) {
+ o = c.getItem(i);
+ if (o instanceof XmlSchemaElement) {
+ String name = ((XmlSchemaElement)o).getName();
+ if (name.equals("id")) {
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "integer"),
+ ((XmlSchemaElement)o).getSchemaTypeName());
+ } else if (name.equals("name")) {
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"),
+ ((XmlSchemaElement)o).getSchemaTypeName());
+ }
+ s.remove(name);
+ } else if (o instanceof XmlSchemaAny) {
+ XmlSchemaContentProcessing xscp =
+ ((XmlSchemaAny)o).getProcessContent();
+ assertEquals("none", xscp.toString());
+ assertEquals(5L, ((XmlSchemaAny)o).getMinOccurs());
+ assertEquals(10L, ((XmlSchemaAny)o).getMaxOccurs());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/AttributeGroupTest.java b/XmlSchema/src/test/java/tests/AttributeGroupTest.java
new file mode 100644
index 0000000..4cbe400
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/AttributeGroupTest.java
@@ -0,0 +1,126 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class AttributeGroupTest extends TestCase {
+
+ /**
+ * This method will test the list.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testAttributeGroup() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified" >
+
+ <attributeGroup name="department">
+ <attribute name="name" type="string"/>
+ <attribute name="id" type="integer"/>
+ </attributeGroup>
+
+ <element name="member">
+ <complexType>
+ <attributeGroup ref="tns:department"/>
+ </complexType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "member");
+ InputStream is = new FileInputStream(Resources.asURI("attributegroup.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("member", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "member"),
+ elem.getQName());
+
+ XmlSchemaComplexType t = (XmlSchemaComplexType)elem.getSchemaType();
+ assertNotNull(t);
+
+ XmlSchemaObjectCollection c = t.getAttributes();
+ for (Iterator i = c.getIterator(); i.hasNext(); ) {
+ XmlSchemaAttributeGroupRef agrn = (XmlSchemaAttributeGroupRef)i.next();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "department"), agrn.getRefName());
+ }
+
+ XmlSchemaObjectTable attG = schema.getAttributeGroups();
+ assertNotNull(attG);
+ assertEquals(1, attG.getCount());
+
+ for (Iterator i = attG.getNames(); i.hasNext(); ) {
+ assertEquals("department", ((QName)i.next()).getLocalPart());
+ }
+
+ for (Iterator i = attG.getValues(); i.hasNext(); ) {
+ Object obj1 = i.next();
+ if (obj1 instanceof XmlSchemaAttributeGroup) {
+ assertEquals("department", ((XmlSchemaAttributeGroup)obj1).getName());
+ XmlSchemaObjectCollection attributes =
+ ((XmlSchemaAttributeGroup)obj1).getAttributes();
+ assertNotNull(attributes);
+ assertEquals(2, attributes.getCount());
+ for (Iterator j = attributes.getIterator(); j.hasNext(); ) {
+ XmlSchemaAttribute obj2 = (XmlSchemaAttribute)j.next();
+ String name = obj2.getName();
+ if (name.equals("id")) {
+ assertEquals(new QName("http://soapinterop.org/types", "id"),
+ obj2.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "integer"), obj2.getSchemaTypeName());
+ } else if (name.equals("name")) {
+ assertEquals(new QName("http://soapinterop.org/types", "name"),
+ obj2.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"), obj2.getSchemaTypeName());
+ } else {
+ fail("The name \"" + name + "\" should not have been found "
+ + "for an attribute.");
+
+ }
+ }
+ } else {
+ fail("There should have been one instance of the "
+ + "class " + XmlSchemaAttributeGroup.class.getName()
+ + " , but instead " + obj1.getClass().getName() + " was"
+ + " found.");
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/BlockTest.java b/XmlSchema/src/test/java/tests/BlockTest.java
new file mode 100644
index 0000000..e1990b6
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/BlockTest.java
@@ -0,0 +1,45 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class BlockTest extends TestCase {
+ public void testMixedContent() throws Exception {
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/xsd",
+ "complexElt");
+
+
+ InputStream is = new FileInputStream(Resources.asURI("block.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+
+ XmlSchemaElement elementByName = s.getElementByName(ELEMENT_QNAME);
+ assertNotNull(elementByName);
+
+ String value = elementByName.getBlock().getValue();
+ assertEquals("restriction",value);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/ChoiceTest.java b/XmlSchema/src/test/java/tests/ChoiceTest.java
new file mode 100644
index 0000000..a46be47
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ChoiceTest.java
@@ -0,0 +1,106 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class ChoiceTest extends TestCase {
+
+ /**
+ * This method will test the choice.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testChoice() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="computer">
+ <complexType>
+ <choice>
+ <element name="desktop" type="string"/>
+ <element name="laptop" type="string"/>
+ </choice>
+ </complexType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "computer");
+ InputStream is = new FileInputStream(Resources.asURI("choice.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ QName WRONG_QNAME = new QName("http://soapinterop.org/types",
+ "machine");
+ XmlSchemaElement elem = schemaCol.getElementByQName(WRONG_QNAME);
+ assertNull(elem);
+ elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertEquals("computer", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "computer"),
+ elem.getQName());
+
+ XmlSchemaComplexType cType = (XmlSchemaComplexType)elem.getSchemaType();
+ assertNotNull(cType);
+
+ XmlSchemaChoice choice = (XmlSchemaChoice)cType.getParticle();
+ assertNotNull(choice);
+
+ Set s = new HashSet();
+ s.add("desktop");
+ s.add("laptop");
+ XmlSchemaObjectCollection items = choice.getItems();
+ Iterator iterator = items.getIterator();
+ while (iterator.hasNext()) {
+ XmlSchemaElement e = (XmlSchemaElement)iterator.next();
+ String eName = e.getName();
+ if (eName.equals("desktop")) {
+ assertEquals(new QName("", "desktop"), e.getQName());
+ assertEquals(e.getName(), "desktop");
+ } else if (eName.equals("laptop")) {
+ assertEquals(new QName("", "laptop"), e.getQName());
+ assertEquals(e.getName(), "laptop");
+ } else {
+ fail("Should have had a name of desktop or laptop, but"
+ + " instead had " + eName);
+ }
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"), e.getSchemaTypeName());
+ assertTrue(s.remove(e.getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/CircularSchemaTest.java b/XmlSchema/src/test/java/tests/CircularSchemaTest.java
new file mode 100644
index 0000000..8351886
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/CircularSchemaTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.xml.sax.InputSource;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+public class CircularSchemaTest extends TestCase
+{
+ public void testCircular() throws Exception {
+ XmlSchemaCollection schemas = new XmlSchemaCollection();
+ File file = new File(Resources.asURI("circular/a.xsd"));
+ InputSource source = new InputSource(new FileInputStream(file));
+ source.setSystemId(file.toURL().toString());
+
+ schemas.read(source, null);
+
+ XmlSchema[] xmlSchemas = schemas.getXmlSchemas();
+ assertNotNull(xmlSchemas);
+ assertEquals(3, xmlSchemas.length);
+ }
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java b/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java
new file mode 100644
index 0000000..be471a2
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ComplexContentRestrictionTest.java
@@ -0,0 +1,134 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class ComplexContentRestrictionTest extends TestCase {
+
+ /**
+ * This method will test complex content restriction.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testComplexContentRestriction() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+
+ <complexType name="AssemblyRequiredProduct">
+ <sequence>
+ <element name="Name" type="string"/>
+ <element name="Description" type="string" nillable="true"/>
+ <element name="Parts" type="string" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="NoAssemblyRequiredProduct">
+ <complexContent>
+ <restriction base="tns:AssemblyRequiredProduct">
+ <sequence>
+ <element name="Name" type="string"/>
+ <element name="Description" type="string" nillable="true"/>
+ <element name="Parts" type="string"/>
+ </sequence>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+ </schema>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "NoAssemblyRequiredProduct");
+ InputStream is = new FileInputStream(Resources.asURI("deriverestriction.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaComplexType cType =
+ (XmlSchemaComplexType)schemaCol.getTypeByQName(TYPE_QNAME);
+ assertNotNull(cType);
+
+ XmlSchemaContentModel xscm = cType.getContentModel();
+ assertNotNull(xscm);
+
+ XmlSchemaComplexContentRestriction xsccr =
+ (XmlSchemaComplexContentRestriction)xscm.getContent();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "AssemblyRequiredProduct"),
+ xsccr.getBaseTypeName());
+
+ XmlSchemaSequence xsp = (XmlSchemaSequence)xsccr.getParticle();
+ assertNotNull(xsp);
+
+ XmlSchemaObjectCollection col = xsp.getItems();
+
+ Set s = new HashSet();
+ s.add("Name");
+ s.add("Description");
+ s.add("Parts");
+ for (int i = 0; i < col.getCount(); i++) {
+ XmlSchemaElement xse = (XmlSchemaElement)col.getItem(i);
+ String name = xse.getName();
+ if (name.equals("Name")) {
+ assertEquals(new QName("", "Name"),
+ xse.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"),
+ xse.getSchemaTypeName());
+ assertTrue(!xse.isAbstract());
+ assertTrue(!xse.isNillable());
+ } else if (name.equals("Description")) {
+ assertEquals(new QName("", "Description"),
+ xse.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"),
+ xse.getSchemaTypeName());
+ assertTrue(!xse.isAbstract());
+ assertTrue(xse.isNillable());
+ } else if (name.equals("Parts")) {
+ assertEquals(new QName("", "Parts"),
+ xse.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"),
+ xse.getSchemaTypeName());
+ } else {
+ fail("An invalid name of \"" + name + "\" was found.");
+ }
+ s.remove(name);
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/ConstraintsTest.java b/XmlSchema/src/test/java/tests/ConstraintsTest.java
new file mode 100644
index 0000000..00a87be
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ConstraintsTest.java
@@ -0,0 +1,198 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+ */
+public class ConstraintsTest extends TestCase {
+
+ /**
+ * This method will test the unique, key, and
+ * keyref constaints.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testConstraints() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ elementFormDefault="qualified">
+
+ <element name="constraintTest">
+ <complexType>
+ <sequence>
+ <element name="manufacturers" type="tns:ManufacturerType"/>
+ <element name="products" type="tns:ProductType"/>
+ </sequence>
+ </complexType>
+
+ <unique name="uniqueTest">
+ <selector xpath="tns:manufacturers/tns:location"/>
+ <field xpath="@district"/>
+ </unique>
+
+ <key name="keyTest">
+ <selector xpath="tns:products/tns:productName"/>
+ <field xpath="@productId"/>
+ </key>
+
+ <keyref name="keyRefTest" refer="tns:keyTest">
+ <selector xpath="tns:manufacturers/tns:location/tns:productName"/>
+ <field xpath="@productId"/>
+ </keyref>
+
+ </element>
+
+ <complexType name="ManufacturerType">
+ <sequence>
+ <element name="location" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" maxOccurs="unbounded"/>
+ <complexType>
+ <complexContent>
+ <extension base="string">
+ <attribute name="productId" type="integer"/>
+ <attribute name="units" type="integer"/>
+ </extension>
+ </complexContent>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute name="district" type="integer"/>
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <complexType name="ProductType">
+ <sequence>
+ <element name="productName" maxOccurs="unbounded">
+ <complexType>
+ <simpleContent>
+ <extension base="string">
+ <attribute name="productId" type="integer"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "constraintTest");
+ InputStream is = new FileInputStream(Resources.asURI("constraints.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("constraintTest", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "constraintTest"),
+ elem.getQName());
+
+ XmlSchemaObjectCollection c = elem.getConstraints();
+ assertEquals(3, c.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaKey.class.getName());
+ s.add(XmlSchemaKeyref.class.getName());
+ s.add(XmlSchemaUnique.class.getName());
+ for (int i = 0; i < c.getCount(); i++) {
+ Object o = c.getItem(i);
+ if (o instanceof XmlSchemaKey) {
+ XmlSchemaKey key = (XmlSchemaKey)o;
+ assertEquals("keyTest", key.getName());
+
+ XmlSchemaXPath selectorXpath = key.getSelector();
+ assertEquals("tns:products/tns:productName",
+ selectorXpath.getXPath());
+
+ XmlSchemaObjectCollection fields = key.getFields();
+ assertEquals(1, fields.getCount());
+ XmlSchemaXPath fieldXpath = null;
+ for (int j = 0; j < fields.getCount(); j++) {
+ fieldXpath = (XmlSchemaXPath)fields.getItem(j);
+ }
+ assertNotNull(fieldXpath);
+ assertEquals("@productId", fieldXpath.getXPath());
+ } else if (o instanceof XmlSchemaKeyref) {
+ XmlSchemaKeyref keyref = (XmlSchemaKeyref)o;
+ assertNotNull(keyref);
+ assertEquals("keyRefTest", keyref.getName());
+ assertEquals(new QName("http://soapinterop.org/types",
+ "keyTest"),
+ keyref.getRefer());
+
+ XmlSchemaXPath selectorXpath = keyref.getSelector();
+ assertEquals("tns:manufacturers/tns:location/tns:productName",
+ selectorXpath.getXPath());
+
+ XmlSchemaObjectCollection fields = keyref.getFields();
+ assertEquals(1, fields.getCount());
+ XmlSchemaXPath fieldXpath = null;
+ for (int j = 0; j < fields.getCount(); j++) {
+ fieldXpath = (XmlSchemaXPath)fields.getItem(j);
+ }
+ assertNotNull(fieldXpath);
+ assertEquals("@productId", fieldXpath.getXPath());
+ } else if (o instanceof XmlSchemaUnique) {
+ XmlSchemaUnique unique = (XmlSchemaUnique)o;
+ assertNotNull(unique);
+ assertEquals("uniqueTest", unique.getName());
+ XmlSchemaXPath selectorXpath = unique.getSelector();
+ assertEquals("tns:manufacturers/tns:location",
+ selectorXpath.getXPath());
+
+ XmlSchemaObjectCollection fields = unique.getFields();
+ assertEquals(1, fields.getCount());
+ XmlSchemaXPath fieldXpath = null;
+ for (int j = 0; j < fields.getCount(); j++) {
+ fieldXpath = (XmlSchemaXPath)fields.getItem(j);
+ }
+ assertNotNull(fieldXpath);
+ assertEquals("@district", fieldXpath.getXPath());
+ } else {
+ fail("An unexpected constraint of \""
+ + o.getClass().getName() + "\" was found.");
+ }
+ s.remove(o.getClass().getName());
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/ExternalAttTest.java b/XmlSchema/src/test/java/tests/ExternalAttTest.java
new file mode 100644
index 0000000..e2ba6a6
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ExternalAttTest.java
@@ -0,0 +1,52 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.constants.Constants;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Map;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class ExternalAttTest extends TestCase {
+
+
+ public void testExternalAtt() throws Exception{
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("externalAttributes.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema s = schemaCol.read(doc.getDocumentElement());
+
+ //check the meta data
+ Map metaInfoMap = s.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ Map extenalAttributeMap = (Map)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
+ assertNotNull(extenalAttributeMap);
+
+ assertEquals(1,extenalAttributeMap.size());
+
+
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/FacetsTest.java b/XmlSchema/src/test/java/tests/FacetsTest.java
new file mode 100644
index 0000000..21bdb02
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/FacetsTest.java
@@ -0,0 +1,677 @@
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+public class FacetsTest extends TestCase {
+
+ /**
+ * This method will test for the length facet.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testLengthFacet() throws Exception {
+
+ /*
+ <simpleType name="zipCode">
+ <restriction base="string">
+ <length value="5"/>
+ <pattern value="\d{5}"/>
+ </restriction>
+ </simpleType>
+ <element name="myZipCode" type="tns:zipCode"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myZipCode");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myZipCode", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myZipCode"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "zipCode"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaLengthFacet.class.getName());
+ s.add(XmlSchemaPatternFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaLengthFacet) {
+ assertEquals("5", ((XmlSchemaLengthFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaLengthFacet)o).isFixed());
+ String toStr = ((XmlSchemaLengthFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"length\", but did contain: " + toStr,
+ toStr.indexOf("length value=\"5\"") != -1);
+ } else if (o instanceof XmlSchemaPatternFacet) {
+ assertEquals("\\d{5}", ((XmlSchemaPatternFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaPatternFacet)o).isFixed());
+ String toStr = ((XmlSchemaPatternFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"pattern\", but did contain: " + toStr,
+ toStr.indexOf("pattern value=\"\\d{5}\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test for the pattern facet.
+ *
+ * @throwss Exception Any Exception encountered
+ */
+ public void testPatternFacet() throws Exception {
+
+ /*
+ <simpleType name="creditCardNumber">
+ <restriction base="integer">
+ <pattern value="\d{15}"/>
+ </restriction>
+ </simpleType>
+ <element name="myCreditCardNumber" type="tns:creditCardNumber"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myCreditCardNumber");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myCreditCardNumber", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myCreditCardNumber"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "creditCardNumber"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(1, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaPatternFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaPatternFacet) {
+ assertEquals("\\d{15}", ((XmlSchemaPatternFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaPatternFacet)o).isFixed());
+ String toStr = ((XmlSchemaPatternFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"pattern\", but did contain: " + toStr,
+ toStr.indexOf("pattern value=\"\\d{15}\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test the total digits facet.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testTotalDigitsFacet() throws Exception {
+
+ /*
+ <simpleType name="age">
+ <restriction base="decimal">
+ <totalDigits value="3"/>
+ </restriction>
+ </simpleType>
+ <element name="myAge" type="tns:age"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myAge");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myAge", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myAge"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "age"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "decimal"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(1, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaTotalDigitsFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaTotalDigitsFacet) {
+ assertEquals("3", ((XmlSchemaTotalDigitsFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaTotalDigitsFacet)o).isFixed());
+ String toStr = ((XmlSchemaTotalDigitsFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"totalDigits\", but did contain: " + toStr,
+ toStr.indexOf("totalDigits value=\"3\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test the Min and Max Inclusive facets.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testMinMaxInclusiveFacets() throws Exception {
+
+ /*
+ <simpleType name="distance">
+ <restriction base="integer">
+ <maxInclusive value="100" fixed="true"/>
+ <minInclusive value="0"/>
+ </restriction>
+ </simpleType>
+ <element name="myDistance" type="tns:distance"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myDistance");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myDistance", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myDistance"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "distance"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaMaxInclusiveFacet.class.getName());
+ s.add(XmlSchemaMinInclusiveFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaMaxInclusiveFacet) {
+ assertEquals("100", ((XmlSchemaMaxInclusiveFacet)o).getValue());
+ assertEquals(true, ((XmlSchemaMaxInclusiveFacet)o).isFixed());
+ String toStr = ((XmlSchemaMaxInclusiveFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"maxInclusive\", but did contain: " + toStr,
+ toStr.indexOf("maxInclusive value=\"100\"") != -1);
+ } else if (o instanceof XmlSchemaMinInclusiveFacet) {
+ assertEquals("0", ((XmlSchemaMinInclusiveFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMinInclusiveFacet)o).isFixed());
+ String toStr = ((XmlSchemaMinInclusiveFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"minInclusive\", but did contain: " + toStr,
+ toStr.indexOf("minInclusive value=\"0\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test the Min and Max Exclusive facets.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testMinMaxExlusiveFacets() throws Exception {
+
+ /*
+ <simpleType name="weight">
+ <restriction base="integer">
+ <maxExclusive value="200"/>
+ <minExclusive value="1"/>
+ </restriction>
+ </simpleType>
+ <element name="myWeight" type="tns:weight"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myWeight");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myWeight", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myWeight"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "weight"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaMaxExclusiveFacet.class.getName());
+ s.add(XmlSchemaMinExclusiveFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaMaxExclusiveFacet) {
+ assertEquals("200", ((XmlSchemaMaxExclusiveFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMaxExclusiveFacet)o).isFixed());
+ String toStr = ((XmlSchemaMaxExclusiveFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"maxExclusive\", but did contain: " + toStr,
+ toStr.indexOf("maxExclusive value=\"200\"") != -1);
+ } else if (o instanceof XmlSchemaMinExclusiveFacet) {
+ assertEquals("1", ((XmlSchemaMinExclusiveFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMinExclusiveFacet)o).isFixed());
+ String toStr = ((XmlSchemaMinExclusiveFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"minExclusive\", but did contain: " + toStr,
+ toStr.indexOf("minExclusive value=\"1\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This will test the whiteSpace facet.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testWhiteSpaceFacet() throws Exception {
+
+ /*
+ <simpleType name="noWhiteSpace">
+ <restriction base="integer">
+ <whiteSpace value="collapse"/>
+ </restriction>
+ </simpleType>
+ <element name="myWhiteSpace" type="tns:noWhiteSpace"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myWhiteSpace");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myWhiteSpace", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myWhiteSpace"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "noWhiteSpace"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "normalizedString"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(1, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaWhiteSpaceFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaWhiteSpaceFacet) {
+ assertEquals("collapse", ((XmlSchemaWhiteSpaceFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaWhiteSpaceFacet)o).isFixed());
+ String toStr = ((XmlSchemaWhiteSpaceFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"minExclusive\", but did contain: " + toStr,
+ toStr.indexOf("whiteSpace value=\"collapse\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This will test the fractionDigits facet.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testFractionDigitsFacet() throws Exception {
+
+ /*
+ <simpleType name="height">
+ <restriction base="decimal">
+ <totalDigits value="3"/>
+ <fractionDigits value="2"/>
+ </restriction>
+ </simpleType>
+ <element name="myHeight" type="tns:height"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myHeight");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myHeight", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myHeight"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "height"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "decimal"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaFractionDigitsFacet.class.getName());
+ s.add(XmlSchemaTotalDigitsFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaFractionDigitsFacet) {
+ assertEquals("2", ((XmlSchemaFractionDigitsFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaFractionDigitsFacet)o).isFixed());
+ String toStr = ((XmlSchemaFractionDigitsFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"fractionDigits\", but did contain: " + toStr,
+ toStr.indexOf("fractionDigits value=\"2\"") != -1);
+ } else if (o instanceof XmlSchemaTotalDigitsFacet) {
+ assertEquals("3", ((XmlSchemaTotalDigitsFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaTotalDigitsFacet)o).isFixed());
+ String toStr = ((XmlSchemaTotalDigitsFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"totalDigits\", but did contain: " + toStr,
+ toStr.indexOf("totalDigits value=\"3\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test the Min and Max Length facets.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testMinMaxLengthFacets() throws Exception {
+
+ /*
+ <simpleType name="yardLength">
+ <restriction base="nonNegativeInteger">
+ <minLength value="45"/>
+ <maxLength value="205"/>
+ </restriction>
+ </simpleType>
+ <element name="myYardLength" type="tns:yardLength"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "myYardLength");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("myYardLength", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "myYardLength"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "yardLength"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "nonNegativeInteger"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaMinLengthFacet.class.getName());
+ s.add(XmlSchemaMaxLengthFacet.class.getName());
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaMinLengthFacet) {
+ assertEquals("45", ((XmlSchemaMinLengthFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMinLengthFacet)o).isFixed());
+ String toStr = ((XmlSchemaMinLengthFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"minExclusive\", but did contain: " + toStr,
+ toStr.indexOf("minLength value=\"45\"") != -1);
+ } else if (o instanceof XmlSchemaMaxLengthFacet) {
+ assertEquals("205", ((XmlSchemaMaxLengthFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMaxLengthFacet)o).isFixed());
+ String toStr = ((XmlSchemaMaxLengthFacet)o).toString("xsd", 1);
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"maxLength\", but did contain: " + toStr,
+ toStr.indexOf("maxLength value=\"205\"") != -1);
+ } else {
+ fail("Unexpected object encountered: " + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test the enumeration facet.
+ *
+ * @throws Exception Any Exception encountered
+ */
+ public void testEnumerationFacet() throws Exception {
+
+ /*
+ <simpleType name="layoutComponentType">
+ <restriction base="string">
+ <enumeration value="Field"/>
+ <enumeration value="Separator"/>
+ </restriction>
+ </simpleType>
+ <element name="layoutComponent" type="tns:layoutComponentType"/>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "layoutComponent");
+ InputStream is = new FileInputStream(Resources.asURI("facets.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("layoutComponent", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "layoutComponent"),
+ elem.getQName());
+ assertEquals(new QName("http://soapinterop.org/types", "layoutComponentType"),
+ elem.getSchemaTypeName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
+ r.getBaseTypeName());
+
+ XmlSchemaSimpleType xsst = r.getBaseType();
+ assertNull(xsst);
+
+ XmlSchemaObjectCollection collection = r.getFacets();
+ assertEquals(2, collection.getCount());
+
+ Set s = new HashSet();
+ s.add("Field");
+ s.add("Separator");
+ for (Iterator i = collection.getIterator(); i.hasNext(); ) {
+ XmlSchemaEnumerationFacet xsef = (XmlSchemaEnumerationFacet)i.next();
+ String value = (String)xsef.getValue();
+ assertTrue("Atempted to remove an enumeration with the value of "
+ + "\"" + value + "\", but the value was not in the set.",
+ s.remove(value));
+ String toStr = xsef.toString("xsd", 1);
+ if (value.equals("Field")) {
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"enumeration\", but did contain: " + toStr,
+ toStr.indexOf("enumeration value=\"Field\"") != -1);
+ } else if (value.equals("Separator")) {
+ assertTrue("The toString(String, int) method did not contain "
+ + "\"enumeration\", but did contain: " + toStr,
+ toStr.indexOf("enumeration value=\"Separator\"") != -1);
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/GroupTest.java b/XmlSchema/src/test/java/tests/GroupTest.java
new file mode 100644
index 0000000..e3907a1
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/GroupTest.java
@@ -0,0 +1,156 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class GroupTest extends TestCase {
+
+ /**
+ * This method will test the group.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testGroup() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <group name="priceGroup">
+ <annotation>
+ <documentation xml:lang="en">
+ A price is any one of the following:
+ * Full Price (with amount)
+ * Sale Price (with amount and authorization)
+ * Clearance Price (with amount and authorization)
+ * Free (with authorization)
+ </documentation>
+ </annotation>
+ <choice id="pg.choice">
+ <element name="fullPrice" type="decimal"/>
+ <element name="salePrice" type="decimal"/>
+ <element name="clearancePrice" type="decimal"/>
+ <element name="freePrice" type="decimal"/>
+ </choice>
+ </group>
+
+ <element name="price">
+ <complexType>
+ <group ref="tns:priceGroup" />
+ </complexType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "price");
+ InputStream is = new FileInputStream(Resources.asURI("group.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("price", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "price"),
+ elem.getQName());
+
+ XmlSchemaComplexType cType = (XmlSchemaComplexType)elem.getSchemaType();
+ assertNotNull(cType);
+
+ XmlSchemaGroupRef ref = (XmlSchemaGroupRef)cType.getParticle();
+ assertEquals(new QName("http://soapinterop.org/types", "priceGroup"),
+ ref.getRefName());
+
+ XmlSchemaObjectTable t = schema.getGroups();
+ assertEquals(1, t.getCount());
+
+ XmlSchemaObject o = t.getItem(ref.getRefName());
+
+ Set s = new HashSet();
+ s.add("priceGroup");
+ for (Iterator i = t.getNames(); i.hasNext(); ) {
+ String name = ((QName)i.next()).getLocalPart();
+ assertEquals("priceGroup", name);
+ s.remove(name);
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ s.clear();
+ s.add("org.apache.ws.commons.schema.XmlSchemaGroup");
+ XmlSchemaGroup xsg = null;
+ for (Iterator i = t.getValues(); i.hasNext(); ) {
+ xsg = (XmlSchemaGroup)i.next();
+ s.remove(xsg.getClass().getName());
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ assertEquals("priceGroup", xsg.getName());
+
+ XmlSchemaChoice xsc = (XmlSchemaChoice)xsg.getParticle();
+ assertNotNull(xsc);
+
+ s.clear();
+ s.add("fullPrice");
+ s.add("salePrice");
+ s.add("clearancePrice");
+ s.add("freePrice");
+ XmlSchemaObjectCollection items = xsc.getItems();
+ Iterator iterator = items.getIterator();
+ while (iterator.hasNext()) {
+ XmlSchemaElement e = (XmlSchemaElement)iterator.next();
+ String eName = e.getName();
+ if (eName.equals("fullPrice")) {
+ assertEquals(new QName("", "fullPrice"), e.getQName());
+ } else if (eName.equals("salePrice")) {
+ assertEquals(new QName("", "salePrice"), e.getQName());
+ } else if (eName.equals("clearancePrice")) {
+ assertEquals(new QName("", "clearancePrice"), e.getQName());
+ } else if (eName.equals("freePrice")) {
+ assertEquals(new QName("", "freePrice"), e.getQName());
+ } else {
+ fail("The name \"" + eName + "\" was found but shouldn't "
+ + "have been found.");
+ }
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "decimal"), e.getSchemaTypeName());
+ assertTrue(s.remove(e.getName()));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/ImportTest.java b/XmlSchema/src/test/java/tests/ImportTest.java
new file mode 100644
index 0000000..0b3e851
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ImportTest.java
@@ -0,0 +1,64 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.File;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class ImportTest extends TestCase {
+
+ public void testSchemaImport() throws Exception{
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("importBase.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ schemaCol.setBaseUri(Resources.TEST_RESOURCES);
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // attempt with slash now
+ schemaCol = new XmlSchemaCollection();
+ schemaCol.setBaseUri(Resources.TEST_RESOURCES + "/");
+ schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+ }
+
+ /**
+ * variation of above don't set the base uri.
+ * @throws Exception
+ */
+ public void testSchemaImport2() throws Exception{
+ File file = new File(Resources.asURI("importBase.xsd"));
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(file.toURL().toString());
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
+ assertNotNull(schema);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/IncludeTest.java b/XmlSchema/src/test/java/tests/IncludeTest.java
new file mode 100644
index 0000000..9306d63
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/IncludeTest.java
@@ -0,0 +1,154 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+import org.xml.sax.InputSource;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class IncludeTest extends TestCase {
+
+ /**
+ * This method will test the include.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testInclude() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <include schemaLocation="include2.xsd"/>
+ <include schemaLocation="include3.xsd"/>
+
+ </schema>
+
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="test1include" type="string"/>
+
+ </schema>
+
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="test2include" type="integer"/>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "test1include");
+ InputStream is = new FileInputStream(Resources.asURI("include.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectCollection c = schema.getIncludes();
+ assertEquals(2, c.getCount());
+
+ Set set = new HashSet();
+ set.add(Resources.asURI("include2.xsd"));
+ set.add(Resources.asURI("include3.xsd"));
+ for (int i = 0; i < c.getCount(); i++) {
+ XmlSchemaInclude include = (XmlSchemaInclude)c.getItem(i);
+ assertNotNull(include);
+ XmlSchema s = include.getSchema();
+ assertNotNull(s);
+ String schemaLocation = include.getSchemaLocation();
+ if (schemaLocation.equals(Resources.asURI("include2.xsd"))) {
+ XmlSchemaElement xse =
+ s.getElementByName(new
+ QName("http://soapinterop.org/types", "test1include"));
+ assertEquals("test1include", xse.getName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
+ xse.getSchemaTypeName());
+ } else if (schemaLocation.equals(Resources.asURI("include3.xsd"))) {
+ XmlSchemaElement xse =
+ s.getElementByName(new
+ QName("http://soapinterop.org/types", "test2include"));
+ assertEquals("test2include", xse.getName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ xse.getSchemaTypeName());
+ } else {
+ fail("The schemaLocation of \"" + schemaLocation + "\" was"
+ + " not expected.");
+ }
+ set.remove(schemaLocation);
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + set + ".",
+ set.isEmpty());
+
+ }
+
+ /**
+ * Test importing a schema without namespace into a schema
+ * with namespace.
+ */
+ public void testImportSchemaWithoutNamespace() throws Exception {
+ InputStream is = new FileInputStream(Resources.asURI("includingWithNamespace.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ schemaCol.read(new StreamSource(is), null);
+
+ assertNotNull(schemaCol.getTypeByQName(new QName("http://tns.demo.org", "XdwsGroupId")));
+ }
+
+ /**
+ * Schema included defined xmlns="http://www.w3.org/2001/XMLSchema"
+ * @throws Exception
+ */
+ public void testSchemaInclude() throws Exception{
+ String uri = Resources.asURI("WSCOMMONS-87/includeBase.xsd");
+ InputSource isource = new InputSource(new FileInputStream(uri));
+ isource.setSystemId(uri);
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(isource, null);
+ assertNotNull(schema);
+ }
+
+ /**
+ * Schema included does not define xmlns="http://www.w3.org/2001/XMLSchema"
+ * @throws Exception
+ */
+ public void testSchemaIncludeNoDefaultNS() throws Exception{
+ String uri = Resources.asURI("WSCOMMONS-87/includeBaseNoDefaultNS.xsd");
+ InputSource isource = new InputSource(new FileInputStream(uri));
+ isource.setSystemId(uri);
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(isource, null);
+ assertNotNull(schema);
+ }
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/ListTest.java b/XmlSchema/src/test/java/tests/ListTest.java
new file mode 100644
index 0000000..ae32f32
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ListTest.java
@@ -0,0 +1,88 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class ListTest extends TestCase {
+
+ /**
+ * This method will test the list.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testList() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="workDays">
+ <simpleType>
+ <restriction base="tns:daysInWeek">
+ <length value="5"/>
+ </restriction>
+ </simpleType>
+ </element>
+
+ <simpleType name="daysInWeek">
+ <list itemType="xsd:integer"/>
+ </simpleType>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "workDays");
+ InputStream is = new FileInputStream(Resources.asURI("list.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("workDays", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "workDays"),
+ elem.getQName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+ assertNotNull(simpleType);
+
+ XmlSchemaSimpleTypeRestriction r =
+ (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
+ assertNotNull(r);
+
+ QName baseTypeName = r.getBaseTypeName();
+ assertEquals(new QName("http://soapinterop.org/types", "daysInWeek"),
+ baseTypeName);
+ XmlSchemaType type = schemaCol.getTypeByQName(baseTypeName);
+
+ XmlSchemaSimpleTypeContent content = ((XmlSchemaSimpleType)type).getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ ((XmlSchemaSimpleTypeList)content).getItemTypeName());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/MixedContentTest.java b/XmlSchema/src/test/java/tests/MixedContentTest.java
new file mode 100644
index 0000000..3185e30
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/MixedContentTest.java
@@ -0,0 +1,47 @@
+package tests;
+
+import junit.framework.TestCase;
+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.XmlSchemaType;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class MixedContentTest extends TestCase {
+ public void testMixedContent() throws Exception {
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/xsd",
+ "complexElt");
+
+
+ InputStream is = new FileInputStream(Resources.asURI("mixedContent.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+
+ XmlSchemaElement elementByName = s.getElementByName(ELEMENT_QNAME);
+ assertNotNull(elementByName);
+
+ XmlSchemaType schemaType = elementByName.getSchemaType();
+ assertNotNull(schemaType);
+
+ assertTrue(schemaType.isMixed());
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/NamespaceContextTest.java b/XmlSchema/src/test/java/tests/NamespaceContextTest.java
new file mode 100644
index 0000000..e67258b
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/NamespaceContextTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package tests;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.utils.NamespaceMap;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.xml.sax.InputSource;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+public class NamespaceContextTest extends XMLTestCase {
+ protected boolean whitespace = true;
+ protected void setUp() throws Exception {
+ whitespace = XMLUnit.getIgnoreWhitespace();
+ XMLUnit.setIgnoreWhitespace(true);
+ }
+ protected void tearDown() throws java.lang.Exception {
+ XMLUnit.setIgnoreWhitespace(whitespace);
+ }
+ public void testNamespaceContext() throws Exception {
+ Map namespaceMapFromWSDL = new HashMap();
+ namespaceMapFromWSDL.put("tns", new URI("http://example.org/getBalance/"));
+ namespaceMapFromWSDL.put("xsd", new URI("http://www.w3.org/2001/XMLSchema"));
+ String schema = "\t\t<xsd:schema targetNamespace=\"http://example.org/getBalance/\"\n" +
+ "attributeFormDefault=\"unqualified\" elementFormDefault=\"unqualified\"" +
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
+ "\t\t\t<xsd:include schemaLocation=\"getBalance.xsd\" />\n" +
+ "\n" +
+ "\t\t\t<xsd:element name=\"newCustomer\">\n" +
+ "\t\t\t\t<xsd:complexType>\n" +
+ "\t\t\t\t\t<xsd:sequence>\n" +
+ "\t\t\t\t\t\t<xsd:element name=\"details\" type=\"tns:cinfoct\" />\n" +
+ "\t\t\t\t\t\t<xsd:element name=\"id\" type=\"xsd:string\" />\n" +
+ "\t\t\t\t\t</xsd:sequence>\n" +
+ "\t\t\t\t</xsd:complexType>\n" +
+ "\t\t\t</xsd:element>\n" +
+ "\n" +
+ "\t\t\t<xsd:element name=\"customerId\">\n" +
+ "\t\t\t\t<xsd:complexType>\n" +
+ "\t\t\t\t\t<xsd:sequence>\n" +
+ "\t\t\t\t\t\t<xsd:element name=\"id\" type=\"xsd:string\" />\n" +
+ "\t\t\t\t\t</xsd:sequence>\n" +
+ "\t\t\t\t</xsd:complexType>\n" +
+ "\t\t\t</xsd:element>\n" +
+ "\n" +
+ "\t\t</xsd:schema>";
+ org.xml.sax.InputSource schemaInputSource = new InputSource(new StringReader(schema));
+ XmlSchemaCollection xsc = new XmlSchemaCollection();
+ xsc.setBaseUri(Resources.TEST_RESOURCES);
+
+ //Set the namespaces explicitly
+ NamespaceMap prefixmap = new NamespaceMap(namespaceMapFromWSDL);
+ xsc.setNamespaceContext(prefixmap);
+ XmlSchema schemaDef = xsc.read(schemaInputSource, null);
+ StringWriter sw = new StringWriter();
+ schemaDef.write(sw);
+
+ assertXMLEqual(sw.toString(), schema);
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/NotationTest.java b/XmlSchema/src/test/java/tests/NotationTest.java
new file mode 100644
index 0000000..aa5b64d
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/NotationTest.java
@@ -0,0 +1,202 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+ */
+public class NotationTest extends TestCase {
+
+ /**
+ * This method will test the notation.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testNotation() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <notation name="teamLogo"
+ system="com/team/graphics/teamLogo"
+ public="http://www.team.com/graphics/teamLogo"
+ id="notation.teamLogo">
+ <annotation>
+ <documentation xml:lang="en">Location of the corporate logo.</documentation>
+ </annotation>
+ </notation>
+
+ <notation name="teamMascot"
+ system="com/team/graphics/teamMascot"
+ public="http://www.team.com/graphics/teamMascot"
+ id="notation.teamMascot">
+ <annotation>
+ <documentation xml:lang="en">Location of the corporate mascot.</documentation>
+ </annotation>
+ </notation>
+
+ <element name="demoNotation">
+ <simpleType>
+ <restriction base="NOTATION">
+ <enumeration value="tns:teamLogo"/>
+ <enumeration value="tns:teamMascot"/>
+ </restriction>
+ </simpleType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "demoNotation");
+ QName notationName = new QName("http://soapinterop.org/types",
+ "teamLogo");
+
+
+
+ InputStream is = new FileInputStream(Resources.asURI("notation.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectTable notations = schema.getNotations();
+ assertNotNull(notations.getItem(notationName));
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("demoNotation", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "demoNotation"),
+ elem.getQName());
+
+ XmlSchemaSimpleType type =
+ (XmlSchemaSimpleType)elem.getSchemaType();
+ assertNotNull(type);
+
+ XmlSchemaSimpleTypeRestriction xsstc =
+ (XmlSchemaSimpleTypeRestriction)type.getContent();
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema","NOTATION"),
+ xsstc.getBaseTypeName());
+
+ XmlSchemaObjectCollection xsoc = xsstc.getFacets();
+ assertEquals(2, xsoc.getCount());
+ Set s = new HashSet();
+ s.add("tns:teamLogo");
+ s.add("tns:teamMascot");
+ for (int i = 0; i < xsoc.getCount(); i++) {
+ XmlSchemaEnumerationFacet xsef =
+ (XmlSchemaEnumerationFacet)xsoc.getItem(i);
+ String value = (String)xsef.getValue();
+ if (!(value.equals("tns:teamLogo")
+ || value.equals("tns:teamMascot"))) {
+ fail("An unexpected value of \"" + value
+ + "\" was found.");
+ }
+ assertTrue(s.remove(value));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ XmlSchemaObjectTable xsot = schema.getNotations();
+ assertEquals(2, xsot.getCount());
+
+ s.clear();
+ s.add("teamMascot");
+ s.add("teamLogo");
+ for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+ String name = ((QName)i.next()).getLocalPart();
+ if (!(name.equals("teamLogo")
+ || name.equals("teamMascot"))) {
+ fail("An unexpected name of \"" + name
+ + "\" was found.");
+ }
+ assertTrue(s.remove(name));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ s.clear();
+ s.add("teamMascot");
+ s.add("teamLogo");
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ XmlSchemaNotation xsn = (XmlSchemaNotation)i.next();
+ String name = xsn.getName();
+ XmlSchemaAnnotation xsa = xsn.getAnnotation();
+ XmlSchemaObjectCollection col = xsa.getItems();
+ assertEquals(1, col.getCount());
+ XmlSchemaDocumentation xsd = null;
+ for (int k = 0; k < col.getCount(); k++) {
+ xsd = (XmlSchemaDocumentation)col.getItem(k);
+ }
+ if (name.equals("teamMascot")) {
+ assertEquals("http://www.team.com/graphics/teamMascot",
+ xsn.getPublic());
+ assertEquals("com/team/graphics/teamMascot",
+ xsn.getSystem());
+ assertEquals("notation.teamMascot", xsn.getId());
+ assertEquals("en", xsd.getLanguage());
+ NodeList nl = xsd.getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("Location of the corporate mascot.",
+ n.getNodeValue());
+ }
+ }
+ } else if (name.equals("teamLogo")) {
+ assertEquals("http://www.team.com/graphics/teamLogo",
+ xsn.getPublic());
+ assertEquals("com/team/graphics/teamLogo",
+ xsn.getSystem());
+ assertEquals("notation.teamLogo", xsn.getId());
+ assertEquals("en", xsd.getLanguage());
+ NodeList nl = xsd.getMarkup();
+ for (int j = 0; j < nl.getLength(); j++) {
+ Node n = nl.item(j);
+ if (n.getNodeType() == Node.TEXT_NODE) {
+ assertEquals("Location of the corporate logo.",
+ n.getNodeValue());
+ }
+ }
+ } else {
+ fail("An unexpected name of \"" + name
+ + "\" was found.");
+ }
+ assertTrue(s.remove(name));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/RedefineTest.java b/XmlSchema/src/test/java/tests/RedefineTest.java
new file mode 100644
index 0000000..3036403
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/RedefineTest.java
@@ -0,0 +1,436 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+ */
+public class RedefineTest extends TestCase {
+
+ /**
+ * This method will test a complex type redefine.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testComplexTypeRedefine() throws Exception {
+
+ /*
+ redefine1.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="person">
+ <sequence>
+ <element name="firstname" type="string"/>
+ <element name="lastname" type="string"/>
+ </sequence>
+ </complexType>
+
+ <element name="customer" type="tns:person"/>
+
+ </schema>
+
+
+ redefine2.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="src/test/test-resources/redefine1.xsd">
+ <complexType name="person">
+ <complexContent>
+ <extension base="tns:person">
+ <sequence>
+ <element name="id" type="string"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ </redefine>
+
+ <element name="vip" type="tns:person"/>
+
+ </schema>
+ */
+
+ InputStream is = new FileInputStream(Resources.asURI("redefine2.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectTable xsot = schema.getElements();
+ assertEquals(1, xsot.getCount());
+
+ XmlSchemaElement xse = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xse = (XmlSchemaElement)i.next();
+ }
+ assertEquals("vip", xse.getName());
+ assertEquals(new QName("http://soapinterop.org/types",
+ "person"),
+ xse.getSchemaTypeName());
+
+ XmlSchemaObjectCollection xsoc = schema.getIncludes();
+ assertEquals(1, xsoc.getCount());
+
+ XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+ xsot = xsr.getSchemaTypes();
+ assertEquals(1, xsot.getCount());
+
+ for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+ QName qname = (QName)i.next();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "person"), qname);
+ }
+
+ XmlSchemaComplexType xsct = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xsct = (XmlSchemaComplexType)i.next();
+ }
+ assertNotNull(xsct);
+
+ XmlSchemaContentModel xscm = xsct.getContentModel();
+ assertNotNull(xscm);
+
+ XmlSchemaComplexContentExtension xscce =
+ (XmlSchemaComplexContentExtension)xscm.getContent();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "person"),
+ xscce.getBaseTypeName());
+
+ XmlSchemaSequence xsp = (XmlSchemaSequence)xscce.getParticle();
+ assertNotNull(xsp);
+
+ XmlSchemaObjectCollection c = xsp.getItems();
+ assertEquals(1, c.getCount());
+
+ xse = null;
+ for (int i = 0; i < c.getCount(); i++) {
+ xse = (XmlSchemaElement)c.getItem(i);
+ }
+ assertEquals("id", xse.getName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
+ "string"),
+ xse.getSchemaTypeName());
+
+ }
+
+ /**
+ * This method will test a simple type redefine.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testSimpleTypeRedefine() throws Exception {
+ /*
+
+ redefine3.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <simpleType name="drinksize">
+ <restriction base="integer"/>
+ </simpleType>
+
+ <element name="size" type="tns:drinksize"/>
+
+ </schema>
+
+
+ redefine4.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="test-resources/redefine3.xsd">
+ <simpleType name="drinksize">
+ <restriction base="tns:drinksize">
+ <minInclusive value="1"/>
+ <maxInclusive value="3"/>
+ </restriction>
+ </simpleType>
+ </redefine>
+
+ <element name="childsizedrink" type="tns:drinksize"/>
+
+ </schema>
+ */
+
+ InputStream is = new FileInputStream(Resources.asURI("redefine4.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectTable xsot = schema.getElements();
+ assertEquals(1, xsot.getCount());
+
+ XmlSchemaElement xse = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xse = (XmlSchemaElement)i.next();
+ }
+ assertEquals("childsizedrink", xse.getName());
+ assertEquals(new QName("http://soapinterop.org/types",
+ "drinksize"),
+ xse.getSchemaTypeName());
+
+ XmlSchemaObjectCollection xsoc = schema.getIncludes();
+ assertEquals(1, xsoc.getCount());
+
+ XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+ xsot = xsr.getSchemaTypes();
+ assertEquals(1, xsot.getCount());
+
+ for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+ QName qname = (QName)i.next();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "drinksize"), qname);
+ }
+
+ XmlSchemaSimpleType xsst = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xsst = (XmlSchemaSimpleType)i.next();
+ }
+ assertNotNull(xsst);
+
+ XmlSchemaSimpleTypeRestriction xsstr =
+ (XmlSchemaSimpleTypeRestriction)xsst.getContent();
+ assertEquals(new QName("http://soapinterop.org/types",
+ "drinksize"),
+ xsstr.getBaseTypeName());
+
+ xsoc = xsstr.getFacets();
+
+ Set s = new HashSet();
+ s.add(XmlSchemaMinInclusiveFacet.class.getName());
+ s.add(XmlSchemaMaxInclusiveFacet.class.getName());
+ for (Iterator i = xsoc.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaMinInclusiveFacet) {
+ assertEquals("1", ((XmlSchemaMinInclusiveFacet)o).getValue());
+ } else if (o instanceof XmlSchemaMaxInclusiveFacet) {
+ assertEquals("3", ((XmlSchemaMaxInclusiveFacet)o).getValue());
+ } else {
+ fail("Unexpected object encountered: "
+ + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test a group redefine.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testGroupRedefine() throws Exception {
+
+ /*
+ redefine5.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <group name="PrologGroup">
+ <sequence>
+ <element name="date" type="string"/>
+ <element name="author" type="string"/>
+ <element name="defect" type="integer"/>
+ </sequence>
+ </group>
+
+ </schema>
+
+
+ redefine6.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="redefine5.xsd">
+ <group name="PrologGroup">
+ <sequence>
+ <group ref="tns:PrologGroup"/>
+ <element name="description" type="string"/>
+ </sequence>
+ </group>
+ </redefine>
+
+ </schema>
+ */
+
+ InputStream is = new FileInputStream(Resources.asURI("redefine6.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectCollection xsoc = schema.getIncludes();
+ assertEquals(1, xsoc.getCount());
+
+ XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+ XmlSchemaObjectTable xsot = xsr.getGroup();
+ assertEquals(1, xsot.getCount());
+
+ for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+ assertEquals("PrologGroup", (String)i.next());
+ }
+
+ XmlSchemaGroup xsg = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xsg = (XmlSchemaGroup)i.next();
+ }
+
+ XmlSchemaSequence xss = (XmlSchemaSequence)xsg.getParticle();
+
+ xsoc = xss.getItems();
+ assertEquals(2, xsoc.getCount());
+
+ Set s = new HashSet();
+ s.add(XmlSchemaGroupRef.class.getName());
+ s.add(XmlSchemaElement.class.getName());
+ for (Iterator i = xsoc.getIterator(); i.hasNext(); ) {
+ Object o = i.next();
+ assertTrue(s.remove(o.getClass().getName()));
+ if (o instanceof XmlSchemaGroupRef) {
+ assertEquals(new QName("http://soapinterop.org/types",
+ "PrologGroup"),
+ ((XmlSchemaGroupRef)o).getRefName());
+ } else if (o instanceof XmlSchemaElement) {
+ assertEquals("description", ((XmlSchemaElement)o).getName());
+ } else {
+ fail("Unexpected object encountered: "
+ + o.getClass().getName());
+ }
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+ /**
+ * This method will test a attribute group redefine.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testAttributeGroupRedefine() throws Exception {
+
+ /*
+ redefine7.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <attributeGroup name="AttribGroup">
+ <attribute name="type" type="string"/>
+ <attribute name="units" type="string"/>
+ <attribute name="serialId" type="string"/>
+ </attributeGroup>
+
+ </schema>
+
+
+ redefine8.xsd
+ -----------------
+
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="redefine7.xsd">
+ <attributeGroup name="AttribGroup">
+ <attribute name="type" type="string"/>
+ <attribute name="units" type="string"/>
+ </attributeGroup>
+ </redefine>
+
+ </schema>
+ */
+
+ InputStream is = new FileInputStream(Resources.asURI("redefine8.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaObjectCollection xsoc = schema.getIncludes();
+ assertEquals(1, xsoc.getCount());
+
+ XmlSchemaRedefine xsr = (XmlSchemaRedefine)xsoc.getItem(0);
+ XmlSchemaObjectTable xsot = xsr.getAttributeGroup();
+ assertEquals(1, xsot.getCount());
+
+ for (Iterator i = xsot.getNames(); i.hasNext(); ) {
+ assertEquals("AttribGroup", (String)i.next());
+ }
+
+ XmlSchemaAttributeGroup xsag = null;
+ for (Iterator i = xsot.getValues(); i.hasNext(); ) {
+ xsag = (XmlSchemaAttributeGroup)i.next();
+ }
+ assertEquals("AttribGroup", xsag.getName());
+ xsoc = xsag.getAttributes();
+
+ Set s = new HashSet();
+ s.add("type");
+ s.add("units");
+ for (Iterator i = xsoc.getIterator(); i.hasNext(); ) {
+ XmlSchemaAttribute xsa = (XmlSchemaAttribute)i.next();
+ assertTrue(s.remove(xsa.getName()));
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/Resources.java b/XmlSchema/src/test/java/tests/Resources.java
new file mode 100644
index 0000000..29fed38
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/Resources.java
@@ -0,0 +1,31 @@
+package tests;
+
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class Resources {
+ /**
+ * Location of the test resources.
+ */
+ public static final String TEST_RESOURCES = "src/test/test-resources";
+
+ /**
+ * Returns a files location as a string.
+ */
+ public static String asURI(String pURI) {
+ return TEST_RESOURCES + "/" + pURI;
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java b/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java
new file mode 100644
index 0000000..ab33884
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/SimpleContentExtensionTest.java
@@ -0,0 +1,129 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class SimpleContentExtensionTest extends TestCase {
+
+ /**
+ * This method will test the simple content extension.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testSimpleContentExtension() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified">
+
+ <element name="height">
+ <complexType>
+ <simpleContent>
+ <extension base="integer">
+ <attribute name="units" type="string" use="required"/>
+ <attribute name="id" type="integer" use="required" default="001"/>
+ <attribute name="desc" type="decimal" fixed="1.1"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "height");
+ InputStream is = new FileInputStream(Resources.asURI("simplecontentextension.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schema.getElementByName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("height", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "height"),
+ elem.getQName());
+
+ XmlSchemaComplexType xsct = (XmlSchemaComplexType)elem.getSchemaType();
+ assertNotNull(xsct);
+ XmlSchemaSimpleContent xssc = (XmlSchemaSimpleContent)xsct.getContentModel();
+ assertNotNull(xssc);
+
+ XmlSchemaSimpleContentExtension xssce
+ = (XmlSchemaSimpleContentExtension)xssc.getContent();
+ assertNotNull(xssce);
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ xssce.getBaseTypeName());
+
+ XmlSchemaObjectCollection xsoc = xssce.getAttributes();
+ assertEquals(3, xsoc.getCount());
+
+ Set s = new HashSet();
+ s.add("units");
+ s.add("id");
+ s.add("desc");
+ for (int i = 0; i < xsoc.getCount(); i++) {
+ XmlSchemaAttribute xsa = (XmlSchemaAttribute)xsoc.getItem(i);
+ String name = xsa.getName();
+ if (name.equals("units")) {
+ assertEquals(new QName("http://soapinterop.org/types", "units"),
+ xsa.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
+ xsa.getSchemaTypeName());
+ assertNull(xsa.getDefaultValue());
+ assertEquals("required", xsa.getUse().getValue());
+ assertNull(xsa.getFixedValue());
+ } else if (name.equals("id")) {
+ assertEquals(new QName("http://soapinterop.org/types", "id"),
+ xsa.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ xsa.getSchemaTypeName());
+ assertEquals("001", xsa.getDefaultValue());
+ assertEquals("required", xsa.getUse().getValue());
+ assertNull(xsa.getFixedValue());
+ } else if (name.equals("desc")) {
+ assertEquals(new QName("http://soapinterop.org/types", "desc"),
+ xsa.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "decimal"),
+ xsa.getSchemaTypeName());
+ assertEquals("none", xsa.getUse().getValue());
+ assertEquals("1.1", xsa.getFixedValue());
+ } else {
+ fail("The name \"" + name + "\" was not expected.");
+ }
+ s.remove(name);
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/SimpleContentRestrictionTest.java b/XmlSchema/src/test/java/tests/SimpleContentRestrictionTest.java
new file mode 100644
index 0000000..2a89324
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/SimpleContentRestrictionTest.java
@@ -0,0 +1,144 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class SimpleContentRestrictionTest extends TestCase {
+
+ /**
+ * This method will test the simple content restriction.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testSimpleContentRestriction() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified">
+
+ <simpleType name="drinksize">
+ <restriction base="string">
+ <enumeration value="small"/>
+ <enumeration value="medium"/>
+ <enumeration value="large"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="dietdrinksize">
+ <simpleContent>
+ <restriction base="tns:drinksize">
+ <enumeration value="small"/>
+ <enumeration value="medium"/>
+ <attribute name="units" type="string" use="required"/>
+ <attribute name="id" type="integer" use="required" default="001"/>
+ </restriction>
+ </simpleContent>
+ </complexType>
+
+ </schema>
+ */
+
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "dietdrinksize");
+ InputStream is = new FileInputStream(Resources.asURI("screstriction.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaComplexType xsct =
+ (XmlSchemaComplexType)schema.getTypeByName(TYPE_QNAME);
+ assertNotNull(xsct);
+
+ XmlSchemaSimpleContent xssc = (XmlSchemaSimpleContent)xsct.getContentModel();
+ assertNotNull(xssc);
+
+ XmlSchemaSimpleContentRestriction xsscr
+ = (XmlSchemaSimpleContentRestriction)xssc.getContent();
+ assertNotNull(xsscr);
+ assertEquals(new QName("http://soapinterop.org/types", "drinksize"),
+ xsscr.getBaseTypeName());
+ XmlSchemaObjectCollection xsoc = xsscr.getAttributes();
+ assertNotNull(xsoc);
+ assertEquals(2, xsoc.getCount());
+
+ Set s = new HashSet();
+ s.add("units");
+ s.add("id");
+ for (int i = 0; i < xsoc.getCount(); i++) {
+ XmlSchemaAttribute xsa = (XmlSchemaAttribute)xsoc.getItem(i);
+ String name = xsa.getName();
+ if (name.equals("units")) {
+ assertEquals(new QName("http://soapinterop.org/types", "units"),
+ xsa.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
+ xsa.getSchemaTypeName());
+ assertNull(xsa.getDefaultValue());
+ assertEquals("required", xsa.getUse().getValue());
+ assertNull(xsa.getFixedValue());
+ } else if (name.equals("id")) {
+ assertEquals(new QName("http://soapinterop.org/types", "id"),
+ xsa.getQName());
+ assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
+ xsa.getSchemaTypeName());
+ assertEquals("001", xsa.getDefaultValue());
+ assertEquals("required", xsa.getUse().getValue());
+ assertNull(xsa.getFixedValue());
+ } else {
+ fail("The name \"" + name + "\" was not expected.");
+ }
+ assertTrue(s.remove(name));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ XmlSchemaObjectCollection xsoc2 = xsscr.getFacets();
+ assertNotNull(xsoc2);
+ assertEquals(2, xsoc2.getCount());
+
+ s.clear();
+ s.add("small");
+ s.add("medium");
+ for (int i = 0; i < xsoc2.getCount(); i++) {
+ XmlSchemaEnumerationFacet xsef =
+ (XmlSchemaEnumerationFacet)xsoc2.getItem(i);
+ String value = (String)xsef.getValue();
+ if (!(value.equals("small") || value.equals("medium"))) {
+ fail("Unexpected enumeration value of \"" + value
+ + "\" found.");
+ }
+ assertTrue(s.remove(value));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/TestElementForm.java b/XmlSchema/src/test/java/tests/TestElementForm.java
new file mode 100644
index 0000000..baf1944
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestElementForm.java
@@ -0,0 +1,54 @@
+/*
+* Copyright 2004,2007 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.
+*/
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * TestElementForm
+ */
+public class TestElementForm extends TestCase {
+ String NS = "http://unqualified-elements.example.com";
+ QName UNQUAL = new QName(NS, "unQualifiedLocals");
+ private XmlSchemaCollection schema;
+
+ protected void setUp() throws Exception {
+ InputStream is = new FileInputStream(Resources.asURI("elementForm.xsd"));
+ schema = new XmlSchemaCollection();
+ schema.read(new StreamSource(is), null);
+ }
+
+ public void testLocalElements() throws Exception {
+ XmlSchemaElement element = schema.getElementByQName(UNQUAL);
+ assertNotNull("Couldn't find unQualifiedLocals element", element);
+ XmlSchemaComplexType type = (XmlSchemaComplexType)element.getSchemaType();
+ XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
+ XmlSchemaObjectCollection items = seq.getItems();
+ XmlSchemaElement subElement;
+ subElement = (XmlSchemaElement)items.getItem(0);
+ QName qname = subElement.getQName();
+ assertEquals("Namespace on unqualified element", "", qname.getNamespaceURI());
+ subElement = (XmlSchemaElement)items.getItem(1);
+ qname = subElement.getQName();
+ assertEquals("Bad namespace on qualified element", NS, qname.getNamespaceURI());
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/TestElementRefs.java b/XmlSchema/src/test/java/tests/TestElementRefs.java
new file mode 100644
index 0000000..03e5086
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestElementRefs.java
@@ -0,0 +1,54 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Iterator;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class TestElementRefs extends TestCase {
+ public void testElementRefs() throws Exception {
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "attTests");
+ InputStream is = new FileInputStream(Resources.asURI("elementreferences.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+
+ assertNotNull(elem);
+
+ XmlSchemaComplexType cmplxType = (XmlSchemaComplexType)elem.getSchemaType();
+ XmlSchemaObjectCollection items = ((XmlSchemaSequence)cmplxType.getParticle()).getItems();
+
+ Iterator it = items.getIterator();
+ while (it.hasNext()) {
+ XmlSchemaElement innerElement = (XmlSchemaElement)it.next();
+ assertNotNull(innerElement.getRefName());
+ }
+
+ // test writing
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ schema.write(bos);
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/TestForwardRefs.java b/XmlSchema/src/test/java/tests/TestForwardRefs.java
new file mode 100644
index 0000000..0761bab
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestForwardRefs.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ */
+public class TestForwardRefs extends TestCase {
+
+ public void testForwardRefs() throws Exception {
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "attrTest");
+ InputStream is = new FileInputStream(Resources.asURI("forwardRef.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ schema.read(new StreamSource(is), null);
+
+ XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ XmlSchemaType type = elem.getSchemaType();
+ assertNotNull(type);
+ assertTrue(type instanceof XmlSchemaComplexType);
+ XmlSchemaComplexType cType = (XmlSchemaComplexType)type;
+ XmlSchemaSequence seq = (XmlSchemaSequence)cType.getParticle();
+ assertNotNull(seq);
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/TestLocalUnnamedSimpleType.java b/XmlSchema/src/test/java/tests/TestLocalUnnamedSimpleType.java
new file mode 100644
index 0000000..1d535dc
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestLocalUnnamedSimpleType.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+
+/**
+ * TestElementForm
+ */
+public class TestLocalUnnamedSimpleType extends TestCase {
+ String schemaXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<schema xmlns=\"http://www.w3.org/2001/XMLSchema\"\n" +
+ "targetNamespace=\"http://finance.example.com/CreditCardFaults/xsd\"\n" +
+ "xmlns:tns=\"http://finance.example.com/CreditCardFaults/xsd\"\n" +
+ "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ "xsi:schemaLocation=\"http://www.w3.org/2001/XMLSchema\n" +
+ " http://www.w3.org/2001/XMLSchema.xsd\">\n" +
+ "\n" +
+ "<element name=\"tns:CreditCardNumber\" type=\"string\"></element>\n" +
+ "\n" +
+ "<element name=\"tns:CreditCardType\">\n" +
+ "<simpleType>\n" +
+ "<restriction base=\"string\">\n" +
+ "<enumeration value=\"AMEX\" />\n" +
+ "<enumeration value=\"MASTERCARD\" />\n" +
+ "<enumeration value=\"VISA\" />\n" +
+ "</restriction>\n" +
+ "</simpleType>\n" +
+ "</element>\n" +
+ "</schema> ";
+
+ public void testLocalUnnamedSimpleType() throws Exception {
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ schema.read(new StreamSource(new ByteArrayInputStream(schemaXML.getBytes())), null);
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/TestSimpleRestriction.java b/XmlSchema/src/test/java/tests/TestSimpleRestriction.java
new file mode 100644
index 0000000..d6912da
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestSimpleRestriction.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests;
+
+import junit.framework.TestCase;
+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.XmlSchemaType;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+public class TestSimpleRestriction extends TestCase {
+ public void testSimpleRestriction() throws Exception {
+ QName TYPE_QNAME = new QName("http://soapinterop.org/types",
+ "layoutComponentType");
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "foo");
+
+ InputStream is = new FileInputStream(Resources.asURI("SimpleContentRestriction.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+
+ XmlSchemaType simpleType = schema.getTypeByQName(TYPE_QNAME);
+ assertNotNull(simpleType);
+
+ XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+
+ XmlSchemaType type = elem.getSchemaType();
+ assertNotNull(type);
+ }
+
+ public void testSimpleTypeRestrictionWithoutNamespace() throws Exception {
+ InputStream is = new FileInputStream(Resources.asURI("includedWithoutNamespace.xsd"));
+ XmlSchemaCollection schema = new XmlSchemaCollection();
+ XmlSchema s = schema.read(new StreamSource(is), null);
+ XmlSchemaType principalId = schema.getTypeByQName(new QName("", "XdwsPrincipalId"));
+ assertNotNull(principalId);
+ XmlSchemaType groupId = schema.getTypeByQName(new QName("", "XdwsGroupId"));
+ assertNotNull(groupId);
+ assertEquals(groupId.getBaseSchemaType(), principalId);
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/TestUnqualifiedSchema.java b/XmlSchema/src/test/java/tests/TestUnqualifiedSchema.java
new file mode 100644
index 0000000..7e70c4f
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TestUnqualifiedSchema.java
@@ -0,0 +1,59 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+import org.w3c.dom.Document;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Iterator;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class TestUnqualifiedSchema extends TestCase {
+
+
+ public void testUnqualifiedSchemas() throws Exception {
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("unqualifiedTypes.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema s = schemaCol.read(doc.getDocumentElement());
+
+ assertNotNull(s);
+
+ XmlSchemaElement e=s.getElementByName(new QName("http://soapinterop.org/xsd","complexElt") );
+ XmlSchemaComplexType t =(XmlSchemaComplexType)e.getSchemaType();
+ assertNotNull(t);
+
+ XmlSchemaSequence seq = (XmlSchemaSequence)t.getParticle();
+ XmlSchemaObjectCollection items = seq.getItems();
+ Iterator iterator = items.getIterator();
+ while (iterator.hasNext()) {
+ XmlSchemaElement elt2 = (XmlSchemaElement) iterator.next();
+ System.out.println(elt2.getQName());
+ XmlSchemaType schemaType2 = elt2.getSchemaType();
+
+ assertNotNull(schemaType2);
+ }
+
+
+
+ }
+
+
+}
diff --git a/XmlSchema/src/test/java/tests/TwoSchemasRefTest.java b/XmlSchema/src/test/java/tests/TwoSchemasRefTest.java
new file mode 100644
index 0000000..4e2146a
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TwoSchemasRefTest.java
@@ -0,0 +1,50 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class TwoSchemasRefTest extends TestCase {
+
+ public void testTwoSchemas() throws Exception{
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("twoSchemas-ref.wsdl"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ NodeList schemaNodes = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","schema");
+ for (int j = 0; j < schemaNodes.getLength(); j++) {
+ Node schemaNode = schemaNodes.item(j);
+ if("schema".equals(schemaNode.getLocalName())){
+ schemaCol.read((Element)schemaNode);
+ }
+ }
+
+ XmlSchemaElement elementByQName = schemaCol.getElementByQName(new QName("http://tns.demo.org", "elem1"));
+ assertNotNull(elementByQName);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/TwoSchemasTest.java b/XmlSchema/src/test/java/tests/TwoSchemasTest.java
new file mode 100644
index 0000000..c4e77bd
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/TwoSchemasTest.java
@@ -0,0 +1,48 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+/*
+ * Copyright 2004,2007 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.
+ */
+
+public class TwoSchemasTest extends TestCase {
+
+ public void testTwoSchemas() throws Exception{
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("twoSchemas.wsdl"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ NodeList schemaNodes = doc.getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema","schema");
+ for (int j = 0; j < schemaNodes.getLength(); j++) {
+ Node schemaNode = schemaNodes.item(j);
+ if("schema".equals(schemaNode.getLocalName())){
+ schemaCol.read((Element)schemaNode);
+ }
+ }
+
+ assertNotNull(schemaCol.getElementByQName(new QName("http://tns.demo.org","elem1")));
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/UnionTest.java b/XmlSchema/src/test/java/tests/UnionTest.java
new file mode 100644
index 0000000..330717c
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/UnionTest.java
@@ -0,0 +1,89 @@
+package tests;
+
+import junit.framework.TestCase;
+import org.apache.ws.commons.schema.*;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/*
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ */
+public class UnionTest extends TestCase {
+
+ /**
+ * This method will test the union.
+ *
+ * @throws Exception Any exception encountered
+ */
+ public void testUnion() throws Exception {
+
+ /*
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="unionTest">
+ <simpleType>
+ <union memberTypes="float decimal"/>
+ </simpleType>
+ </element>
+
+ </schema>
+ */
+
+ QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
+ "unionTest");
+ InputStream is = new FileInputStream(Resources.asURI("union.xsd"));
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(new StreamSource(is), null);
+
+
+ XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
+ assertNotNull(elem);
+ assertEquals("unionTest", elem.getName());
+ assertEquals(new QName("http://soapinterop.org/types", "unionTest"),
+ elem.getQName());
+
+ XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
+ assertNotNull(simpleType);
+
+ XmlSchemaSimpleTypeUnion xsstu =
+ (XmlSchemaSimpleTypeUnion)simpleType.getContent();
+ assertNotNull(xsstu);
+
+ QName[] qname = xsstu.getMemberTypesQNames();
+ Set s = new HashSet();
+ s.add(new QName("http://www.w3.org/2001/XMLSchema", "float"));
+ s.add(new QName("http://www.w3.org/2001/XMLSchema", "decimal"));
+ for (int i = 0; i < qname.length; i++) {
+ assertTrue(s.remove(qname[i]));
+ }
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ assertEquals("float decimal", xsstu.getMemberTypesSource());
+
+ }
+
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomAttribute.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttribute.java
new file mode 100644
index 0000000..9c84678
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttribute.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Custom Attribute class
+ * The is will be with reference to the http://customattrib.org
+ * namespace and will have 'customAttrib' as the name and the
+ * value will be a prefix and a suffix seperated with a colon
+ * see the externalAnnotations.xsd for an example schema.
+ */
+public class CustomAttribute {
+
+ public static final QName CUSTOM_ATTRIBUTE_QNAME = new QName("http://customattrib.org","customAttrib");
+ private String prefix;
+ private String suffix;
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+
+}
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
new file mode 100644
index 0000000..71c7ba0
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeDeserializer.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.extensions.ExtensionDeserializer;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Custom attribute deserializer for our test custom attribute
+ */
+public class CustomAttributeDeserializer implements ExtensionDeserializer {
+
+ /**
+ * deserialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param name - the QName of the element/attribute to be deserialized.
+ * in the case where a deserializer is used to handle multiple elements/attributes
+ * this may be useful to determine the correct deserialization
+ * @param domNode - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or the extension attribute object if
+ * it is an attribute
+ */
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node domNode) {
+ if (CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.equals(name)){
+ Attr attrib = (Attr)domNode;
+ String value = attrib.getValue();
+ //break the attrib into
+ CustomAttribute customAttrib = new CustomAttribute();
+ String[] strings = value.split(":");
+ customAttrib.setPrefix(strings[0]);
+ customAttrib.setSuffix(strings[1]);
+
+ //put this in the schema object meta info map
+ schemaObject.addMetaInfo(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME,customAttrib);
+ }
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java
new file mode 100644
index 0000000..36af1bf
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomAttributeSerializer.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import java.util.Map;
+
+/**
+ * serializer for the custom attribute
+ */
+public class CustomAttributeSerializer implements ExtensionSerializer {
+
+ /**
+ * serialize the given element
+ *
+ * @param schemaObject - Parent schema object.contains the extension
+ * to be serialized
+ * @param classOfType - The class of type to be serialized
+ * @param domNode - the parent DOM Node that will ultimately be serialized. The XMLSchema
+ * serialization mechanism is to create a DOM tree first and serialize it
+ */
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ CustomAttribute att = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+
+ Element elt = (Element)domNode;
+ Attr att1 = elt.getOwnerDocument().createAttributeNS(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getNamespaceURI(),
+ CustomAttribute.CUSTOM_ATTRIBUTE_QNAME.getLocalPart());
+ att1.setValue(att.getPrefix() + ":" + att.getSuffix());
+ elt.setAttributeNodeNS(att1);
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
new file mode 100644
index 0000000..0414398
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtDeserializerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import junit.framework.TestCase;
+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.constants.Constants;
+import org.w3c.dom.Document;
+import tests.Resources;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Deserialize the custom extension types
+ */
+public class CustomExtDeserializerTest extends TestCase {
+
+
+ public void testDeserialization() throws Exception {
+ //set the system property for the custom extension registry
+ System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ CustomAttribute customAttrib = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+ assertNotNull(customAttrib);
+
+ }
+
+ //remove our system property
+ System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);;
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionRegistry.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionRegistry.java
new file mode 100644
index 0000000..152fa3e
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionRegistry.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+
+/**
+ * Custom extension registry to test the functionality
+ * of the extension mechanism
+ */
+public class CustomExtensionRegistry extends ExtensionRegistry {
+
+ public CustomExtensionRegistry() {
+ //register our custom type
+ registerDeserializer(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME,new CustomAttributeDeserializer());
+ registerSerializer(CustomAttribute.class,new CustomAttributeSerializer());
+ }
+
+
+}
diff --git a/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
new file mode 100644
index 0000000..08dfee0
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/attrib/CustomExtensionSerializerTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.attrib;
+
+import junit.framework.TestCase;
+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.constants.Constants;
+import org.w3c.dom.Document;
+import tests.Resources;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Test class to do a full parsing run with the extensions
+ */
+public class CustomExtensionSerializerTest extends TestCase {
+
+ public void testSerialization() throws Exception {
+ //set the system property for the custom extension registry
+ System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc1 = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc1,null);
+ assertNotNull(schema);
+
+ //now serialize it to a byte stream
+ //and build a new document out of it
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ schema.write(baos);
+
+
+ Document doc2 = documentBuilderFactory.newDocumentBuilder().
+ parse(new ByteArrayInputStream(baos.toByteArray()));
+
+ schema = schemaCol.read(doc2,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ CustomAttribute customAttrib = (CustomAttribute)metaInfoMap.get(CustomAttribute.CUSTOM_ATTRIBUTE_QNAME);
+ assertNotNull(customAttrib);
+
+ }
+
+
+ //remove our system property
+ System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
+
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomElement.java b/XmlSchema/src/test/java/tests/customext/elt/CustomElement.java
new file mode 100644
index 0000000..0da647b
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomElement.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Custom Element class
+ * The is will be with reference to the http://customattrib.org
+ * namespace and will have 'customElt' as the name and the
+ * value will have two attributes , prefix and a suffix
+ * see the externalAnnotationsElt.xsd for an example schema.
+ */
+public class CustomElement {
+
+ public static final QName CUSTOM_ELT_QNAME = new QName("http://customattrib.org","customElt");
+ private String prefix;
+ private String suffix;
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ this.suffix = suffix;
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java b/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
new file mode 100644
index 0000000..0cd4568
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomElementDeserializer.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.extensions.ExtensionDeserializer;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Custom element deserializer
+ */
+public class CustomElementDeserializer implements ExtensionDeserializer {
+ /**
+ * deserialize the given element
+ *
+ * @param schemaObject - Parent schema element
+ * @param name - the QName of the element/attribute to be deserialized.
+ * in the case where a deserializer is used to handle multiple elements/attributes
+ * this may be useful to determine the correct deserialization
+ * @param domNode - the raw DOM Node read from the source. This will be the
+ * extension element itself if for an element or the extension attribute object if
+ * it is an attribute
+ */
+ public void deserialize(XmlSchemaObject schemaObject, QName name, Node domNode) {
+ if (CustomElement.CUSTOM_ELT_QNAME.equals(name)){
+ Element elt = (Element)domNode;
+
+ CustomElement customElement = new CustomElement();
+ customElement.setPrefix(elt.getAttribute("prefix"));
+ customElement.setSuffix(elt.getAttribute("suffix"));
+
+ //put this in the schema object meta info map
+ schemaObject.addMetaInfo(CustomElement.CUSTOM_ELT_QNAME,customElement);
+ }
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java b/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
new file mode 100644
index 0000000..23edf2c
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomElementSerializer.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import org.apache.ws.commons.schema.XmlSchemaObject;
+import org.apache.ws.commons.schema.extensions.ExtensionSerializer;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import java.util.Map;
+
+/**
+ * Custom element serializer
+ */
+public class CustomElementSerializer implements ExtensionSerializer {
+ /**
+ * serialize the given element
+ *
+ * @param schemaObject - Parent schema object.contains the extension
+ * to be serialized
+ * @param classOfType - The class of type to be serialized
+ * @param domNode - the parent DOM Node that will ultimately be serialized. The XMLSchema
+ * serialization mechanism is to create a DOM tree first and serialize it
+ */
+ public void serialize(XmlSchemaObject schemaObject, Class classOfType, Node domNode) {
+ Map metaInfoMap = schemaObject.getMetaInfoMap();
+ CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+
+ Element elt = (Element)domNode;
+ Element extElt = elt.getOwnerDocument().createElementNS(CustomElement.CUSTOM_ELT_QNAME.getNamespaceURI(),
+ CustomElement.CUSTOM_ELT_QNAME.getLocalPart());
+ extElt.setAttribute("prefix",customElt.getPrefix());
+ extElt.setAttribute("suffix",customElt.getSuffix());
+
+ elt.appendChild(extElt);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java b/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
new file mode 100644
index 0000000..c5fa29b
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementDeserializerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import junit.framework.TestCase;
+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.constants.Constants;
+import org.w3c.dom.Document;
+import tests.Resources;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Test class to run through the full cycle of build-check
+ */
+public class CustomExtElementDeserializerTest extends TestCase {
+
+
+ public void testDeserialization() throws Exception {
+ //set the system property for the custom extension registry
+ System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+ assertNotNull(customElt);
+
+ }
+
+ //remove our system property
+ System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java b/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
new file mode 100644
index 0000000..e0a209e
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomExtElementSerializerTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import junit.framework.TestCase;
+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.constants.Constants;
+import org.w3c.dom.Document;
+import tests.Resources;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Test class to run through the full cycle of build-serialize-build-check
+ */
+public class CustomExtElementSerializerTest extends TestCase {
+
+
+ public void testSerialization() throws Exception {
+ //set the system property for the custom extension registry
+ System.setProperty(Constants.SystemConstants.EXTENSION_REGISTRY_KEY,
+ CustomExtensionRegistry.class.getName());
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ //now serialize it to a byte stream
+ //and build a new document out of it
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ schema.write(baos);
+ Document doc2 = documentBuilderFactory.newDocumentBuilder().
+ parse(new ByteArrayInputStream(baos.toByteArray()));
+
+ schema = schemaCol.read(doc2,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ CustomElement customElt = (CustomElement)metaInfoMap.get(CustomElement.CUSTOM_ELT_QNAME);
+ assertNotNull(customElt);
+
+ }
+
+ //remove our system property
+ System.getProperties().remove(Constants.SystemConstants.EXTENSION_REGISTRY_KEY);
+
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java b/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java
new file mode 100644
index 0000000..f8d0a9c
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/customext/elt/CustomExtensionRegistry.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.customext.elt;
+
+import org.apache.ws.commons.schema.extensions.ExtensionRegistry;
+
+/**
+ * Custom extension registry
+ */
+public class CustomExtensionRegistry extends ExtensionRegistry {
+
+ public CustomExtensionRegistry() {
+ //register our custom type
+ registerDeserializer(CustomElement.CUSTOM_ELT_QNAME,new CustomElementDeserializer());
+ registerSerializer(CustomElement.class,new CustomElementSerializer());
+ }
+
+}
diff --git a/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java b/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
new file mode 100644
index 0000000..118cee1
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ext/PlainExtensionDeserializerTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.ext;
+
+import junit.framework.TestCase;
+
+import java.util.Map;
+import java.util.Iterator;
+
+import tests.Resources;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.w3c.dom.Document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * Test the custom extension dserialization without any specialized
+ * hooks
+ */
+public class PlainExtensionDeserializerTest extends TestCase {
+
+ public void testDeserialization() throws Exception {
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ }
+ }
+
+
+ public void testDeserialization1() throws Exception {
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ // get the elements and check whether their annotations are properly
+ // populated
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ assertNotNull(elt);
+ Map metaInfoMap = elt.getMetaInfoMap();
+ assertNotNull(metaInfoMap);
+
+ }
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java b/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java
new file mode 100644
index 0000000..86eabc7
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/ext/PlainExtensionSerializerTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004,2007 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.
+ */
+package tests.ext;
+
+import junit.framework.TestCase;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import tests.Resources;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.io.ByteArrayOutputStream;
+
+/**
+ * try writing the schemas after they are built
+ */
+public class PlainExtensionSerializerTest extends TestCase {
+
+ public void testSerialization() throws Exception {
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ schema.write(new ByteArrayOutputStream());
+ }
+
+
+ public void testSerialization1() throws Exception {
+
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse(Resources.asURI("/external/externalElementAnnotations.xsd"));
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ schema.write(new ByteArrayOutputStream());
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/w3c/SchemaTest.java b/XmlSchema/src/test/java/tests/w3c/SchemaTest.java
new file mode 100644
index 0000000..08bc0c8
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/w3c/SchemaTest.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2006 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.
+ */
+package tests.w3c;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Class representing a single schema test as described in a .testSet file.
+ *
+ */
+public class SchemaTest {
+
+ private final static String SCHEMA_DOCUMENT = "schemaDocument";
+
+ private final static String EXPECTED = "expected";
+
+ private final static String CURRENT = "current";
+
+ String schemaDocumentLink = null;
+
+ private String expectedValidity = null;
+
+ String currentStatus = null;
+
+ String currentDate = null;
+
+ public SchemaTest(Element n) throws Exception {
+ NodeList nl = n.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node c = nl.item(i);
+ if (!(c instanceof Element))
+ continue;
+ Element elem = (Element) c;
+ String elemName = elem.getNodeName();
+ if (elemName.equals(SCHEMA_DOCUMENT)) {
+ schemaDocumentLink = elem.getAttributeNS(
+ "http://www.w3.org/1999/xlink", "href");
+
+ // Workaround for mistake in the NISTXMLSchema1-0-20020116.testSet file
+ // See http://lists.w3.org/Archives/Public/www-xml-schema-comments/2006JulSep/0000.html
+ if (schemaDocumentLink.equals("./NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd")) {
+ schemaDocumentLink = "./nisttest/NISTTestsAll/NISTSchema-anyURI-maxLength-1.xsd";
+ }
+ }
+
+ if (elemName.equals(EXPECTED)) {
+ expectedValidity = elem.getAttribute("validity");
+ }
+
+ if (elemName.equals(CURRENT)) {
+ currentStatus = elem.getAttribute("status");
+ currentDate = elem.getAttribute("date");
+ }
+ }
+ }
+
+ public boolean isValid() {
+ return expectedValidity.equals("valid");
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("href=");
+ sb.append(schemaDocumentLink);
+ sb.append(" expectedValidity=");
+ sb.append(expectedValidity);
+ sb.append(" currentStatus=");
+ sb.append(currentStatus);
+ sb.append(" currentDate=");
+ sb.append(currentDate);
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/XmlSchema/src/test/java/tests/w3c/TestRoundTripXSD.java b/XmlSchema/src/test/java/tests/w3c/TestRoundTripXSD.java
new file mode 100644
index 0000000..9597565
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/w3c/TestRoundTripXSD.java
@@ -0,0 +1,183 @@
+/**
+ * Copyright 2006 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.
+ */
+package tests.w3c;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.custommonkey.xmlunit.*;
+import org.w3c.dom.Element;
+
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ListIterator;
+
+/**
+ * Class to test a single schema by roundtripping it using XMLUnit
+ * cmd line parms: arg0 - valid|invalid arg1 - path to xsd file
+ *
+ */
+public class TestRoundTripXSD extends XMLTestCase {
+
+ private static boolean debug;
+
+ static {
+ String debugString = System.getProperty("debug");
+ debug = (debugString == null) ? false : debugString.equals("true");
+ }
+
+ private File fileToTest = null;
+
+ private boolean valid = false;
+
+ public final static void main(String[] args) {
+ junit.textui.TestRunner.run(new TestRoundTripXSD(new File(args[1]),
+ args[0].equals("valid")));
+ }
+
+
+ public TestRoundTripXSD() {
+ this(new File(System.getProperty("W3CTestLocation")),
+ System.getProperty("W3CTestValidity").equals("valid"));
+
+ }
+
+ public TestRoundTripXSD(File f, boolean valid) {
+ super(basename(f));
+
+ this.fileToTest = f;
+ this.valid = valid;
+ }
+
+ private static String basename(File f) {
+ String path = f.getPath();
+ int i = path.lastIndexOf(System.getProperty("file.separator"));
+ String retval = path.substring(i+1);
+ return retval;
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ testRoundTrip();
+ }
+ catch (InvocationTargetException e) {
+ e.fillInStackTrace();
+ throw e.getTargetException();
+ }
+ catch (IllegalAccessException e) {
+ e.fillInStackTrace();
+ throw e;
+ }
+ }
+
+
+ public void testRoundTrip() throws Exception {
+
+ XmlSchema schema = null;
+ DetailedDiff detaileddiffs = null;
+
+ try {
+ if (debug) {
+ System.out.println("fileToTest=" + this.fileToTest);
+ System.out.println("valid=" + this.valid);
+ }
+ schema = loadSchema(fileToTest);
+
+ // TODO: if we get here and the input was meant to be invalid perhaps
+ // should fail. Depends on whether XmlSchema is doing validation. For
+ // now we're ignoring invalid tests.
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ schema.write(baos);
+ Diff diff = new Diff(new FileReader(fileToTest),
+ new InputStreamReader(new ByteArrayInputStream(baos
+ .toByteArray())));
+
+ detaileddiffs = new DetailedDiff(diff);
+ detaileddiffs.overrideDifferenceListener(new SchemaAttrDiff());
+ boolean result = detaileddiffs.similar();
+ if (!result && debug) printFailureDetail(schema, detaileddiffs);
+ assertTrue("Serialized out schema not similar to original", result);
+ } catch (Exception e) {
+ if (this.valid) {
+ if (debug) printFailureDetail(schema, detaileddiffs);
+ throw new Exception(this.fileToTest.getPath(), e);
+ }
+ }
+
+
+ }
+
+ public XmlSchema loadSchema(File f) throws Exception {
+ XmlSchemaCollection col = new XmlSchemaCollection();
+ col.setBaseUri(f.getPath());
+ XmlSchema xmlSchema = col.read(new FileReader(f), null);
+ return xmlSchema;
+ }
+
+ static class SchemaAttrDiff extends
+ IgnoreTextAndAttributeValuesDifferenceListener {
+
+ public int differenceFound(Difference difference) {
+
+ if (difference.getId() == DifferenceConstants.ELEMENT_NUM_ATTRIBUTES
+ .getId()) {
+ // control and test have to be elements
+ // check if they are schema elements .. they only
+ // seem to have the added attributeFormDefault and
+ // elementFormDefault attributes
+ // so shldnt have more than 2 attributes difference
+ Element actualEl = (Element) difference.getControlNodeDetail()
+ .getNode();
+
+ if (actualEl.getLocalName().equals("schema")) {
+
+ int expectedAttrs = Integer.parseInt(difference
+ .getControlNodeDetail().getValue());
+ int actualAttrs = Integer.parseInt(difference
+ .getTestNodeDetail().getValue());
+ if (Math.abs(actualAttrs - expectedAttrs) <= 2) {
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ }
+ }
+ } else if (difference.getId() == DifferenceConstants.ATTR_NAME_NOT_FOUND_ID) {
+ // sometimes the serializer throws in a few extra attributes...
+ Element actualEl = (Element) difference.getControlNodeDetail()
+ .getNode();
+
+ if (actualEl.getLocalName().equals("schema")) {
+ return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+ }
+ }
+
+ return super.differenceFound(difference);
+ }
+ }
+
+ private void printFailureDetail(XmlSchema schema, DetailedDiff detaileddiffs) {
+ System.err.println(super.getName() + " failure detail");
+ System.err.println("-----");
+ schema.write(System.err);
+ if (detaileddiffs != null) {
+ ListIterator li = detaileddiffs.getAllDifferences().listIterator();
+
+ while (li.hasNext()) {
+ System.err.println(li.next());
+ }
+ }
+ }
+
+
+}
diff --git a/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaBucket.java b/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaBucket.java
new file mode 100644
index 0000000..f0cf2a4
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaBucket.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2006 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.
+ */
+package tests.w3c;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Class to represent a bucket of tests described by a set of .testSet files.
+ * All of the tests described in all of the .testSet files present in the top
+ * level of the directory supplied will be round-trip tested.
+ * Note: Subdirs are not traversed because the .testSet files in the top level
+ * of the xmlschema2002-01-16 bucket describe all the tests in the bucket.
+ * cmd line parms: arg0 - location of the directory containing .testSet files
+ * defaults to ./target/xmlschema2002-01-16
+ *
+ */
+public class TestW3CSchemaBucket extends TestSuite {
+
+ private static List allTestSetFiles;
+
+ // If tests run from cmd line without any args, run the full suite
+ private static String testSetsLocation = "./target/xmlschema2002-01-16";
+
+ public TestW3CSchemaBucket(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ try {
+ junit.textui.TestRunner.run(TestW3CSchemaBucket.suite());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static Test suite() throws Exception {
+ testSetsLocation = System.getProperty("W3CTestLocation", testSetsLocation);
+ TestSuite suite = new TestSuite("Test for tests");
+ allTestSetFiles = getTestSetFiles(testSetsLocation);
+ ListIterator li = allTestSetFiles.listIterator();
+ while (li.hasNext()) {
+ Object o = li.next();
+ File testSet = null;
+ if (o instanceof File) {
+ testSet = (File) o;
+ }
+ suite.addTest(TestW3CSchemaTestSet.suite(testSet));
+ }
+ return suite;
+ }
+
+ private static List getTestSetFiles(String testSetsLocation) throws Exception {
+ File dir = new File(testSetsLocation);
+ if (!dir.isDirectory()) {
+ throw new Exception ("testSet files location must be a directory");
+ }
+ ArrayList testSetFiles = new ArrayList();
+ File[] files = dir.listFiles();
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].getAbsolutePath().endsWith("testSet")) {
+ testSetFiles.add(files[i]);
+ }
+ }
+ return testSetFiles;
+ }
+}
diff --git a/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaTestSet.java b/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaTestSet.java
new file mode 100644
index 0000000..f9013cb
--- /dev/null
+++ b/XmlSchema/src/test/java/tests/w3c/TestW3CSchemaTestSet.java
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2006 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.
+ */
+package tests.w3c;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+
+/**
+ * Class to represent a set of schema tests as described by a .testSet file
+ * When executed each of the schemas described in the .testSet file is round-trip
+ * tested.
+ * cmd line parms: arg0 - location of the .testSet file. Defaults to:
+ * ./target/xmlschema2002-01-16/NISTXMLSchema1-0-20020116.testSet
+ *
+ */
+public class TestW3CSchemaTestSet extends TestSuite {
+
+ private List schemaTests = null;
+
+ private File testSetFile = null;
+
+ // If junit called from cmd line without any args, use the NIST test bucket
+ private static String testSetLocation = "./target/xmlschema2002-01-16/NISTXMLSchema1-0-20020116.testSet";
+
+ private TestW3CSchemaTestSet(String name, File testSetFile) {
+ super(name);
+ this.testSetFile = testSetFile;
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (args[0] != null) {
+ testSetLocation = args[0];
+ }
+ junit.textui.TestRunner.run(TestW3CSchemaTestSet.suite(new File(testSetLocation)));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static Test suite() throws Exception {
+ testSetLocation = System.getProperty("W3CTestLocation", testSetLocation);
+ return suite(new File(testSetLocation));
+ }
+
+ /**
+ * Returns a suite of TestRoundTripXSD test case instances. One for each of the tests
+ * described in the testSetFile
+ * @param testSetFile the File object of the .testSet file
+ * @throws Exception
+ */
+ public static Test suite(File testSetFile) throws Exception {
+ TestW3CSchemaTestSet suite = new TestW3CSchemaTestSet("Test for tests", testSetFile);
+ String testSetLocation = suite.testSetFile.getPath();
+ suite.schemaTests = getSchemaTests(testSetLocation);
+ ListIterator li = suite.schemaTests.listIterator();
+ while (li.hasNext()) {
+ SchemaTest st = (SchemaTest) li.next();
+ File f = new File(testSetFile.getParent(), st.schemaDocumentLink);
+
+ if (st.currentStatus!=null) {
+ if (!st.currentStatus.equals("accepted")) {
+ System.out.println("Warning: SchemaTest which isn't accepted: " + st);
+ } else if (st.isValid()){
+ // for now only test schemas that are valid
+ suite.addTest(new TestRoundTripXSD(f, true));
+ }
+ }
+ }
+ return suite;
+ }
+
+ /**
+ * Returns a list of SchemaTest objects created from the .testSet xml file passed
+ * in to the testSet parameter
+ * @param testSet the filename of the .testSet file
+ * @return List of SchemaTest objects describing the schema files to test
+ * @throws Exception
+ */
+ private static List getSchemaTests(String testSet) throws Exception {
+ List schemaTests = new ArrayList();
+ Document doc = getDocument(new InputSource(testSet));
+ NodeList testGroups = doc.getElementsByTagName("testGroup");
+ for (int i = 0; i < testGroups.getLength(); i++) {
+ Node testGroup = testGroups.item(i);
+ NodeList testGroupChildren = testGroup.getChildNodes();
+ Element schemaTestElem = null;
+ for (int j = 0; j < testGroupChildren.getLength(); j++) {
+ Node n = testGroupChildren.item(j);
+ if (!(n instanceof Element))
+ continue;
+ schemaTestElem = (Element) n;
+ if (schemaTestElem.getNodeName().equals("schemaTest")) {
+ break;
+ }
+ }
+ if (schemaTestElem != null) {
+ try {
+
+ SchemaTest schemaTest = new SchemaTest((Element) schemaTestElem);
+ if (schemaTest.schemaDocumentLink != null) schemaTests.add(schemaTest);
+ } catch (Exception e) {
+
+ }
+ }
+ }
+
+ return schemaTests;
+ }
+
+ /**
+ * Returns a DOM Document of the file passed in as the inputsource parameter
+ * @param inputSource input to read in as DOM Document
+ * @return DOM Document of the input source
+ * @throws Exception can be IOException or SAXException
+ */
+ private static Document getDocument(InputSource inputSource)
+ throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setValidating(false);
+
+ return dbf.newDocumentBuilder().parse(inputSource);
+ }
+}
diff --git a/XmlSchema/src/test/test-resources/SimpleContentRestriction.xsd b/XmlSchema/src/test/test-resources/SimpleContentRestriction.xsd
new file mode 100644
index 0000000..1612336
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/SimpleContentRestriction.xsd
@@ -0,0 +1,20 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <simpleType name="layoutComponentType">
+ <restriction base="xsd:string">
+ <enumeration value="Field"/>
+ <enumeration value="Separator"/>
+ </restriction>
+ </simpleType>
+ <simpleType name="layoutComponentTypeName">
+ <restriction base="xsd:string"/>
+ </simpleType>
+
+ <element name="foo" type="tns:layoutComponentType"/>
+ <element name="bar" type="tns:layoutComponentTypeName"/>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAux.xsd b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAux.xsd
new file mode 100644
index 0000000..57b1616
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAux.xsd
@@ -0,0 +1,23 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+
+ <xs:simpleType name="PaymentCardCodeType">
+ <xs:union>
+ <xs:simpleType>
+ <xs:restriction base="UpperCaseAlphaLength1to2"/>
+ </xs:simpleType>
+ </xs:union>
+ </xs:simpleType>
+
+ <xs:simpleType name="UpperCaseAlphaLength1to2">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[A-Z]{1,2}"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAuxNoDefaultNS.xsd b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAuxNoDefaultNS.xsd
new file mode 100644
index 0000000..7ede5f5
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeAuxNoDefaultNS.xsd
@@ -0,0 +1,27 @@
+<!--
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema" <== Removed this line
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+-->
+<schema
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+
+ <xs:simpleType name="PaymentCardCodeType">
+ <xs:union>
+ <xs:simpleType>
+ <xs:restriction base="UpperCaseAlphaLength1to2"/>
+ </xs:simpleType>
+ </xs:union>
+ </xs:simpleType>
+
+ <xs:simpleType name="UpperCaseAlphaLength1to2">
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[A-Z]{1,2}"/>
+ </xs:restriction>
+ </xs:simpleType>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBase.xsd b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBase.xsd
new file mode 100644
index 0000000..23c48ad
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBase.xsd
@@ -0,0 +1,9 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <include schemaLocation="includeAux.xsd"/>
+</schema>
diff --git a/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBaseNoDefaultNS.xsd b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBaseNoDefaultNS.xsd
new file mode 100644
index 0000000..4d0ac6d
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/WSCOMMONS-87/includeBaseNoDefaultNS.xsd
@@ -0,0 +1,9 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <include schemaLocation="includeAuxNoDefaultNS.xsd"/>
+</schema>
diff --git a/XmlSchema/src/test/test-resources/allSimpleTypes.xsd b/XmlSchema/src/test/test-resources/allSimpleTypes.xsd
new file mode 100644
index 0000000..e83548c
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/allSimpleTypes.xsd
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <!--
+ 3.2.1 string
+ 3.2.2 boolean
+ 3.2.3 decimal
+ 3.2.4 float
+ 3.2.5 double
+ 3.2.6 duration
+ 3.2.7 dateTime
+ 3.2.8 time
+ 3.2.9 date
+ 3.2.10 gYearMonth
+ 3.2.11 gYear
+ 3.2.12 gMonthDay
+ 3.2.13 gDay
+ 3.2.14 gMonth
+ 3.2.15 hexBinary
+ 3.2.16 base64Binary
+ 3.2.17 anyURI
+ 3.2.18 QName
+ 3.2.19 NOTATION
+
+ -->
+ <xs:element name="PrimitiveString" type="xs:string"/>
+ <xs:element name="PrimitiveBoolean" type="xs:boolean"/>
+ <xs:element name="PrimitiveDecimal" type="xs:decimal"/>
+ <xs:element name="PrimitiveFloat" type="xs:float"/>
+ <xs:element name="PrimitiveDouble" type="xs:double"/>
+ <xs:element name="PrimitiveDate" type="xs:date"/>
+ <xs:element name="PrimitiveDateTime" type="xs:dateTime"/>
+ <xs:element name="PrimitiveDuration" type="xs:duration"/>
+ <xs:element name="PrimitiveDay" type="xs:gDay"/>
+ <xs:element name="PrimitiveMonth" type="xs:gMonth"/>
+ <xs:element name="PrimitiveMonthDay" type="xs:gMonthDay"/>
+ <xs:element name="PrimitiveYear" type="xs:gYear"/>
+ <xs:element name="PrimitiveBase64Bin" type="xs:base64Binary"/>
+ <xs:element name="PrimitiveHexBin" type="xs:hexBinary"/>
+ <xs:element name="PrimitiveQName" type="xs:QName"/>
+ <xs:element name="PrimitiveNotation" type="xs:NOTATION"/>
+ <xs:element name="PrimitiveAnyURI" type="xs:anyURI"/>
+ <xs:element name="PrimitiveYearMonth" type="xs:gYearMonth"/>
+ <xs:element name="PrimitiveTime" type="xs:time"/>
+ <!--3.3.1 normalizedString
+ 3.3.2 token
+ 3.3.3 language
+ 3.3.4 NMTOKEN
+ 3.3.5 NMTOKENS
+ 3.3.6 Name
+ 3.3.7 NCName
+ 3.3.8 ID
+ 3.3.9 IDREF
+ 3.3.10 IDREFS
+ 3.3.11 ENTITY
+ 3.3.12 ENTITIES
+ 3.3.13 integer
+ 3.3.14 nonPositiveInteger
+ 3.3.15 negativeInteger
+ 3.3.16 long
+ 3.3.17 int
+ 3.3.18 short
+ 3.3.19 byte
+ 3.3.20 nonNegativeInteger
+ 3.3.21 unsignedLong
+ 3.3.22 unsignedInt
+ 3.3.23 unsignedShort
+ 3.3.24 unsignedByte
+ 3.3.25 positiveInteger
+
+-->
+ <xs:element name="DerivedPositiveInteger" type="xs:positiveInteger"/>
+ <xs:element name="DerivedNegativeInteger" type="xs:negativeInteger"/>
+ <xs:element name="DerivedNonNegativeInteger" type="xs:nonNegativeInteger"/>
+ <xs:element name="DerivedNonpositiveInteger" type="xs:nonPositiveInteger"/>
+ <xs:element name="DerivedUnsignedShort" type="xs:unsignedShort"/>
+ <xs:element name="DerivedUnsignedLong" type="xs:unsignedLong"/>
+ <xs:element name="DerivedUnsignedInt" type="xs:unsignedInt"/>
+ <xs:element name="DerivedUnsignedByte" type="xs:unsignedByte"/>
+ <xs:element name="DerivedLong" type="xs:long"/>
+ <xs:element name="DerivedShort" type="xs:short"/>
+ <xs:element name="DerivedInt" type="xs:int"/>
+ <xs:element name="DerivedByte" type="xs:byte"/>
+ <xs:element name="DerivedToken" type="xs:token"/>
+ <xs:element name="DerivedLanguage" type="xs:language"/>
+ <xs:element name="DerivedNMTOKEN" type="xs:NMTOKEN"/>
+ <xs:element name="DerivedNMTOKENS" type="xs:NMTOKENS"/>
+ <xs:element name="DerivedID" type="xs:ID"/>
+ <xs:element name="DerivedIDRef" type="xs:IDREF"/>
+ <xs:element name="DerivedEntity" type="xs:ENTITY"/>
+ <xs:element name="DerivedEntities" type="xs:ENTITIES"/>
+ <xs:element name="DerivedName" type="xs:Name"/>
+ <xs:element name="DerivedNameToken" type="xs:NMTOKEN"/>
+ <xs:element name="DerivedNCName" type="xs:NCName"/>
+ <xs:element name="DerivedNormalizedString" type="xs:normalizedString"/>
+ <xs:element name="DerivedInteger" type="xs:integer"/>
+</xs:schema>
diff --git a/XmlSchema/src/test/test-resources/annotation.xsd b/XmlSchema/src/test/test-resources/annotation.xsd
new file mode 100644
index 0000000..e912bb6
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/annotation.xsd
@@ -0,0 +1,69 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:abc="http://www.abc.com/validation"
+ targetNamespace="http://soapinterop.org/types">
+
+ <simpleType name="emptyAppinfo">
+ <annotation>
+ <documentation source="http://test/source/doc" xml:lang="en">testing987</documentation>
+ <appinfo/>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="emptyDocumentation">
+ <annotation>
+ <documentation/>
+ <appinfo source="http://test/source/appinfo">testing123</appinfo>
+ </annotation>
+ <restriction base="string">
+ <length value="2"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="emptyAppinfoDocumentation">
+ <annotation>
+ <documentation/>
+ <appinfo/>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="annotationTest">
+ <annotation>
+ <documentation source="http://test/source/doc" xml:lang="en">testing987</documentation>
+ <appinfo source="http://test/source/appinfo">testing123</appinfo>
+ </annotation>
+ <restriction base="string">
+ <length value="1"/>
+ </restriction>
+ </simpleType>
+
+ <annotation id="schemaAnnotation">
+ <documentation source="http://test101/source/doc" xml:lang="en">testing101</documentation>
+ <appinfo source="http://test101/source/appinfo">testing101</appinfo>
+ </annotation>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/any.xsd b/XmlSchema/src/test/test-resources/any.xsd
new file mode 100644
index 0000000..d0b15e9
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/any.xsd
@@ -0,0 +1,33 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ elementFormDefault="qualified">
+
+ <element name="department">
+ <complexType>
+ <sequence>
+ <element name="id" type="xsd:integer"/>
+ <element name="name" type="xsd:string"/>
+ <any minOccurs="5" maxOccurs="10"/>
+ </sequence>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/anyAttTest.xsd b/XmlSchema/src/test/test-resources/anyAttTest.xsd
new file mode 100644
index 0000000..459b5a3
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/anyAttTest.xsd
@@ -0,0 +1,18 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://unqualified-elements.example.com"
+ targetNamespace="http://unqualified-elements.example.com">
+
+ <element name="AnyAttContainer">
+ <complexType>
+ <sequence>
+ <element name="chileValue" type="xsd:string"/>
+ </sequence>
+ <anyAttribute namespace="##other" processContents="lax"></anyAttribute>
+ </complexType>
+ </element>
+
+ <element name="global" type="xsd:int"/>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/attributegroup.xsd b/XmlSchema/src/test/test-resources/attributegroup.xsd
new file mode 100644
index 0000000..732a2b6
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/attributegroup.xsd
@@ -0,0 +1,35 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified">
+
+ <attributeGroup name="department">
+ <attribute name="name" type="string"/>
+ <attribute name="id" type="integer"/>
+ </attributeGroup>
+
+ <element name="member">
+ <complexType>
+ <attributeGroup ref="tns:department"/>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/block.xsd b/XmlSchema/src/test/test-resources/block.xsd
new file mode 100644
index 0000000..83ab1f5
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/block.xsd
@@ -0,0 +1,16 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <element name="complexElt" block="restriction">
+ <complexType>
+ <sequence>
+ <element name="name" type="string"/>
+ <element name="age" type="int"/>
+ </sequence>
+ </complexType>
+ </element>
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/choice.xsd b/XmlSchema/src/test/test-resources/choice.xsd
new file mode 100644
index 0000000..677b484
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/choice.xsd
@@ -0,0 +1,32 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="computer">
+ <complexType>
+ <choice>
+ <element name="desktop" type="string"/>
+ <element name="laptop" type="string"/>
+ </choice>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/circular/a.xsd b/XmlSchema/src/test/test-resources/circular/a.xsd
new file mode 100644
index 0000000..1a42314
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/circular/a.xsd
@@ -0,0 +1,8 @@
+<schema targetNamespace="urn:xmlschema:recursive:a"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ elementFormDefault="qualified" >
+
+ <import namespace="urn:xmlschema:recursive:b" schemaLocation="b.xsd"></import>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/circular/b.xsd b/XmlSchema/src/test/test-resources/circular/b.xsd
new file mode 100644
index 0000000..e466dc6
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/circular/b.xsd
@@ -0,0 +1,8 @@
+<schema targetNamespace="urn:xmlschema:recursive:b"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ elementFormDefault="qualified" >
+
+ <import namespace="urn:xmlschema:recursive:a" schemaLocation="a.xsd"></import>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/constraints.xsd b/XmlSchema/src/test/test-resources/constraints.xsd
new file mode 100644
index 0000000..453a8cb
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/constraints.xsd
@@ -0,0 +1,86 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ elementFormDefault="qualified">
+
+ <element name="constraintTest">
+ <complexType>
+ <sequence>
+ <element name="manufacturers" type="tns:ManufacturerType"/>
+ <element name="products" type="tns:ProductType"/>
+ </sequence>
+ </complexType>
+
+ <unique name="uniqueTest">
+ <selector xpath="tns:manufacturers/tns:location"/>
+ <field xpath="@district"/>
+ </unique>
+
+ <key name="keyTest">
+ <selector xpath="tns:products/tns:productName"/>
+ <field xpath="@productId"/>
+ </key>
+
+ <keyref name="keyRefTest" refer="tns:keyTest">
+ <selector xpath="tns:manufacturers/tns:location/tns:productName"/>
+ <field xpath="@productId"/>
+ </keyref>
+
+ </element>
+
+ <complexType name="ManufacturerType">
+ <sequence>
+ <element name="location" maxOccurs="unbounded">
+ <complexType>
+ <sequence>
+ <element name="productName" maxOccurs="unbounded">
+ <complexType>
+ <complexContent>
+ <extension base="string">
+ <attribute name="productId" type="integer"/>
+ <attribute name="units" type="integer"/>
+ </extension>
+ </complexContent>
+ </complexType>
+ </element>
+ </sequence>
+ <attribute name="district" type="integer"/>
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+ <complexType name="ProductType">
+ <sequence>
+ <element name="productName" maxOccurs="unbounded">
+ <complexType>
+ <simpleContent>
+ <extension base="string">
+ <attribute name="productId" type="integer"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element>
+ </sequence>
+ </complexType>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/credit-card-faults.xsd b/XmlSchema/src/test/test-resources/credit-card-faults.xsd
new file mode 100644
index 0000000..fc8bfee
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/credit-card-faults.xsd
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://finance.example.com/CreditCardFaults/xsd"
+ xmlns:tns="http://finance.example.com/CreditCardFaults/xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.w3.org/2001/XMLSchema ../../../xmlcatalog/xsd/XMLSchema.xsd">
+
+ <element name="CreditCardNumber" type="string"></element>
+
+ <element name="CreditCardType">
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="AMEX" />
+ <enumeration value="MASTERCARD" />
+ <enumeration value="VISA" />
+ </restriction>
+ </simpleType>
+ </element>
+
+ <element name="ExpirationDate" type="date"></element>
+
+ <element name="InvalidCreditCardNumber">
+ <complexType>
+ <sequence>
+ <element ref="tns:CreditCardType"></element>
+ <element ref="tns:CreditCardNumber"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="InvalidExpirationDate">
+ <complexType>
+ <sequence>
+ <element ref="tns:CreditCardNumber"></element>
+ <element ref="tns:ExpirationDate"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="ExpiredCreditCard">
+ <complexType>
+ <sequence>
+ <element ref="tns:CreditCardNumber"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="CancelledCreditCard">
+ <complexType>
+ <sequence>
+ <element ref="tns:CreditCardNumber"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/deriverestriction.xsd b/XmlSchema/src/test/test-resources/deriverestriction.xsd
new file mode 100644
index 0000000..0c7c274
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/deriverestriction.xsd
@@ -0,0 +1,44 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+
+ <complexType name="AssemblyRequiredProduct">
+ <sequence>
+ <element name="Name" type="string"/>
+ <element name="Description" type="string" nillable="true"/>
+ <element name="Parts" type="string" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="NoAssemblyRequiredProduct">
+ <complexContent>
+ <restriction base="tns:AssemblyRequiredProduct">
+ <sequence>
+ <element name="Name" type="string"/>
+ <element name="Description" type="string" nillable="true"/>
+ <element name="Parts" type="string"/>
+ </sequence>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/elementForm.xsd b/XmlSchema/src/test/test-resources/elementForm.xsd
new file mode 100644
index 0000000..86500fb
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/elementForm.xsd
@@ -0,0 +1,19 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://unqualified-elements.example.com"
+ targetNamespace="http://unqualified-elements.example.com">
+
+ <element name="unQualifiedLocals">
+ <complexType>
+ <sequence>
+ <element name="unqualified" type="xsd:string"/>
+ <element name="qualified" form="qualified" type="xsd:int"/>
+<!-- <element ref="tns:global"/>-->
+ </sequence>
+ </complexType>
+ </element>
+
+ <element name="global" type="xsd:int"/>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/elementreferences.xsd b/XmlSchema/src/test/test-resources/elementreferences.xsd
new file mode 100644
index 0000000..8129b6d
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/elementreferences.xsd
@@ -0,0 +1,28 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct">
+ <sequence>
+ <element name="varString" type="xsd:string"/>
+ <element name="varInt" type="xsd:int"/>
+ <element name="varFloat" type="xsd:float"/>
+ <element name="varStruct" type="tns:Struct"/>
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct"/>
+
+ <element name="attTests">
+ <complexType>
+ <sequence>
+ <element ref="tns:attrTest" maxOccurs="5"></element>
+ </sequence>
+ </complexType>
+ </element>
+
+
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd b/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
new file mode 100644
index 0000000..c08a960
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/external/externalAnnotations.xsd
@@ -0,0 +1,19 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:ext="http://customattrib.org"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct" ext:customAttrib="toplevel:type">
+ <sequence>
+ <element name="varString" type="xsd:string" ext:customAttrib="inner:element"/>
+ <element name="varInt" type="xsd:int" ext:customAttrib="inner:element"/>
+ <element name="varFloat" type="xsd:float" ext:customAttrib="inner:element"/>
+ <element name="varStruct" type="tns:Struct" ext:customAttrib="inner:element"/>
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct" ext:customAttrib="toplevel:element"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/external/externalElementAnnotations.xsd b/XmlSchema/src/test/test-resources/external/externalElementAnnotations.xsd
new file mode 100644
index 0000000..cfa8459
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/external/externalElementAnnotations.xsd
@@ -0,0 +1,22 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ xmlns:ext="http://customattrib.org"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="Struct">
+ <ext:customElt prefix="ext" suffix="type"/>
+ <sequence>
+ <element name="varString" type="xsd:string"/>
+ <element name="varInt" type="xsd:int" />
+ <element name="varFloat" type="xsd:float" />
+ <element name="varStruct" type="tns:Struct" />
+ </sequence>
+ </complexType>
+
+ <element name="attrTest" type="tns:Struct" >
+ <ext:customElt prefix="ext" suffix="elt"/>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/externalAttributes.xsd b/XmlSchema/src/test/test-resources/externalAttributes.xsd
new file mode 100644
index 0000000..3ad4d96
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/externalAttributes.xsd
@@ -0,0 +1,20 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://unqualified-elements.example.com"
+ xmlns:test="http://test-namespace"
+ targetNamespace="http://unqualified-elements.example.com"
+ test:level="1">
+
+ <element name="AnyAttContainer" test:level="2">
+ <complexType>
+ <sequence>
+ <element name="chileValue" type="xsd:string"/>
+ </sequence>
+ <anyAttribute namespace="##other" processContents="lax"></anyAttribute>
+ </complexType>
+ </element>
+
+ <element name="global" type="xsd:int"/>
+
+</schema>
diff --git a/XmlSchema/src/test/test-resources/facets.xsd b/XmlSchema/src/test/test-resources/facets.xsd
new file mode 100644
index 0000000..aebe737
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/facets.xsd
@@ -0,0 +1,106 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <simpleType name="zipCode">
+ <restriction base="string">
+ <length value="5"/>
+ <pattern value="\d{5}"/>
+ </restriction>
+ </simpleType>
+ <element name="myZipCode" type="tns:zipCode"/>
+
+ <simpleType name="age">
+ <restriction base="decimal">
+ <totalDigits value="3"/>
+ </restriction>
+ </simpleType>
+ <element name="myAge" type="tns:age"/>
+
+ <simpleType name="distance">
+ <restriction base="integer">
+ <maxInclusive value="100" fixed="true"/>
+ <minInclusive value="0"/>
+ </restriction>
+ </simpleType>
+ <element name="myDistance" type="tns:distance"/>
+
+ <simpleType name="weight">
+ <restriction base="integer">
+ <maxExclusive value="200"/>
+ <minExclusive value="1"/>
+ </restriction>
+ </simpleType>
+ <element name="myWeight" type="tns:weight"/>
+
+ <simpleType name="creditCardNumber">
+ <restriction base="integer">
+ <pattern value="\d{15}"/>
+ </restriction>
+ </simpleType>
+ <element name="myCreditCardNumber" type="tns:creditCardNumber"/>
+
+ <simpleType name="noWhiteSpace">
+ <restriction base="normalizedString">
+ <whiteSpace value="collapse"/>
+ </restriction>
+ </simpleType>
+ <element name="myWhiteSpace" type="tns:noWhiteSpace"/>
+
+ <simpleType name="petWeight">
+ <restriction base="tns:weight">
+ <maxExclusive value="50"/>
+ <minExclusive value="5"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="fixedDistance">
+ <restriction base="tns:distance">
+ <minInclusive value="1"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="height">
+ <restriction base="decimal">
+ <totalDigits value="3"/>
+ <fractionDigits value="2"/>
+ </restriction>
+ </simpleType>
+ <element name="myHeight" type="tns:height"/>
+
+ <simpleType name="yardLength">
+ <restriction base="nonNegativeInteger">
+ <minLength value="45"/>
+ <maxLength value="205"/>
+ </restriction>
+ </simpleType>
+ <element name="myYardLength" type="tns:yardLength"/>
+
+ <simpleType name="layoutComponentType">
+ <restriction base="string">
+ <enumeration value="Field"/>
+ <enumeration value="Separator"/>
+ </restriction>
+ </simpleType>
+ <element name="layoutComponent" type="tns:layoutComponentType"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/forwardRef.xsd b/XmlSchema/src/test/test-resources/forwardRef.xsd
new file mode 100644
index 0000000..b1fc90e
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/forwardRef.xsd
@@ -0,0 +1,62 @@
+<schema
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="attrTest">
+ <complexType>
+ <sequence>
+ <element name="foo" type="xsd:string"/>
+ </sequence>
+ <attribute name="forward" type="xsd:int"/>
+ </complexType>
+ </element>
+
+ <complexType name="Struct">
+ <sequence>
+ <element name="varString" type="xsd:string"/>
+ <element name="varInt" type="xsd:int"/>
+ <element name="varFloat" type="xsd:float"/>
+ <element name="varStruct" type="tns:Struct"/>
+ <element name="varForward" type="tns:Forward"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="Forward">
+ <sequence>
+ <element name="soapStruct" type="tns:Struct"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="BaseStruct">
+ <sequence>
+ <element name="structMessage" type="tns:Struct"/>
+ <element name="shortMessage" type="xsd:short"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="ExtendedStruct">
+ <complexContent>
+ <extension base="tns:BaseStruct">
+ <sequence>
+ <element name="stringMessage" type="xsd:string"/>
+ <element name="intMessage" type="xsd:int"/>
+ <element name="anotherIntMessage" type="xsd:int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="MoreExtendedStruct">
+ <complexContent>
+ <extension base="tns:ExtendedStruct">
+ <sequence>
+ <element name="booleanMessage" type="xsd:boolean"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <element name="foo" type="tns:ExtendedStruct"/>
+</schema>
diff --git a/XmlSchema/src/test/test-resources/getBalance.xsd b/XmlSchema/src/test/test-resources/getBalance.xsd
new file mode 100644
index 0000000..c281b8a
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/getBalance.xsd
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:complexType name="cinfoct">
+ <xsd:sequence>
+ <xsd:element name="customerSurname" type="xsd:string" />
+ <xsd:element name="customerForname" type="xsd:string" />
+ <xsd:element name="branchCode">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern
+ value="[0-9]{2}[\-][0-9]{2}[\-][0-9]{2}" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:element name="custInfo" type="cinfoct" />
+ <xsd:complexType name="accinfct">
+ <xsd:sequence maxOccurs="unbounded" minOccurs="0">
+ <xsd:element name="accName">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="Cheque" />
+ <xsd:enumeration value="Credit" />
+ <xsd:enumeration value="Savings" />
+ <xsd:enumeration value="Loan" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="accNumber">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern value="[0-9]{12}" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="accBalance">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:decimal">
+ <xsd:fractionDigits value="2" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:element name="accInfo" type="accinfct" />
+</xsd:schema>
diff --git a/XmlSchema/src/test/test-resources/group.xsd b/XmlSchema/src/test/test-resources/group.xsd
new file mode 100644
index 0000000..afcdb17
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/group.xsd
@@ -0,0 +1,47 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <group name="priceGroup">
+ <annotation>
+ <documentation xml:lang="en">
+ A price is any one of the following:
+ * Full Price (with amount)
+ * Sale Price (with amount and authorization)
+ * Clearance Price (with amount and authorization)
+ * Free (with authorization)
+ </documentation>
+ </annotation>
+ <choice id="pg.choice">
+ <element name="fullPrice" type="decimal"/>
+ <element name="salePrice" type="decimal"/>
+ <element name="clearancePrice" type="decimal"/>
+ <element name="freePrice" type="decimal"/>
+ </choice>
+ </group>
+
+ <element name="price">
+ <complexType>
+ <group ref="tns:priceGroup" />
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/importAux.xsd b/XmlSchema/src/test/test-resources/importAux.xsd
new file mode 100644
index 0000000..5c0ce93
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/importAux.xsd
@@ -0,0 +1,14 @@
+<schema targetNamespace="http://soapinterop.org/xsd2"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <complexType name="SOAPStruct">
+ <all>
+ <element name="varFloat" type="xsd:float"/>
+ <element name="varInt" type="xsd:int"/>
+ <element name="varString" type="xsd:string"/>
+ </all>
+ </complexType>
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/importBase.xsd b/XmlSchema/src/test/test-resources/importBase.xsd
new file mode 100644
index 0000000..6903263
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/importBase.xsd
@@ -0,0 +1,10 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <import namespace="http://soapinterop.org/xsd2" schemaLocation="importAux.xsd"></import>
+ <element name="echoStructParam" type="xsd2:SOAPStruct"/>
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/include.xsd b/XmlSchema/src/test/test-resources/include.xsd
new file mode 100644
index 0000000..8f8ddd9
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/include.xsd
@@ -0,0 +1,26 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <include schemaLocation="src/test/test-resources/include2.xsd"/>
+ <include schemaLocation="src/test/test-resources/include3.xsd"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/include2.xsd b/XmlSchema/src/test/test-resources/include2.xsd
new file mode 100644
index 0000000..66a90da
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/include2.xsd
@@ -0,0 +1,25 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="test1include" type="string"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/include3.xsd b/XmlSchema/src/test/test-resources/include3.xsd
new file mode 100644
index 0000000..6e800ca
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/include3.xsd
@@ -0,0 +1,25 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="test2include" type="integer"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd b/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd
new file mode 100644
index 0000000..5c03bbd
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/includedWithoutNamespace.xsd
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified">
+ <xs:simpleType name="XdwsPrincipalId">
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+
+ <xs:simpleType name="XdwsGroupId">
+ <xs:restriction base="XdwsPrincipalId"/>
+ </xs:simpleType>
+</xs:schema>
diff --git a/XmlSchema/src/test/test-resources/includingWithNamespace.xsd b/XmlSchema/src/test/test-resources/includingWithNamespace.xsd
new file mode 100644
index 0000000..b403a46
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/includingWithNamespace.xsd
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://tns.demo.org"
+ targetNamespace="http://tns.demo.org"
+ attributeFormDefault="unqualified"
+ elementFormDefault="qualified">
+ <xs:include schemaLocation="src/test/test-resources/includedWithoutNamespace.xsd"/>
+
+ <xs:element name="foo" type="tns:XdwsGroupId"/>
+</xs:schema>
diff --git a/XmlSchema/src/test/test-resources/list.xsd b/XmlSchema/src/test/test-resources/list.xsd
new file mode 100644
index 0000000..3b0aeec
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/list.xsd
@@ -0,0 +1,36 @@
+<!--
+ *
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="workDays">
+ <simpleType>
+ <restriction base="tns:daysInWeek">
+ <length value="5"/>
+ </restriction>
+ </simpleType>
+ </element>
+
+ <simpleType name="daysInWeek">
+ <list itemType="xsd:integer"/>
+ </simpleType>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/mixedContent.xsd b/XmlSchema/src/test/test-resources/mixedContent.xsd
new file mode 100644
index 0000000..274f442
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/mixedContent.xsd
@@ -0,0 +1,16 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <element name="complexElt">
+ <complexType mixed="true">
+ <sequence>
+ <element name="name" type="string"/>
+ <element name="age" type="int"/>
+ </sequence>
+ </complexType>
+ </element>
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/notation.xsd b/XmlSchema/src/test/test-resources/notation.xsd
new file mode 100644
index 0000000..277dc6f
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/notation.xsd
@@ -0,0 +1,51 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <notation name="teamLogo"
+ system="com/team/graphics/teamLogo"
+ public="http://www.team.com/graphics/teamLogo"
+ id="notation.teamLogo">
+ <annotation>
+ <documentation xml:lang="en">Location of the corporate logo.</documentation>
+ </annotation>
+ </notation>
+
+ <notation name="teamMascot"
+ system="com/team/graphics/teamMascot"
+ public="http://www.team.com/graphics/teamMascot"
+ id="notation.teamMascot">
+ <annotation>
+ <documentation xml:lang="en">Location of the corporate mascot.</documentation>
+ </annotation>
+ </notation>
+
+ <element name="demoNotation">
+ <simpleType>
+ <restriction base="NOTATION">
+ <enumeration value="tns:teamLogo"/>
+ <enumeration value="tns:teamMascot"/>
+ </restriction>
+ </simpleType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine1.xsd b/XmlSchema/src/test/test-resources/redefine1.xsd
new file mode 100644
index 0000000..1729933
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine1.xsd
@@ -0,0 +1,34 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <complexType name="person">
+ <sequence>
+ <element name="firstname" type="string"/>
+ <element name="lastname" type="string"/>
+ </sequence>
+ </complexType>
+
+ <element name="customer" type="tns:person"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine2.xsd b/XmlSchema/src/test/test-resources/redefine2.xsd
new file mode 100644
index 0000000..4194a65
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine2.xsd
@@ -0,0 +1,39 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="src/test/test-resources/redefine1.xsd">
+ <complexType name="person">
+ <complexContent>
+ <extension base="tns:person">
+ <sequence>
+ <element name="id" type="string"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ </redefine>
+
+ <element name="vip" type="tns:person"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine3.xsd b/XmlSchema/src/test/test-resources/redefine3.xsd
new file mode 100644
index 0000000..3e72c7b
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine3.xsd
@@ -0,0 +1,28 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:simpleType name="drinksize">
+ <xsd:restriction base="xsd:integer"/>
+ </xsd:simpleType>
+
+ <xsd:element name="size" type="drinksize"/>
+
+</xsd:schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine4.xsd b/XmlSchema/src/test/test-resources/redefine4.xsd
new file mode 100644
index 0000000..87a0bbc
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine4.xsd
@@ -0,0 +1,36 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="src/test/test-resources/redefine3.xsd">
+ <simpleType name="drinksize">
+ <restriction base="tns:drinksize">
+ <minInclusive value="1"/>
+ <maxInclusive value="3"/>
+ </restriction>
+ </simpleType>
+ </redefine>
+
+ <element name="childsizedrink" type="tns:drinksize"/>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine5.xsd b/XmlSchema/src/test/test-resources/redefine5.xsd
new file mode 100644
index 0000000..3d16717
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine5.xsd
@@ -0,0 +1,33 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <group name="PrologGroup">
+ <sequence>
+ <element name="date" type="string"/>
+ <element name="author" type="string"/>
+ <element name="defect" type="integer"/>
+ </sequence>
+ </group>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine6.xsd b/XmlSchema/src/test/test-resources/redefine6.xsd
new file mode 100644
index 0000000..d3da5a9
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine6.xsd
@@ -0,0 +1,34 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="src/test/test-resources/redefine5.xsd">
+ <group name="PrologGroup">
+ <sequence>
+ <group ref="tns:PrologGroup"/>
+ <element name="description" type="string"/>
+ </sequence>
+ </group>
+ </redefine>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine7.xsd b/XmlSchema/src/test/test-resources/redefine7.xsd
new file mode 100644
index 0000000..ac5c8d7
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine7.xsd
@@ -0,0 +1,31 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <attributeGroup name="AttribGroup">
+ <attribute name="type" type="string"/>
+ <attribute name="units" type="string"/>
+ <attribute name="serialId" type="string"/>
+ </attributeGroup>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/redefine8.xsd b/XmlSchema/src/test/test-resources/redefine8.xsd
new file mode 100644
index 0000000..4c54b01
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/redefine8.xsd
@@ -0,0 +1,32 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+ * @author Brent Ulbricht
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <redefine schemaLocation="src/test/test-resources/redefine7.xsd">
+ <attributeGroup name="AttribGroup">
+ <attribute name="type" type="string"/>
+ <attribute name="units" type="string"/>
+ </attributeGroup>
+ </redefine>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/resSvc.xsd b/XmlSchema/src/test/test-resources/resSvc.xsd
new file mode 100644
index 0000000..ae01ffa
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/resSvc.xsd
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://greath.example.com/2004/schemas/resSvc"
+ xmlns="http://greath.example.com/2004/schemas/resSvc"
+ xmlns:cc="http://finance.example.com/CreditCardFaults/xsd">
+
+ <xs:import xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ namespace="http://finance.example.com/CreditCardFaults/xsd"
+ schemaLocation="credit-card-faults.xsd" />
+
+ <xs:element name="checkAvailability" type="tCheckAvailability" />
+ <xs:complexType name="tCheckAvailability">
+ <xs:sequence>
+ <xs:element name="checkInDate" type="xs:date" />
+ <xs:element name="checkOutDate" type="xs:date" />
+ <xs:element name="roomType" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="checkAvailabilityResponse" type="xs:double" />
+
+ <xs:element name="makeReservation" type="tMakeReservation" />
+ <xs:complexType name="tMakeReservation">
+ <xs:sequence>
+ <xs:element ref="cc:CreditCardType" />
+ <xs:element ref="cc:CreditCardNumber" />
+ <xs:element name="checkInDate" type="xs:date" />
+ <xs:element name="checkOutDate" type="xs:date" />
+ <xs:element name="roomType" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="makeReservationResponse" type="xs:double" />
+
+ <xs:element name="invalidDataError" type="xs:string" />
+
+</xs:schema>
diff --git a/XmlSchema/src/test/test-resources/screstriction.xsd b/XmlSchema/src/test/test-resources/screstriction.xsd
new file mode 100644
index 0000000..4adeb76
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/screstriction.xsd
@@ -0,0 +1,43 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified">
+
+ <simpleType name="drinksize">
+ <restriction base="string">
+ <enumeration value="small"/>
+ <enumeration value="medium"/>
+ <enumeration value="large"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="dietdrinksize">
+ <simpleContent>
+ <restriction base="tns:drinksize">
+ <enumeration value="small"/>
+ <enumeration value="medium"/>
+ <attribute name="units" type="string" use="required"/>
+ <attribute name="id" type="integer" use="required" default="001"/>
+ </restriction>
+ </simpleContent>
+ </complexType>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/simplecontentextension.xsd b/XmlSchema/src/test/test-resources/simplecontentextension.xsd
new file mode 100644
index 0000000..bf22130
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/simplecontentextension.xsd
@@ -0,0 +1,36 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types"
+ attributeFormDefault="qualified">
+
+ <element name="height">
+ <complexType>
+ <simpleContent>
+ <extension base="integer">
+ <attribute name="units" type="string" use="required"/>
+ <attribute name="id" type="integer" use="required" default="001"/>
+ <attribute name="desc" type="decimal" fixed="1.1"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/subgroup.xsd b/XmlSchema/src/test/test-resources/subgroup.xsd
new file mode 100644
index 0000000..fa4edda
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/subgroup.xsd
@@ -0,0 +1,39 @@
+<!--
+ *
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="ID" type="string"/>
+
+ <element name="Name" substitutionGroup="tns:ID" type="string"/>
+
+ <element name="IDBlock" type="string" block="substitution"/>
+
+ <element name="TestSubstitutionGroup">
+ <complexType>
+ <sequence>
+ <element ref="tns:ID"/>
+ </sequence>
+ </complexType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/twoSchemas-ref.wsdl b/XmlSchema/src/test/test-resources/twoSchemas-ref.wsdl
new file mode 100644
index 0000000..35169f1
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/twoSchemas-ref.wsdl
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:ns1="http://ns1.demo.org"
+ xmlns:tns="http://tns.demo.org"
+ xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tns.demo.org">
+ <wsdl:types>
+ <xsd:schema targetNamespace="http://tns.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+ <xsd:element name="elem1">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element ref="ns1:elem3" minOccurs="1" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <xsd:schema targetNamespace="http://ns1.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+ <xsd:element name="elem3" type="xsd:string"/>
+ </xsd:schema>
+ </wsdl:types>
+</wsdl:definitions>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/twoSchemas.wsdl b/XmlSchema/src/test/test-resources/twoSchemas.wsdl
new file mode 100644
index 0000000..17abe9b
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/twoSchemas.wsdl
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:ns1="http://ns1.demo.org"
+ xmlns:tns="http://tns.demo.org"
+ xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tns.demo.org">
+ <wsdl:types>
+ <xsd:schema targetNamespace="http://tns.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+ <xsd:element name="elem1">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="elem2" type="ns1:elem3" minOccurs="1" maxOccurs="1"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <xsd:schema targetNamespace="http://ns1.demo.org" elementFormDefault="qualified" attributeFormDefault="qualified">
+ <xsd:complexType name="elem3">
+ <xsd:sequence>
+ <xsd:element name="elem4" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:schema>
+ </wsdl:types>
+</wsdl:definitions>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/union.xsd b/XmlSchema/src/test/test-resources/union.xsd
new file mode 100644
index 0000000..1a1f330
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/union.xsd
@@ -0,0 +1,29 @@
+<!--
+ * Copyright 2004,2007 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.
+ *
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://soapinterop.org/types"
+ targetNamespace="http://soapinterop.org/types">
+
+ <element name="unionTest">
+ <simpleType>
+ <union memberTypes="float decimal"/>
+ </simpleType>
+ </element>
+
+</schema>
\ No newline at end of file
diff --git a/XmlSchema/src/test/test-resources/unqualifiedTypes.xsd b/XmlSchema/src/test/test-resources/unqualifiedTypes.xsd
new file mode 100644
index 0000000..06cb8a4
--- /dev/null
+++ b/XmlSchema/src/test/test-resources/unqualifiedTypes.xsd
@@ -0,0 +1,16 @@
+<schema targetNamespace="http://soapinterop.org/xsd"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsd1="http://soapinterop.org/xsd"
+ xmlns:xsd2="http://soapinterop.org/xsd2"
+ elementFormDefault="qualified">
+ <element name="complexElt">
+ <complexType>
+ <sequence>
+ <element name="name" type="string"/>
+ <element name="age" type="int"/>
+ </sequence>
+ </complexType>
+ </element>
+</schema>
\ No newline at end of file