You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mu...@apache.org on 2011/04/17 01:28:18 UTC

svn commit: r1094087 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs: XMLAssertPsychopathXPath2Impl.java XMLSchemaValidator.java XSDAssertionValidator.java

Author: mukulg
Date: Sat Apr 16 23:28:17 2011
New Revision: 1094087

URL: http://svn.apache.org/viewvc?rev=1094087&view=rev
Log:
committing few fixes for schema 1.1 assertions processing. if xs:any wildcard has processContents="skip" then that part of XML content tree should be available to relevant assertions. Xerces code-base before this commit didn't handle this case correctly. this scenario is reflected in the W3C XML Schema 1.1 test case "assert009.n1.xml". the changes in this commit implements improvements to comply to this test case.

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/XMLSchemaValidator.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.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=1094087&r1=1094086&r2=1094087&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 Sat Apr 16 23:28:17 2011
@@ -144,19 +144,13 @@ public class XMLAssertPsychopathXPath2Im
 
         // 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);
-            String attrLocalName = attributes.getLocalName(attIndex);
-            String attValue = attributes.getValue(attIndex);             
-
-            PSVIAttrNSImpl attrNode = new PSVIAttrNSImpl((PSVIDocumentImpl)fAssertDocument, attrUri, attQName, attrLocalName);
-            attrNode.setNodeValue(attValue);
-
+            PSVIAttrNSImpl attrNode = new PSVIAttrNSImpl((PSVIDocumentImpl)fAssertDocument, attributes.getURI(attIndex), attributes.getQName(attIndex), attributes.getLocalName(attIndex));
+            attrNode.setNodeValue(attributes.getValue(attIndex));
             // set PSVI information for the attribute
-            Augmentations attrAugs = attributes.getAugmentations(attIndex);
-            AttributePSVImpl attrPSVI = (AttributePSVImpl) attrAugs.getItem(Constants.ATTRIBUTE_PSVI);
-            attrNode.setPSVI(attrPSVI);
-
+            AttributePSVImpl attrPSVI = (AttributePSVImpl) (attributes.getAugmentations(attIndex)).getItem(Constants.ATTRIBUTE_PSVI);
+            if (attrPSVI != null) {
+               attrNode.setPSVI(attrPSVI);
+            }
             fCurrentAssertDomNode.setAttributeNode(attrNode);
         }
 
@@ -219,13 +213,12 @@ public class XMLAssertPsychopathXPath2Im
         if (fCurrentAssertDomNode != null) {            
             // set PSVI information on the element
             ElementPSVI elemPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI);
-            ((PSVIElementNSImpl) fCurrentAssertDomNode).setPSVI((ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI));
+            ((PSVIElementNSImpl) fCurrentAssertDomNode).setPSVI(elemPSVI);
             
             // handling default values of elements (adding them as 'text' node in the assertion XDM tree)
             XSElementDecl elemDecl = (XSElementDecl) elemPSVI.getElementDeclaration();
-            if (elemDecl != null && elemDecl.fDefault != null && fCurrentAssertDomNode.getChildNodes().getLength() == 0) {
-                String normalizedDefaultValue = elemDecl.fDefault.normalizedValue;
-                fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(normalizedDefaultValue));
+            if (elemDecl != null && elemDecl.fDefault != null && !fCurrentAssertDomNode.hasChildNodes()) {
+                fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(elemDecl.fDefault.normalizedValue));
             }               
             
             if (!fAssertRootStack.empty() && (fCurrentAssertDomNode == fAssertRootStack.peek())) {               

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=1094087&r1=1094086&r2=1094087&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 Apr 16 23:28:17 2011
@@ -2021,6 +2021,9 @@ public class XMLSchemaValidator
             fElementDepth++;
             if (fAugPSVI)
                 augs = getEmptyAugs(augs);
+            if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+                assertionValidatorStartElementDelegate(element, attributes);                        
+            }
             return augs;
         }
 
@@ -2134,11 +2137,14 @@ public class XMLSchemaValidator
             }
         }
 
-        // if the wildcard is skip, then return
+        // if the wildcard is skip
         if (wildcard != null && wildcard.fProcessContents == XSWildcardDecl.PC_SKIP) {
             fSkipValidationDepth = fElementDepth;
             if (fAugPSVI)
                 augs = getEmptyAugs(augs);
+            if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+                assertionValidatorStartElementDelegate(element, attributes);                        
+            }
             return augs;
         }
         
@@ -2424,12 +2430,12 @@ public class XMLSchemaValidator
         XMLAttribute[] inheritedAttributesForPsvi = null; 
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
             fInhrAttrCountStack.push(fInheritableAttrList.size());
-            inheritedAttributesForPsvi = getInheritedAttributesForPsvi();
+            inheritedAttributesForPsvi = getInheritedAttributesForPSVI();
         }
 
         if (fAugPSVI) {
             augs = getEmptyAugs(augs);
-            
+
             // PSVI: add validation context
             fCurrentPSVI.fValidationContext = fValidationRoot;
             // PSVI: add element declaration
@@ -2446,21 +2452,26 @@ public class XMLSchemaValidator
                 
         if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
             // find attributes among the attributes of the current element, which are declared inheritable and store them for later processing.
-            // one of the uses of inherited attributes is in type alternatives processing.
+            // one of the uses of inheritable attributes is in type alternatives processing.
             saveInheritableAttributes(fCurrentElemDecl, attributes);
-            try {
-               // delegate to assertions validator subcomponent
-               fAssertionValidator.handleStartElement(element, attributes);
-            }
-            catch(Exception ex) {
-                throw new XNIException(ex.getMessage(), ex); 
-            }
+            assertionValidatorStartElementDelegate(element, attributes);                       
         }
 
         return augs;
 
     } // handleStartElement(QName,XMLAttributes,boolean)
     
