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 2010/08/19 10:56:28 UTC

svn commit: r987085 - in /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl: msg/XMLSchemaMessages.properties xs/AbstractPsychoPathImpl.java xs/XMLAssertPsychopathImpl.java xs/XSDAssertionValidator.java xs/alternative/Test.java

Author: mukulg
Date: Thu Aug 19 08:56:28 2010
New Revision: 987085

URL: http://svn.apache.org/viewvc?rev=987085&view=rev
Log:
committing few improvements for assertions processing for 'simpleType -> list/union' schema components.

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
    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
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=987085&r1=987084&r2=987085&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Thu Aug 19 08:56:28 2010
@@ -105,9 +105,9 @@
         cvc-type.3.1.1 = cvc-type.3.1.1: Element ''{0}'' is a simple type, so it cannot have attributes, excepting those whose namespace name is identical to ''http://www.w3.org/2001/XMLSchema-instance'' and whose [local name] is one of ''type'', ''nil'', ''schemaLocation'' or ''noNamespaceSchemaLocation''. However, the attribute, ''{1}'' was found.
         cvc-type.3.1.2 = cvc-type.3.1.2: Element ''{0}'' is a simple type, so it must have no element information item [children].
         cvc-type.3.1.3 = cvc-type.3.1.3: The value ''{1}'' of element ''{0}'' is not valid.
