Author: mukulg
Date: Tue Apr 12 12:51:12 2022
New Revision: 1899779

URL: http://svn.apache.org/viewvc?rev=1899779&view=rev
Log:
improvements to, fixes for jira issue XERCESJ-1743

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=1899779&r1=1899778&r2=1899779&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
 Tue Apr 12 12:51:12 2022
@@ -41,6 +41,7 @@ import org.apache.xerces.impl.xs.util.Ob
 import org.apache.xerces.impl.xs.util.ShortListImpl;
 import org.apache.xerces.impl.xs.util.StringListImpl;
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
+import org.apache.xerces.util.NamespaceSupport;
 import org.apache.xerces.util.XML11Char;
 import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
@@ -825,6 +826,8 @@ public class XSSimpleTypeDecl implements
     void applyFacets(XSFacets facets, int presentFacet, int fixedFacet, short 
patternType, ValidationContext context)
     throws InvalidDatatypeFacetException {
         
+        boolean isXsd11 = context.getTypeValidatorHelper().isXMLSchema11();
+        
         // if the object is immutable, should not apply facets...
         if(fIsImmutable) return;
         ValidatedInfo tempInfo = new ValidatedInfo();
@@ -949,39 +952,50 @@ public class XSSimpleTypeDecl implements
                     }
                 }
                 
-                if (fAssertion != null && fAssertion.size() > 0) {
+                if (isXsd11) {
                     // added for XML Schema 1.1
                     String enumVal = null;
                     try {
-                        Map assertProcessorParams = new HashMap();
-                        
assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, 
((XSAssertImpl)fAssertion.get(0)).
-                                                                               
                  getXPath2NamespaceContext());                        
+                        boolean isTypeDerivedFromList = ((XSSimpleType) 
this.getBaseType()).
+                                                                               
     getVariety() == XSSimpleType.VARIETY_LIST;
+                        boolean isTypeDerivedFromUnion = ((XSSimpleType) 
this.getBaseType()).
+                                                                               
     getVariety() == XSSimpleType.VARIETY_UNION;
+                        Map assertProcessorParams = new HashMap();             
           
+                        
assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, new 
NamespaceSupport());
                         XMLAssertXPath2EngineImpl fAssertionProcessor = new 
XMLAssertXPath2EngineImpl(assertProcessorParams);
                         fAssertionProcessor.initXPathProcessor();
+                        
                         QName elemQname = new QName(null, "enumeration", 
"enumeration", Constants.NS_XMLSCHEMA);
                         QName attrQname = new QName(null, "value", "value", 
null);
-                        boolean isTypeDerivedFromList = ((XSSimpleType) 
this.getBaseType().getBaseType()).
-                                                                               
        getVariety() == XSSimpleType.VARIETY_LIST;
-                        boolean isTypeDerivedFromUnion = ((XSSimpleType) 
this.getBaseType().getBaseType()).
-                                                                               
        getVariety() == XSSimpleType.VARIETY_UNION;
-                        for (int idx = 0; idx < fAssertion.size(); idx++) {
-                           XSAssertImpl assertImpl = 
(XSAssertImpl)fAssertion.get(idx);                       
-                           for (int i = 0; i < size; i++) {
-                              enumVal = (String)enumVals.elementAt(i);         
                 
-                              Boolean isAssertSucceeded = 
fAssertionProcessor.evaluateOneAssertionFromSimpleType(elemQname, enumVal, 
null, 
-                                                                               
    (XSSimpleTypeDefinition)this.getBaseType(), isTypeDerivedFromList, 
-                                                                               
     isTypeDerivedFromUnion, assertImpl, true, attrQname, true);
-                              if (isAssertSucceeded.booleanValue() == false) { 
+                        
+                        for (int i = 0; i < size; i++) {
+                           enumVal = (String)enumVals.elementAt(i);
+                           if (fAssertion != null && fAssertion.size() > 0) {  
                                                                                
        
+                               for (int idx = 0; idx < fAssertion.size(); 
idx++) {
+                                  XSAssertImpl assertImpl = 
(XSAssertImpl)fAssertion.get(idx);
+                                  Boolean isAssertSucceeded = 
fAssertionProcessor.evaluateOneAssertionFromSimpleType(elemQname, enumVal, 
null, 
+                                                                               
            (XSSimpleTypeDefinition)this.getBaseType(), isTypeDerivedFromList, 
+                                                                               
             isTypeDerivedFromUnion, assertImpl, true, attrQname, true);
+                                  if (isAssertSucceeded.booleanValue() == 
false) { 
+                                     throw new 
InvalidDatatypeFacetException(null, null);
+                                  }
+                               }
+                           }
+                           
+                           if (isTypeDerivedFromList) {
+                               Boolean isAssertSucceeded = 
fAssertionProcessor.evaluateAssertsFromItemTypeOfSTList(elemQname, 
+                                                                               
   ((XSSimpleTypeDefinition)this.getBaseType()).getItemType(), enumVal, true);
+                               if (isAssertSucceeded.booleanValue() == false) 
{ 
                                  throw new InvalidDatatypeFacetException(null, 
null);
-                              }
+                               }
                            }
-                        }
+                        }                                                
                     }
                     catch (InvalidDatatypeFacetException ex) {
                        reportError("enumeration-valid-restriction", new 
Object[]{enumVal, this.getBaseType().getName()});    
                     }
                     catch (Exception ex) {
-                      // NO OP    
+                       // NO OP   
                     }
                 }
                 

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java?rev=1899779&r1=1899778&r2=1899779&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.java
 Tue Apr 12 12:51:12 2022
