ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1610783 - in /webservices/xmlschema/trunk: .gitignore xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java xmlschema-core/src/test/java/tests/FacetsTest.java
Date Tue, 15 Jul 2014 18:00:20 GMT
Author: dkulp
Date: Tue Jul 15 18:00:19 2014
New Revision: 1610783

URL: http://svn.apache.org/r1610783
Log:
[XMLSCHEMA-33] Define facets for the built in types
Patch from Michael Pigott applied

Modified:
    webservices/xmlschema/trunk/.gitignore
    webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
    webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/FacetsTest.java

Modified: webservices/xmlschema/trunk/.gitignore
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/.gitignore?rev=1610783&r1=1610782&r2=1610783&view=diff
==============================================================================
--- webservices/xmlschema/trunk/.gitignore (original)
+++ webservices/xmlschema/trunk/.gitignore Tue Jul 15 18:00:19 2014
@@ -29,3 +29,4 @@ xmlschema-eclipse/.settings/
 xmlschema-eclipse/target/
 .project
 .settings/
+.svn*
\ No newline at end of file

Modified: webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java?rev=1610783&r1=1610782&r2=1610783&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
(original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaCollection.java
Tue Jul 15 18:00:19 2014
@@ -21,6 +21,7 @@ package org.apache.ws.commons.schema;
 
 import java.io.IOException;
 import java.io.Reader;
+import java.math.BigInteger;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
@@ -385,47 +386,46 @@ public final class XmlSchemaCollection {
     private void setupBuiltinDatatypeHierarchy(XmlSchema xsd) {
 
         setDerivationByRestriction(xsd, Constants.XSD_ANYSIMPLETYPE, Constants.XSD_ANYTYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DURATION, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DATETIME, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_TIME, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DATE, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_YEARMONTH, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_YEAR, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_MONTHDAY, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DAY, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_MONTH, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_BOOLEAN, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_BASE64, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_HEXBIN, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_FLOAT, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DOUBLE, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_ANYURI, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_QNAME, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_NOTATION, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_NOTATION, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_DECIMAL, Constants.XSD_ANYSIMPLETYPE);
-
-        setDerivationByRestriction(xsd, Constants.XSD_INTEGER, Constants.XSD_DECIMAL);
-        setDerivationByRestriction(xsd, Constants.XSD_NONPOSITIVEINTEGER, Constants.XSD_INTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_NEGATIVEINTEGER, Constants.XSD_NONPOSITIVEINTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_LONG, Constants.XSD_INTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_INT, Constants.XSD_LONG);
-        setDerivationByRestriction(xsd, Constants.XSD_SHORT, Constants.XSD_INT);
-        setDerivationByRestriction(xsd, Constants.XSD_BYTE, Constants.XSD_SHORT);
-        setDerivationByRestriction(xsd, Constants.XSD_NONNEGATIVEINTEGER, Constants.XSD_INTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_POSITIVEINTEGER, Constants.XSD_NONNEGATIVEINTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDLONG, Constants.XSD_NONNEGATIVEINTEGER);
-        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDINT, Constants.XSD_UNSIGNEDLONG);
-        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDSHORT, Constants.XSD_UNSIGNEDINT);
-        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDBYTE, Constants.XSD_UNSIGNEDSHORT);
-
-        setDerivationByRestriction(xsd, Constants.XSD_STRING, Constants.XSD_ANYSIMPLETYPE);
-        setDerivationByRestriction(xsd, Constants.XSD_NORMALIZEDSTRING, Constants.XSD_STRING);
-        setDerivationByRestriction(xsd, Constants.XSD_TOKEN, Constants.XSD_NORMALIZEDSTRING);
-        setDerivationByRestriction(xsd, Constants.XSD_LANGUAGE, Constants.XSD_TOKEN);
-        setDerivationByRestriction(xsd, Constants.XSD_NMTOKEN, Constants.XSD_TOKEN);
-        setDerivationByRestriction(xsd, Constants.XSD_NAME, Constants.XSD_NMTOKEN);
-        setDerivationByRestriction(xsd, Constants.XSD_NCNAME, Constants.XSD_TOKEN);
+        setDerivationByRestriction(xsd, Constants.XSD_DURATION, Constants.XSD_ANYSIMPLETYPE,
 new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_DATETIME, Constants.XSD_ANYSIMPLETYPE,
 new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_TIME, Constants.XSD_ANYSIMPLETYPE,
     new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_DATE, Constants.XSD_ANYSIMPLETYPE,
     new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_YEARMONTH, Constants.XSD_ANYSIMPLETYPE,
new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_YEAR, Constants.XSD_ANYSIMPLETYPE,
     new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_MONTHDAY, Constants.XSD_ANYSIMPLETYPE,
 new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_DAY, Constants.XSD_ANYSIMPLETYPE, 
     new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_MONTH, Constants.XSD_ANYSIMPLETYPE,
    new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_BOOLEAN, Constants.XSD_ANYSIMPLETYPE,
  new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_BASE64, Constants.XSD_ANYSIMPLETYPE,
   new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_HEXBIN, Constants.XSD_ANYSIMPLETYPE,
   new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_FLOAT, Constants.XSD_ANYSIMPLETYPE,
    new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_DOUBLE, Constants.XSD_ANYSIMPLETYPE,
   new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_ANYURI, Constants.XSD_ANYSIMPLETYPE,
   new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_QNAME, Constants.XSD_ANYSIMPLETYPE,
    new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_NOTATION, Constants.XSD_ANYSIMPLETYPE,
 new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+        setDerivationByRestriction(xsd, Constants.XSD_DECIMAL, Constants.XSD_ANYSIMPLETYPE,
  new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", true) });
+
+        setDerivationByRestriction(xsd, Constants.XSD_INTEGER, Constants.XSD_DECIMAL,   
                new XmlSchemaFacet[] { new XmlSchemaFractionDigitsFacet(new Integer(0), true),
                new XmlSchemaPatternFacet("[\\-+]?[0-9]+", false)                     });
+        setDerivationByRestriction(xsd, Constants.XSD_NONPOSITIVEINTEGER, Constants.XSD_INTEGER,
        new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new Integer(0), false)     
   });