+    /*
+     * Delegate to assertions validator startElement handler.
+     */
+    private void assertionValidatorStartElementDelegate(QName element, XMLAttributes attributes) {
+        try {
+            fAssertionValidator.handleStartElement(element, attributes);
+         }
+         catch(Exception ex) {
+             throw new XNIException(ex.getMessage(), ex); 
+         } 
+    } // assertionValidatorStartElementDelegate
 
     /**
      *  Handle end element. If there is not text content, and there is a
@@ -2512,6 +2523,26 @@ public class XMLSchemaValidator
 
             if (fAugPSVI)
                 augs = getEmptyAugs(augs);
+            
+            // delegate to assertions validator subcomponent
+            if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+                // initialize augmentations to be passed to assertions processor
+                Augmentations assertAugs = new AugmentationsImpl();
+                ElementPSVImpl assertElemPSVI = new ElementPSVImpl();
+                assertElemPSVI.fDeclaration = fCurrentElemDecl;
+                assertElemPSVI.fTypeDecl = fCurrentType;
+                assertElemPSVI.fNotation = fNotation;
+                assertElemPSVI.fGrammars = fGrammarBucket.getGrammars();
+                assertAugs.putItem(Constants.ELEMENT_PSVI, assertElemPSVI);
+                assertAugs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion));            
+                fAssertionValidator.handleEndElement(element, assertAugs);            
+                if (fAugPSVI && fIsAssertProcessingNeededForSTUnion) {
+                    // update PSVI
+                    fValidatedInfo.memberType = ((ElementPSVImpl) assertAugs.getItem(Constants.ELEMENT_PSVI)).fValue.memberType;                
+                } 
+                fIsAssertProcessingNeededForSTUnion = true;            
+            }
+            
             return augs;
         }
 
@@ -2692,7 +2723,7 @@ public class XMLSchemaValidator
             XMLAttribute[] inheritedAttributesForPsvi = null;
             if (fInhrAttrCountStack.size() > 0) {
                 fInheritableAttrList.setSize(fInhrAttrCountStack.pop());
-                inheritedAttributesForPsvi = getInheritedAttributesForPsvi();
+                inheritedAttributesForPsvi = getInheritedAttributesForPSVI();
             }
             fCurrentPSVI.fInheritedAttributes = inheritedAttributesForPsvi;
             // PSVI: validation attempted
@@ -4876,7 +4907,7 @@ public class XMLSchemaValidator
                 fIsAssertProcessingNeededForSTUnion = false;
             }
             if (augs != null) {
-                // set value for an attribute
+                // set augmentation information for an attribute
                 augs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion));                
             }
         }
@@ -4910,7 +4941,7 @@ public class XMLSchemaValidator
     /*
      * Get inherited attributes for copying into an element PSVI.
      */
-    private XMLAttribute[] getInheritedAttributesForPsvi() {        
+    private XMLAttribute[] getInheritedAttributesForPSVI() {        
         XMLAttribute[] inheritedAttributes = null; 
         if (fInheritableAttrList.size() > 0) {
             inheritedAttributes = new XMLAttribute[fInheritableAttrList.size()]; 
@@ -4919,6 +4950,6 @@ public class XMLSchemaValidator
             }  
         }
         return inheritedAttributes; 
-    } // getInheritedAttributesForPsvi
+    } // getInheritedAttributesForPSVI
     
 } // class XMLSchemaValidator

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=1094087&r1=1094086&r2=1094087&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 Sat Apr 16 23:28:17 2011
@@ -146,20 +146,22 @@ public class XSDAssertionValidator {
      * for the current context. Return the assertions list.
      */
     private List getAssertsForEvaluation(QName element, XMLAttributes attributes) {
-        
-       XSTypeDefinition typeDefn = fXmlSchemaValidator.fCurrentPSVI.getTypeDefinition();
-
-       List assertionList = null;            
-       if (typeDefn.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
-           // if element's schema type is a "complex type"               
-           XSObjectListImpl complexTypeAsserts = getAssertsFromComplexType((XSComplexTypeDefinition) typeDefn, attributes);
-           if (complexTypeAsserts.size() > 0) {
-               assertionList = complexTypeAsserts;             
+       
+       List assertionList = null;
+       
+       XSTypeDefinition typeDefn = fXmlSchemaValidator.fCurrentPSVI.getTypeDefinition();       
+       if (typeDefn != null) {
+           if (typeDefn.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
+               // if element's schema type is a "complex type"               
+               XSObjectListImpl complexTypeAsserts = getAssertsFromComplexType((XSComplexTypeDefinition) typeDefn, attributes);
+               if (complexTypeAsserts.size() > 0) {
+                   assertionList = complexTypeAsserts;             
+               }
+           }
+           else {
+               // if element's schema type is a "simple type"
+               assertionList = getAssertsFromSimpleType((XSSimpleTypeDefinition) typeDefn);            
            }
-       }
-       else if (typeDefn.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
-           // if element's schema type is a "simple type"
-           assertionList = getAssertsFromSimpleType((XSSimpleTypeDefinition) typeDefn);            
        }
                
        return assertionList;



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