[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xerces-cvs
Subject:    svn commit: r990348 - in
From:       mukulg () apache ! org
Date:       2010-08-28 11:36:51
Message-ID: 20100828113651.2D34C23888FD () eris ! apache ! org
[Download RAW message or body]

Author: mukulg
Date: Sat Aug 28 11:36:50 2010
New Revision: 990348

URL: http://svn.apache.org/viewvc?rev=990348&view=rev
Log:
doing little refactoring of assertions code

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/XSDAssertionValidator.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/apac \
he/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=990348&r1=990347&r2=990348&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 Aug 28 11:36:50 2010 @@ -48,6 +48,7 @@ import org.eclipse.wst.xml.xpath2.proces
 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.SchemaTypeValueFactory;
+import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -92,6 +93,8 @@ public class XMLAssertPsychopathImpl ext
     // parameters to pass to PsychoPath engine (like, the namespace bindings) 
     Map fAssertParams = null;
     
+    // an instance variable to track the name of an attribute currently
+    // processed for assertions.
     String fAttrName = null;
 
     
@@ -236,179 +239,222 @@ public class XMLAssertPsychopathImpl ext
     /*
      * Method to evaluate all of assertions for an element tree.
      */
-    private void processAllAssertionsOnElement(
-                                    QName element,
-                                    XSSimpleTypeDefinition itemType,
-                                    XSObjectList memberTypes,
-                                    List assertions)
+    private void processAllAssertionsOnElement(QName element,
+                                           XSSimpleTypeDefinition itemType,
+                                           XSObjectList memberTypes,
+                                           List assertions)
                                     throws Exception {
          
          // initialize the XPath engine
          initXPathProcessor();
          
          // determine value of variable, $value
-         String value = "";
-         NodeList childList = fCurrentAssertDomNode.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) {
-                 textChildCount++;
-                 value = value + node.getNodeValue();
-             }
+         String value = getValueOf$Value();
+
+         // evaluate assertions
+         if (assertions instanceof XSObjectList) {
+            // assertions from a "complex type" definition             
+            evaluateAssertionsFromComplexType(element, assertions, value);           \
 +         }
+         else if (assertions instanceof Vector) {
+            // assertions from a "simple type" definition
+            evaluateAssertionsFromSimpleType(element, itemType, memberTypes,
+                                             assertions, value);            
          }
          
-         if (textChildCount != childList.getLength()) {
+    } // processAllAssertionsOnElement
+
+
+    /*
+     * Find value of XPath2 context variable $value.
+     */
+    private String getValueOf$Value() throws DOMException {
+        
+        String value = "";
+
+        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();
+                                                         childNodeIndex++) {
+            Node node = childList.item(childNodeIndex);
+            if (node.getNodeType() == Node.TEXT_NODE) {
+                textChildCount++;
+                value = value + node.getNodeValue();
+            }
+        }
+
+        if (textChildCount != childList.getLength()) {
             value = null;  
-         }
+        }
+        
+        return value;
+        
+    } // getValueOf$Value
 
-         // evaluate assertions
-         if (assertions instanceof XSObjectList) {
-            // assertions from a complex type definition             
-            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 
-            }
-            XSObjectList assertList = (XSObjectList) assertions;
-            XSObjectList attrMemberTypes = null;
-            for (int i = 0; i < assertList.size(); i++) {
-                XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);          \
                
-                boolean xpathContextExists = false;
-                if (assertImpl.getType() == XSConstants.ASSERTION) {
-                   // not an assertion facet
-                   xpathContextExists = true;   
-                }
-                // check if this is an assertion, from the attribute
-                if (assertImpl.getAttrName() != null) {
-                   value = assertImpl.getAttrValue();
-                   
-                   XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) \
                assertImpl.
-                                                                  \
                getTypeDefinition();
