Author: mukulg Date: Sat Jan 5 10:43:18 2013 New Revision: 1429247 URL: http://svn.apache.org/viewvc?rev=1429247&view=rev Log: schema 1.1 commit: when an attribute's simpleType has assertions and the type is a union of an atomic type and a list, the assertion context variable $value needs to have a relevant typed value. this commit provides few improvements related to this. there are also few minor refactorings and javadoc improvements.
Added: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java (with props) Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XSDAssertionValidator.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java?rev=1429247&r1=1429246&r2=1429247&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathXPath2Impl.java Sat Jan 5 10:43:18 2013 @@ -34,6 +34,7 @@ import org.apache.xerces.impl.dv.XSSimpl import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl; import org.apache.xerces.impl.xs.assertion.XMLAssertAdapter; import org.apache.xerces.impl.xs.assertion.XSAssert; +import org.apache.xerces.impl.xs.assertion.XSAssertConstants; import org.apache.xerces.impl.xs.assertion.XSAssertImpl; import org.apache.xerces.impl.xs.util.ObjectListImpl; import org.apache.xerces.impl.xs.util.XS11TypeHelper; @@ -163,7 +164,7 @@ public class XMLAssertPsychopathXPath2Im } // if we have assertions applicable to this element, store the element reference and the assertions on it on the runtime stacks - List assertionList = (List) augs.getItem("ASSERT"); + List assertionList = (List) augs.getItem(XSAssertConstants.assertList); if (assertionList != null) { fAssertRootStack.push(fCurrentAssertDomNode); fAssertListStack.push(assertionList); @@ -172,7 +173,7 @@ public class XMLAssertPsychopathXPath2Im // evaluate assertions from attributes. evaluation of assertions on attributes in startElement call, helps us setting the PSVI results // for attributes appropriately. - if (((Boolean)augs.getItem("ATTRIBUTES-HAVE-ASSERTS")).booleanValue()) { + if (((Boolean)augs.getItem(XSAssertConstants.isAttrHaveAsserts)).booleanValue()) { evaluateAssertsFromAttributes(element, attributes); } @@ -389,18 +390,18 @@ public class XMLAssertPsychopathXPath2Im // evaluating assertions for "simpleType -> list" evaluateAssertionOnSTListValue(element, value, assertImpl, false, simpleTypeDefn.getItemType(), isTypeDerivedFromList); } - else if (((Boolean)augs.getItem("ASSERT_PROC_NEEDED_FOR_UNION")).booleanValue()) { - // evaluating assertions for "simpleType -> union" - boolean isValueValidWithSTUnion = evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, assertImpl, value, augs); - if (!isValueValidWithSTUnion) { - if (isAttribute) { - fXmlSchemaValidator.reportSchemaError("cvc-attribute.3", new Object[] {element.rawname, attrQname.localpart, value, ((XSSimpleTypeDecl)simpleTypeDefn).getTypeName()}); - } - else { - fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new Object[] {element.rawname, value}); - } + else if (!isAttribute && ((Boolean)augs.getItem(XSAssertConstants.isAssertProcNeededForUnionElem)).booleanValue()) { + // evaluating assertions for "simpleType -> union" for an element + if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, assertImpl, value, augs)) { + fXmlSchemaValidator.reportSchemaError("cvc-type.3.1.3", new Object[] {element.rawname, value}); } } + else if (isAttribute && ((Boolean)augs.getItem(XSAssertConstants.isAssertProcNeededForUnionAttr)).booleanValue()) { + // evaluating assertions for "simpleType -> union" for an attribute + if (!evaluateAssertionOnSTUnion(element, simpleTypeDefn, isTypeDerivedFromUnion, assertImpl, value, augs)) { + fXmlSchemaValidator.reportSchemaError("cvc-attribute.3", new Object[] {element.rawname, attrQname.localpart, value, ((XSSimpleTypeDecl)simpleTypeDefn).getTypeName()}); + } + } } // evaluateOneAssertionFromSimpleType Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=1429247&r1=1429246&r2=1429247&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Sat Jan 5 10:43:18 2013 @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Stack; import java.util.Vector; @@ -41,6 +42,7 @@ import org.apache.xerces.impl.dv.xs.Type import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl; import org.apache.xerces.impl.validation.ValidationManager; import org.apache.xerces.impl.validation.ValidationState; +import org.apache.xerces.impl.xs.assertion.XSAssertConstants; import org.apache.xerces.impl.xs.identity.Field; import org.apache.xerces.impl.xs.identity.FieldActivator; import org.apache.xerces.impl.xs.identity.IdentityConstraint; @@ -1409,9 +1411,13 @@ public class XMLSchemaValidator // assertion validator subcomponent private XSDAssertionValidator fAssertionValidator = null; - // variable to track validity of simple content for union types. if a member type of union in XML Schema namespace, can - // successfully validate (in a preprocess step in this class) an atomic value, we don't process assertions for such union types. - private boolean fIsAssertProcessingNeededForSTUnion = true; + // variable to track validity of element simple content for union types. if a member type of union in XML Schema namespace can + // successfully validate an atomic value, we don't process assertions for such union types in downstream checks. i.e, a known + // valid element doesn't require assertion evaluations. + private boolean fIsAssertProcessingNeededForSTUnionElem = true; + + // a similar variable as above to track union type validity for attributes of one element. + private List fIsAssertProcessingNeededForSTUnionAttrs = new ArrayList(); // 'type alternative' validator subcomponent private XSDTypeAlternativeValidator fTypeAlternativeValidator = null; @@ -2083,6 +2089,11 @@ public class XMLSchemaValidator } } + + if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { + // reset the list for next element + fIsAssertProcessingNeededForSTUnionAttrs.clear(); + } // get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes, // parse them to get the grammars. But only do this if the grammar can grow. @@ -2550,6 +2561,11 @@ public class XMLSchemaValidator addDefaultAttributes(element, attributes, attrGrp); } + // assert check for union types, for attributes + if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { + extraCheckForSTUnionAssertsAttrs(attributes); + } + // Set ID scope to parent // simple content of an element identifies the parent of the element if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { @@ -2588,10 +2604,15 @@ public class XMLSchemaValidator } if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - // find attributes among the attributes of the current element, which are declared inheritable and store them for later processing. - // one of the uses of inheritable attributes is in type alternatives processing. + // find attributes among the attributes of the current element which are declared inheritable, and store them for later processing saveInheritableAttributes(fCurrentElemDecl, attributes); - assertionValidatorStartElementDelegate(element, attributes, augs); + // for each attribute, update its augmentation information to tell if its simpleType->union requires assertion evaluations + XMLAttributesImpl attrsImpl = (XMLAttributesImpl)attributes; + for (int attrIdx = 0; attrIdx < attrsImpl.getLength(); attrIdx++) { + Augmentations attrAugs = attrsImpl.getAugmentations(attrIdx); + attrAugs.putItem(XSAssertConstants.isAssertProcNeededForUnionAttr, fIsAssertProcessingNeededForSTUnionAttrs.get(attrIdx)); + } + assertionValidatorStartElementDelegate(element, attributes, augs); } return augs; @@ -2856,14 +2877,14 @@ public class XMLSchemaValidator assertElemPSVI.fNotation = fNotation; assertElemPSVI.fGrammars = fGrammarBucket.getGrammars(); assertAugs.putItem(Constants.ELEMENT_PSVI, assertElemPSVI); - assertAugs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion)); + assertAugs.putItem(XSAssertConstants.isAssertProcNeededForUnionElem, Boolean.valueOf(fIsAssertProcessingNeededForSTUnionElem)); fAssertionValidator.handleEndElement(element, assertAugs); fFailedAssertions = assertElemPSVI.fFailedAssertions; - if (fAugPSVI && fIsAssertProcessingNeededForSTUnion) { + if (fAugPSVI && fIsAssertProcessingNeededForSTUnionElem) { // update PSVI fValidatedInfo.memberType = assertElemPSVI.fValue.memberType; } - fIsAssertProcessingNeededForSTUnion = true; + fIsAssertProcessingNeededForSTUnionElem = true; } // assertionValidatorEndElementDelegate @@ -3561,12 +3582,6 @@ public class XMLSchemaValidator try { actualValue = attDV.validate(attrValue, fValidationState, fValidatedInfo); - // additional check for assertions processing, for simple type having variety 'union' - if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - extraCheckForSTUnionAsserts(attDV, attrValue, fValidatedInfo, attributes.getAugmentations(index)); - fIsAssertProcessingNeededForSTUnion = true; - } - // store the normalized value if (fNormalizeData) { attributes.setValue(index, fValidatedInfo.normalizedValue); @@ -3589,7 +3604,6 @@ public class XMLSchemaValidator } } catch (InvalidDatatypeValueException idve) { - fIsAssertProcessingNeededForSTUnion = false; reportSchemaError(idve.getKey(), idve.getArgs()); reportSchemaError( "cvc-attribute.3", @@ -3712,15 +3726,8 @@ public class XMLSchemaValidator try { fValidationState.setFacetChecking(false); attDV.validate(fValidationState, defaultValue); - - // additional check for assertions processing, for simple type having variety 'union' - if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - extraCheckForSTUnionAsserts(attDV, defaultValue.stringValue(), defaultValue, attributes.getAugmentations(i)); - fIsAssertProcessingNeededForSTUnion = true; - } } catch (InvalidDatatypeValueException idve) { - fIsAssertProcessingNeededForSTUnion = false; reportSchemaError(idve.getKey(), idve.getArgs()); } fValidationState.setFacetChecking(facetChecking); @@ -3925,10 +3932,10 @@ public class XMLSchemaValidator // additional check for assertions processing, for simple type having variety 'union' if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - extraCheckForSTUnionAsserts(dv, String.valueOf(textContent), fValidatedInfo, null); + extraCheckForSTUnionAssertsElem(dv, String.valueOf(textContent), fValidatedInfo); } } catch (InvalidDatatypeValueException e) { - fIsAssertProcessingNeededForSTUnion = false; + fIsAssertProcessingNeededForSTUnionElem = false; reportSchemaError(e.getKey(), e.getArgs()); reportSchemaError( "cvc-type.3.1.3", @@ -3970,10 +3977,10 @@ public class XMLSchemaValidator // additional check for assertions processing, for simple type having variety 'union' if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - extraCheckForSTUnionAsserts(dv, String.valueOf(textContent), fValidatedInfo, null); + extraCheckForSTUnionAssertsElem(dv, String.valueOf(textContent), fValidatedInfo); } } catch (InvalidDatatypeValueException e) { - fIsAssertProcessingNeededForSTUnion = false; + fIsAssertProcessingNeededForSTUnionElem = false; reportSchemaError(e.getKey(), e.getArgs()); reportSchemaError("cvc-complex-type.2.2", new Object[] { element.rawname }); } @@ -5136,19 +5143,41 @@ public class XMLSchemaValidator } /* - * Extra checks for assertion evaluations for simpleType definitions with variety union. + * Extra checks for assertion evaluations for simpleType definitions with variety union, for attributes of one element. */ - private void extraCheckForSTUnionAsserts(XSSimpleType simpleTypeDv, String content, ValidatedInfo validatedInfo, Augmentations augs) { + private void extraCheckForSTUnionAssertsAttrs(XMLAttributes attributes) { + + XMLAttributes attrsImpl = (XMLAttributesImpl)attributes; + + for (int attrIdx = 0; attrIdx < attrsImpl.getLength(); attrIdx++) { + Augmentations attrAugs = attrsImpl.getAugmentations(attrIdx); + AttributePSVImpl attrPsvi = (AttributePSVImpl)attrAugs.getItem(Constants.ATTRIBUTE_PSVI); + XSSimpleTypeDefinition attrSimpleType = (XSSimpleTypeDefinition) attrPsvi.getTypeDefinition(); + if (attrSimpleType != null && attrSimpleType.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION && ((XSSimpleType) attrSimpleType.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) { + if (XS11TypeHelper.isAtomicStrValueValidForSTUnion(attrSimpleType.getMemberTypes(), attrsImpl.getValue(attrIdx), attrPsvi.fValue, Constants.SCHEMA_VERSION_1_1)) { + fIsAssertProcessingNeededForSTUnionAttrs.add(Boolean.valueOf(false)); + } + else { + fIsAssertProcessingNeededForSTUnionAttrs.add(Boolean.valueOf(true)); + } + } + else { + fIsAssertProcessingNeededForSTUnionAttrs.add(Boolean.valueOf(true)); + } + } + + } // extraCheckForSTUnionAssertsAttrs + + /* + * Extra checks for assertion evaluations for simpleType definitions with variety union, for an element. + */ + private void extraCheckForSTUnionAssertsElem(XSSimpleType simpleTypeDv, String content, ValidatedInfo validatedInfo) { if (simpleTypeDv.getVariety() == XSSimpleTypeDefinition.VARIETY_UNION && ((XSSimpleType) simpleTypeDv.getBaseType()).getVariety() != XSSimpleTypeDefinition.VARIETY_UNION) { if (XS11TypeHelper.isAtomicStrValueValidForSTUnion(simpleTypeDv.getMemberTypes(), content, validatedInfo, Constants.SCHEMA_VERSION_1_1)) { - fIsAssertProcessingNeededForSTUnion = false; - } - if (augs != null) { - // set augmentation information for an attribute - augs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion)); + fIsAssertProcessingNeededForSTUnionElem = false; } } - } // extraCheckForSTUnionAsserts + } // extraCheckForSTUnionAssertsElem /* * For the current element being handled by the XML Schema validator, find all inheritable attributes for this element. 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=1429247&r1=1429246&r2=1429247&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 Jan 5 10:43:18 2013 @@ -27,6 +27,7 @@ import java.util.Vector; import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.xs.assertion.XMLAssertHandler; import org.apache.xerces.impl.xs.assertion.XSAssert; +import org.apache.xerces.impl.xs.assertion.XSAssertConstants; import org.apache.xerces.impl.xs.assertion.XSAssertImpl; import org.apache.xerces.impl.xs.util.XSObjectListImpl; import org.apache.xerces.impl.xs.util.XS11TypeHelper; @@ -116,8 +117,8 @@ public class XSDAssertionValidator { if (fAssertionProcessor != null) { // construct the augmentations object, for assertions AugmentationsImpl assertAugs = new AugmentationsImpl(); - assertAugs.putItem("ASSERT", assertionList); - assertAugs.putItem("ATTRIBUTES-HAVE-ASSERTS", Boolean.valueOf(fAttributesHaveAsserts)); + assertAugs.putItem(XSAssertConstants.assertList, assertionList); + assertAugs.putItem(XSAssertConstants.isAttrHaveAsserts, Boolean.valueOf(fAttributesHaveAsserts)); fAttributesHaveAsserts = false; fAssertionProcessor.startElement(element, attributes, assertAugs); } Added: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java?rev=1429247&view=auto ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java (added) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java Sat Jan 5 10:43:18 2013 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.xerces.impl.xs.assertion; + +/** + * A class containing few constants related to XML Schema 1.1 assertion implementation. + * + * @xerces.internal + * + * @author Mukul Gandhi, IBM + * + * @version $Id$ + */ +public class XSAssertConstants { + + // a list of assertion components + public static String assertList = "ASSERT_LIST"; + + // are there any assertions present within an attribute's type + public static String isAttrHaveAsserts = "ATTRIBUTES_HAVE_ASSERTS"; + + // is assertion processing needed for a simpleType->union for an element + public static String isAssertProcNeededForUnionElem = "ASSERT_PROC_NEEDED_FOR_UNION_ELEM"; + + // is assertion processing needed for a simpleType->union for attributes of one element + public static String isAssertProcNeededForUnionAttr = "ASSERT_PROC_NEEDED_FOR_UNION_ATTR"; + +} // class XSAssertConstants Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/assertion/XSAssertConstants.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java?rev=1429247&r1=1429246&r2=1429247&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/util/XS11TypeHelper.java Sat Jan 5 10:43:18 2013 @@ -98,14 +98,14 @@ public class XS11TypeHelper { /* - * Determine if a string value (which will result in an XDM atomic value) is valid with respect to any of the simpleType -> union's member types - * (those that are in XML Schema namespace). If this method returns a boolean 'true', then the value is valid with respect to entire union schema component. + * Determine if a string value is valid with respect to any of the simpleType -> union's member types which are in XML Schema namespace. + * If this method returns a boolean 'true', then the value is valid with respect to entire union schema component. */ public static boolean isAtomicStrValueValidForSTUnion(XSObjectList memberTypes, String content, ValidatedInfo validatedInfo, short schemaVersion) { boolean isValueValid = false; - // check the union member types in order to check for validity of an atomic value. the validity of atomic value wrt + // check the union member types in order to find validity of an atomic value. the validity of atomic value wrt // to the 1st available type in union's member type collection, is sufficient to achieve the objective of this method. for (int memTypeIdx = 0; memTypeIdx < memberTypes.getLength(); memTypeIdx++) { XSSimpleType simpleTypeDv = (XSSimpleType) memberTypes.item(memTypeIdx); @@ -122,8 +122,7 @@ public class XS11TypeHelper { /* - * Determine if a lexical "string value" belongs to the value space (i.e is valid according to the type) of a given schema - * simpleType definition. Using Xerces API 'XSSimpleType.validate' for this need. + * Determine if a string value is valid with a given simpleType definition. Using Xerces API 'XSSimpleType.validate' for this need. */ public static boolean isStrValueValidForASimpleType(String value, XSSimpleType simplType, short schemaVersion) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org