Author: mukulg Date: Sat Apr 16 09:53:36 2022 New Revision: 1899904 URL: http://svn.apache.org/viewvc?rev=1899904&view=rev Log: committing fix for jira issue, XERCESJ-1744
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/msg/XMLSchemaMessages.properties xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertXPath2EngineImpl.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/assertion/XSAssertionXPath2ValueImpl.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=1899904&r1=1899903&r2=1899904&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 Sat Apr 16 09:53:36 2022 @@ -3887,5 +3887,10 @@ public class XSSimpleTypeDecl implements } sb.append(']'); } + + public Vector getAssertions() { + return fAssertion; + } + } // class XSSimpleTypeDecl 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=1899904&r1=1899903&r2=1899904&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 Sat Apr 16 09:53:36 2022 @@ -77,6 +77,7 @@ cvc-datatype-valid.1.2.2 = cvc-datatype-valid.1.2.2: ''{0}'' is not a valid value of list type ''{1}''. cvc-datatype-valid.1.2.3 = cvc-datatype-valid.1.2.3: ''{0}'' is not a valid value of union type ''{1}''. cvc-datatype-valid.1.2.4 = cvc-datatype-valid.1.2.4: The NOTATION type, ''{0}'' used to validate ''{1}'', must have an enumeration facet value which specifies the notation elements used by this type. + cvc-datatype-valid.4.1.4 = cvc-datatype-valid.4.1.4: The value ''{0}'' of element ''{1}'' is not valid with the required simple type. Value ''{2}'' is not valid with any member of union type ''{3}''. cvc-elt.1.a = cvc-elt.1.a: Cannot find the declaration of element ''{0}''. cvc-elt.1.b = cvc-elt.1.b: The name of the element does not match the name of the element declaration. Saw ''{0}''. Expected ''{1}''. cvc-elt.2 = cvc-elt.2: The value of '{'abstract'}' in the element declaration for ''{0}'' must be false. 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=1899904&r1=1899903&r2=1899904&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 Sat Apr 16 09:53:36 2022 @@ -381,24 +381,70 @@ public class XMLAssertXPath2EngineImpl e * Evaluate assertions from a "simple type" definition, on elements. */ private void evaluateAssertionsFromSimpleType(QName element, List assertions, String value, Augmentations augs) throws Exception { - - XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) ((ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI)).getTypeDefinition(); - boolean isTypeDerivedFromList = isTypeDerivedFromSTList(simpleTypeDefn); - boolean isTypeDerivedFromUnion = isTypeDerivedFromSTUnion(simpleTypeDefn); - - Vector assertList = (Vector) assertions; - for (int assertIdx = 0; assertIdx < assertList.size(); assertIdx++) { - XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx); - String xPathDefaultNamespace = assertImpl.getXPathDefaultNamespace(); - if (xPathDefaultNamespace != null) { - fXpath2DynamicContext.add_namespace(null, xPathDefaultNamespace); - } - evaluateOneAssertionFromSimpleType(element, value, augs, simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl, false, null, false); + + if (assertions.get(0) instanceof XSSimpleTypeDecl) { + // handling, assertions on, simpleType with variety list whose itemType is union + + // tokenize the list value by a sequence of white spaces + StringTokenizer listStrTokens = new StringTokenizer(value, " \n\t\r"); + while (listStrTokens.hasMoreTokens()) { + String listItemStrValue = listStrTokens.nextToken(); + // iterate over all the members types of union + boolean isListItemValidWithXSNsType = false; + for (int idx = 0; idx < assertions.size(); idx++) { + XSSimpleTypeDecl xsSimpleTypeDecl = (XSSimpleTypeDecl)assertions.get(idx); + if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(xsSimpleTypeDecl.getNamespace()) && + XS11TypeHelper.isStrValueValidForASimpleType(listItemStrValue, + xsSimpleTypeDecl, Constants.SCHEMA_VERSION_1_1)) { + isListItemValidWithXSNsType = true; + break; + } + } + if (!isListItemValidWithXSNsType) { + for (int idx = 0; idx < assertions.size(); idx++) { + XSSimpleTypeDecl xsSimpleTypeDecl = (XSSimpleTypeDecl)assertions.get(idx); + if (!SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(xsSimpleTypeDecl.getNamespace()) && + XS11TypeHelper.isStrValueValidForASimpleType(listItemStrValue, + xsSimpleTypeDecl, Constants.SCHEMA_VERSION_1_1)) { + Vector assertVector = xsSimpleTypeDecl.getAssertions(); + if (assertVector != null) { + for (int idx1 = 0; idx1 < assertVector.size(); idx1++) { + setXDMTypedValueOf$valueForSTVarietyAtomic(listItemStrValue, getXercesXSDTypeCodeFor$value((XSTypeDefinition)xsSimpleTypeDecl), + fXpath2DynamicContext); + AssertionError assertError = evaluateOneAssertion(element, (XSAssertImpl)assertVector.get(idx1), listItemStrValue, false, true); + if (assertError != null) { + XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) ((ElementPSVI) + augs.getItem(Constants.ELEMENT_PSVI)).getTypeDefinition(); + fXmlSchemaValidator.reportSchemaError("cvc-datatype-valid.4.1.4", new Object[] {value, element.rawname, + listItemStrValue, XS11TypeHelper.getSchemaTypeName((XSTypeDefinition) + simpleTypeDefn.getItemType())}); + } + } + } + } + } + } + } } - - // evaluate assertions on itemType of xs:list - if (isTypeDerivedFromList && simpleTypeDefn.getItemType() != null) { - evaluateAssertsFromItemTypeOfSTList(element, simpleTypeDefn.getItemType(), value, false); + else { + XSSimpleTypeDefinition simpleTypeDefn = (XSSimpleTypeDefinition) ((ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI)).getTypeDefinition(); + boolean isTypeDerivedFromList = isTypeDerivedFromSTList(simpleTypeDefn); + boolean isTypeDerivedFromUnion = isTypeDerivedFromSTUnion(simpleTypeDefn); + + Vector assertList = (Vector) assertions; + for (int assertIdx = 0; assertIdx < assertList.size(); assertIdx++) { + XSAssertImpl assertImpl = (XSAssertImpl) assertList.get(assertIdx); + String xPathDefaultNamespace = assertImpl.getXPathDefaultNamespace(); + if (xPathDefaultNamespace != null) { + fXpath2DynamicContext.add_namespace(null, xPathDefaultNamespace); + } + evaluateOneAssertionFromSimpleType(element, value, augs, simpleTypeDefn, isTypeDerivedFromList, isTypeDerivedFromUnion, assertImpl, false, null, false); + } + + // evaluate assertions on itemType of xs:list + if (isTypeDerivedFromList && simpleTypeDefn.getItemType() != null) { + evaluateAssertsFromItemTypeOfSTList(element, simpleTypeDefn.getItemType(), value, false); + } } } // evaluateAssertionsFromSimpleType 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=1899904&r1=1899903&r2=1899904&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java Sat Apr 16 09:53:36 2022 @@ -27,6 +27,7 @@ import java.util.Vector; import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.dv.ValidatedInfo; import org.apache.xerces.impl.dv.XSSimpleType; +import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl; import org.apache.xerces.impl.xs.assertion.XMLAssertHandler; import org.apache.xerces.impl.xs.assertion.XSAssert; import org.apache.xerces.impl.xs.assertion.XSAssertConstants; @@ -99,20 +100,41 @@ public class XSDAssertionValidator { // instantiate the assertions processor if (assertionList != null && fAssertionProcessor == null) { - // construct parameter values for the assertion processor - NamespaceSupport xpathNamespaceContext = null; - if (assertionList instanceof XSObjectList) { - xpathNamespaceContext = ((XSAssertImpl)((XSObjectList) assertionList).item(0)).getXPath2NamespaceContext(); - } - else { - Vector assertVector = (Vector) assertionList; - xpathNamespaceContext = ((XSAssertImpl)assertVector.get(0)).getXPath2NamespaceContext(); + constructAssertProcessor(assertionList); + } + + // handling, assertions on, simpleType with variety list whose itemType is union. + // only supporting, when all the union member types are with variety atomic. + int unionTypeNoOfMembers = 0; + int noOfUnionAtomicTypes = 0; + if (assertionList == null && fAssertionProcessor == null) { + XSTypeDefinition typeDefn = fXmlSchemaValidator.fCurrentPSVI.getTypeDefinition(); + if (typeDefn != null && typeDefn.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) { + XSSimpleTypeDefinition xsSimpleTypeDefn = (XSSimpleTypeDefinition)typeDefn; + if (xsSimpleTypeDefn.getVariety() == XSSimpleTypeDefinition.VARIETY_LIST) { + XSSimpleTypeDefinition xsItemTypeDefn = xsSimpleTypeDefn.getItemType(); + if (xsItemTypeDefn.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION) { + XSObjectList memberTypes = xsItemTypeDefn.getMemberTypes(); + unionTypeNoOfMembers = memberTypes.getLength(); + assertionList = new Vector(); + for (int idx = 0; idx < memberTypes.getLength(); idx++) { + XSSimpleTypeDefinition memberType = (XSSimpleTypeDefinition) + memberTypes.get(idx); + if (memberType.getVariety() == XSSimpleTypeDefinition.VARIETY_ATOMIC) { + noOfUnionAtomicTypes++; + XSSimpleTypeDecl xsSimpleTypeDecl = (XSSimpleTypeDecl)memberType; + assertionList.add(xsSimpleTypeDecl); // add the simpleType definition itself, to list + } + } + } + } } - - Map assertProcessorParams = new HashMap(); - assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, xpathNamespaceContext); - // initialize the assertions processor - initializeAssertProcessor(assertProcessorParams); + } + + // instantiate the assertions processor + if (unionTypeNoOfMembers > 0 && unionTypeNoOfMembers == noOfUnionAtomicTypes && + assertionList != null && fAssertionProcessor == null) { + constructAssertProcessor(assertionList); } // invoke the assertions processor method @@ -126,6 +148,36 @@ public class XSDAssertionValidator { } } // handleStartElement + + // construct and initialize, an assert processor + private void constructAssertProcessor(List assertionList) { + // construct parameter values for the assertion processor + NamespaceSupport xpathNamespaceContext = null; + if (assertionList instanceof XSObjectList) { + xpathNamespaceContext = ((XSAssertImpl)((XSObjectList) assertionList).item(0)).getXPath2NamespaceContext(); + } + else { + Vector assertVector = (Vector) assertionList; + if (assertVector.get(0) instanceof XSAssertImpl) { + xpathNamespaceContext = ((XSAssertImpl)assertVector.get(0)).getXPath2NamespaceContext(); + } + else { + XSSimpleTypeDecl xsSimpleTypeDecl = (XSSimpleTypeDecl)assertVector.get(0); + if (xsSimpleTypeDecl.getAssertions() != null && xsSimpleTypeDecl.getAssertions().size() > 0) { + xpathNamespaceContext = ((XSAssertImpl)(xsSimpleTypeDecl.getAssertions()).get(0)). + getXPath2NamespaceContext(); + } + } + } + + Map assertProcessorParams = new HashMap(); + if (xpathNamespaceContext == null) { + xpathNamespaceContext = new NamespaceSupport(); + } + assertProcessorParams.put(Constants.XPATH2_NAMESPACE_CONTEXT, xpathNamespaceContext); + // initialize the assertions processor + initializeAssertProcessor(assertProcessorParams); + } // constructAssertProcessor /* Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java?rev=1899904&r1=1899903&r2=1899904&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertionXPath2ValueImpl.java Sat Apr 16 09:53:36 2022 @@ -303,7 +303,7 @@ public class XSAssertionXPath2ValueImpl * recursively searches the XML schema type hierarchy navigating up the base types, to * find the needed built-in type. */ - private short getXercesXSDTypeCodeFor$value(XSTypeDefinition elementType) { + public short getXercesXSDTypeCodeFor$value(XSTypeDefinition elementType) { if (Constants.NS_XMLSCHEMA.equals(elementType.getNamespace())) { short typeCode = -100; // xsd type short code initializer --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org