-                   attrMemberTypes = attrType.getMemberTypes();
-                   if (assertImpl.getVariety() == \
                XSSimpleTypeDefinition.VARIETY_LIST) {
-                       // this assertion belongs to a type, that is an item type
-                       // of a simpleType -> list.
-                       // 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);
-                           AssertionError assertError = evaluateAssertion(element, 
-                                                                  assertImpl, 
-                                                                  values[valIdx], 
-                                                                  \
                xpathContextExists,
-                                                                  true);
-                           if (assertError != null) {
-                               reportError(assertError);    
-                           }
+
+    /*
+     * Evaluate assertions on a "complex type".
+     */
+    private void evaluateAssertionsFromComplexType(QName element, List 
+                                              assertions, String value) 
+                                                   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
+        }
+        
+        XSObjectList assertList = (XSObjectList) assertions;
+        XSObjectList attrMemberTypes = null;        
+        for (int i = 0; i < assertList.size(); i++) {
+            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);              \
 +            boolean xpathContextExists = false;
+            if (assertImpl.getType() == XSConstants.ASSERTION) {
+                // not an assertion facet
+                xpathContextExists = true;   
+            }
+            // check if this is an assertion, from the attribute
+            if (assertImpl.getAttrName() != null) {
+                value = assertImpl.getAttrValue();
+                XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) 
+                                                assertImpl.getTypeDefinition();
+                attrMemberTypes = attrType.getMemberTypes();
+                if (assertImpl.getVariety() == XSSimpleTypeDefinition.
+                                                                VARIETY_LIST) {
+                    // this assertion belongs to a type, that is an item type
+                    // of a simpleType -> list.
+                    // 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);
+                        AssertionError assertError = evaluateAssertion(element, 
+                                                                    assertImpl, 
+                                                                values[valIdx], 
+                                                            xpathContextExists,
+                                                                        true);
+                        if (assertError != null) {
+                            reportAssertionsError(assertError);    
                         }
-                   }
-                   else if (assertImpl.getVariety() == XSSimpleTypeDefinition.
-                                                                  VARIETY_ATOMIC) {
-                       // evaluating assertions for simpleType -> restriction
-                       setValueOf$value(value, null, attrType);
-                       AssertionError assertError = evaluateAssertion(element,
-                                                         assertImpl, value,
-                                                         xpathContextExists,
-                                                         false);
-                       if (assertError != null) {
-                          reportError(assertError);    
-                       }
-                   }                
+                    }
                 }
-                else {
+                else if (assertImpl.getVariety() == XSSimpleTypeDefinition.
+                                                            VARIETY_ATOMIC) {
+                    // evaluating assertions for simpleType -> restriction
+                    setValueOf$value(value, null, attrType);
                     AssertionError assertError = evaluateAssertion(element,
                                                          assertImpl, value,
                                                         xpathContextExists,
-                                                                  false);
-                    if (assertError != null) {
-                        reportError(assertError);    
-                    }  
-                }
-            }
-            
-            // evaluate assertions on simpleType -> union on an attribute
-            if (attrMemberTypes != null && attrMemberTypes.getLength() > 0) {        \
                
-                boolean isValidationFailedForUnion = 
-                                                 isValidationFailedForUnion
-                                                              (attrMemberTypes,
-                                                               element,
-                                                               value, true);
-           
-                if (isValidationFailedForUnion) {
-                    // none of the member types of union (the assertions in
-                    // them) can successfully validate an atomic value. this
-                    // results in an overall validation failure. report an
-                    // error message.
-                    fValidator.reportSchemaError("cvc-assertion.attr.union." +
-                    		                                    "3.13.4.1", 
-                                 new Object[] { element.rawname, fAttrName, 
-                                                                   value } );   
-                }
-                
-                fAttrName = null;
-            }
-            
-         }
-         else if (assertions instanceof Vector) {
-            // assertions from a simple type definition           
-            Vector assertList = (Vector) assertions;
-            
-            for (int i = 0; i < assertList.size(); i++) {
-                XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
-                if (itemType != null) {
-                   // evaluating assertions for simpleType -> list.                  \
                
-                   // 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], itemType, null);
-                      AssertionError assertError = evaluateAssertion(element, 
-                                                                  assertImpl, 
-                                                              values[valIdx], 
-                                                                   false,
-                                                                   true);
-                      if (assertError != null) {
-                          reportError(assertError);    
-                      }
-                   }
-                }
-                else if (memberTypes != null && memberTypes.getLength() == 0) {
-                    // evaluating assertions for simpleType -> restriction
-                    setValueOf$value(value, null, null);
-                    AssertionError assertError = evaluateAssertion(element, 
-                                                                assertImpl,
-                                                                value, 
-                                                                false,
-                                                                false);
+                                                                   false);
                     if (assertError != null) {
-                        reportError(assertError);    
-                    }    
+                        reportAssertionsError(assertError);    
+                    }
                 }                
             }
