# HG changeset patch
# User wleggette
# Date 1240439920 18000
# Branch clean
# Node ID edbf436314aec56d4a01b697216564ed6d2a1e91
# Parent  4abe14e0a45d809d61da94f9e9b4aef9b674f843
Adds validation by projection to XmlBeans. This feature provides a validation 
mode using the "must ignore" extensibility rule set.

diff -r 4abe14e0a45d -r edbf436314ae 
src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
--- a/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java    Wed Apr 
22 17:37:41 2009 -0500
+++ b/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java    Wed Apr 
22 17:38:40 2009 -0500
@@ -81,6 +81,7 @@
         options = XmlOptions.maskNull(options);
         _errorListener = (Collection) options.get(XmlOptions.ERROR_LISTENER);
         _treatLaxAsSkip = 
options.hasOption(XmlOptions.VALIDATE_TREAT_LAX_AS_SKIP);
+        _validationByProjection = 
options.hasOption(XmlOptions.VALIDATE_BY_PROJECTION);
 
         if (_errorListener == null)
             _errorListener = defaultErrorListener;
@@ -296,7 +297,8 @@
 
             if (!state.visit( name ))
             {
-                findDetailedErrorBegin(event ,state , name);
+                if (!_validationByProjection)
+                    findDetailedErrorBegin(event ,state , name);
 
                 _eatContent = 1;
 
@@ -638,6 +640,8 @@
 
         if (!state._canHaveAttrs)
         {
+            if (_validationByProjection)
+                return;
             emitFieldError( event, 
XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD,
                 new Object[] {QNameHelper.pretty( attrName )}, attrName, null, 
null,
                 XmlValidationError.INCORRECT_ATTRIBUTE, state._type);
@@ -677,6 +681,9 @@
 
         if (wildcardProcess == SchemaAttributeModel.NONE)
         {
+            if (_validationByProjection)
+                return;
+
             // todo (dutta) need additional logic to determine the 
expectedSchemaType
             emitFieldError( event, 
XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD,
                 new Object[] { QNameHelper.pretty( attrName ) },
@@ -1733,6 +1740,7 @@
     private int                _errorState;
     private Collection         _errorListener;
     private boolean            _treatLaxAsSkip;
+    private boolean            _validationByProjection;
     private ValidatorVC        _vc;
     private int                _suspendErrors;
     private IdentityConstraint _constraintEngine;
diff -r 4abe14e0a45d -r edbf436314ae 
src/xmlpublic/org/apache/xmlbeans/XmlOptions.java
--- a/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java Wed Apr 22 17:37:41 
2009 -0500
+++ b/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java Wed Apr 22 17:38:40 
2009 -0500
@@ -771,6 +771,15 @@
     public XmlOptions setValidateTreatLaxAsSkip() {
         return set ( VALIDATE_TREAT_LAX_AS_SKIP );
     }
+    
+    /**
+     * Instructs the validator to ignore and remove any items not understood
+     * by the schema. This is useful for XML languages that specify a "must
+     * ignore" rule to allow for forward compatibility.
+     */
+    public XmlOptions setValidateByProjection() {
+        return set ( VALIDATE_BY_PROJECTION );
+    }
 
     /**
      * This option controls whether or not operations on XmlBeans are
@@ -946,6 +955,8 @@
     /** @exclude */
     public static final String VALIDATE_TEXT_ONLY              = 
"VALIDATE_TEXT_ONLY";
     /** @exclude */
+    public static final String VALIDATE_BY_PROJECTION          = 
"VALIDATE_BY_PROJECTION";
+    /** @exclude */
     public static final String UNSYNCHRONIZED                  = 
"UNSYNCHRONIZED";
     /** @exclude */
     public static final String ENTITY_RESOLVER                 = 
"ENTITY_RESOLVER";

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: dev-h...@xmlbeans.apache.org

Reply via email to