+        setDerivationByRestriction(xsd, Constants.XSD_NEGATIVEINTEGER, Constants.XSD_NONPOSITIVEINTEGER,
new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new Integer(-1), false)        });
+        setDerivationByRestriction(xsd, Constants.XSD_LONG, Constants.XSD_INTEGER,      
                new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Long(-9223372036854775808L),
false), new XmlSchemaMaxInclusiveFacet(new Long(9223372036854775807L), false) });
+        setDerivationByRestriction(xsd, Constants.XSD_INT, Constants.XSD_LONG,          
                new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Integer(-2147483648),
false),        new XmlSchemaMaxInclusiveFacet(2147483647, false)                     });
+        setDerivationByRestriction(xsd, Constants.XSD_SHORT, Constants.XSD_INT,         
                new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Short((short) -32768),
false),       new XmlSchemaMaxInclusiveFacet(new Short((short) 32767), false)       });
+        setDerivationByRestriction(xsd, Constants.XSD_BYTE, Constants.XSD_SHORT,        
                new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Byte((byte) -128),
false),           new XmlSchemaMaxInclusiveFacet(new Byte((byte) 127), false)           });
+        setDerivationByRestriction(xsd, Constants.XSD_NONNEGATIVEINTEGER, Constants.XSD_INTEGER,
        new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Integer(0), false)     
   });
+        setDerivationByRestriction(xsd, Constants.XSD_POSITIVEINTEGER, Constants.XSD_NONNEGATIVEINTEGER,
new XmlSchemaFacet[] { new XmlSchemaMinInclusiveFacet(new Integer(1), false)         });
+        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDLONG, Constants.XSD_NONNEGATIVEINTEGER,
   new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new BigInteger("18446744073709551615"),
false) });
+        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDINT, Constants.XSD_UNSIGNEDLONG,
          new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new Long(4294967295L), false)
 });