+            else {
+                AssertionError assertError = evaluateAssertion(element,
+                                                          assertImpl, value,
+                                                         xpathContextExists,
+                                                             false);
+                if (assertError != null) {
+                    reportAssertionsError(assertError);    
+                }  
+            }
+        }
 
-            if (memberTypes != null && memberTypes.getLength() > 0) {                \
                
-                 boolean isValidationFailedForUnion = 
-                                                  isValidationFailedForUnion
-                                                                 (memberTypes,
-                                                                  element,
-                                                                  value, false);
-            
-                if (isValidationFailedForUnion) {
-                     fValidator.reportSchemaError("cvc-assertion.union.3.13.4.1", 
-                                  new Object[] { element.rawname, value } );   
-                }
-            }            
-         }
-         
-    } // processAllAssertionsOnElement
+        // evaluate assertions on simpleType -> union on an attribute
+        if (attrMemberTypes != null && attrMemberTypes.getLength() > 0) {            \
 +            boolean isValidationFailedForUnion = isValidationFailedForUnion
+                                                            (attrMemberTypes,
+                                                             element,
+                                                             value, true);
+
+            if (isValidationFailedForUnion) {
+                // none of the member types of union (the assertions in
+                // them) can successfully validate an atomic value. this
+                // results in an overall validation failure. report an
+                // error message.
+                fValidator.reportSchemaError("cvc-assertion.attr.union." +
+                                                                 "3.13.4.1", 
+                                  new Object[] { element.rawname, fAttrName, 
+                                                                  value } );   
+            }
+
+            fAttrName = null;            
+        }
+        
+    } // evaluateAssertionsFromComplexType
+    
+    
+    /*
+     * Evaluate assertions on a "simple type".
+     */
+    private void evaluateAssertionsFromSimpleType(QName element,
+                                             XSSimpleTypeDefinition itemType,
+                                             XSObjectList memberTypes,
+                                             List assertions, String value) 
+                                                   throws Exception {
+        
+        // assertions from a simple type definition           
+        Vector assertList = (Vector) assertions;
+        
+        for (int i = 0; i < assertList.size(); i++) {
+            XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
+            if (itemType != null) {
+               // evaluating assertions for simpleType -> list.                    
+               // 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], itemType, null);
+                  AssertionError assertError = evaluateAssertion(element, 
+                                                              assertImpl, 
+                                                          values[valIdx], 
+                                                               false,
+                                                               true);
+                  if (assertError != null) {
+                      reportAssertionsError(assertError);    
+                  }
+               }
+            }
+            else if (memberTypes != null && memberTypes.getLength() == 0) {
+                // evaluating assertions for simpleType -> restriction
+                setValueOf$value(value, null, null);
+                AssertionError assertError = evaluateAssertion(element, 
+                                                            assertImpl,
+                                                            value, 
+                                                            false,
+                                                            false);
+                if (assertError != null) {
+                    reportAssertionsError(assertError);    
+                }    
+            }                
+        }
+
+        if (memberTypes != null && memberTypes.getLength() > 0) {
+             // evaluate assertions for simpleType -> union
+             boolean isValidationFailedForUnion = isValidationFailedForUnion
+                                                             (memberTypes,
+                                                              element,
+                                                              value, false);
+            // only 1 error message is reported for assertion failures on
+            // simpleType -> union, since it is hard (perhaps impossible?)
+            // to determine statically that what all assertions can cause 
+            // failure, when participating in an union.
+            if (isValidationFailedForUnion) {
+                 fValidator.reportSchemaError("cvc-assertion.union.3.13.4.1", 
+                              new Object[] { element.rawname, value } );   
+            }
+        }
+        
+    } // evaluateAssertionsFromSimpleType
     
     
     /*
@@ -426,6 +472,8 @@ public class XMLAssertPsychopathImpl ext
                                                          memberTypeIdx++) {
             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)) {
@@ -458,7 +506,6 @@ public class XMLAssertPsychopathImpl ext
                                // value cannot be constructed by PsychoPath engine
                                // for a given string value (say a value '5' was 
                                // attempted to be formed as a typed value xs:date).  \
                
-                               
                                // it's useful to report warning ... TO DO
                             }
                         }
@@ -585,13 +632,13 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-     * Assign value to the XPath2 "dynamic context" variable, $value.
+     * Assign a typed value to the XPath2 "dynamic context" variable, $value.
      */
     private void setValueOf$value(String value, 
                                   XSSimpleTypeDefinition listOrUnionType, 
                                   XSTypeDefinition attrType) throws Exception {
         
-        // XML Schema type for variable $value
+        // XML Schema 1.1 type for variable $value
         String xsdTypeName = "";
         
         if (listOrUnionType != null) {
@@ -634,7 +681,7 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-       Find the built in XSD type for XPath2 variable, $value. This function
+       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.
     */
@@ -651,9 +698,9 @@ public class XMLAssertPsychopathImpl ext
     
     
     /*
-     * Method to report error messages.
+     * Method to report assertions error messages.
      */
-    private void reportError(AssertionError assertError) {
+    private void reportAssertionsError(AssertionError assertError) {
         
         String key = assertError.getErrorCode();
         QName element = assertError.getElement();
@@ -704,7 +751,7 @@ public class XMLAssertPsychopathImpl ext
                                typeString, listAssertErrMessage} );
         }
         
-    } // reportError
+    } // reportAssertionsError
     
     
     /*

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/apac \
he/xerces/impl/xs/XSDAssertionValidator.java?rev=990348&r1=990347&r2=990348&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 Aug 28 11:36:50 2010 @@ -171,167 +171,210 @@ public class XSDAssertionValidator {
        List assertionList = null;
             
        if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
-           // if element's governing type is a "complex type"
-           XSObjectListImpl assertions = new XSObjectListImpl();                
-           XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) 
-                                                                typeDef;
-          
-           XSObjectList complexTypeAsserts = complexTypeDef.getAssertions();
-           if (complexTypeAsserts.getLength() > 0) {
-              for (int i = 0; i < complexTypeAsserts.getLength(); i++) {
-                 assertions.addXSObject((XSAssert)complexTypeAsserts.get(i));
-              }
+           // if element's governing type is a "complex type"               
+           XSObjectListImpl complexTypeAsserts = getAssertsFromComplexType(
+                                                       typeDef, attributes);
+           if (complexTypeAsserts.size() > 0) {
+               assertionList = complexTypeAsserts;             
            }
-          
-           // add assertion facets, from "complexType -> simpleContent -> 
-           // restriction".
-           XSSimpleTypeDefinition simpleTypeDef = complexTypeDef.getSimpleType();
-           if (simpleTypeDef != null) {
-               XSObjectList complexTypeFacets = simpleTypeDef.getMultiValueFacets();
-               for (int i = 0; i < complexTypeFacets.getLength(); i++) {
-                  XSMultiValueFacet facet = (XSMultiValueFacet) 
-                                                    complexTypeFacets.item(i);
-                  if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
-                      Vector simpleContentAsserts = facet.getAsserts();
-                      for (int simpleAssertIdx = 0; simpleAssertIdx < 
-                                   simpleContentAsserts.size(); simpleAssertIdx++) {
-                         XSAssert simpleContentAssert = (XSAssert)
-                                           \
                simpleContentAsserts.get(simpleAssertIdx);
-                         assertions.addXSObject(simpleContentAssert);
-                      }
-                   }
-                }
+       }
+       else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
+           // if element's governing type is a "simple type"
+           assertionList = getAssertsFromSimpleType(typeDef);            
+       }
+               
+       return assertionList;
+         
+    } // getAssertsForEvaluation
+
+
+    /*
+     * Accumulate assertions from a complex type.
+     */
+    private XSObjectListImpl getAssertsFromComplexType(XSTypeDefinition 
+                                       typeDef, XMLAttributes attributes) {
+        
+        XSObjectListImpl complexTypeAsserts = new XSObjectListImpl();
+
+        XSComplexTypeDefinition complexTypeDef = (XSComplexTypeDefinition) 
+                                                               typeDef;
+
+        XSObjectList primaryAssertions = complexTypeDef.getAssertions();
+        if (primaryAssertions.getLength() > 0) {
+            for (int i = 0; i < primaryAssertions.getLength(); i++) {
+                complexTypeAsserts.addXSObject((XSAssert) primaryAssertions.
+                                                            get(i));
             }
+        }
 
-            // there could be assertions, to be evaluated on attributes. add these
-            // 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
-                                                   (Constants.ATTRIBUTE_PSVI);
-                XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition)attrPSVI.
-                                                          getTypeDefinition();
-                if (attrType != null) {
-                    // this accumulates assertions only for simpleType -> 
-                    // restriction.
-                    XSObjectList facets = attrType.getMultiValueFacets();
-                    
-                    // variety is 'unknown/absent' at the moment                    
-                    short attrTypeVariety = XSSimpleTypeDefinition.
-                                                            VARIETY_ABSENT;
-                    
-                    if (facets.getLength() == 0 && attrType.getItemType() != 
-                                                                       null) {
-                       // facets for simpleType -> list
-                       attrTypeVariety = XSSimpleTypeDefinition.VARIETY_LIST;
-                       facets = (XSObjectListImpl) attrType.getItemType().
-                                                       getMultiValueFacets();    
+        // add assertion facets, from "complexType -> simpleContent -> 
+        // restriction".
+        XSSimpleTypeDefinition simpleContentType = complexTypeDef.
+                                                       getSimpleType();
+        if (simpleContentType != null) {
+            XSObjectList complexTypeFacets = simpleContentType.
+                                                  getMultiValueFacets();
+            for (int i = 0; i < complexTypeFacets.getLength(); i++) {
+                XSMultiValueFacet facet = (XSMultiValueFacet) 
+                                                   complexTypeFacets.item(i);
+                if (facet.getFacetKind() == XSSimpleTypeDefinition.
+                                                               FACET_ASSERT) {
+                    Vector simpleContentAsserts = facet.getAsserts();
+                    for (int simpleAssertIdx = 0; simpleAssertIdx < 
+                                   simpleContentAsserts.size(); 
+                                                         simpleAssertIdx++) {
+                        XSAssert simpleContentAssert = (XSAssert)
+                        simpleContentAsserts.get(simpleAssertIdx);
+                        complexTypeAsserts.addXSObject(simpleContentAssert);
                     }
-                    else if (attrType.getVariety() == XSSimpleTypeDefinition.
-                                                              VARIETY_UNION) {
-                        attrTypeVariety = XSSimpleTypeDefinition.VARIETY_UNION;
-                        
-                        // Assertions on a simpleType with variety union, are
-                        // handled in a special way. These are not accumulated
-                        // here. Create a dummy assertions list (so that a non-null 
-                        // assertions context is pushed on to a run-time assertions 
-                        // stack).                
-                        XSAssertImpl assertImpl = \
                getFirstAssertFromUnionMemberTypes(
-                                                          \
                attrType.getMemberTypes());
-                           if (assertImpl != null) {
-                               // This is done to construct a correct schema 
-                               // NamespaceContext for 'simpleType -> union' \
                assertions
-                               // evaluation. Since NamespaceContext is available in \
                an
-                               // assertions object, therefore we utilize the 1st 
-                               // assertion of an union for this need.
-                               // An assertion object here is not actually \
                evaluated, to
-                               // check an XML instance validity.
-                               // For union types, assertions are later again \
                determined
-                               // in XMLAssertPsychopathImpl.
-                               assertImpl.setTypeDefinition(attrType);
-                               assertImpl.setVariety(attrTypeVariety);
-                               assertImpl.setAttrName(attributes.getLocalName
-                                                      (attrIndx));
-                               assertImpl.setAttrValue(attributes.getValue
-                                                       (attrIndx));
-                               assertions.addXSObject(assertImpl);
-                           }
-                    }
-                    
-                    for (int facetIdx = 0; facetIdx < facets.getLength(); 
-                                                                facetIdx++) {
-                        XSMultiValueFacet facet = (XSMultiValueFacet) 
-                                                      facets.item(facetIdx);
-                        if (facet.getFacetKind() == XSSimpleTypeDefinition.
-                                                              FACET_ASSERT) {
-                            Vector attrAsserts = facet.getAsserts();
-                            for (int j = 0; j < attrAsserts.size(); j++) {
-                                XSAssertImpl attrAssert = (XSAssertImpl) 
-                                                     attrAsserts.elementAt(j);
-                                attrAssert.setAttrName(attributes.getLocalName
-                                                                    (attrIndx));
-                                attrAssert.setAttrValue(attributes.getValue
-                                                                   (attrIndx));
-                                attrAssert.setVariety(attrTypeVariety);              \
                
-                                assertions.addXSObject(attrAssert);    
-                             }
-                             // break from the for loop
-                             break;
-                         }
-                     }
-                  }
-              }
-              
-              if (assertions.size() > 0) {
-                 assertionList = assertions;             
-              }
-           }
-           else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
-               // if element's governing type is a "simple type"
-               XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) 
-                                                                 typeDef;            \
                
-            
-               XSObjectListImpl facets = (XSObjectListImpl) simpleTypeDef.
-                                                     getMultiValueFacets();
+                }
+            }
+        }
+
+        // find assertions from attributes of a complex type, and add them
+        // to the parent assertions list.
+        XSObjectListImpl attrAsserts = getAssertsFromAttributes(attributes);
+        for (int attrAssertIdx = 0; attrAssertIdx < attrAsserts.getLength(); 
+                                                            attrAssertIdx++) {
+            complexTypeAsserts.addXSObject(attrAsserts.item(attrAssertIdx)); 
+        }
+
+        return complexTypeAsserts;
             