-        cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed.
-        cvc-assertion.4.3.15.3 = cvc-assertion.4.3.15.3: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed (undefined context).
-        cvc-assertion.failure = cvc-assertion.failure: {0} 
+        cvc-assertion.3.13.4.1 = cvc-assertion.3.13.4.1: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed. {3}
+        cvc-assertion.4.3.15.3 = cvc-assertion.4.3.15.3: Assertion evaluation (''{1}'') for element ''{0}'' with type ''{2}'' did not succeed (undefined context). {3}
+        cvc-assertion.failure = cvc-assertion.failure: {0} {1} 
         cvc-xpath.3.13.4.2 = cvc-xpath.3.13.4.2: Assertion XPath expression, (''{0}'') on the Schema type ''{1}'' couldn''t compile successfully.
         
 #schema valid (3.X.3)

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java?rev=987085&r1=987084&r2=987085&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/AbstractPsychoPathImpl.java Thu Aug 19 08:56:28 2010
@@ -98,7 +98,8 @@ public class AbstractPsychoPathImpl {
     protected boolean evaluatePsychoPathExpr(XPath xp,
                                  String xPathDefaultNamespace,
                                  Element contextNode)
-                                 throws StaticError, DynamicError {
+                                 throws StaticError, DynamicError,
+                                        Exception {
         
         StaticChecker sc = new StaticNameResolver(fDynamicContext);
         sc.check(xp);

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=987085&r1=987084&r2=987085&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 Thu Aug 19 08:56:28 2010
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.impl.xs;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Stack;
@@ -37,7 +39,9 @@ import org.apache.xerces.xs.ElementPSVI;
 import org.apache.xerces.xs.XSComplexTypeDefinition;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSModel;
+import org.apache.xerces.xs.XSMultiValueFacet;
 import org.apache.xerces.xs.XSObjectList;
+import org.apache.xerces.xs.XSSimpleTypeDefinition;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
 import org.eclipse.wst.xml.xpath2.processor.DynamicError;
@@ -116,7 +120,7 @@ public class XMLAssertPsychopathImpl ext
                                                     fSchema,
                                                     assertDocument,
                                                     assertParams);
-    }
+    } // initXPathProcessor
     
 
     /*
@@ -181,6 +185,22 @@ public class XMLAssertPsychopathImpl ext
             ElementPSVI elemPSVI = (ElementPSVI) augs.getItem(
                                                  Constants.ELEMENT_PSVI);
             ((PSVIElementNSImpl)currentAssertDomNode).setPSVI(elemPSVI);
+       
+            // itemType for xs:list
+            XSSimpleTypeDefinition itemType = null;
+            
+            // memberTypes for xs:union
+            XSObjectList memberTypes = null;
+            
+            if (elemPSVI.getTypeDefinition().getTypeCategory() == 
+                                                     XSTypeDefinition.SIMPLE_TYPE) {
+                XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) 
+                                                       elemPSVI.getTypeDefinition();
+                itemType = simpleTypeDefn.getItemType();
+                if (itemType == null) {
+                    memberTypes = simpleTypeDefn.getMemberTypes();    
+                }
+            }
             
             if (!assertRootStack.empty() && (currentAssertDomNode == 
                                              assertRootStack.peek())) {               
@@ -193,7 +213,8 @@ public class XMLAssertPsychopathImpl ext
                  // get assertions, and go one level up
                  List assertions = (List) assertListStack.pop(); 
                  
-                 processAllAssertionsOnElement(element, assertions);
+                 processAllAssertionsOnElement(element, itemType, 
+                                               memberTypes, assertions);
             }
 
             if (currentAssertDomNode.getParentNode() instanceof Element) {
@@ -206,10 +227,12 @@ public class XMLAssertPsychopathImpl ext
     
 
     /*
-     * Method to evaluate all assertions for the element tree.
+     * Method to evaluate all of assertions for an element tree.
      */
     private void processAllAssertionsOnElement(
                                     QName element,
+                                    XSSimpleTypeDefinition itemType,
+                                    XSObjectList memberTypes,
                                     List assertions)
                                     throws Exception {
          
@@ -239,11 +262,11 @@ public class XMLAssertPsychopathImpl ext
          if (assertions instanceof XSObjectList) {
             // assertions from a complex type definition             
             if (value != null) {
-              // complex type with simple content
-              setValueOf$value(value, null);
+               // complex type with simple content
+              setValueOf$value(value, null, null);
             } else {
-              // complex type with complex content                
-              // $value should be, the XPath2 "empty sequence" ... TO DO 
+               // complex type with complex content                
+               // $value should be, the XPath2 "empty sequence" ... TO DO 
             }
             XSObjectList assertList = (XSObjectList) assertions;
             for (int i = 0; i < assertList.size(); i++) {
@@ -258,22 +281,98 @@ public class XMLAssertPsychopathImpl ext
                   // reassign value (the attribute's value) to variable
                   // $value.
                   value = assertImpl.getAttrValue();
-                  setValueOf$value(value, assertImpl.getTypeDefinition());
+                  setValueOf$value(value, null, 
+                                   assertImpl.getTypeDefinition());
+               }
+               
+               AssertionError assertError = evaluateAssertion(element,
+                                                assertImpl, value,
+                                                xpathContextExists,
+                                                false, false);
+               if (assertError != null) {
+                   reportError(assertError);    
                }
-               evaluateAssertion(element,
-                                 assertImpl,
-                                 value,
-                                 xpathContextExists);
             }
          }
          else if (assertions instanceof Vector) {
-            // assertions from a simple type definition
-            setValueOf$value(value, null);
-            Vector assertList = (Vector) assertions;                    
+            // assertions from a simple type definition           
+            Vector assertList = (Vector) assertions;
+            List assertUnionErrorList = new ArrayList();
+            
             for (int i = 0; i < assertList.size(); i++) {
                 XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(i);
-                evaluateAssertion(element, assertImpl, value, false);
+                if (itemType != null) {
+                   // evaluating assertions for simpleType -> list
+                   String[] values = value.split("\\s+");
+                   for (int valIdx = 0; valIdx < values.length; valIdx++) {
+                      setValueOf$value(values[valIdx], itemType, null);
+                      AssertionError assertError = evaluateAssertion(element, 
+                                                                  assertImpl, 
+                                                                  values[valIdx], 
+                                                                  false,
+                                                                  true, false);
+                      if (assertError != null) {
+                          reportError(assertError);    
+                      }
+                   }
+                }
+                else if (memberTypes.getLength() > 0) {
+                    // evaluating assertions for simpleType -> union
+                    boolean isValueSuccess = true;
+                    try {
+                       setValueOf$value(value, (XSSimpleTypeDefinition) 
+                                     assertImpl.getTypeDefinition(), 
+                                     null);
+                    }
+                    catch (Exception ex) {
+                        // there was some problem in constructing value of the
+                        // XPath2 context variable $value.
+                        isValueSuccess = false;
+                        AssertionError assertError = new AssertionError
+                                             ("cvc-assertion.3.13.4.1", 
+                                             element, assertImpl, value,
+                                             false, true);
+                        assertUnionErrorList.add(assertError);
+                    }
+                    
+                    if (isValueSuccess) {
+                        AssertionError assertError = evaluateAssertion(element, 
+                                                                assertImpl,
+                                                                value, 
+                                                                false,
+                                                                false, true);
+                        if (assertError != null) {
+                            assertUnionErrorList.add(assertError);    
+                        }  
+                    }
+                }
+                else {
+                    // evaluating assertions for simpleType -> restriction
+                    setValueOf$value(value, null, null);
+                    AssertionError assertError = evaluateAssertion(element, 
+                                                                assertImpl,
+                                                                value, 
+                                                                false,
+                                                                false, false);
+                    if (assertError != null) {
+                        reportError(assertError);    
+                    }    
+                }
+            }  
+            
+            // if all of assertions in the schema component 'simpleType -> 
+            // union' have failed, then the overall schema validation should 
+            // fail, and all assertion failures should be reported.
+            if (memberTypes != null && assertUnionErrorList.size() == 
+                                         getAssertCountForSimpletypeUnion
+                                                          (memberTypes)) {
+               for (Iterator iter = assertUnionErrorList.iterator(); 
+                                                           iter.hasNext(); ) {
+                   AssertionError assertError = (AssertionError) iter.next();
+                   reportError(assertError);
+               }
             }
+            
          }
          
     } // processAllAssertionsOnElement