+        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDSHORT, Constants.XSD_UNSIGNEDINT,
         new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new Integer(65535), false)
    });
+        setDerivationByRestriction(xsd, Constants.XSD_UNSIGNEDBYTE, Constants.XSD_UNSIGNEDSHORT,
        new XmlSchemaFacet[] { new XmlSchemaMaxInclusiveFacet(new Short((short) 255), false)
});
+
+        setDerivationByRestriction(xsd, Constants.XSD_STRING, Constants.XSD_ANYSIMPLETYPE,
   new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("preserve", false) });
+        setDerivationByRestriction(xsd, Constants.XSD_NORMALIZEDSTRING, Constants.XSD_STRING,
new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("replace", false) });
+        setDerivationByRestriction(xsd, Constants.XSD_TOKEN, Constants.XSD_NORMALIZEDSTRING,
 new XmlSchemaFacet[] { new XmlSchemaWhiteSpaceFacet("collapse", false) });
+        setDerivationByRestriction(xsd, Constants.XSD_LANGUAGE, Constants.XSD_TOKEN,    
     new XmlSchemaFacet[] { new XmlSchemaPatternFacet("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*",
false) });
+        setDerivationByRestriction(xsd, Constants.XSD_NMTOKEN, Constants.XSD_TOKEN,     
     new XmlSchemaFacet[] { new XmlSchemaPatternFacet("\\c+", false) });
+        setDerivationByRestriction(xsd, Constants.XSD_NAME, Constants.XSD_NMTOKEN,      
     new XmlSchemaFacet[] { new XmlSchemaPatternFacet("\\i\\c*", false) });
+        setDerivationByRestriction(xsd, Constants.XSD_NCNAME, Constants.XSD_TOKEN,      
     new XmlSchemaFacet[] { new XmlSchemaPatternFacet("[\\i-[:]][\\c-[:]]*", false) });
         setDerivationByRestriction(xsd, Constants.XSD_ID, Constants.XSD_NCNAME);
         setDerivationByRestriction(xsd, Constants.XSD_IDREF, Constants.XSD_NCNAME);
         setDerivationByRestriction(xsd, Constants.XSD_ENTITY, Constants.XSD_NCNAME);