@@ -220,7 +220,7 @@ public class XMLAssertXPath2EngineImpl e
                         // evaluate assertions on itemType of xs:list
                         XSSimpleTypeDefinition attrItemType = 
attrSimpleType.getItemType();
                         if (isTypeDerivedFromList && attrItemType != null) {
-                            evaluateAssertsFromItemTypeOfSTList(element, 
attrItemType, attrValue);
+                            evaluateAssertsFromItemTypeOfSTList(element, 
attrItemType, attrValue, false);
                         }
                     }                
                 }
@@ -398,7 +398,7 @@ public class XMLAssertXPath2EngineImpl e
         
         // evaluate assertions on itemType of xs:list
         if (isTypeDerivedFromList && simpleTypeDefn.getItemType() != null) {
-            evaluateAssertsFromItemTypeOfSTList(element, 
simpleTypeDefn.getItemType(), value); 
+            evaluateAssertsFromItemTypeOfSTList(element, 
simpleTypeDefn.getItemType(), value, false); 
         }
         
     } // evaluateAssertionsFromSimpleType
@@ -408,7 +408,7 @@ public class XMLAssertXPath2EngineImpl e
      * Evaluate one assertion instance for a simpleType (this assertion could 
be from an attribute, simpleType on element or a complexType with simple 
content).
      */
     public Boolean evaluateOneAssertionFromSimpleType(QName element, String 
value, Augmentations augs, XSSimpleTypeDefinition simpleTypeDefn, boolean 
isTypeDerivedFromList, boolean isTypeDerivedFromUnion,
-                                                    XSAssertImpl assertImpl, 
boolean isAttribute, QName attrQname, boolean isAssertEvaluationFromSchema) 
throws Exception {
+                                                      XSAssertImpl assertImpl, 
boolean isAttribute, QName attrQname, boolean isAssertEvaluationFromSchema) 
throws Exception {
         
         Boolean isAssertSucceeded = Boolean.TRUE; 
         
@@ -465,9 +465,13 @@ public class XMLAssertXPath2EngineImpl e
     /*
      * Evaluate assertions from itemType with variety 'atomic' on a 
simpleType->list.
      */
-    private void evaluateAssertsFromItemTypeOfSTList(QName element, 
XSSimpleTypeDefinition listItemType, String value) throws Exception {
+    public Boolean evaluateAssertsFromItemTypeOfSTList(QName element, 
XSSimpleTypeDefinition listItemType, String value, 
+                                                       boolean 
isAssertEvaluationFromSchema) throws Exception {
+        
+        Boolean isAssertSucceeded = Boolean.TRUE;
         
         Vector itemTypeAsserts = 
XS11TypeHelper.getAssertsFromSimpleType(listItemType);
+        
         if (listItemType.getVariety() ==  
XSSimpleTypeDefinition.VARIETY_ATOMIC && itemTypeAsserts.size() > 0) {
             for (int assertIdx = 0; assertIdx < itemTypeAsserts.size(); 
assertIdx++) {
                 XSAssertImpl itemTypeAssert = (XSAssertImpl) 
itemTypeAsserts.get(assertIdx);
@@ -477,13 +481,20 @@ public class XMLAssertXPath2EngineImpl e
                     
setXDMTypedValueOf$valueForSTVarietyList(fCurrentAssertDomNode, 
listItemStrValue, listItemType, false, fXpath2DynamicContext);                  
      
                     AssertionError assertError = evaluateOneAssertion(element, 
itemTypeAssert, listItemStrValue, false, true);                        
                     if (assertError != null) {
-                        assertError.setIsTypeDerivedFromList(false);
-                        reportAssertionsError(assertError);    
+                       if (isAssertEvaluationFromSchema) {
+                          isAssertSucceeded = Boolean.FALSE;  
+                       }
+                       else {
+                          assertError.setIsTypeDerivedFromList(false);
+                          reportAssertionsError(assertError);
+                       }
                     }
                 }
             }
         }
         
+        return isAssertSucceeded;
+        
     } // evaluateAssertsFromItemTypeOfSTList
     
     
@@ -491,7 +502,7 @@ public class XMLAssertXPath2EngineImpl e
      * Evaluate assertion on a simpleType xs:list value.
      */
     private Boolean evaluateAssertionOnSTListValue(QName element, String 
listStrValue, XSAssertImpl assertImpl, boolean xpathContextExists,
-                                                XSSimpleTypeDefinition 
itemType, boolean isTypeDerivedFromList, boolean isAssertEvaluationFromSchema) 
throws Exception {
+                                                   XSSimpleTypeDefinition 
itemType, boolean isTypeDerivedFromList, boolean isAssertEvaluationFromSchema) 
throws Exception {
         
         Boolean isAssertSucceeded = Boolean.TRUE;
         
@@ -626,7 +637,7 @@ public class XMLAssertXPath2EngineImpl e
                 XSSimpleTypeDefinition listItemType = 
simpleTypeDefn.getItemType();
                 if (isTypeDerivedFromList && listItemType != null) {
                     restorePsviInfoForXPathContext(elemPsvi);
-                    evaluateAssertsFromItemTypeOfSTList(element, listItemType, 
value);
+                    evaluateAssertsFromItemTypeOfSTList(element, listItemType, 
value, false);
                     savePsviInfoWithUntypingOfAssertRoot(elemPsvi, true);;
                 }
             }            



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

Reply via email to