@@ -298,10 +397,14 @@ public class XMLAssertPsychopathImpl ext
     /*
      * Method to evaluate an assertion for the element.
      */
-    private void evaluateAssertion(QName element,
+    private AssertionError evaluateAssertion(QName element,
                                    XSAssertImpl assertImpl,
                                    String value,
-                                   boolean xPathContextExists) {
+                                   boolean xPathContextExists,
+                                   boolean isList,
+                                   boolean isUnion) {
+        
+        AssertionError assertionError = null;
         
         try {  
             XPath xp = assertImpl.getCompiledXPath();
@@ -322,48 +425,175 @@ public class XMLAssertPsychopathImpl ext
             
             if (!result) {
                // assertion evaluation is false
-               reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
+                                                   element, assertImpl, value,
+                                                   isList, isUnion); 
             }
         }
         catch (DynamicError ex) {
             if (ex.code().equals("XPDY0002")) {
                // ref: http://www.w3.org/TR/xpath20/#eval_context
-               reportError("cvc-assertion.4.3.15.3", element, assertImpl);
+               assertionError = new AssertionError("cvc-assertion.4.3.15.3", 
+                                                   element, assertImpl, value,
+                                                   isList, isUnion);
             }
             else {
-               reportError("cvc-assertion.3.13.4.1", element, assertImpl);  
+               assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
+                                                   element, assertImpl, value,
+                                                   isList, isUnion);
             }
         }
         catch (StaticError ex) {
-            reportError("cvc-assertion.3.13.4.1", element, assertImpl);
+            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
+                                                 element, assertImpl, value,
+                                                 isList, isUnion);
+        }
+        catch(Exception ex) {
+            assertionError = new AssertionError("cvc-assertion.3.13.4.1", 
+                                                element, assertImpl, value,
+                                                isList, isUnion);   
         }
         
