Author: mukulg
Date: Sat Sep  4 14:53:12 2010
New Revision: 992616

URL: http://svn.apache.org/viewvc?rev=992616&view=rev
Log:
committing few more improvements to XML schema 1.1 assertions processing, 
specifically for simpleType varieties list and union. specifically improving 
constructing right typed values of XPath2 context variable $value, in case the 
list itemType has variety union (which specifies a heterogeneous schema type 
list). committing a new jar for PsychoPath engine as well (please see following 
Eclipse bug report, https://bugs.eclipse.org/bugs/show_bug.cgi?id=323900), 
where we needed few improvements to support this current Xerces change.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=992616&r1=992615&r2=992616&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
 Sat Sep  4 14:53:12 2010
@@ -28,6 +28,11 @@ import org.apache.xerces.dom.PSVIAttrNSI
 import org.apache.xerces.dom.PSVIDocumentImpl;
 import org.apache.xerces.dom.PSVIElementNSImpl;
 import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.dv.InvalidDatatypeValueException;
+import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.dv.ValidationContext;
+import org.apache.xerces.impl.dv.XSSimpleType;
+import org.apache.xerces.impl.validation.ValidationState;
 import org.apache.xerces.impl.xs.assertion.XMLAssertAdapter;
 import org.apache.xerces.impl.xs.assertion.XSAssertImpl;
 import org.apache.xerces.xni.Augmentations;
@@ -44,9 +49,11 @@ import org.apache.xerces.xs.XSSimpleType
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
+import org.eclipse.wst.xml.xpath2.processor.PsychoPathTypeHelper;
 import org.eclipse.wst.xml.xpath2.processor.StaticError;
 import org.eclipse.wst.xml.xpath2.processor.ast.XPath;
 import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType;
+import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
 import 
org.eclipse.wst.xml.xpath2.processor.internal.types.SchemaTypeValueFactory;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
@@ -58,6 +65,12 @@ import org.w3c.dom.NodeList;
  * An implementation of the XPath interface, for XML Schema 1.1 'assertions'
  * evaluation. This class interfaces with the PsychoPath XPath 2.0 engine.
  * 
+ * This method constructs the PSVI enabled DOM trees for assertions evaluation,
+ * from XNI event calls. The DOM trees constructed in this class, are mapped
+ * by the PsychoPath XPath2 engine to an XPath2 XDM representation.
+ * XML Schema 1.1 assertions are evaluated on these tree instances, in a bottom
+ * up fashion.
+ * 
  * @xerces.internal
  * 
  * @author Mukul Gandhi, IBM
@@ -147,7 +160,7 @@ public class XMLAssertPsychopathImpl ext
             fCurrentAssertDomNode = elem;
         }
 
-        // add attributes to the element
+        // add attribute nodes to DOM element node
         for (int attIndex = 0; attIndex < attributes.getLength(); attIndex++) {
             String attrUri = attributes.getURI(attIndex);
             String attQName = attributes.getQName(attIndex);
@@ -167,6 +180,7 @@ public class XMLAssertPsychopathImpl ext
         }
 
         List assertionList = (List) augs.getItem("ASSERT");
+        
         // if we have assertions applicable to this element, store the element
         // reference and the assertions on it, on the runtime stacks.
         if (assertionList != null) {
@@ -223,7 +237,8 @@ public class XMLAssertPsychopathImpl ext
                     // depending on simple content's validity status from
                     // XMLSchemaValidator, process XML schema assertions.
                     processAllAssertionsOnElement(element, itemType, 
-                                               memberTypes, assertions);
+                                                  memberTypes, assertions,
+                                                  elemPSVI);
                  }
             }
 