@@ -436,17 +436,28 @@ public final class XmlSchemaCollection {
     }
 
     private void setDerivationByRestriction(XmlSchema xsd, QName child, QName parent) {
+    	setDerivationByRestriction(xsd, child, parent, null);
+    }
+
+    private void setDerivationByRestriction(XmlSchema xsd, QName child, QName parent, XmlSchemaFacet[]
facets) {
 
-        XmlSchemaSimpleType simple = (XmlSchemaSimpleType)xsd.getTypeByName(child);
+    	XmlSchemaSimpleType simple = (XmlSchemaSimpleType)xsd.getTypeByName(child);
         XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
         restriction.setBaseTypeName(parent);
         restriction.setBaseType((XmlSchemaSimpleType)xsd.getTypeByName(parent));
+
+        if (facets != null) {
+        	for (XmlSchemaFacet facet : facets) {
+        		restriction.getFacets().add(facet);
+        	}
+        }
+
         simple.setContent(restriction);
     }
 
     private void setDerivationByList(XmlSchema xsd, QName child, QName parent) {
 
-        XmlSchemaSimpleType simple = (XmlSchemaSimpleType)xsd.getTypeByName(child);
+    	XmlSchemaSimpleType simple = (XmlSchemaSimpleType)xsd.getTypeByName(child);
         XmlSchemaSimpleTypeList restriction = new XmlSchemaSimpleTypeList();
         restriction.setItemTypeName(parent);
         restriction.setItemType((XmlSchemaSimpleType)xsd.getTypeByName(parent));

Modified: webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/FacetsTest.java
URL: http://svn.apache.org/viewvc/webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/FacetsTest.java?rev=1610783&r1=1610782&r2=1610783&view=diff
==============================================================================
--- webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/FacetsTest.java (original)
+++ webservices/xmlschema/trunk/xmlschema-core/src/test/java/tests/FacetsTest.java Tue Jul
15 18:00:19 2014
@@ -20,6 +20,7 @@ package tests;
 
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.math.BigInteger;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -45,6 +46,7 @@ import org.apache.ws.commons.schema.XmlS
 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
 import org.apache.ws.commons.schema.XmlSchemaTotalDigitsFacet;
 import org.apache.ws.commons.schema.XmlSchemaWhiteSpaceFacet;
+import org.apache.ws.commons.schema.constants.Constants;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -539,4 +541,260 @@ public class FacetsTest extends Assert {
 
     }
 
+    /**
+     * This method verifies the XML Schema's built-in
+     * types have their facets defined correctly.
+     */
+    @Test
+    public void testBuiltinFacets() {
+    	XmlSchemaCollection collection = new XmlSchemaCollection();
+
+    	// anySimpleType
+    	List<XmlSchemaFacet> anySimpleTypeFacets = getFacetsForQName(collection, Constants.XSD_ANYSIMPLETYPE);
+    	assertEquals(0, anySimpleTypeFacets.size());
+
+    	// Any-Simple-Type-Based Facets
+    	QName[] anySimpleTypeBasedQNames = {
+    			Constants.XSD_DURATION,
+    			Constants.XSD_DATETIME,
+    			Constants.XSD_TIME,
+    			Constants.XSD_DATE,
+    			Constants.XSD_YEARMONTH,
+    			Constants.XSD_YEAR,
+    			Constants.XSD_MONTHDAY,
+    			Constants.XSD_DAY,
+    			Constants.XSD_MONTH,
+    			Constants.XSD_BOOLEAN,
+    			Constants.XSD_BASE64,
+    			Constants.XSD_HEXBIN,
+    			Constants.XSD_FLOAT,
+    			Constants.XSD_DOUBLE,
+    			Constants.XSD_ANYURI,
+    			Constants.XSD_QNAME,
+    			Constants.XSD_NOTATION,
+    			Constants.XSD_DECIMAL
+    		};
+
+    	for (QName qName : anySimpleTypeBasedQNames) {
+    		testWhiteSpaceFacet(
+    				qName,
+    				getFacetsForQName(collection, qName),
+    				"collapse",
+    				true);
+    	}
+
+    	// Numeric Type Facets
+
+    	// integer
+    	List<XmlSchemaFacet> integerFacets = getFacetsForQName(collection, Constants.XSD_INTEGER);
+    	assertEquals(2, integerFacets.size());
+    	XmlSchemaFractionDigitsFacet integerFractionDigitsFacet = null;
+    	XmlSchemaPatternFacet integerPatternFacet = null;
+    	for (XmlSchemaFacet facet : integerFacets) {
+    		if (facet instanceof XmlSchemaPatternFacet) {
+    			integerPatternFacet = (XmlSchemaPatternFacet) facet;
+    		} else if (facet instanceof XmlSchemaFractionDigitsFacet) {
+    			integerFractionDigitsFacet = (XmlSchemaFractionDigitsFacet) facet;
+    		} else {
+    			fail("Simple Type " + Constants.XSD_INTEGER + " should not have a facet of type "
+ facet.getClass().getName());
+    		}
+    	}
+    	assertEquals(new Integer(0), integerFractionDigitsFacet.getValue());
+    	assertTrue(integerFractionDigitsFacet.isFixed());
+    	assertEquals("[\\-+]?[0-9]+", integerPatternFacet.getValue());
+    	assertFalse(integerPatternFacet.isFixed());
+
+    	// nonPositiveInteger
+    	testMaxInclusiveFacet(
+    			Constants.XSD_NONPOSITIVEINTEGER,
+    			getFacetsForQName(collection, Constants.XSD_NONPOSITIVEINTEGER),
+    			new Integer(0));
+
+    	// negativeInteger
+    	testMaxInclusiveFacet(
+    			Constants.XSD_NEGATIVEINTEGER,
+    			getFacetsForQName(collection, Constants.XSD_NEGATIVEINTEGER),
+    			new Integer(-1));
+
+    	// long
+    	testNumericRange(
+    			Constants.XSD_LONG,
+    			getFacetsForQName(collection, Constants.XSD_LONG),
+    			new Long(-9223372036854775808L),
+    			new Long(9223372036854775807L));
+
+    	// int
+    	testNumericRange(
+    			Constants.XSD_INT,
+    			getFacetsForQName(collection, Constants.XSD_INT),
+    			new Integer(-2147483648),
+    			new Integer(2147483647));
+
+    	// short
+    	testNumericRange(
+    			Constants.XSD_SHORT,
+    			getFacetsForQName(collection, Constants.XSD_SHORT),
+    			new Short((short) -32768),
+    			new Short((short)  32767));
+
+    	// byte
+    	testNumericRange(
+    			Constants.XSD_BYTE,
+    			getFacetsForQName(collection, Constants.XSD_BYTE),
+    			new Byte((byte) -128),
+    			new Byte((byte)  127));
+
+    	// nonNegativeInteger
+    	testMinInclusiveFacet(
+    			Constants.XSD_NONNEGATIVEINTEGER,
+    			getFacetsForQName(collection, Constants.XSD_NONNEGATIVEINTEGER),
+    			new Integer(0));
+
+    	// positiveInteger
+    	testMinInclusiveFacet(
+    			Constants.XSD_POSITIVEINTEGER,
+    			getFacetsForQName(collection, Constants.XSD_POSITIVEINTEGER),
+    			new Integer(1));
+
+    	// unsignedLong
+    	testMaxInclusiveFacet(
+    			Constants.XSD_UNSIGNEDLONG,
+    			getFacetsForQName(collection, Constants.XSD_UNSIGNEDLONG),
+    			new BigInteger("18446744073709551615"));
+
+    	// unsignedInt
+    	testMaxInclusiveFacet(
+    			Constants.XSD_UNSIGNEDINT,
+    			getFacetsForQName(collection, Constants.XSD_UNSIGNEDINT),
+    			new Long(4294967295L));
+
+    	// unsignedShort
+    	testMaxInclusiveFacet(
+    			Constants.XSD_UNSIGNEDSHORT,
+    			getFacetsForQName(collection, Constants.XSD_UNSIGNEDSHORT),
+    			new Integer(65535));
+
+    	// unsignedByte
+    	testMaxInclusiveFacet(
+    			Constants.XSD_UNSIGNEDBYTE,
+    			getFacetsForQName(collection, Constants.XSD_UNSIGNEDBYTE),
+    			new Short((short) 255));
+
+    	// String Type Facets
+
+    	// string
+    	testWhiteSpaceFacet(
+    			Constants.XSD_STRING,
+    			getFacetsForQName(collection, Constants.XSD_STRING),
+    			"preserve",
+    			false);
+
+    	// normalizedString
+    	testWhiteSpaceFacet(
+    			Constants.XSD_NORMALIZEDSTRING,
+    			getFacetsForQName(collection, Constants.XSD_NORMALIZEDSTRING),
+    			"replace",
+    			false);
+
+    	// token
+    	testWhiteSpaceFacet(
+    			Constants.XSD_TOKEN,
+    			getFacetsForQName(collection, Constants.XSD_TOKEN),
+    			"collapse",
+    			false);
+
+    	// language
+    	testPatternFacet(
+    			Constants.XSD_LANGUAGE,
+    			getFacetsForQName(collection, Constants.XSD_LANGUAGE),
+    			"[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*");
+
+    	// NMTOKEN
+    	testPatternFacet(
+    			Constants.XSD_NMTOKEN,
+    			getFacetsForQName(collection, Constants.XSD_NMTOKEN),
+    			"\\c+");
+
+    	// Name
+    	testPatternFacet(
+    			Constants.XSD_NAME,
+    			getFacetsForQName(collection, Constants.XSD_NAME),
+    			"\\i\\c*");
+
+    	// NCName
+    	testPatternFacet(
+    			Constants.XSD_NCNAME,
+    			getFacetsForQName(collection, Constants.XSD_NCNAME),
+    			"[\\i-[:]][\\c-[:]]*");
+
+    	// ID
+    	assertTrue(
+    			Constants.XSD_ID.toString(),
+    			getFacetsForQName(collection, Constants.XSD_ID).isEmpty());
+
+    	// IDREF
+    	assertTrue(
+    			Constants.XSD_IDREF.toString(),
+    			getFacetsForQName(collection, Constants.XSD_IDREF).isEmpty());
+
+    	// ENTITY
+    	assertTrue(
+    			Constants.XSD_ENTITY.toString(),
+    			getFacetsForQName(collection, Constants.XSD_ENTITY).isEmpty());
+    }
+
+    private List<XmlSchemaFacet> getFacetsForQName(XmlSchemaCollection collection,
QName qname) {
+    	XmlSchemaSimpleType type = (XmlSchemaSimpleType) collection.getTypeByQName(qname);
+    	return ((XmlSchemaSimpleTypeRestriction) type.getContent()).getFacets();
+    }
+
+    private void testWhiteSpaceFacet(QName qName, List<XmlSchemaFacet> facets, String
value, boolean isFixed) {
+    	assertEquals(qName.toString(), 1, facets.size());
+    	assertTrue(qName.toString(), facets.get(0) instanceof XmlSchemaWhiteSpaceFacet);
+    	assertEquals(qName.toString(), value, facets.get(0).getValue().toString());
+    	assertEquals(qName.toString(), isFixed, facets.get(0).isFixed());
+    }
+
+    private void testMinInclusiveFacet(QName qName, List<XmlSchemaFacet> facets, Number
minInclusiveValue) {
+    	assertEquals(qName.toString(), 1, facets.size());
+    	assertTrue(qName.toString(), facets.get(0) instanceof XmlSchemaMinInclusiveFacet);
+    	assertEquals(qName.toString(), minInclusiveValue, facets.get(0).getValue());
+    	assertFalse(qName.toString(), facets.get(0).isFixed());
+    }
+
+    private void testMaxInclusiveFacet(QName qName, List<XmlSchemaFacet> facets, Number
maxInclusiveValue) {
+    	assertEquals(qName.toString(), 1, facets.size());
+    	assertTrue(qName.toString(), facets.get(0) instanceof XmlSchemaMaxInclusiveFacet);
+    	assertEquals(qName.toString(), maxInclusiveValue, facets.get(0).getValue());
+    	assertFalse(qName.toString(), facets.get(0).isFixed() );
+    }
+
+    private void testNumericRange(QName qName, List<XmlSchemaFacet> facets, Number
min, Number max) {
+    	XmlSchemaMinInclusiveFacet minFacet = null;
+    	XmlSchemaMaxInclusiveFacet maxFacet = null;
+
+    	assertEquals(qName.toString(), 2, facets.size());
+    	for (XmlSchemaFacet facet : facets) {
+    		if (facet instanceof XmlSchemaMinInclusiveFacet) {
+    			minFacet = (XmlSchemaMinInclusiveFacet) facet;
+    		} else if (facet instanceof XmlSchemaMaxInclusiveFacet) {
+    			maxFacet = (XmlSchemaMaxInclusiveFacet) facet;
+    		} else {
+    			fail("Numeric Simple Type " + qName + " should not have a facet of type " + facet.getClass().getName());
+    		}
+    	}
+
+    	assertEquals(qName.toString(), min, minFacet.getValue());
+    	assertEquals(qName.toString(), max, maxFacet.getValue());
+
+    	assertFalse(qName.toString(), minFacet.isFixed());
+    	assertFalse(qName.toString(), maxFacet.isFixed());
+    }
+
+    private void testPatternFacet(QName qName, List<XmlSchemaFacet> facets, String
pattern) {
+    	assertEquals(qName.toString(), 1, facets.size());
+    	assertTrue(qName.toString(), facets.get(0) instanceof XmlSchemaPatternFacet);
+    	assertEquals(qName.toString(), pattern, facets.get(0).getValue());
+    	assertFalse(qName.toString(), facets.get(0).isFixed());
+    }
 }



Mime
View raw message