+        return assertionError;
+        
     } // evaluateAssertion
     
     
     /*
+     * Assign 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
+        String xsdTypeName = "";
+        
+        if (listOrUnionType != null) {
+            xsdTypeName = getXSDtypeOf$Value(listOrUnionType);    
+        }
+        else {
+           if (attrType != null) {
+              // is value of an attribute
+              xsdTypeName = getXSDtypeOf$Value(attrType);  
+           }
+           else {
+              // is "simple type" value of an element
+              PSVIElementNSImpl currentAssertPSVINode = (PSVIElementNSImpl)
+                                                   currentAssertDomNode;
+              XSTypeDefinition typeDef = currentAssertPSVINode.getTypeDefinition();
+              if (typeDef instanceof XSComplexTypeDefinition) {
+                  XSComplexTypeDefinition cmplxTypeDef = (XSComplexTypeDefinition)
+                                                                       typeDef;
+                  if (cmplxTypeDef.getSimpleType() != null) {
+                     xsdTypeName = getXSDtypeOf$Value(cmplxTypeDef.getSimpleType());   
+                  }
+              }
+              else {
+                 xsdTypeName = getXSDtypeOf$Value(currentAssertPSVINode.
+                                               getTypeDefinition());
+              }
+           }
+        }
+        
+        // determine the 'schema type' representation used within PsychoPath XPath 
+        // engine, corresponding to an XML Schema language type.
+        Object psychoPathType = SchemaTypeValueFactory.newSchemaTypeValue
+                                                         (xsdTypeName, value);
+        
+        fDynamicContext.set_variable(
+               new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
+                       "value"), (AnyAtomicType) psychoPathType);
+        
+    } // setValueOf$value
+    
+    
+    /*
+       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.
+    */
+    private String getXSDtypeOf$Value(XSTypeDefinition elementType) {
+      
+      if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) {        
+         return elementType.getName();    
+      }
+      else {
+         return getXSDtypeOf$Value(elementType.getBaseType()); 
+      }
+      
+    } // getXSDtypeOf$Value
+    
+    
+    /*
+     * Find count of number of assertions within a 'simpleType -> union' schema
+     * component.
+     */
+    private int getAssertCountForSimpletypeUnion(XSObjectList memberTypes) {
+       
+        int assertCount = 0;
+        
+        for (int memTypIdx = 0; memTypIdx < memberTypes.getLength(); 
+                                                    memTypIdx++) {
+            XSObjectList memberTypeFacets = ((XSSimpleTypeDefinition) 
+                                            memberTypes.item(memTypIdx)).
+                                            getMultiValueFacets();
+            for (int facetIdx = 0; facetIdx < memberTypeFacets.getLength(); 
+                                                           facetIdx++) {
+                XSMultiValueFacet facet = (XSMultiValueFacet) memberTypeFacets.
+                                                                item(facetIdx);
+                if (facet.getFacetKind() == XSSimpleTypeDefinition.
+                                                          FACET_ASSERT) {
+                    assertCount = assertCount + facet.getAsserts().size();    
+                }
+            }
+        }
+        
+        return assertCount;
+        
+    } // getAssertCountForSimpletypeUnion
+    
+    
+    /*
      * Method to report error messages.
      */
