You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by ra...@apache.org on 2009/07/08 21:05:41 UTC

svn commit: r792266 - in /xmlbeans/trunk/src: typeimpl/org/apache/xmlbeans/impl/validator/ typeimpl/org/apache/xmlbeans/impl/values/ xmlcomp/org/apache/xmlbeans/impl/tool/ xmlpublic/org/apache/xmlbeans/

Author: radup
Date: Wed Jul  8 19:05:41 2009
New Revision: 792266

URL: http://svn.apache.org/viewvc?rev=792266&view=rev
Log:
Added option to perform additional, stricter Schema validation checks. See JIRA issue XMLBEANS-350.

Modified:
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaDecimalHolderEx.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntHolderEx.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntegerHolderEx.java
    xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaLongHolderEx.java
    xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/InstanceValidator.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java
    xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptionsBean.java

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java Wed Jul  8 19:05:41 2009
@@ -22,6 +22,7 @@
 import org.apache.xmlbeans.impl.common.XmlWhitespace;
 import org.apache.xmlbeans.impl.schema.SchemaTypeVisitorImpl;
 import org.apache.xmlbeans.impl.schema.SchemaTypeImpl;
+import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem;
 import org.apache.xmlbeans.impl.values.JavaBase64HolderEx;
 import org.apache.xmlbeans.impl.values.JavaBooleanHolder;
 import org.apache.xmlbeans.impl.values.JavaBooleanHolderEx;
@@ -81,6 +82,7 @@
         options = XmlOptions.maskNull(options);
         _errorListener = (Collection) options.get(XmlOptions.ERROR_LISTENER);
         _treatLaxAsSkip = options.hasOption(XmlOptions.VALIDATE_TREAT_LAX_AS_SKIP);
+        _strict = options.hasOption(XmlOptions.VALIDATE_STRICT);
 
         if (_errorListener == null)
             _errorListener = defaultErrorListener;
