You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2006/06/21 03:58:18 UTC
svn commit: r415872 - in /webservices/commons/trunk/modules/XmlSchema:
src/org/apache/ws/commons/schema/ test-resources/ test/tests/
Author: dims
Date: Tue Jun 20 18:58:18 2006
New Revision: 415872
URL: http://svn.apache.org/viewvc?rev=415872&view=rev
Log:
Fix for WSCOMMONS-28 - substitutionGroup not set for XmlSchemaElement
Fix for WSCOMMONS-30 - Avoid cost of reflection in XmlSchemaFacet
Added:
webservices/commons/trunk/modules/XmlSchema/test-resources/facets.xsd
webservices/commons/trunk/modules/XmlSchema/test-resources/subgroup.xsd
webservices/commons/trunk/modules/XmlSchema/test/tests/FacetsTest.java
Modified:
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java
webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaFacet.java
Modified: webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java?rev=415872&r1=415871&r2=415872&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/SchemaBuilder.java Tue Jun 20 18:58:18 2006
@@ -1583,7 +1583,24 @@
if (el.hasAttribute("nillable"))
element.isNillable =
new Boolean(el.getAttribute("nillable")).booleanValue();
-
+
+ if (el.hasAttribute("substitutionGroup")) {
+ String substitutionGroup = el.getAttribute("substitutionGroup");
+ String[] args = Tokenizer.tokenize(substitutionGroup, ":");
+ String namespace = null;
+ if (args.length > 1) {
+ Object result = schema.namespaces.get(args[0]);
+ if (result == null) {
+ throw new XmlSchemaException("No namespace found in"
+ + "given substitionGroup");
+ }
+ namespace = result.toString();
+ } else {
+ namespace = schema.targetNamespace;
+ }
+ substitutionGroup = Tokenizer.lastToken(substitutionGroup, ":")[1];
+ element.setSubstitutionGroup(new QName(namespace, substitutionGroup));
+ }
element.minOccurs = getMinOccurs(el);
element.maxOccurs = getMaxOccurs(el);
Modified: webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaFacet.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaFacet.java?rev=415872&r1=415871&r2=415872&view=diff
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaFacet.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaFacet.java Tue Jun 20 18:58:18 2006
@@ -1,86 +1,114 @@
-/*
- * Copyright 2004,2005 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.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;
- }
- try {
- // TODO : move this from reflection to a if condition and avoid cost
- // of reflection
- Class facetClass = Class.forName("org.apache.ws.commons.schema.XmlSchema"
- + Character.toUpperCase(name.charAt(0))
- + name.substring(1) + "Facet");
- XmlSchemaFacet facet = (XmlSchemaFacet) facetClass.newInstance();
- facet.setFixed(fixed);
- facet.setValue(el.getAttribute("value"));
- return facet;
- } catch (ClassNotFoundException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (InstantiationException e) {
- throw new XmlSchemaException(e.getMessage());
- } catch (IllegalAccessException e) {
- throw new XmlSchemaException(e.getMessage());
- }
-
- }
-}
+/*
+ * Copyright 2004,2005 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;
+
+import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
+import org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet;
+import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaPatternFacet;
+import org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet;
+import org.apache.ws.commons.schema.XmlSchemaWhiteSpaceFacet;
+
+/**
+ * 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 = null;
+ 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.");
+ }
+ facet.setFixed(fixed);
+ facet.setValue(el.getAttribute("value"));
+ return facet;
+ }
+}
Added: webservices/commons/trunk/modules/XmlSchema/test-resources/facets.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/facets.xsd?rev=415872&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/facets.xsd (added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/facets.xsd Tue Jun 20 18:58:18 2006
@@ -0,0 +1,106 @@
+<!--
+ * Copyright 2004,2005 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
Added: webservices/commons/trunk/modules/XmlSchema/test-resources/subgroup.xsd
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test-resources/subgroup.xsd?rev=415872&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test-resources/subgroup.xsd (added)
+++ webservices/commons/trunk/modules/XmlSchema/test-resources/subgroup.xsd Tue Jun 20 18:58:18 2006
@@ -0,0 +1,39 @@
+<!--
+ *
+ * Copyright 2004,2005 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
Added: webservices/commons/trunk/modules/XmlSchema/test/tests/FacetsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/test/tests/FacetsTest.java?rev=415872&view=auto
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/test/tests/FacetsTest.java (added)
+++ webservices/commons/trunk/modules/XmlSchema/test/tests/FacetsTest.java Tue Jun 20 18:58:18 2006
@@ -0,0 +1,656 @@
+package tests;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSimpleType;
+import org.apache.ws.commons.schema.XmlSchemaPatternFacet;
+import org.apache.ws.commons.schema.XmlSchemaLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet;
+import org.apache.ws.commons.schema.XmlSchemaFractionDigitsFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinInclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinExclusiveFacet;
+import org.apache.ws.commons.schema.XmlSchemaMinLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaMaxLengthFacet;
+import org.apache.ws.commons.schema.XmlSchemaWhiteSpaceFacet;
+import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
+
+import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
+
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaObjectCollection;
+
+/*
+ * Copyright 2004,2005 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 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } else if (o instanceof XmlSchemaPatternFacet) {
+ assertEquals("\\d{5}", ((XmlSchemaPatternFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaPatternFacet)o).isFixed());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } else if (o instanceof XmlSchemaMinInclusiveFacet) {
+ assertEquals("0", ((XmlSchemaMinInclusiveFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMinInclusiveFacet)o).isFixed());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } else if (o instanceof XmlSchemaMinExclusiveFacet) {
+ assertEquals("1", ((XmlSchemaMinExclusiveFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMinExclusiveFacet)o).isFixed());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } else if (o instanceof XmlSchemaTotalDigitsFacet) {
+ assertEquals("3", ((XmlSchemaTotalDigitsFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaTotalDigitsFacet)o).isFixed());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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());
+ } else if (o instanceof XmlSchemaMaxLengthFacet) {
+ assertEquals("205", ((XmlSchemaMaxLengthFacet)o).getValue());
+ assertEquals(false, ((XmlSchemaMaxLengthFacet)o).isFixed());
+ } 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("test-resources/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();
+
+ System.out.println("*** " + simpleType.toString("xsd", 4) + " ***");
+
+ 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));
+ }
+
+ assertTrue("The set should have been empty, but instead contained: "
+ + s + ".",
+ s.isEmpty());
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org