-    private void reportError(String key, QName element,
-                             XSAssertImpl assertImpl) {
+    private void reportError(AssertionError assertError) {
+        
+        String key = assertError.getErrorCode();
+        QName element = assertError.getElement();
+        XSAssertImpl assertImpl = assertError.getAssertion();
+        boolean isList = assertError.isList();
+        boolean isUnion = assertError.isUnion();
         
         XSTypeDefinition typeDef = assertImpl.getTypeDefinition();        
         String typeString = "";
         
         if (typeDef != null) {
-           typeString = (typeDef.getName() != null) ? typeDef.getName() :
+            typeString = (typeDef.getName() != null) ? typeDef.getName() :
                                                       "#anonymous";   
         }
         else {
-           typeString = "#anonymous"; 
+            typeString = "#anonymous"; 
         }
         
         String elemErrorAnnotation = element.rawname;
         if (assertImpl.getAttrName() != null) {
-           elemErrorAnnotation = element.rawname + " (attribute => " +
+            elemErrorAnnotation = element.rawname + " (attribute => " +
                                               assertImpl.getAttrName()+ ")";    
-        }
+        }                
         
+        String listUnionErrMessage = "";        
+        if (isList) {
+           listUnionErrMessage =  "Assertion failed for an xs:list member value '" + 
+                                                   assertError.getValue() + 
+                                                   "'.";
+        }
+        else if (isUnion) {
+           listUnionErrMessage = "Assertion failed for an xs:union with data value '" + 
+                                                   assertError.getValue() + 
+                                                   "'.";     
+        }
+            
         String message = assertImpl.getMessage();
         if (message != null) {
            if (!message.endsWith(".")) {
@@ -376,67 +606,69 @@ public class XMLAssertPsychopathImpl ext
               message = "Assertion failure. " + message; 
            }
            validator.reportSchemaError("cvc-assertion.failure", 
-                                       new Object[] { message } );    
+                               new Object[] { message, listUnionErrMessage } );    
         }
         else {
            validator.reportSchemaError(key, new Object[] { elemErrorAnnotation,
                                assertImpl.getTest().getXPath().toString(),
-                               typeString } );
+                               typeString, listUnionErrMessage} );
         }
         
     } // reportError
     
     
     /*
-     * Assign value to the XPath2 "dynamic context" variable, $value.
+     * An object to store assertion error details.
      */
-    private void setValueOf$value(String value, XSTypeDefinition attrType) {
+    class AssertionError {
         
-        String xsdTypeName = "";
+        // instance variables        
+        String errorCode = null;
+        QName element = null;
+        XSAssertImpl assertImpl = null;
+        String value = null;
+        // does this error concerns simpleType -> list
+        boolean isList;
+        // does this error concerns simpleType -> union
+        boolean isUnion;
         
-        if (attrType != null) {
-           // is value of an attribute
-           xsdTypeName = getXSDtypeOf$Value(attrType);  
+        // class constructor
+        public AssertionError(String errorCode, QName element, 
+                              XSAssertImpl assertImpl, String value,
+                              boolean isList,
+                              boolean isUnion) {
+           this.errorCode = errorCode;
+           this.element = element;
+           this.assertImpl = assertImpl;
+           this.value = value;
+           this.isList = isList;
+           this.isUnion = isUnion;
         }
-        else {
-          // is "simple type" value of an element
-          PSVIElementNSImpl currentAssertPSVINode = (PSVIElementNSImpl)
-                                                 currentAssertDomNode;
-          XSTypeDefinition typeDef = currentAssertPSVINode.getTypeDefinition();
-          if (typeDef instanceof XSComplexTypeDefinition) {
-             XSComplexTypeDefinition cmplxTypeDef = (XSComplexTypeDefinition)
-                                                                       typeDef;
-             if (cmplxTypeDef.getSimpleType() != null) {
-                xsdTypeName = getXSDtypeOf$Value(cmplxTypeDef.getSimpleType());   
-             }
-          }
-          else {
-             xsdTypeName = getXSDtypeOf$Value(currentAssertPSVINode.
-                                               getTypeDefinition());
-          }
+        
+        public String getErrorCode() {
+           return errorCode;    
         }
         
-        Object psychoPathType = SchemaTypeValueFactory.newSchemaTypeValue(xsdTypeName, value);
+        public QName getElement() {
+           return element;       
+        }
         
-        fDynamicContext.set_variable(
-               new org.eclipse.wst.xml.xpath2.processor.internal.types.QName(
-                       "value"), (AnyAtomicType) psychoPathType);
+        public XSAssertImpl getAssertion() {
+           return assertImpl;    
+        }
         
-    } // setValueOf$value
-    
-    
-    /*
-       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.
-    */
-    private String getXSDtypeOf$Value(XSTypeDefinition elementType) {
-      if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) {        
-        return elementType.getName();    
-      }
-      else {
-        return getXSDtypeOf$Value(elementType.getBaseType()); 
-      }
-    }
+        public String getValue() {
+           return value; 
+        }
+        
+        public boolean isList() {
+           return isList;    
+        }
+        
+        public boolean isUnion() {
+           return isUnion;
+        }
+        
+    } // class AssertionError
     
 } // class XMLAssertPsychopathImpl

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=987085&r1=987084&r2=987085&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 Aug 19 08:56:28 2010
@@ -220,27 +220,56 @@ public class XSDAssertionValidator {
         else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
             // if element's governing type is a "simple type"
             XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) 