-               if (facets.getLength() == 0 && simpleTypeDef.getItemType() != 
-                                                              null) {
-                   // facets for simpleType -> list
-                   facets = (XSObjectListImpl) simpleTypeDef.getItemType().
-                                                   getMultiValueFacets();    
-               }
-               else if (simpleTypeDef.getVariety() == XSSimpleTypeDefinition.
-                                                         VARIETY_UNION) {
-                   // Special handling for assertions on simpleType -> union
-                   // cases. Adding an assertion here, for determining the
-                   // NamespaceContext.
-                   // An assertion object here is not actually evaluated.
-                   XSAssertImpl assertImpl = getFirstAssertFromUnionMemberTypes(
-                                                simpleTypeDef.getMemberTypes());
-                   if (assertImpl != null) {
-                       assertionList = new Vector();
-                       assertionList.add(assertImpl);
+    } // getAssertsFromComplexType
+
+
+    /*
+     * Get assertions from attributes of a complex type.
+     */
+    private XSObjectListImpl getAssertsFromAttributes(XMLAttributes attributes) {
+        
+        XSObjectListImpl attrAssertList = new XSObjectListImpl();
+        
+        for (int attrIndx = 0; attrIndx < attributes.getLength(); attrIndx++) {
+            Augmentations attrAugs = attributes.getAugmentations(attrIndx);
+            AttributePSVImpl attrPSVI = (AttributePSVImpl) attrAugs.getItem
+                                                    (Constants.ATTRIBUTE_PSVI);
+            XSSimpleTypeDefinition attrType = (XSSimpleTypeDefinition) attrPSVI.
+                                                       getTypeDefinition();
+            if (attrType != null) {
+                // this accumulates assertions only for simpleType -> 
+                // restriction.
+                XSObjectList facets = attrType.getMultiValueFacets();
+
+                // variety is 'unknown/absent' at the moment                    
+                short attrTypeVariety = XSSimpleTypeDefinition.VARIETY_ABSENT;
+
+                if (facets.getLength() == 0 && attrType.getItemType() != null) {
+                    // facets for simpleType -> list
+                    attrTypeVariety = XSSimpleTypeDefinition.VARIETY_LIST;
+                    facets = (XSObjectListImpl) attrType.getItemType().
+                                                           getMultiValueFacets();    \
 +                }
+                else if (attrType.getVariety() == XSSimpleTypeDefinition.
+                                                                 VARIETY_UNION) {
+                    attrTypeVariety = XSSimpleTypeDefinition.VARIETY_UNION;
+                    // Special handling for assertions on simpleType -> union
+                    // cases. Adding an assertion here, for determining the
+                    // NamespaceContext.
+                    // This particular assertion object is not actually evaluated.
+                    // For union types, assertions are later again determined
+                    // in XMLAssertPsychopathImpl, which are evaluated to determine
+                    // validity of an XML instance.               
+                    XSAssertImpl assertImpl = getFirstAssertFromUnionMemberTypes(
+                                                        attrType.getMemberTypes());
+                    if (assertImpl != null) {
+                        assertImpl.setTypeDefinition(attrType);
+                        assertImpl.setVariety(attrTypeVariety);
+                        assertImpl.setAttrName(attributes.getLocalName(attrIndx));
+                        assertImpl.setAttrValue(attributes.getValue(attrIndx));
+                        attrAssertList.addXSObject(assertImpl);
                     }
-               }
-            
-               // iterate 'multi value' facets and get assertions from them
-               for (int facetIdx = 0; facetIdx < facets.getLength(); 
-                                                       facetIdx++) {
-                   XSMultiValueFacet facet = (XSMultiValueFacet) facets.
-                                                          item(facetIdx);
-                   if (facet.getFacetKind() == XSSimpleTypeDefinition.
-                                                           FACET_ASSERT) {
-                       if (assertionList == null) {
-                          assertionList = new Vector();   
-                       }                  
-                       assertionList.addAll(facet.getAsserts());                  
-                   }
-               }            
-          }
-               
-          return assertionList;
-         
-    } // getAssertsForEvaluation
+                }
+
+                // iterate all the facets, for attributes having the 'simple
+                // type' variety "atomic | list", and accumulate assertions
+                // from them.
+                for (int facetIdx = 0; facetIdx < facets.getLength(); 
+                                                               facetIdx++) {
+                    XSMultiValueFacet facet = (XSMultiValueFacet) facets.item
+                                                                    (facetIdx);
+                    if (facet.getFacetKind() == XSSimpleTypeDefinition.
+                                                               FACET_ASSERT) {
+                        Vector attrAsserts = facet.getAsserts();
+                        for (int j = 0; j < attrAsserts.size(); j++) {
+                            XSAssertImpl attrAssert = (XSAssertImpl) 
+                                                         attrAsserts.elementAt(j);
+                            attrAssert.setAttrName(attributes.getLocalName
+                                                                 (attrIndx));
+                            attrAssert.setAttrValue(attributes.getValue
+                                                                 (attrIndx));
+                            attrAssert.setVariety(attrTypeVariety);                  \
 +                            attrAssertList.addXSObject(attrAssert);    
+                        }
+                        // break from the for loop
+                        break;
+                    }
+                }                
+            }           
+        }
+        
+        return attrAssertList;
+        
+    } // getAssertsFromAttributes
+    
+    
+    /*
+     * Get assertions from a simpleType.
+     */
+    private List getAssertsFromSimpleType(XSTypeDefinition typeDef) {
+        
+        List simpleTypeAsserts = null;
+
+        XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) 
+                                                             typeDef;                \
 +