@@ -1286,6 +1288,16 @@
         {
             JavaDecimalHolderEx.validateLexical( value, type, _vc );
 
+            // An additional rule states that if the type is xs:integer or derived from it,
+            // then the decimal dot is not allowed.
+            // verify that values extending xsd:integer don't have a decimal point
+            if ( _strict &&
+                BuiltinSchemaTypeSystem.ST_INTEGER.isAssignableFrom( type ) &&
+                value.lastIndexOf('.') >= 0)
+            {
+                _vc.invalid(XmlErrorCodes.INTEGER, new Object[] { value });
+            }
+
             if (errorState == _errorState)
             {
                 _decimalValue = new BigDecimal( value );
@@ -1339,6 +1351,14 @@
             _stringValue = value;
             break;
         }
+        case SchemaType.BTC_G_MONTH :
+        {
+            // In the case of gMonth, there is some strict mode validation to do
+            if (_strict && value.length() == 6 &&
+                value.charAt( 4 ) == '-' && value.charAt( 5 ) == '-')
+                _vc.invalid(XmlErrorCodes.DATE, new Object[] { value });
+            // Fall through
+        }
         case SchemaType.BTC_DATE_TIME :
         case SchemaType.BTC_TIME :
         case SchemaType.BTC_DATE :
@@ -1346,7 +1366,6 @@
         case SchemaType.BTC_G_YEAR :
         case SchemaType.BTC_G_MONTH_DAY :
         case SchemaType.BTC_G_DAY :
-        case SchemaType.BTC_G_MONTH :
         {
             GDate d = XmlDateImpl.validateLexical( value, type, _vc );
 
@@ -1732,6 +1751,7 @@
     private int                _errorState;
     private Collection         _errorListener;
     private boolean            _treatLaxAsSkip;
+    private boolean            _strict;
     private ValidatorVC        _vc;
     private int                _suspendErrors;
     private IdentityConstraint _constraintEngine;

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaDecimalHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaDecimalHolderEx.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaDecimalHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaDecimalHolderEx.java Wed Jul  8 19:05:41 2009
@@ -87,7 +87,7 @@
         XmlObject fd = sType.getFacet(SchemaType.FACET_FRACTION_DIGITS);
         if (fd != null)
         {
-            int scale = ((XmlObjectBase)fd).bigIntegerValue().intValue();
+            int scale = ((XmlObjectBase)fd).getBigIntegerValue().intValue();
             try
             {
                 // used only for side-effect - this does not change v despite
@@ -110,7 +110,7 @@
         if (td != null)
         {
             String temp = v.unscaledValue().toString();
-            int tdf = ((XmlObjectBase)td).bigIntegerValue().intValue();
+            int tdf = ((XmlObjectBase)td).getBigIntegerValue().intValue();
             int origLen = temp.length();
             int len = origLen;
             if (origLen > 0)
@@ -146,7 +146,7 @@
         XmlObject mine = sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE);
         if (mine != null)
         {
-            BigDecimal m = ((XmlObjectBase)mine).bigDecimalValue();
+            BigDecimal m = ((XmlObjectBase)mine).getBigDecimalValue();
             if (v.compareTo(m) <= 0)
             {
                 context.invalid(XmlErrorCodes.DATATYPE_MIN_EXCLUSIVE_VALID,
@@ -159,7 +159,7 @@
         XmlObject mini = sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE);
         if (mini != null)
         {
-            BigDecimal m = ((XmlObjectBase)mini).bigDecimalValue();
+            BigDecimal m = ((XmlObjectBase)mini).getBigDecimalValue();
             if (v.compareTo(m) < 0)
             {
                 context.invalid(XmlErrorCodes.DATATYPE_MIN_INCLUSIVE_VALID,
@@ -172,7 +172,7 @@
         XmlObject maxi = sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE);
         if (maxi != null)
         {
-            BigDecimal m = ((XmlObjectBase)maxi).bigDecimalValue();
+            BigDecimal m = ((XmlObjectBase)maxi).getBigDecimalValue();
             if (v.compareTo(m) > 0)
             {
                 context.invalid(XmlErrorCodes.DATATYPE_MAX_INCLUSIVE_VALID,
@@ -185,7 +185,7 @@
         XmlObject maxe = sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE);
         if (maxe != null)
         {
-            BigDecimal m = ((XmlObjectBase)maxe).bigDecimalValue();
+            BigDecimal m = ((XmlObjectBase)maxe).getBigDecimalValue();
             if (v.compareTo(m) >= 0)
             {
                 context.invalid(XmlErrorCodes.DATATYPE_MAX_EXCLUSIVE_VALID,
@@ -199,7 +199,7 @@
         if (vals != null)
         {
             for (int i = 0; i < vals.length; i++)
-                if (v.equals(((XmlObjectBase)vals[i]).bigDecimalValue()))
+                if (v.equals(((XmlObjectBase)vals[i]).getBigDecimalValue()))
                     return;
             context.invalid(XmlErrorCodes.DATATYPE_ENUM_VALID,
                 new Object[] { "decimal", v, QNameHelper.readable(sType) });
@@ -209,7 +209,7 @@
     protected void validate_simpleval(String lexical, ValidationContext ctx)
     {
         validateLexical(lexical, schemaType(), ctx);
-        validateValue(bigDecimalValue(), schemaType(), ctx);
+        validateValue(getBigDecimalValue(), schemaType(), ctx);
     }
 
 }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntHolderEx.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntHolderEx.java Wed Jul  8 19:05:41 2009
@@ -60,7 +60,7 @@
     public static void validateLexical(String v, SchemaType sType, ValidationContext context)
     {
         JavaDecimalHolder.validateLexical(v, context);
-        
+
         // check pattern
         if (sType.hasPatternFacet())
         {
@@ -162,13 +162,13 @@
         switch (s.getDecimalSize()) 
         {
             case SchemaType.SIZE_BIG_DECIMAL:
-                return ((XmlObjectBase)o).bigDecimalValue().intValue();
+                return ((XmlObjectBase)o).getBigDecimalValue().intValue();
             case SchemaType.SIZE_BIG_INTEGER:
-                return ((XmlObjectBase)o).bigIntegerValue().intValue();
+                return ((XmlObjectBase)o).getBigIntegerValue().intValue();
             case SchemaType.SIZE_LONG:
-                return (int)((XmlObjectBase)o).longValue();
+                return (int)((XmlObjectBase)o).getLongValue();
             default:
-                return ((XmlObjectBase)o).intValue();
+                return ((XmlObjectBase)o).getIntValue();
         }
 
     }
@@ -176,7 +176,7 @@
     protected void validate_simpleval(String lexical, ValidationContext ctx)
     {
         validateLexical(lexical, schemaType(), ctx);
-        validateValue(intValue(), schemaType(), ctx);
+        validateValue(getIntValue(), schemaType(), ctx);
     }
     
 }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntegerHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntegerHolderEx.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntegerHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaIntegerHolderEx.java Wed Jul  8 19:05:41 2009
@@ -59,7 +59,7 @@
     public static void validateLexical(String v, SchemaType sType, ValidationContext context)
     {
         JavaDecimalHolder.validateLexical(v, context);
-        
+
         // check pattern
         if (sType.hasPatternFacet())
         {
@@ -172,7 +172,7 @@
     protected void validate_simpleval(String lexical, ValidationContext ctx)
     {
         validateLexical(lexical, schemaType(), ctx);
-        validateValue(bigIntegerValue(), schemaType(), ctx);
+        validateValue(getBigIntegerValue(), schemaType(), ctx);
     }
     
 }

Modified: xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaLongHolderEx.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaLongHolderEx.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaLongHolderEx.java (original)
+++ xmlbeans/trunk/src/typeimpl/org/apache/xmlbeans/impl/values/JavaLongHolderEx.java Wed Jul  8 19:05:41 2009
@@ -60,7 +60,7 @@
     public static void validateLexical(String v, SchemaType sType, ValidationContext context)
     {
         JavaDecimalHolder.validateLexical(v, context);
-        
+
         // check pattern
         if (sType.hasPatternFacet())
         {
@@ -162,11 +162,11 @@
         switch (s.getDecimalSize()) 
         {
             case SchemaType.SIZE_BIG_DECIMAL:
-                return ((XmlObjectBase)o).bigDecimalValue().longValue();
+                return ((XmlObjectBase)o).getBigDecimalValue().longValue();
             case SchemaType.SIZE_BIG_INTEGER:
-                return ((XmlObjectBase)o).bigIntegerValue().longValue();
+                return ((XmlObjectBase)o).getBigIntegerValue().longValue();
             case SchemaType.SIZE_LONG:
-                return ((XmlObjectBase)o).longValue();
+                return ((XmlObjectBase)o).getLongValue();
             default:
                 throw new IllegalStateException("Bad facet type: " + s);
         }
@@ -176,6 +176,6 @@
     protected void validate_simpleval(String lexical, ValidationContext ctx)
     {
         validateLexical(lexical, schemaType(), ctx);
-        validateValue(longValue(), schemaType(), ctx);
+        validateValue(getLongValue(), schemaType(), ctx);
     }
 }

Modified: xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/InstanceValidator.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/InstanceValidator.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/InstanceValidator.java (original)
+++ xmlbeans/trunk/src/xmlcomp/org/apache/xmlbeans/impl/tool/InstanceValidator.java Wed Jul  8 19:05:41 2009
@@ -41,6 +41,7 @@
         System.out.println("    -dl - permit network downloads for imports and includes (default is off)");
         System.out.println("    -noupa - do not enforce the unique particle attribution rule");
         System.out.println("    -nopvr - do not enforce the particle valid (restriction) rule");
+        System.out.println("    -strict - performs strict(er) validation");
         System.out.println("    -partial - allow partial schema type system");
         System.out.println("    -license - prints license information");
     }
@@ -56,6 +57,7 @@
         flags.add("dl");
         flags.add("noupa");
         flags.add("nopvr");
+        flags.add("strict");
         flags.add("partial");
 
         CommandLine cl = new CommandLine(args, flags, Collections.EMPTY_SET);
@@ -99,6 +101,7 @@
         boolean dl = (cl.getOpt("dl") != null);
         boolean nopvr = (cl.getOpt("nopvr") != null);
         boolean noupa = (cl.getOpt("noupa") != null);
+        boolean strict = (cl.getOpt("strict") != null);
         boolean partial = (cl.getOpt("partial") != null);
 
         File[] schemaFiles = cl.filesEndingWith(".xsd");
@@ -191,7 +194,9 @@
                 System.out.println(instanceFiles[i] + " NOT valid.  ");
                 System.out.println("  Document type not found." );
             }
-            else if (xobj.validate(new XmlOptions().setErrorListener(errors)))
+            else if (xobj.validate(strict ?
+                new XmlOptions().setErrorListener(errors).setValidateStrict() :
+                new XmlOptions().setErrorListener(errors)))
                 System.out.println(instanceFiles[i] + " valid.");
             else
             {

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java Wed Jul  8 19:05:41 2009
@@ -70,7 +70,8 @@
  *   <td align="center"><code>setLoad***</code><br/>
  *                      <code>setEntityResolver</code></td>
  *   <td align="center"><code>setErrorListener</code><br/>
- *                      <code>setValidateTreatLaxAsSkip</code></td>
+ *                      <code>setValidateTreatLaxAsSkip</code>
+ *                      <code>setValidateStrict</code></td>
  *   <td align="center"><code>setErrorListener</code><br/>
  *                      <code>setCompile***</code><br/>
  *                      <code>setEntityResolver</code><br/>
@@ -773,6 +774,14 @@
     }
 
     /**
+     * Performs additional validation checks that are disabled by
+     * default for better compatibility.
+     */
+    public XmlOptions setValidateStrict() {
+        return set ( VALIDATE_STRICT );
+    }
+
+    /**
      * This option controls whether or not operations on XmlBeans are
      * thread safe.  When not on, all XmlBean operations will be syncronized.
      * This provides for multiple thread the ability to access a single
@@ -944,6 +953,8 @@
     /** @exclude */
     public static final String VALIDATE_TREAT_LAX_AS_SKIP      = "VALIDATE_TREAT_LAX_AS_SKIP";
     /** @exclude */
+    public static final String VALIDATE_STRICT                 = "VALIDATE_STRICT";
+    /** @exclude */
     public static final String VALIDATE_TEXT_ONLY              = "VALIDATE_TEXT_ONLY";
     /** @exclude */
     public static final String UNSYNCHRONIZED                  = "UNSYNCHRONIZED";

Modified: xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptionsBean.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptionsBean.java?rev=792266&r1=792265&r2=792266&view=diff
==============================================================================
--- xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptionsBean.java (original)
+++ xmlbeans/trunk/src/xmlpublic/org/apache/xmlbeans/XmlOptionsBean.java Wed Jul  8 19:05:41 2009
@@ -407,6 +407,19 @@
         return hasOption( VALIDATE_TREAT_LAX_AS_SKIP );
     }
 
+    public void setValidateStrict(boolean b)
+    {
+        if (b)
+            super.setValidateStrict();
+        else
+            remove( VALIDATE_STRICT );
+    }
+
+    public boolean isValidateStrict()
+    {
+        return hasOption( VALIDATE_STRICT );
+    }
+
     public void setUnsynchronized(boolean b)
     {
         if (b)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org