-                                                                typeDef;
-            XSObjectList facets = simpleTypeDef.getMultiValueFacets();
-            for (int i = 0; i < facets.getLength(); i++) {
-               XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
-               if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
-                  assertionList = facet.getAsserts();
+                                                                typeDef;                     
+            
+            XSObjectListImpl facets = (XSObjectListImpl) simpleTypeDef.
+                                                   getMultiValueFacets();
+            
+            if (facets.getLength() == 0 && simpleTypeDef.getItemType() != 
+                                                              null) {
+                // facets for list -> simpleType
+                facets = (XSObjectListImpl) simpleTypeDef.getItemType().
+                                                getMultiValueFacets();    
+            }
+            else {
+                // facets for union -> simpleType*
+                XSObjectList memberTypes = simpleTypeDef.getMemberTypes();
+                for (int memberTypeIdx = 0; memberTypeIdx < 
+                                  memberTypes.getLength(); memberTypeIdx++) {
+                    XSObjectList memberTypeFacets = ((XSSimpleTypeDefinition) 
+                                             memberTypes.item(memberTypeIdx)).
+                                                        getMultiValueFacets();
+                    for (int memberTypeFacetIdx = 0; memberTypeFacetIdx < 
+                           memberTypeFacets.getLength(); memberTypeFacetIdx++) {
+                         facets.addXSObject(memberTypeFacets.item
+                                              (memberTypeFacetIdx));
+                    }
+                }
+            }
+            
+            // 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());
                   // instantiate the assertions processor
                   if (fAssertionProcessor == null) {
-                     // construct parameter values for the assertion processor
-                     Map assertProcessorParams = new HashMap();
-                     assertProcessorParams.put("XPATH2_NS_CONTEXT",
-                                       ((XSAssertImpl)facet.getAsserts().get(0)).
-                                         getXPath2NamespaceContext());
-                     // initialize the assertions processor
-                     initializeAssertProcessor(assertProcessorParams);
-                  }
-                  
-                  break;
-                  
+                      // construct parameter values for the assertion processor
+                      Map assertProcessorParams = new HashMap();
+                      assertProcessorParams.put("XPATH2_NS_CONTEXT",
+                                      ((XSAssertImpl)facet.getAsserts().get(0)).
+                                      getXPath2NamespaceContext());
+                      // initialize the assertions processor
+                      initializeAssertProcessor(assertProcessorParams);
+                  }                  
                }
-            }
+            }            
          }
                
          return assertionList;

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java?rev=987085&r1=987084&r2=987085&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/alternative/Test.java Thu Aug 19 08:56:28 2010
@@ -145,11 +145,16 @@ public class Test extends AbstractPsycho
          result = evaluatePsychoPathExpr(fXPathPsychoPath,
                                 fTypeAlternative.fXPathDefaultNamespace,
                                 elem);
-       } catch (StaticError ex) {
+       } 
+       catch (StaticError ex) {
            result = false; 
-       } catch(DynamicError ex) {
+       } 
+       catch(DynamicError ex) {
            result = false;
        }
+       catch(Exception ex) {
+           result = false;  
+       }
        
        return result;
        



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