+        XSObjectListImpl facets = (XSObjectListImpl) simpleTypeDef.
+                                                    getMultiValueFacets();
+
+        if (facets.getLength() == 0 && simpleTypeDef.getItemType() != null) {
+            // facets for simpleType -> list
+            facets = (XSObjectListImpl) simpleTypeDef.getItemType().
+                                                        getMultiValueFacets();    
+        }
+        else if (simpleTypeDef.getVariety() == XSSimpleTypeDefinition.
+                                                            VARIETY_UNION) {
+            // Special handling for assertions on simpleType -> union
+            // cases. Adding an assertion here, for determining the
+            // NamespaceContext.
+            // This particular assertion object is not actually evaluated.
+            // For union types, assertions are later again determined
+            // in XMLAssertPsychopathImpl, which are evaluated to determine
+            // validity of an XML instance.
+            XSAssertImpl assertImpl = getFirstAssertFromUnionMemberTypes(
+                                              simpleTypeDef.getMemberTypes());
+            if (assertImpl != null) {
+                simpleTypeAsserts = new Vector();
+                simpleTypeAsserts.add(assertImpl);
+            }
+        }
+
+        // iterate all the facets, having the 'simple type' variety "atomic | 
+        // list", and accumulate assertions from them.
+        for (int facetIdx = 0; facetIdx < facets.getLength(); facetIdx++) {
+            XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(
+                                                               facetIdx);
+            if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
+                if (simpleTypeAsserts == null) {
+                    simpleTypeAsserts = new Vector();   
+                }                  
+                simpleTypeAsserts.addAll(facet.getAsserts());                  
+            }
+        }
+
+        return simpleTypeAsserts;
+        
+    } // getAssertsFromSimpleType
     
     
     /*



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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic