Author: mukulg
Date: Thu Mar 24 04:22:53 2011
New Revision: 1084840

URL: http://svn.apache.org/viewvc?rev=1084840&view=rev
Log:
refactoring schema 1.1 assertions codebase a bit. also moved methods textually 
within a class, and miscellaneous comments & javadocs improvements. i did try 
to improve the readability and maintainibility of the code base involved in 
this commit.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java?rev=1084840&r1=1084839&r2=1084840&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java
 Thu Mar 24 04:22:53 2011
@@ -197,32 +197,14 @@ public class XMLAssertPsychopathXPath2Im
             Augmentations attrAugs = attributes.getAugmentations(attrIdx);
             AttributePSVImpl attrPsvi = 
(AttributePSVImpl)attrAugs.getItem(Constants.ATTRIBUTE_PSVI);
             XSSimpleTypeDefinition attrSimpleType = (XSSimpleTypeDefinition) 
attrPsvi.getTypeDefinition();
-            final boolean isTypeDerivedFromList = ((XSSimpleType) 
attrSimpleType.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
-            final boolean isTypeDerivedFromUnion = ((XSSimpleType) 
attrSimpleType.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;       
     
             List attrAssertList = 
fXmlSchemaValidator.getAssertionValidator().getAssertsFromSimpleType(attrSimpleType);
-            if (attrAssertList != null) {                
+            if (attrAssertList != null) {
+                boolean isTypeDerivedFromList = ((XSSimpleType) 
attrSimpleType.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
+                boolean isTypeDerivedFromUnion = ((XSSimpleType) 
attrSimpleType.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;       
         
                 for (int assertIdx = 0; assertIdx < attrAssertList.size(); 
assertIdx++) {
                     XSAssertImpl assertImpl = 
(XSAssertImpl)attrAssertList.get(assertIdx);
                     assertImpl.setAttrName(attrQname.localpart);
-                    if (attrSimpleType.getVariety() == 
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
-                        // evaluating assertions for "simpleType -> 
restriction" (not derived by union)
-                        setTypedValueFor$value(attrValue, null, 
attrSimpleType, false);
-                        AssertionError assertError = 
evaluateOneAssertion(element, assertImpl, attrValue, false, false);
-                        if (assertError != null) {
-                            reportAssertionsError(assertError);    
-                        }                         
-                    }
-                    else if (attrSimpleType.getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST) {
-                        // evaluating assertions for "simpleType -> list"      
              
-                        evaluateAssertionOnSTListValue(element, attrValue, 
assertImpl, false, attrSimpleType.getItemType(), isTypeDerivedFromList); 
-                    }
-                    else if 
(((Boolean)attrAugs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) {
-                        // evaluating assertions for "simpleType -> union" 
-                        boolean isAttrValidWithAssertions = 
evaluateAssertionOnSTUnion(element, attrSimpleType, isTypeDerivedFromUnion, 
assertImpl, attrValue, attrAugs);
-                        if (!isAttrValidWithAssertions) {                      
      
-                            
fXmlSchemaValidator.reportSchemaError("cvc-attribute.3", new Object[] 
{element.rawname, attrQname.localpart, attrValue, 
((XSSimpleTypeDecl)attrSimpleType).getTypeName()});   
-                        }
-                    }
+                    evaluateOneAssertionFromSimpleType(element, attrValue, 
attrAugs, attrSimpleType, isTypeDerivedFromList, isTypeDerivedFromUnion, 
assertImpl, true, attrQname);
                     // evaluate assertions on itemType of xs:list
                     XSSimpleTypeDefinition attrItemType = 
attrSimpleType.getItemType();
                     if (isTypeDerivedFromList && attrItemType != null) {
@@ -295,199 +277,75 @@ public class XMLAssertPsychopathXPath2Im
          
     } // processAllAssertionsOnElement
 
-
-    /*
-     * Determine "string value" of XPath2 context variable $value.
-     */
-    private String getStringValueOf$value(ElementPSVI pElemPSVI) throws 
DOMException {
-        
-        // there could be adjacent text nodes in a DOM tree. merge them to get 
the value.
-        NodeList childList = fCurrentAssertDomNode.getChildNodes();
-        StringBuffer textValueContents = new StringBuffer();
-        final int childListLength = childList.getLength();
-        int textChildCount = 0;
-        // we are only interested in text & element nodes. store count of them 
in this variable.
-        int effectiveChildNodeCount = 0;
-        for (int childNodeIndex = 0; childNodeIndex < childListLength; 
childNodeIndex++) {
-            Node node = childList.item(childNodeIndex);
-            short nodeType = node.getNodeType();
-            if (nodeType == Node.TEXT_NODE) {
-                textChildCount++;
-                effectiveChildNodeCount++;
-                textValueContents.append(node.getNodeValue());
-            }
-            else if (nodeType == Node.ELEMENT_NODE) {
-                effectiveChildNodeCount++;  
-            }
-        }
-        
-        String strValueOf$value = "";
-        
-        if (textChildCount == effectiveChildNodeCount) {
-            // the DOM tree we are inspecting has simple content. therefore we 
can find the desired string value. 
-            XSElementDeclaration elemDecl = pElemPSVI.getElementDeclaration();
-            if 
((elemDecl.getTypeDefinition()).derivedFrom(SchemaSymbols.URI_SCHEMAFORSCHEMA, 
SchemaSymbols.ATTVAL_STRING, XSConstants.DERIVATION_RESTRICTION)) {
-                // if element's schema type is derived by restriction from 
xs:string, white-space normalization is not needed for the
-                // string value for context variable $value.
-                strValueOf$value = textValueContents.toString();  
-            }
-            else {
-                // white-space normalization is needed for the string value of 
$value in case of derivation from non xs:string atomic types
-                strValueOf$value = XMLChar.trim(textValueContents.toString());
-            }    
-        }
-        else {
-            // the DOM tree we are inspecting has 'mixed/element only' content.
-            strValueOf$value = null; 
-        }
-        
-        return strValueOf$value;
-        
-    } // getStringValueOf$value
-
-
+    
     /*
-     * Evaluate assertions on a "complex type".
+     * Evaluate assertions on a "simple type" on elements.
      */
-    private void evaluateAssertionsFromAComplexType(QName element, List 
assertions, String value, Augmentations augs) throws Exception {
-        
-        if (value != null) {
-            // complex type with simple content
-            setTypedValueFor$value(value, null, null, false);
-        } else {
-            // complex type with complex content. set xpath context variable 
$value to an empty sequence.
-            fXpath2DynamicContext.set_variable(new 
org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"), 
getXPath2ResultSequence(new ArrayList()));
-        }
+    private void evaluateAssertionsFromASimpleType(QName element, List 
assertions, String value, Augmentations augs) throws Exception {  
+              
+        XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) 
((ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI)).getTypeDefinition();
+        boolean isTypeDerivedFromList = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
+        boolean isTypeDerivedFromUnion = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
         
-        XSObjectList assertList = (XSObjectList) assertions;
+        Vector assertList = (Vector) assertions;
         for (int assertIdx = 0; assertIdx < assertList.size(); assertIdx++) {
             XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
-            String xPathDefaultNamespace = 
assertImpl.getXPathDefaultNamespace();             
+            String xPathDefaultNamespace = 
assertImpl.getXPathDefaultNamespace(); 
             if (xPathDefaultNamespace != null) {
                 fXpath2DynamicContext.add_namespace(null, 
xPathDefaultNamespace);  
             }
-            // NOTE: asserts from attributes are not evaluated here. they are 
evaluated in method startElement -> evaluateAssertsFromAttributes.  
-            if (assertImpl.getType() == XSConstants.ASSERTION) {
-                // is an xs:assert component
-                AssertionError assertError = evaluateOneAssertion(element, 
assertImpl, value, true, false);
-                if (assertError != null) {
-                    reportAssertionsError(assertError);    
-                }   
-            } 
-            else if (assertImpl.getAttrName() == null) {
-                // complex type with simple content
-                XSSimpleTypeDefinition simpleTypeDefn = null;
-                XSTypeDefinition xsTypeDefn = assertImpl.getTypeDefinition();  
              
-                if (xsTypeDefn instanceof XSComplexTypeDefinition) {
-                    simpleTypeDefn = ((XSComplexTypeDefinition) 
xsTypeDefn).getSimpleType();   
-                }
-                else {
-                    simpleTypeDefn = (XSSimpleTypeDefinition) xsTypeDefn;  
-                }
-                ElementPSVI elemPSVI = (ElementPSVI) 
augs.getItem(Constants.ELEMENT_PSVI);
-                XSComplexTypeDefinition complexTypeDef = 
(XSComplexTypeDefinition)elemPSVI.getTypeDefinition();
-                if 
(XSTypeHelper.isComplexTypeDerivedFromSTListByExt(complexTypeDef)) {
-                    // reassign value to simple type instance
-                    simpleTypeDefn = 
(XSSimpleTypeDefinition)complexTypeDef.getBaseType(); 
-                }
-                final boolean isTypeDerivedFromList = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
-                final boolean isTypeDerivedFromUnion = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
-                if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
-                    // evaluating assertions for "simpleType -> restriction" 
(not derived by union)
-                    setTypedValueFor$value(value, null, simpleTypeDefn, false);
-                    AssertionError assertError = evaluateOneAssertion(element, 
assertImpl, value, false, false);
-                    if (assertError != null) {
-                        reportAssertionsError(assertError);    
-                    }
-                }
-                else if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST) {
-                    // evaluating assertions for "simpleType -> list"          
          
-                    evaluateAssertionOnSTListValue(element, value, assertImpl, 
false, simpleTypeDefn.getItemType(), isTypeDerivedFromList);
-                }
-                else if (((Boolean) 
augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) {
-                    // evaluating assertions for "simpleType -> union" 
-                    boolean isElemValidWithAssertions = 
evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, 
assertImpl, value, augs);
-                    if (!isElemValidWithAssertions) {
-                        
fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new Object[] 
{element.rawname, value}); 
-                    }
-                }                
-                // evaluate assertions on itemType of xs:list
-                XSSimpleTypeDefinition listItemType = 
simpleTypeDefn.getItemType();
-                if (isTypeDerivedFromList && listItemType != null) {
-                    evaluateAssertsFromItemTypeOfSTList(element, listItemType, 
value);
-                }
-            }            
+            evaluateOneAssertionFromSimpleType(element, value, augs, 
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl, 
false, null);
         }
-       
         
-    } // evaluateAssertionsFromAComplexType
-
+        // evaluate assertions on itemType of xs:list
+        if (isTypeDerivedFromList && simpleTypeDefn.getItemType() != null) {
+            evaluateAssertsFromItemTypeOfSTList(element, 
simpleTypeDefn.getItemType(), value); 
+        }
+        
+    } // evaluateAssertionsFromASimpleType
+    
     
     /*
-     * Evaluate assertions on a "simple type" on elements.
+     * Evaluate one assertion instance for a simpleType (this assertion could 
be from an attribute, simpleType on element or a complexType with simple 
content).
      */
-    private Augmentations evaluateAssertionsFromASimpleType(QName element, 
List assertions, String value, Augmentations augs) throws Exception {
-        
-        // initially PSVI object to be returned
-        ElementPSVI elemPSVI = (ElementPSVI) 
augs.getItem(Constants.ELEMENT_PSVI);
+    private void evaluateOneAssertionFromSimpleType(QName element, String 
value, Augmentations augs, XSSimpleTypeDefinition simpleTypeDefn, boolean 
isTypeDerivedFromList, boolean isTypeDerivedFromUnion,
+                                                    XSAssertImpl assertImpl, 
boolean isAttribute, QName attrQname) throws Exception {
         
-        // find the itemType and memberTypes of xs:list and xs:union 
respectively (only one of these will be applicable)        
-        XSSimpleTypeDefinition itemType = null;               
-        XSObjectList memberTypes = null;
-        XSSimpleTypeDefinition simpleTypeDefn = null;
-        if (elemPSVI.getTypeDefinition().getTypeCategory() == 
XSTypeDefinition.SIMPLE_TYPE) {
-            simpleTypeDefn = (XSSimpleTypeDefinition) 
elemPSVI.getTypeDefinition();
-            itemType = simpleTypeDefn.getItemType();
-            if (itemType == null) {
-                memberTypes = simpleTypeDefn.getMemberTypes();    
-            }
-        }
-        
-        final boolean isTypeDerivedFromList = ((XSSimpleType) 
elemPSVI.getTypeDefinition().getBaseType()).getVariety() == 
XSSimpleType.VARIETY_LIST;
-        final boolean isTypeDerivedFromUnion = ((XSSimpleType) 
elemPSVI.getTypeDefinition().getBaseType()).getVariety() == 
XSSimpleType.VARIETY_UNION;
-        // process assertions from a simple type definition           
-        Vector assertList = (Vector) assertions;
-        final int assertListLength = assertList.size();
-        for (int assertIdx = 0; assertIdx < assertListLength; assertIdx++) {
-            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
-            String xPathDefaultNamespace = 
assertImpl.getXPathDefaultNamespace(); 
-            if (xPathDefaultNamespace != null) {
-                fXpath2DynamicContext.add_namespace(null, 
xPathDefaultNamespace);  
-            }
-            if (memberTypes != null && memberTypes.getLength() == 0) {
-                // evaluating assertions for "simpleType -> restriction" (not 
derived by union)
-                setTypedValueFor$value(value, null, null, false);
-                AssertionError assertError = evaluateOneAssertion(element, 
assertImpl, value, false, false);
-                if (assertError != null) {
-                    reportAssertionsError(assertError);    
-                }    
+        if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_ATOMIC) {
+            // evaluating assertions for "simpleType -> restriction" (not 
derived by union)
+            if (isAttribute) {
+               setTypedValueFor$value(value, null, simpleTypeDefn, false);
             }
-            else if (itemType != null) {
-               // evaluating assertions for "simpleType -> list"               
-               evaluateAssertionOnSTListValue(element, value, assertImpl, 
false, itemType, isTypeDerivedFromList);
-            }            
-            else if (((Boolean) 
augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) {
-               // evaluating assertions for "simpleType -> union"              
 
-               boolean isElemValidWithAssertions = 
evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, 
assertImpl, value, augs);
-               if (!isElemValidWithAssertions) {
-                   fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new 
Object[] {element.rawname, value}); 
-               }
+            else {
+               setTypedValueFor$value(value, null, null, false);
             }
+            AssertionError assertError = evaluateOneAssertion(element, 
assertImpl, value, false, false);
+            if (assertError != null) {
+                reportAssertionsError(assertError);    
+            }                         
         }
-        
-        // evaluate assertions on itemType of xs:list
-        if (isTypeDerivedFromList && itemType != null) {
-            evaluateAssertsFromItemTypeOfSTList(element, itemType, value); 
+        else if (simpleTypeDefn.getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST) {
+            // evaluating assertions for "simpleType -> list"                  
  
+            evaluateAssertionOnSTListValue(element, value, assertImpl, false, 
simpleTypeDefn.getItemType(), isTypeDerivedFromList); 
+        }
+        else if 
(((Boolean)augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) {
+            // evaluating assertions for "simpleType -> union" 
+            boolean isValueValidWithSTUnion = 
evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, 
assertImpl, value, augs);
+            if (!isValueValidWithSTUnion) { 
+                if (isAttribute) {
+                   fXmlSchemaValidator.reportSchemaError("cvc-attribute.3", 
new Object[] {element.rawname, attrQname.localpart, value, 
((XSSimpleTypeDecl)simpleTypeDefn).getTypeName()});
+                }
+                else {
+                    fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", 
new Object[] {element.rawname, value}); 
+                }
+            }
         }
         
-        return augs;
-        
-    } // evaluateAssertionsFromASimpleType
+    } // evaluateOneAssertionFromSimpleType
     
     
     /*
-     * Evaluate assertions from itemType (having variety 'atomic') of xs:list. 
This method is used to evaluate assertions from elements
-     * with simple content, and simpleType definitions from attributes.
+     * Evaluate assertions from itemType with variety 'atomic' on a 
simpleType->list.
      */
     private void evaluateAssertsFromItemTypeOfSTList(QName element, 
XSSimpleTypeDefinition listItemType, String value) throws Exception {
         
@@ -581,6 +439,110 @@ public class XMLAssertPsychopathXPath2Im
     
     
     /*
+     * Evaluate assertions on a "complex type".
+     */
+    private void evaluateAssertionsFromAComplexType(QName element, List 
assertions, String value, Augmentations augs) throws Exception {
+        
+        if (value != null) {
+            // complex type with simple content
+            setTypedValueFor$value(value, null, null, false);
+        } else {
+            // complex type with complex content. set xpath context variable 
$value to an empty sequence.
+            fXpath2DynamicContext.set_variable(new 
org.eclipse.wst.xml.xpath2.processor.internal.types.QName("value"), 
getXPath2ResultSequence(new ArrayList()));
+        }
+        
+        XSObjectList assertList = (XSObjectList) assertions;
+        for (int assertIdx = 0; assertIdx < assertList.size(); assertIdx++) {
+            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx);
+            String xPathDefaultNamespace = 
assertImpl.getXPathDefaultNamespace();             
+            if (xPathDefaultNamespace != null) {
+                fXpath2DynamicContext.add_namespace(null, 
xPathDefaultNamespace);  
+            }
+            // NOTE: asserts from attributes are not evaluated here. they are 
evaluated in method startElement -> evaluateAssertsFromAttributes.  
+            if (assertImpl.getType() == XSConstants.ASSERTION) {
+                // is an xs:assert component
+                AssertionError assertError = evaluateOneAssertion(element, 
assertImpl, value, true, false);
+                if (assertError != null) {
+                    reportAssertionsError(assertError);    
+                }   
+            } 
+            else if (assertImpl.getAttrName() == null) {
+                // complex type with simple content
+                XSSimpleTypeDefinition simpleTypeDefn = null;
+                XSTypeDefinition xsTypeDefn = assertImpl.getTypeDefinition();  
              
+                if (xsTypeDefn instanceof XSComplexTypeDefinition) {
+                    simpleTypeDefn = ((XSComplexTypeDefinition) 
xsTypeDefn).getSimpleType();   
+                }
+                else {
+                    simpleTypeDefn = (XSSimpleTypeDefinition) xsTypeDefn;  
+                }
+                ElementPSVI elemPSVI = (ElementPSVI) 
augs.getItem(Constants.ELEMENT_PSVI);
+                XSComplexTypeDefinition complexTypeDef = 
(XSComplexTypeDefinition)elemPSVI.getTypeDefinition();
+                if 
(XSTypeHelper.isComplexTypeDerivedFromSTList(complexTypeDef, 
XSConstants.DERIVATION_EXTENSION)) {
+                    // reassign value to simple type instance
+                    simpleTypeDefn = 
(XSSimpleTypeDefinition)complexTypeDef.getBaseType(); 
+                }
+                boolean isTypeDerivedFromList = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_LIST;
+                boolean isTypeDerivedFromUnion = ((XSSimpleType) 
simpleTypeDefn.getBaseType()).getVariety() == XSSimpleType.VARIETY_UNION;
+                evaluateOneAssertionFromSimpleType(element, value, augs, 
simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl, 
false, null);                
+                // evaluate assertions on itemType of xs:list
+                XSSimpleTypeDefinition listItemType = 
simpleTypeDefn.getItemType();
+                if (isTypeDerivedFromList && listItemType != null) {
+                    evaluateAssertsFromItemTypeOfSTList(element, listItemType, 
value);
+                }
+            }            
+        }       
+        
+    } // evaluateAssertionsFromAComplexType
+    
+    
+    /*
+     * Method to evaluate an assertion. Returns the evaluation error details 
in an AssertionError object.
+     */
+    private AssertionError evaluateOneAssertion(QName element, XSAssertImpl 
assertImpl, String value, boolean xPathContextExists, boolean isList) {
+        
+        AssertionError assertionError = null;
+        
+        try {  
+            XPath xp = assertImpl.getCompiledXPath();
+            
+            boolean result;            
+            if ((value == null) ||
+                (xPathContextExists == true)) {
+                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, 
fCurrentAssertDomNode);  
+            } 
+            else {
+                // XPath context is "undefined"
+                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, null); 
+            }
+            
+            if (!result) {
+               // assertion evaluation is false
+               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList); 
+            }
+        }
+        catch (DynamicError ex) {
+            if (ex.code().equals("XPDY0002")) {
+               // ref: http://www.w3.org/TR/xpath20/#eval_context
+               assertionError = new 
AssertionError("cvc-assertions-valid-context", element, assertImpl, value, 
isList);
+            }
+            else {
+               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);
+            }
+        }
+        catch (StaticError ex) {
+            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);
+        }
+        catch(Exception ex) {
+            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);   
+        }
+        
+        return assertionError;
+        
+    } // evaluateOneAssertion
+    
+    
+    /*
      * Determine if an validation episode must fail due to assertions 
evaluation for "simpleType -> union" member types.
      */
     private boolean isValidationFailedForSTUnion(XSObjectList memberTypes, 
QName element, String value, boolean isAttribute, Augmentations augs) {
@@ -592,7 +554,7 @@ public class XMLAssertPsychopathXPath2Im
             XSSimpleTypeDefinition memType = (XSSimpleTypeDefinition) 
memberTypes.item(memberTypeIdx);
             
             // check for assertions on types in an non-schema namespace
-            if 
(!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(memType.getNamespace()) && 
simpleTypeHasAsserts(memType)) {
+            if 
(!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(memType.getNamespace()) && 
XSTypeHelper.simpleTypeHasAsserts(memType)) {
                 XSObjectList memberTypeFacets = memType.getMultiValueFacets();
                 final int memberTypeFacetsLength = 
memberTypeFacets.getLength();
                 for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < 
memberTypeFacetsLength; memberTypeFacetIdx++) {
@@ -641,25 +603,26 @@ public class XMLAssertPsychopathXPath2Im
     
     
     /*
-     * Check if a simple type has assertion facets.
+     * Find the actual schema type of "list item" instance if the "item type" 
of list has variety union. 
      */
-    private boolean simpleTypeHasAsserts(XSSimpleTypeDefinition simpleType) {
-        
-        boolean simpleTypehasAsserts = false;
+    private XSSimpleTypeDefinition 
getActualListItemTypeForVarietyUnion(XSObjectList memberTypes, String 
listItemStrValue) {
+
+        XSSimpleTypeDefinition listItemType = null;
         
-        XSObjectList simpleTypeFacets = simpleType.getMultiValueFacets();
-        final int simpleTypeFacetsLength = simpleTypeFacets.getLength();
-        for (int facetIdx = 0; facetIdx < simpleTypeFacetsLength; facetIdx++) {
-            XSMultiValueFacet facet = (XSMultiValueFacet) 
simpleTypeFacets.item(facetIdx);
-            if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT && 
facet.getAsserts().size() > 0) {
-                simpleTypehasAsserts = true;
-                break;
-            }
+        // iterate the member types of union in order, to find that which 
schema type can successfully validate an atomic value first
+        final int memberTypesLength = memberTypes.getLength();
+        for (int memTypeIdx = 0; memTypeIdx < memberTypesLength; memTypeIdx++) 
{
+           XSSimpleType memSimpleType = (XSSimpleType) 
memberTypes.item(memTypeIdx);
+           if (XSTypeHelper.isValueValidForASimpleType(listItemStrValue, 
memSimpleType)) {
+              // no more memberTypes need to be checked
+              listItemType = memSimpleType; 
+              break; 
+           }
         }
         
-        return simpleTypehasAsserts;
-
-    } // simpleTypeHasAsserts
+        return listItemType;
+        
+    } // getActualListItemTypeForVarietyUnion
     
 
     /*
@@ -673,52 +636,56 @@ public class XMLAssertPsychopathXPath2Im
             
fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(new 
String(text.ch, text.offset, text.length)));
         }        
     }
+        
     
-
     /*
-     * Method to evaluate an assertion. Returns the evaluation error details 
in an AssertionError object.
+     * Determine "string value" of XPath2 context variable $value.
      */
-    private AssertionError evaluateOneAssertion(QName element, XSAssertImpl 
assertImpl, String value, boolean xPathContextExists, boolean isList) {
-        
-        AssertionError assertionError = null;
+    private String getStringValueOf$value(ElementPSVI pElemPSVI) throws 
DOMException {
         
-        try {  
-            XPath xp = assertImpl.getCompiledXPath();
-            
-            boolean result;            
-            if ((value == null) ||
-                (xPathContextExists == true)) {
-                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, 
fCurrentAssertDomNode);  
-            } 
-            else {
-                // XPath context is "undefined"
-                result = fAbstrPsychopathImpl.evaluateXPathExpr(xp, null); 
+        // there could be adjacent text nodes in a DOM tree. merge them to get 
the value.
+        NodeList childList = fCurrentAssertDomNode.getChildNodes();
+        StringBuffer textValueContents = new StringBuffer();
+        final int childListLength = childList.getLength();
+        int textChildCount = 0;
+        // we are only interested in text & element nodes. store count of them 
in this variable.
+        int effectiveChildNodeCount = 0;
+        for (int childNodeIndex = 0; childNodeIndex < childListLength; 
childNodeIndex++) {
+            Node node = childList.item(childNodeIndex);
+            short nodeType = node.getNodeType();
+            if (nodeType == Node.TEXT_NODE) {
+                textChildCount++;
+                effectiveChildNodeCount++;
+                textValueContents.append(node.getNodeValue());
             }
-            
-            if (!result) {
-               // assertion evaluation is false
-               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList); 
+            else if (nodeType == Node.ELEMENT_NODE) {
+                effectiveChildNodeCount++;  
             }
         }
-        catch (DynamicError ex) {
-            if (ex.code().equals("XPDY0002")) {
-               // ref: http://www.w3.org/TR/xpath20/#eval_context
-               assertionError = new 
AssertionError("cvc-assertions-valid-context", element, assertImpl, value, 
isList);
+        
+        String strValueOf$value = "";
+        
+        if (textChildCount == effectiveChildNodeCount) {
+            // the DOM tree we are inspecting has simple content. therefore we 
can find the desired string value. 
+            XSElementDeclaration elemDecl = pElemPSVI.getElementDeclaration();
+            if 
((elemDecl.getTypeDefinition()).derivedFrom(SchemaSymbols.URI_SCHEMAFORSCHEMA, 
SchemaSymbols.ATTVAL_STRING, XSConstants.DERIVATION_RESTRICTION)) {
+                // if element's schema type is derived by restriction from 
xs:string, white-space normalization is not needed for the
+                // string value for context variable $value.
+                strValueOf$value = textValueContents.toString();  
             }
             else {
-               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);
-            }
-        }
-        catch (StaticError ex) {
-            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);
+                // white-space normalization is needed for the string value of 
$value in case of derivation from non xs:string atomic types
+                strValueOf$value = XMLChar.trim(textValueContents.toString());
+            }    
         }
-        catch(Exception ex) {
-            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
element, assertImpl, value, isList);   
+        else {
+            // the DOM tree we are inspecting has 'mixed/element only' content.
+            strValueOf$value = null; 
         }
         
-        return assertionError;
+        return strValueOf$value;
         
-    } // evaluateOneAssertion
+    } // getStringValueOf$value
     
     
     /*
@@ -913,29 +880,6 @@ public class XMLAssertPsychopathXPath2Im
         return xpath2Seq;
         
     } // getXPath2ResultSequence
-
-    
-    /*
-     * Find the actual schema type of "list item" instance if the "item type" 
of list has variety union. 
-     */
-    private XSSimpleTypeDefinition 
getActualListItemTypeForVarietyUnion(XSObjectList memberTypes, String 
listItemStrValue) {
-
-        XSSimpleTypeDefinition listItemType = null;
-        
-        // iterate the member types of union in order, to find that which 
schema type can successfully validate an atomic value first
-        final int memberTypesLength = memberTypes.getLength();
-        for (int memTypeIdx = 0; memTypeIdx < memberTypesLength; memTypeIdx++) 
{
-           XSSimpleType memSimpleType = (XSSimpleType) 
memberTypes.item(memTypeIdx);
-           if (XSTypeHelper.isValueValidForASimpleType(listItemStrValue, 
memSimpleType)) {
-              // no more memberTypes need to be checked
-              listItemType = memSimpleType; 
-              break; 
-           }
-        }
-        
-        return listItemType;
-        
-    } // getActualListItemTypeForVarietyUnion
     
     
     /*

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java?rev=1084840&r1=1084839&r2=1084840&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java
 Thu Mar 24 04:22:53 2011
@@ -174,7 +174,7 @@ public class XSDAssertionValidator {
         
         XSObjectListImpl complexTypeAsserts = new XSObjectListImpl();
 
-        XSObjectList primaryAssertions = complexTypeDef.getAssertions();
+        XSObjectList primaryAssertions = complexTypeDef.getAssertions(); // 
assertions stored in the traverser layer
 
         if (primaryAssertions.getLength() > 0) {
             for (int assertIdx = 0; assertIdx < primaryAssertions.getLength(); 
assertIdx++) {
@@ -193,7 +193,7 @@ public class XSDAssertionValidator {
                     complexTypeAsserts.addXSObject((XSAssert) 
simpleContentAsserts.get(assertIdx));
                 }
             }
-            else if 
(XSTypeHelper.isComplexTypeDerivedFromSTListByExt(complexTypeDef)) {
+            else if 
(XSTypeHelper.isComplexTypeDerivedFromSTList(complexTypeDef, 
XSConstants.DERIVATION_EXTENSION)) {
                 // add assertions from the list->itemType of base schema 
simple type
                 Vector baseItemTypeAsserts = 
XSTypeHelper.getAssertsFromSimpleType(((XSSimpleTypeDefinition)complexTypeDef.getBaseType()).getItemType());
                 for (int assertIdx = 0; assertIdx < 
baseItemTypeAsserts.size(); assertIdx++) {
@@ -202,10 +202,9 @@ public class XSDAssertionValidator {
             }
         }
         
-
         // find assertions from attributes of a complex type, and add them to 
the parent assertions list
         XSObjectListImpl attrAsserts = getAssertsFromAttributes(attributes);
-        final int attrAssertCount = attrAsserts.getLength(); 
+        int attrAssertCount = attrAsserts.getLength(); 
         for (int attrAssertIdx = 0; attrAssertIdx < attrAssertCount; 
attrAssertIdx++) {
             complexTypeAsserts.addXSObject(attrAsserts.item(attrAssertIdx)); 
         }

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java?rev=1084840&r1=1084839&r2=1084840&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XSTypeHelper.java
 Thu Mar 24 04:22:53 2011
@@ -34,7 +34,6 @@ import org.apache.xerces.impl.xs.XSMessa
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
-import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSMultiValueFacet;
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSSimpleTypeDefinition;
@@ -50,8 +49,7 @@ import org.apache.xerces.xs.XSTypeDefini
  */
 public class XSTypeHelper {
     
-    private static final String EMPTY_STRING = "".intern();
-    
+    private static final String EMPTY_STRING = "".intern();    
     
     /*
      * Checks if the two schema type components are identical.
@@ -195,6 +193,28 @@ public class XSTypeHelper {
     
     
     /*
+     * Check if a simple type has assertion facets.
+     */
+    public static boolean simpleTypeHasAsserts(XSSimpleTypeDefinition 
simpleType) {
+        
+        boolean simpleTypehasAsserts = false;
+        
+        XSObjectList simpleTypeFacets = simpleType.getMultiValueFacets();
+        final int simpleTypeFacetsLength = simpleTypeFacets.getLength();
+        for (int facetIdx = 0; facetIdx < simpleTypeFacetsLength; facetIdx++) {
+            XSMultiValueFacet facet = (XSMultiValueFacet) 
simpleTypeFacets.item(facetIdx);
+            if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT && 
facet.getAsserts().size() > 0) {
+                simpleTypehasAsserts = true;
+                break;
+            }
+        }
+        
+        return simpleTypehasAsserts;
+
+    } // simpleTypeHasAsserts
+    
+    
+    /*
      * Find if a list contains a specified schema type.
      */
     public static boolean isListContainsType(List typeList, XSTypeDefinition 
targetType) {
@@ -212,15 +232,14 @@ public class XSTypeHelper {
     
     
     /*
-     * Find if a complexType is derived by extension from a simpleType->list 
component.
+     * Find if a complexType is derived from a simpleType->list component.
      */
-    public static boolean 
isComplexTypeDerivedFromSTListByExt(XSComplexTypeDefinition complexTypeDef) {
+    public static boolean 
isComplexTypeDerivedFromSTList(XSComplexTypeDefinition complexTypeDef, short 
derivationMethod) {
         
-        return complexTypeDef.getDerivationMethod() == 
XSConstants.DERIVATION_EXTENSION &&
-               complexTypeDef.getBaseType() instanceof XSSimpleTypeDefinition 
&&
+        return complexTypeDef.getDerivationMethod() == derivationMethod && 
complexTypeDef.getBaseType() instanceof XSSimpleTypeDefinition &&
                
((XSSimpleTypeDefinition)complexTypeDef.getBaseType()).getVariety() == 
XSSimpleTypeDefinition.VARIETY_LIST;
         
-    } // isComplexTypeDerivedFromSTListByExt
+    } // isComplexTypeDerivedFromSTList
     
     
     /*



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

Reply via email to