Author: mukulg
Date: Sun Dec 27 17:03:44 2009
New Revision: 894079

URL: http://svn.apache.org/viewvc?rev=894079&view=rev
Log:
improvement to assertions implementation. improved handling of assertions on 
xs:complexType extending from a simple type, having assertion facets. 

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/traversers/XSDComplexTypeTraverser.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=894079&r1=894078&r2=894079&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
 Sun Dec 27 17:03:44 2009
@@ -200,14 +200,23 @@
          initXPathProcessor();
          
          // determine value of variable, $value
-         String value = null;
-         NodeList childList = currentAssertDomNode.getChildNodes();
-         if (childList.getLength() == 1) {
-             Node node = childList.item(0);
+         String value = "";
+         NodeList childList = currentAssertDomNode.getChildNodes();         
+         int textChildCount = 0;
+         // there could be adjacent text nodes. merge them to get the value.
+         for (int childNodeIndex = 0; childNodeIndex < childList.getLength();
+                                                       childNodeIndex++) {
+             Node node = childList.item(childNodeIndex);
              if (node.getNodeType() == Node.TEXT_NODE) {
-                 value = node.getNodeValue();
+                 textChildCount++;
+                 value = value + node.getNodeValue();
              }
          }
+         
+         if (!(textChildCount > 0 && (textChildCount ==
+                                      childList.getLength()))) {
+            value = null;  
+         }
 
          // evaluate assertions
          if (assertions instanceof XSObjectList) {

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=894079&r1=894078&r2=894079&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
 Sun Dec 27 17:03:44 2009
@@ -2485,35 +2485,16 @@
           // if elements's governing type is a "complex type"
           XSObjectListImpl assertions = new XSObjectListImpl();                
           XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) 
typeDef;
-                
-          // there could be assertion facets from complexType -> simpleContent
-          // (xs:assertion). add them to the list of assertions to be 
evaluated.
-          XSSimpleTypeDefinition simpleContentModel = 
complexTypeDef.getSimpleType();                
-          if (simpleContentModel != null) {
-             XSObjectList facets = simpleContentModel.getMultiValueFacets();
-             for (int i = 0; i < facets.getLength(); i++) {
-               XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
-               if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
-                 Vector simpleTypeAsserts = facet.getAsserts();
-                 for (int j = 0; j < simpleTypeAsserts.size(); j++) {
-                   
assertions.addXSObject((XSAssert)simpleTypeAsserts.elementAt(j));    
-                 }                        
-                 break;
-               }
-             }  
-          }
-              
-          // there could be assertions, from the complex type definition
-          // (xs:assert). add them to the list of assertions to be evaluated.
+          
           XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
           if (complexTypeAsserts.getLength() > 0) {
             for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
                assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
             }
           }
-          
+
           // there could be assertions, to be evaluated on attributes. add 
these
-          // assertions to the assertions to be processed.
+          // assertions to the list of assertions to be processed.
           for (int attrIndx = 0; attrIndx < attributes.getLength(); 
attrIndx++) {
               Augmentations attrAugs = attributes.getAugmentations(attrIndx);
               AttributePSVImpl attrPSVI = (AttributePSVImpl)attrAugs.getItem

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java?rev=894079&r1=894078&r2=894079&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.java
 Sun Dec 27 17:03:44 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.xerces.impl.xs.traversers;
 
+import java.util.Vector;
+
 import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.dv.InvalidDatatypeFacetException;
 import org.apache.xerces.impl.dv.XSFacets;
@@ -42,8 +44,10 @@
 import org.apache.xerces.xs.XSAttributeUse;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
 import org.apache.xerces.xs.XSConstants;
+import org.apache.xerces.xs.XSMultiValueFacet;
 import org.apache.xerces.xs.XSObject;
 import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.w3c.dom.Element;
 
@@ -668,6 +672,11 @@
             }
         }
         
+        // add any assertions from the base types, for assertions to be 
processed
+        if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
+            addAssertsFromBaseTypes(fBaseType);
+        }
+        
         // 
-----------------------------------------------------------------------
         // Process a RESTRICTION
         // 
-----------------------------------------------------------------------
@@ -823,7 +832,7 @@
                     if (node != null) {
                         if (isAssert(node)) {
                             traverseAsserts(node, schemaDoc, grammar,
-                                    fComplexTypeDecl);
+                                            fComplexTypeDecl);
                         } else {
                             // a non assert element after attributes is an 
error
                             
fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
@@ -1022,7 +1031,7 @@
                 
         // add any assertions from the base types, for assertions to be 
processed
         if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
-            getAssertsFromBaseTypes(fBaseType);
+            addAssertsFromBaseTypes(fBaseType);
         }
         
         // 
-----------------------------------------------------------------------
@@ -1345,22 +1354,43 @@
     }
 
     /*
-     * Helper method to find all assertions up in the type hierarchy
+     * Method to find all assertions up in the type hierarchy, and add them to
+     * the list of assertions to be processed.
      */
-    private void getAssertsFromBaseTypes(XSTypeDefinition baseValidator) {     
   
-        if (baseValidator != null && baseValidator instanceof 
XSComplexTypeDefinition) {
-            XSObjectList assertList = ((XSComplexTypeDefinition) baseValidator)
+    private void addAssertsFromBaseTypes(XSTypeDefinition baseValidator) {     
   
+        if (baseValidator != null) {
+            if (baseValidator instanceof XSComplexTypeDefinition) {
+               XSObjectList assertList = ((XSComplexTypeDefinition) 
baseValidator)
                                                  .getAssertions();
-            for (int i = 0; i < assertList.size(); i++) {
-                // add assertion to the list, only if it's already not present
-                if (!assertExists((XSAssertImpl) assertList.get(i))) {
-                  addAssertion((XSAssertImpl) assertList.get(i));
+               for (int i = 0; i < assertList.size(); i++) {
+                  // add assertion to the list, only if it's already not 
present
+                  if (!assertExists((XSAssertImpl) assertList.get(i))) {
+                    addAssertion((XSAssertImpl) assertList.get(i));
+                  }
+               }
+            }
+            else if (baseValidator instanceof XSSimpleTypeDefinition) {
+                XSObjectList facets = 
((XSSimpleTypeDefinition)baseValidator).getMultiValueFacets();
+                for (int i = 0; i < facets.getLength(); i++) {
+                    XSMultiValueFacet facet = (XSMultiValueFacet) 
facets.item(i);
+                    if (facet.getFacetKind() == 
XSSimpleTypeDefinition.FACET_ASSERT) {
+                       Vector assertionFacets = facet.getAsserts();
+                       for (int j = 0; j < assertionFacets.size(); j++) {
+                          XSAssertImpl assertImpl = (XSAssertImpl) 
assertionFacets.get(j);
+                          addAssertion(assertImpl);
+                       }
+                       break;
+                    }
                 }
             }
             
             // invoke the method recursively. go up the type hierarchy.
-            if (!baseValidator.getBaseType().getName().equals("anyType")) {    
          
-              getAssertsFromBaseTypes(baseValidator.getBaseType());
+            XSTypeDefinition ancestorType = baseValidator.getBaseType();
+            if (ancestorType != null && 
+                           !(ancestorType.getName().equals("anyType") ||
+                                
ancestorType.derivedFrom(Constants.NS_XMLSCHEMA,
+                                "anyAtomicType", 
XSConstants.DERIVATION_RESTRICTION))) {              
+               addAssertsFromBaseTypes(ancestorType);
             }
         } 
     } // end of method, getAssertsFromBaseTypes



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

Reply via email to