@@ -237,12 +252,15 @@ public class XMLAssertPsychopathImpl ext
     
 
     /*
-     * Method to evaluate all of assertions for an element tree.
+     * Method to evaluate all of assertions for an element tree. This is the
+     * root method, which drives entire assertions evaluation within Xerces XML
+     * Schema 1.1 implementation.
      */
     private void processAllAssertionsOnElement(QName element,
-                                           XSSimpleTypeDefinition itemType,
-                                           XSObjectList memberTypes,
-                                           List assertions)
+                                               XSSimpleTypeDefinition itemType,
+                                               XSObjectList memberTypes,
+                                               List assertions, 
+                                               ElementPSVI elemPSVI)
                                     throws Exception {
          
          // initialize the XPath engine
@@ -254,19 +272,20 @@ public class XMLAssertPsychopathImpl ext
          // evaluate assertions
          if (assertions instanceof XSObjectList) {
             // assertions from a "complex type" definition             
-            evaluateAssertionsFromComplexType(element, assertions, value);     
       
+            evaluateAssertionsFromAComplexType(element, assertions, value, 
+                                              elemPSVI);            
          }
          else if (assertions instanceof Vector) {
             // assertions from a "simple type" definition
-            evaluateAssertionsFromSimpleType(element, itemType, memberTypes,
-                                             assertions, value);            
+            evaluateAssertionsFromASimpleType(element, itemType, memberTypes,
+                                             assertions, value, elemPSVI);     
       
          }
          
     } // processAllAssertionsOnElement
 
 
     /*
-     * Find value of XPath2 context variable $value.
+     * Determine value of XPath2 context variable $value.
      */
     private String getValueOf$Value() throws DOMException {
         
@@ -275,6 +294,7 @@ public class XMLAssertPsychopathImpl ext
         NodeList childList = fCurrentAssertDomNode.getChildNodes();         
         
         int textChildCount = 0;
+        
         // there could be adjacent text nodes in a DOM tree. merge them to 
         // get the value.
         for (int childNodeIndex = 0; childNodeIndex < childList.getLength();
@@ -287,6 +307,8 @@ public class XMLAssertPsychopathImpl ext
         }
 
         if (textChildCount != childList.getLength()) {
+            // this means, that the DOM tree we are inspecting, has
+            // mixed/complex content.
             value = null;  
         }
         
@@ -298,15 +320,19 @@ public class XMLAssertPsychopathImpl ext
     /*
      * Evaluate assertions on a "complex type".
      */
-    private void evaluateAssertionsFromComplexType(QName element, List 
-                                              assertions, String value) 
+    private void evaluateAssertionsFromAComplexType(QName element, List 
+                                                   assertions, String value,
+                                                   ElementPSVI elemPSVI) 
                                                    throws Exception {
         if (value != null) {
             // complex type with simple content
             setValueOf$value(value, null, null);
         } else {
-            // complex type with complex content                
-            // $value should be, the XPath2 "empty sequence" ... TO DO
+            // complex type with complex content            
+            // notes: $value should be, the XPath2 "empty sequence" ... TO DO
+            // user's are not expected to use XPath2 context variable $value
+            // for complex contents, so it's harmless to leave this
+            // unimplemented as of now.
         }
         
         XSObjectList assertList = (XSObjectList) assertions;
@@ -318,7 +344,7 @@ public class XMLAssertPsychopathImpl ext
                 // not an assertion facet
                 xpathContextExists = true;   
             }
-            // check if this is an assertion, from the attribute
+            // check if this is an assertion, from an attribute
             if (assertImpl.getAttrName() != null) {
                 value = assertImpl.getAttrValue();
                 XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) 
@@ -331,9 +357,10 @@ public class XMLAssertPsychopathImpl ext
                     // tokenize the list value by the longest sequence of
                     // white-spaces.
                     String[] values = value.split("\\s+");
+                    
                     // evaluate assertion on all of list items
                     for (int valIdx = 0; valIdx < values.length; valIdx++) {
-                        setValueOf$value(values[valIdx], attrType, null);
+                        setValueOf$valueForAListItem(attrType, 
values[valIdx]);                        
                         AssertionError assertError = 
evaluateAssertion(element, 
                                                                     
assertImpl, 
                                                                 
values[valIdx], 
@@ -350,7 +377,7 @@ public class XMLAssertPsychopathImpl ext
                     setValueOf$value(value, null, attrType);
                     AssertionError assertError = evaluateAssertion(element,
                                                          assertImpl, value,
-                                                        xpathContextExists,
+                                                         xpathContextExists,
                                                                    false);
                     if (assertError != null) {
                         reportAssertionsError(assertError);    
@@ -360,7 +387,7 @@ public class XMLAssertPsychopathImpl ext
             else {
                 AssertionError assertError = evaluateAssertion(element,
                                                           assertImpl, value,
-                                                         xpathContextExists,
+                                                          xpathContextExists,
                                                              false);
                 if (assertError != null) {
                     reportAssertionsError(assertError);    
@@ -389,17 +416,18 @@ public class XMLAssertPsychopathImpl ext
             fAttrName = null;            
         }
         
-    } // evaluateAssertionsFromComplexType
+    } // evaluateAssertionsFromAComplexType
     
     
     /*
      * Evaluate assertions on a "simple type".
      */
-    private void evaluateAssertionsFromSimpleType(QName element,
+    private void evaluateAssertionsFromASimpleType(QName element,
                                              XSSimpleTypeDefinition itemType,
                                              XSObjectList memberTypes,
-                                             List assertions, String value) 
-                                                   throws Exception {
+                                             List assertions, String value,
+                                             ElementPSVI elemPSVI)             
                                
+                                             throws Exception {
         
         // assertions from a simple type definition           
         Vector assertList = (Vector) assertions;
@@ -410,15 +438,14 @@ public class XMLAssertPsychopathImpl ext
                // evaluating assertions for simpleType -> list.                
    
                // tokenize the list value by the longest sequence of
                // white-spaces.
-               String[] values = value.split("\\s+");                   
+               String[] values = value.split("\\s+");               
+               
                // evaluate assertion on all of list items
                for (int valIdx = 0; valIdx < values.length; valIdx++) {
-                  setValueOf$value(values[valIdx], itemType, null);
+                  setValueOf$valueForAListItem(itemType, values[valIdx]);
                   AssertionError assertError = evaluateAssertion(element, 
-                                                              assertImpl, 
-                                                          values[valIdx], 
-                                                               false,
-                                                               true);
+                                                 assertImpl, values[valIdx], 
+                                                 false, true);
                   if (assertError != null) {
                       reportAssertionsError(assertError);    
                   }
@@ -428,10 +455,8 @@ public class XMLAssertPsychopathImpl ext
                 // evaluating assertions for simpleType -> restriction
                 setValueOf$value(value, null, null);
                 AssertionError assertError = evaluateAssertion(element, 
-                                                            assertImpl,
-                                                            value, 
-                                                            false,
-                                                            false);
+                                                        assertImpl, value, 
+                                                        false, false);
                 if (assertError != null) {
                     reportAssertionsError(assertError);    
                 }    
@@ -458,7 +483,34 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-     * Determine if validation should fail due to assertions evaluation for
+     * Set a typed value of XPath2 context variable $value, if an atomic
+     * value on which assertion is been evaluated, is an item of a schema
+     * component, xs:list.
+     */
+    private void setValueOf$valueForAListItem(XSSimpleTypeDefinition simpType,
+                                              String value) 
+                                             throws Exception {
+        
+        if ((simpType.getMemberTypes()).getLength() > 0) {
+            // The list item's type has variety 'union'.
+            XSSimpleTypeDefinition actualListItemType = 
+                                        getActualListItemTypeForVarietyUnion(
+                                                     simpType.getMemberTypes(),
+                                                     value);
+            // set a schema 'typed value' to variable $value
+            setValueOf$value(value, actualListItemType,
+                                                 null);
+        } 
+        else {
+           // The list item's type has variety 'atomic'.
+           setValueOf$value(value, simpType, null); 
+        }
+        
+    } // setSchemaTypeOn$valueForAListItem
+    
+    
+    /*
+     * Determine if an validation must fail due to assertions evaluation for
      * 'simpleType -> union' member types.
      */
     private boolean isValidationFailedForUnion(XSObjectList memberTypes, 
@@ -479,21 +531,25 @@ public class XMLAssertPsychopathImpl ext
                                             simpleTypeHasAsserts(memType)) {
                 XSObjectList memberTypeFacets = memType.getMultiValueFacets();
                 for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < 
-                                                       
memberTypeFacets.getLength(); 
-                                                       memberTypeFacetIdx++) {
-                    XSMultiValueFacet facet = (XSMultiValueFacet) 
memberTypeFacets.
-                                                         
item(memberTypeFacetIdx);
-                    if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
+                                              memberTypeFacets.getLength(); 
+                                              memberTypeFacetIdx++) {
+                    XSMultiValueFacet facet = (XSMultiValueFacet) 
+                                   memberTypeFacets.item(memberTypeFacetIdx);
+                    if (facet.getFacetKind() == XSSimpleTypeDefinition.
+                                                             FACET_ASSERT) {
                         Vector assertFacets = facet.getAsserts();
                         int assertsSucceeded = 0;
-                        for (Iterator iter = assertFacets.iterator(); 
iter.hasNext(); ) {
-                            XSAssertImpl assertImpl = (XSAssertImpl) 
iter.next();
+                        for (Iterator iter = assertFacets.iterator(); iter.
+                                                               hasNext(); ) {
+                            XSAssertImpl assertImpl = (XSAssertImpl) iter.
+                                                                      next();
                             try {
                                setValueOf$value(value, memType, null);
-                               AssertionError assertError = 
evaluateAssertion(element, 
-                                                                           
assertImpl,
-                                                                               
 value, 
-                                                                        false, 
false);
+                               AssertionError assertError = evaluateAssertion(
+                                                                     element, 
+                                                                     
assertImpl,
+                                                                     value, 
+                                                                     false, 
false);
                                if (assertError == null) {
                                    assertsSucceeded++;  
                                }
@@ -632,22 +688,23 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-     * Assign a typed value to the XPath2 "dynamic context" variable, $value.
+     * Assign a "XSD typed value" to the XPath2 "dynamic context" variable,
+     * $value.
      */
     private void setValueOf$value(String value, 
                                   XSSimpleTypeDefinition listOrUnionType, 
                                   XSTypeDefinition attrType) throws Exception {
         
-        // XML Schema 1.1 type for variable $value
-        String xsdTypeName = "";
+        // dummy short code initializer
+        short xsdTypecode = -100;
         
         if (listOrUnionType != null) {
-            xsdTypeName = getXSDtypeOf$Value(listOrUnionType);    
+            xsdTypecode = getXSDTypeCodeOf$Value(listOrUnionType);    
         }
         else {
            if (attrType != null) {
               // is value of an attribute
-              xsdTypeName = getXSDtypeOf$Value(attrType);  
+               xsdTypecode = getXSDTypeCodeOf$Value(attrType);  
            }
            else {
               // is "simple type" value of an element
@@ -658,20 +715,21 @@ public class XMLAssertPsychopathImpl ext
                   XSComplexTypeDefinition cmplxTypeDef = 
(XSComplexTypeDefinition)
                                                                        typeDef;
                   if (cmplxTypeDef.getSimpleType() != null) {
-                     xsdTypeName = 
getXSDtypeOf$Value(cmplxTypeDef.getSimpleType());   
+                      xsdTypecode = 
getXSDTypeCodeOf$Value(cmplxTypeDef.getSimpleType());   
                   }
               }
               else {
-                 xsdTypeName = getXSDtypeOf$Value(currentAssertPSVINode.
+                  xsdTypecode = getXSDTypeCodeOf$Value(currentAssertPSVINode.
                                                getTypeDefinition());
               }
            }
         }
         
-        // determine the 'schema type' representation used within PsychoPath 
XPath 
-        // engine, corresponding to an XML Schema language type.
-        Object psychoPathType = SchemaTypeValueFactory.newSchemaTypeValue
-                                                         (xsdTypeName, value);
+        // determine the PsychoPath XML schema 'typed value', given the Xerces
+        // type code as an API method argument(few of the input type code
+        // constants are PsychoPath specific). 
+        AnyType psychoPathType = SchemaTypeValueFactory.newSchemaTypeValue
+                                                         (xsdTypecode, value);
         
         fDynamicContext.set_variable(
                new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
@@ -681,20 +739,39 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-       Find the built-in XSD type for XPath2 variable, $value. This function
-       recursively searches the XSD type hierarchy navigating up the base
-       types, to find the needed built-in type.
+       Find the built-in "XML Schema" Xerces 'type code' for XPath2 variable,
+       $value. This function recursively searches the XSD type hierarchy
+       navigating up the base types, to find the needed built-in type.
+       
+       The value of typeCode is retrieved from PsychoPath XPath2 engine, which
+       returns a proper Xerces schema 'type code', or few of it's own crafted
+       type (for few of XML schema 1.1 types) code values, which are again 
passed
+       on to PsychoPath engine, to determine the right PsychoPath 'schema type'
+       object representation.
     */
-    private String getXSDtypeOf$Value(XSTypeDefinition elementType) {
-      
-      if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) {        
-         return elementType.getName();    
+    private short getXSDTypeCodeOf$Value(XSTypeDefinition elementType) {
+            
+      if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) {
+         short typeCode = -100; // dummy initializer
+         
+         boolean isxsd11Type = false;         
+         if ("dayTimeDuration".equals(elementType.getName())) {
+             typeCode = PsychoPathTypeHelper.DAYTIMEDURATION_DT;
+             isxsd11Type = true;
+         }
+         else if ("yearMonthDuration".equals(elementType.getName())) {
+             typeCode = PsychoPathTypeHelper.YEARMONTHDURATION_DT;
+             isxsd11Type = true;
+         }
+         
+         return (isxsd11Type) ? typeCode : ((XSSimpleTypeDefinition) 
+                                            elementType).getBuiltInKind();    
       }
       else {
-         return getXSDtypeOf$Value(elementType.getBaseType()); 
+         return getXSDTypeCodeOf$Value(elementType.getBaseType()); 
       }
       
-    } // getXSDtypeOf$Value
+    } // getXSDTypeCodeOf$Value
     
     
     /*
@@ -755,6 +832,61 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
+     * Find the actual 'atomic type' of an 'list item' instance, if the
+     * 'item type' of list has variety union. 
+     */
+    private XSSimpleTypeDefinition getActualListItemTypeForVarietyUnion
+                                                    (XSObjectList memberTypes,
+                                                     String value) {
+
+        XSSimpleTypeDefinition simpleTypeDefn = null;
+        
+        // Inspecting the member types of union in order, to see that which
+        // schema type can successfully validate an atomic value first
+        // (and this will be the result for us, from this method).
+        for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength(); 
+                                                            memTypeIdx++) {
+           XSSimpleType memSimpleType = (XSSimpleType) memberTypes.item
+                                                             (memTypeIdx);
+              if (isValueValidForASimpleType(value, memSimpleType)) {
+                 // no more memberTypes need to be checked
+                 simpleTypeDefn = memSimpleType; 
+                 break; 
+              }
+        }
+        
+        return simpleTypeDefn;
+        
+    } // getActualListItemTypeForVarietyUnion
+    
+    
+    /*
+     * Determine if a "string value" is valid for a given simpleType
+     * definition. Using Xerces 'XSSimpleType.validate' API for this need.
+     */
+    private boolean isValueValidForASimpleType(String value, XSSimpleType 
+                                                             simplType) {
+        
+        boolean isValueValid = true;
+        
+        try {
+            // construct necessary context objects
+            ValidatedInfo validatedInfo = new ValidatedInfo();
+            ValidationContext validationState = new ValidationState();
+            
+            // attempt to validate the value with the simpleType
+            simplType.validate(value, validationState, validatedInfo);
+        } 
+        catch(InvalidDatatypeValueException ex){
+            isValueValid = false;
+        }
+        
+        return isValueValid;
+        
+    } // isValueValidForASimpleType
+    
+    
+    /*
      * An object to store assertion error details.
      */
     class AssertionError {
@@ -769,8 +901,8 @@ public class XMLAssertPsychopathImpl ext
         
         // class constructor
         public AssertionError(String errorCode, QName element, 
-                              XSAssertImpl assertImpl, String value,
-                              boolean isList) {
+                              XSAssertImpl assertImpl, 
+                              String value, boolean isList) {
            this.errorCode = errorCode;
            this.element = element;
            this.assertImpl = assertImpl;

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=992616&r1=992615&r2=992616&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
 Sat Sep  4 14:53:12 2010
@@ -1349,7 +1349,7 @@ public class XMLSchemaValidator
     
     // variable to track validity of simple content for union types.
     // used for assertions processing.
-    private boolean fAtomicValueValid = true;
+    private boolean fisAtomicValueValid = true;
     
     // 'type alternative' validator subcomponent
     private XSDTypeAlternativeValidator fTypeAlternativeValidator = null;
@@ -2558,8 +2558,8 @@ public class XMLSchemaValidator
             fAssertionValidator.handleEndElement(element, fCurrentElemDecl, 
                                                 fCurrentType, fNotation, 
                                                 fGrammarBucket,
-                                                fAtomicValueValid);
-            fAtomicValueValid = true;
+                                                fisAtomicValueValid);
+            fisAtomicValueValid = true;
         }
 
         // Check if we should modify the xsi:type ignore depth
@@ -3247,9 +3247,9 @@ public class XMLSchemaValidator
             // additional check for assertions processing, for simple type 
             // variety 'union'.
             if (attDV.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) {
-                if (isUnionValidationAssertCheck(attDV.getMemberTypes(), 
+                if (isAtomicValueValidForAnUnion(attDV.getMemberTypes(), 
                                                   attrValue, null)) {
-                    fAtomicValueValid = false; 
+                    fisAtomicValueValid = false; 
                 }
             }
             
@@ -3275,7 +3275,7 @@ public class XMLSchemaValidator
             }
         } 
         catch (InvalidDatatypeValueException idve) {
-            fAtomicValueValid = false;
+            fisAtomicValueValid = false;
             reportSchemaError(idve.getKey(), idve.getArgs());
             reportSchemaError(
                 "cvc-attribute.3",
@@ -3409,14 +3409,14 @@ public class XMLSchemaValidator
                     // additional check for assertions processing, for simple 
type 
                     // variety 'union'.
                     if (attDV.getVariety() == 
XSSimpleTypeDefinition.VARIETY_UNION) {
-                        if 
(isUnionValidationAssertCheck(attDV.getMemberTypes(), 
+                        if 
(isAtomicValueValidForAnUnion(attDV.getMemberTypes(), 
                                                          null, defaultValue)) {
-                            fAtomicValueValid = false; 
+                            fisAtomicValueValid = false; 
                         }
                     }
                 } 
                 catch (InvalidDatatypeValueException idve) {
-                    fAtomicValueValid = false;
+                    fisAtomicValueValid = false;
                     reportSchemaError(idve.getKey(), idve.getArgs());
                 }
                 fValidationState.setFacetChecking(facetChecking);
@@ -3626,14 +3626,14 @@ public class XMLSchemaValidator
                     // additional check for assertions processing, for simple 
type 
                     // variety 'union'.
                     if (dv.getVariety() == 
XSSimpleTypeDefinition.VARIETY_UNION) {
-                        if (isUnionValidationAssertCheck(dv.getMemberTypes(), 
+                        if (isAtomicValueValidForAnUnion(dv.getMemberTypes(), 
                                                      
String.valueOf(textContent), 
                                                      null)) {
-                            fAtomicValueValid = false; 
+                            fisAtomicValueValid = false; 
                         }
                     }
                 } catch (InvalidDatatypeValueException e) {
-                    fAtomicValueValid = false;
+                    fisAtomicValueValid = false;
                     reportSchemaError(e.getKey(), e.getArgs());
                     reportSchemaError(
                         "cvc-type.3.1.3",
@@ -3676,14 +3676,14 @@ public class XMLSchemaValidator
                     // additional check for assertions processing, for simple 
type 
                     // variety 'union'.
                     if (dv.getVariety() == 
XSSimpleTypeDefinition.VARIETY_UNION) {
-                        if (isUnionValidationAssertCheck(dv.getMemberTypes(), 
+                        if (isAtomicValueValidForAnUnion(dv.getMemberTypes(), 
                                                          
String.valueOf(textContent), 
                                                          null)) {
-                            fAtomicValueValid = false; 
+                            fisAtomicValueValid = false; 
                         }
                     }
                 } catch (InvalidDatatypeValueException e) {
-                    fAtomicValueValid = false;
+                    fisAtomicValueValid = false;
                     reportSchemaError(e.getKey(), e.getArgs());
                     reportSchemaError("cvc-complex-type.2.2", new Object[] { 
element.rawname });
                 }
@@ -4841,16 +4841,22 @@ public class XMLSchemaValidator
         }
     }
     
+    
     /*
      * Determine if an atomic value is valid with respect to any of the 
-     * union's built-in schema types. 
+     * union's built-in schema types. If this method returns 'true', then
+     * the value is valid with respect to an union schema component. 
      */
-    private boolean isUnionValidationAssertCheck(XSObjectList memberTypes,
-                                                 String content,
-                                                 ValidatedInfo validatedInfo) {
+    private boolean isAtomicValueValidForAnUnion(XSObjectList
+                                              memberTypes, String content,
+                                              ValidatedInfo validatedInfo) {
         
         boolean isValid = false;
         
+        // check the union member types in sequence, to check for validity of
+        // an 'atomic value'. the validity of 'atomic value' wrt to 1st type
+        // in this sequence, is sufficient to achieve the objective of this
+        // method.
         for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength(); 
                                                     memTypeIdx++) {
             XSSimpleType simpleTypeDv = (XSSimpleType) memberTypes.item
@@ -4876,6 +4882,6 @@ public class XMLSchemaValidator
         
         return isValid;
         
-    } // isUnionValidationAssertCheck    
+    } // isAtomicValueValidForAnUnion    
     
 } // class SchemaValidator

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java?rev=992616&r1=992615&r2=992616&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertImpl.java
 Sat Sep  4 14:53:12 2010
@@ -54,26 +54,31 @@ public class XSAssertImpl extends Abstra
     /** Default XPath namespace */
     protected String fXPathDefaultNamespace = null;
       
-    /** XPath 2.0 namespace context. Derived from XSDocumentInfo in XSD 
traversers. */
+    /** XPath 2.0 namespace context. Derived from XSDocumentInfo in Xerces
+        schema "component traversers".
+    */
     protected NamespaceSupport fXPath2NamespaceContext = null;
     
-    // a non null value of this object indicates, that this assertion is
-    // for an attribute, and value of this object would be the attribute's
-    // name.
+    // a non null value of this object indicates, that this assertion belongs
+    // to an attribute's schema type, and value of this object would be the
+    // attribute's name.
     protected String attrName = null;
     
-    // a non null value of this object indicates, that this assertion is
-    // for an attribute, and value of this object would be the attribute's
-    // value.
+    // a non null value of this object indicates, that this assertion belongs
+    // to an attribute's schema type, and value of this object would be the
+    // attribute's value.
     protected String attrValue = null;
     
-    // XSDHandler object, passed on from the traversers 
+    // XSDHandler object, passed on from the Xerces schema "component
+    // traversers". 
     protected XSDHandler fSchemaHandler = null;
     
-    // user-defined message, to display, during assertion failures
+    // user-defined message to provide to an user context, during assertion
+    // failures.
     protected String message = null;
     
-    // if assertion belongs to a simpleType, the type's variety
+    // representing the schema type's variety, if an assertion belongs to a
+    // schema simpleType.
     protected short fVariety = 0;
 
     /** Constructor */
@@ -112,10 +117,10 @@ public class XSAssertImpl extends Abstra
     
     /**
      * Sets the kind of assertion this is. This could be one of the following:
-     * -> an assertion from a complexType (XSConstants.ASSERTION)
-     * -> an assertion facet from a complexType -> simpleContent 
-     *                             (XSConstants.ASSERTION_FACET)
-     * -> an assertion facet from a simpleType (XSConstants.ASSERTION_FACET)
+     * -> an assertion from a complexType      :   XSConstants.ASSERTION
+     * -> an assertion facet from a "complexType -> simpleContent" 
+     *                                         :   XSConstants.ASSERTION_FACET
+     * -> an assertion facet from a simpleType :   XSConstants.ASSERTION_FACET
      */
     public void setAssertKind(short assertKind) {
         this.assertKind = assertKind;
@@ -214,7 +219,9 @@ public class XSAssertImpl extends Abstra
     }
     
     /*
-     * Tests if two assert components are equal
+     * Tests if two assertion components are equal. Xerces has a specific
+     * notion of assertions equality, as described by the algorithm in this
+     * method.
      */
     public boolean equals(XSAssertImpl pAssertion) {
       boolean returnVal = false;



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to