Author: mukulg Date: Sun May 29 09:18:06 2011 New Revision: 1128843 URL: http://svn.apache.org/viewvc?rev=1128843&view=rev Log: committing implementation of [failed assertions] schema 1.1 PSVI property.
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/PSVIElementNSImpl.java xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/ElementPSVImpl.java 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/xs/ElementPSVI.java Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/PSVIElementNSImpl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/PSVIElementNSImpl.java?rev=1128843&r1=1128842&r2=1128843&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/PSVIElementNSImpl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/dom/PSVIElementNSImpl.java Sun May 29 09:18:06 2011 @@ -109,7 +109,10 @@ public class PSVIElementNSImpl extends E protected XSModel fSchemaInformation = null; /** inherited attributes */ - protected ObjectList fInheritedAttributes = null; + protected ObjectList fInheritedAttributes = null; + + /** failed assertions */ + protected ObjectList fFailedAssertions = null; // // ElementPSVI methods @@ -285,6 +288,19 @@ public class PSVIElementNSImpl extends E } /** + * Failed assertions. + * + * @return failed assertions list, or an empty list + * if none of assertions failed. + */ + public ObjectList getFailedAssertions() { + if (fFailedAssertions != null) { + return fFailedAssertions; + } + return ObjectListImpl.EMPTY_LIST; + } + + /** * Copy PSVI properties from another psvi item. * * @param elem the source of element PSVI items @@ -309,7 +325,8 @@ public class PSVIElementNSImpl extends E } this.fSpecified = elem.getIsSchemaSpecified(); this.fNil = elem.getNil(); - this.fInheritedAttributes = elem.getInheritedAttributes(); + this.fInheritedAttributes = elem.getInheritedAttributes(); + this.fFailedAssertions = elem.getFailedAssertions(); } /* (non-Javadoc) Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/ElementPSVImpl.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/ElementPSVImpl.java?rev=1128843&r1=1128842&r2=1128843&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/ElementPSVImpl.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/ElementPSVImpl.java Sun May 29 09:18:06 2011 @@ -91,7 +91,10 @@ public class ElementPSVImpl implements E protected boolean fIsConstant; /** inherited attributes **/ - protected ObjectList fInheritedAttributes = null; + protected ObjectList fInheritedAttributes = null; + + /** failed assertions **/ + protected ObjectList fFailedAssertions = null; public ElementPSVImpl() {} @@ -106,6 +109,7 @@ public class ElementPSVImpl implements E fValidity = elementPSVI.getValidity(); fValidationContext = elementPSVI.getValidationContext(); fInheritedAttributes = elementPSVI.getInheritedAttributes(); + fFailedAssertions = elementPSVI.getFailedAssertions(); if (elementPSVI instanceof ElementPSVImpl) { final ElementPSVImpl elementPSVIImpl = (ElementPSVImpl) elementPSVI; fErrors = (elementPSVIImpl.fErrors != null) ? @@ -337,6 +341,19 @@ public class ElementPSVImpl implements E } /** + * Failed assertions. + * + * @return failed assertions list, or an empty list + * if none of assertions failed. + */ + public ObjectList getFailedAssertions() { + if (fFailedAssertions != null) { + return fFailedAssertions; + } + return ObjectListImpl.EMPTY_LIST; + } + + /** * Reset() should be called in validator startElement(..) method. */ public void reset() { @@ -351,6 +368,7 @@ public class ElementPSVImpl implements E fValidationContext = null; fValue.reset(); fInheritedAttributes = null; + fFailedAssertions = null; } public void copySchemaInformationTo(ElementPSVImpl target) { 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=1128843&r1=1128842&r2=1128843&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 Sun May 29 09:18:06 2011 @@ -33,7 +33,9 @@ import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.dv.XSSimpleType; 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.XSAssertImpl; +import org.apache.xerces.impl.xs.util.ObjectListImpl; import org.apache.xerces.impl.xs.util.XSTypeHelper; import org.apache.xerces.xni.Augmentations; import org.apache.xerces.xni.QName; @@ -101,7 +103,10 @@ public class XMLAssertPsychopathXPath2Im // parameters to pass to PsychoPath XPath engine (for e.g, the XML namespace bindings) private Map fAssertParams = null; - + + // failed assertions for an "element information item" + private XSAssert[] fFailedAssertions = null; + /* * Class constructor. @@ -228,6 +233,11 @@ public class XMLAssertPsychopathXPath2Im fAssertRootStack.pop(); // get assertions from the stack, and pass on to the assertions evaluator processAllAssertionsOnElement(element, (List) fAssertListStack.pop(), augs); + // set value of [failed assertions] PSVI property + if (fFailedAssertions != null && elemPSVI != null) { + setFailedAssertionsPSVIResult(elemPSVI); + fFailedAssertions = null; + } } if (fCurrentAssertDomNode.getParentNode() instanceof Element) { @@ -237,6 +247,16 @@ public class XMLAssertPsychopathXPath2Im } // endElement + + /* + * set value of [failed assertions] PSVI property. + */ + private void setFailedAssertionsPSVIResult(ElementPSVI elemPSVI) { + XSAssert[] tempArray = new XSAssert[fFailedAssertions.length]; + System.arraycopy(fFailedAssertions, 0, tempArray, 0, fFailedAssertions.length); + ((ElementPSVImpl)elemPSVI).fFailedAssertions = new ObjectListImpl(tempArray, tempArray.length); + } // setFailedAssertionsPSVIResult + /* * Method to evaluate all of XML Schema 1.1 assertions for an element tree. This is the root method which evaluates @@ -509,6 +529,20 @@ public class XMLAssertPsychopathXPath2Im assertionError = new AssertionError("cvc-assertion", element, assertImpl, value, isList, ex); } + // if an assertion failed, add reference of that assertion to the failed assertions list. + // NOTE: [failed assertions] property need to be set only for "element information items" and not for attributes. + if (assertionError != null && assertImpl.getAttrName() == null) { + if (fFailedAssertions == null) { + fFailedAssertions = new XSAssertImpl[1]; + } + else { + XSAssertImpl [] tempArray = new XSAssertImpl[fFailedAssertions.length + 1]; + System.arraycopy(fFailedAssertions, 0, tempArray, 0, fFailedAssertions.length); + fFailedAssertions = tempArray; + } + fFailedAssertions[fFailedAssertions.length-1] = (XSAssert) assertImpl; + } + return assertionError; } // evaluateOneAssertion 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=1128843&r1=1128842&r2=1128843&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 Sun May 29 09:18:06 2011 @@ -1272,6 +1272,9 @@ public class XMLSchemaValidator /** Current type. */ private XSTypeDefinition fCurrentType; + + /** Failed assertions. */ + private ObjectList fFailedAssertions; /** type stack. */ private XSTypeDefinition[] fTypeStack = new XSTypeDefinition[INITIAL_STACK_SIZE]; @@ -2028,7 +2031,7 @@ public class XMLSchemaValidator if (fAugPSVI) augs = getEmptyAugs(augs); if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - assertionValidatorStartElementDelegate(element, attributes); + assertionValidatorStartElementDelegate(element, attributes, augs); } return augs; } @@ -2149,7 +2152,7 @@ public class XMLSchemaValidator if (fAugPSVI) augs = getEmptyAugs(augs); if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - assertionValidatorStartElementDelegate(element, attributes); + assertionValidatorStartElementDelegate(element, attributes, augs); } return augs; } @@ -2432,13 +2435,6 @@ public class XMLSchemaValidator matcher.startElement( element, attributes); } - // inheritable attributes processing - ObjectList inheritedAttributesForPsvi = null; - if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - fInhrAttrCountStack.push(fInheritableAttrList.size()); - inheritedAttributesForPsvi = getInheritedAttributesForPSVI(); - } - if (fAugPSVI) { augs = getEmptyAugs(augs); @@ -2452,15 +2448,20 @@ public class XMLSchemaValidator fCurrentPSVI.fNotation = fNotation; // PSVI: add nil fCurrentPSVI.fNil = fNil; - // PSVI: add inherited attributes - fCurrentPSVI.fInheritedAttributes = inheritedAttributesForPsvi; + if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { + // PSVI: add inherited attributes + fInhrAttrCountStack.push(fInheritableAttrList.size()); + fCurrentPSVI.fInheritedAttributes = getInheritedAttributesForPSVI(); + // PSVI: add failed assertions + fCurrentPSVI.fFailedAssertions = fFailedAssertions; + } } 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. saveInheritableAttributes(fCurrentElemDecl, attributes); - assertionValidatorStartElementDelegate(element, attributes); + assertionValidatorStartElementDelegate(element, attributes, augs); } return augs; @@ -2470,13 +2471,13 @@ public class XMLSchemaValidator /* * Delegate to assertions validator startElement handler. */ - private void assertionValidatorStartElementDelegate(QName element, XMLAttributes attributes) { + private void assertionValidatorStartElementDelegate(QName element, XMLAttributes attributes, Augmentations augs) { try { fAssertionValidator.handleStartElement(element, attributes); - } - catch(Exception ex) { - throw new XNIException(ex.getMessage(), ex); - } + } + catch(Exception ex) { + throw new XNIException(ex.getMessage(), ex); + } } // assertionValidatorStartElementDelegate /** @@ -2532,21 +2533,7 @@ public class XMLSchemaValidator // delegate to assertions validator subcomponent if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - // initialize augmentations to be passed to assertions processor - Augmentations assertAugs = new AugmentationsImpl(); - ElementPSVImpl assertElemPSVI = new ElementPSVImpl(); - assertElemPSVI.fDeclaration = fCurrentElemDecl; - assertElemPSVI.fTypeDecl = fCurrentType; - assertElemPSVI.fNotation = fNotation; - assertElemPSVI.fGrammars = fGrammarBucket.getGrammars(); - assertAugs.putItem(Constants.ELEMENT_PSVI, assertElemPSVI); - assertAugs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion)); - fAssertionValidator.handleEndElement(element, assertAugs); - if (fAugPSVI && fIsAssertProcessingNeededForSTUnion) { - // update PSVI - fValidatedInfo.memberType = ((ElementPSVImpl) assertAugs.getItem(Constants.ELEMENT_PSVI)).fValue.memberType; - } - fIsAssertProcessingNeededForSTUnion = true; + assertionValidatorEndElementDelegate(element); } return augs; @@ -2626,21 +2613,7 @@ public class XMLSchemaValidator // delegate to assertions validator subcomponent if (fSchemaVersion == Constants.SCHEMA_VERSION_1_1) { - // initialize augmentations to be passed to assertions processor - Augmentations assertAugs = new AugmentationsImpl(); - ElementPSVImpl assertElemPSVI = new ElementPSVImpl(); - assertElemPSVI.fDeclaration = fCurrentElemDecl; - assertElemPSVI.fTypeDecl = fCurrentType; - assertElemPSVI.fNotation = fNotation; - assertElemPSVI.fGrammars = fGrammarBucket.getGrammars(); - assertAugs.putItem(Constants.ELEMENT_PSVI, assertElemPSVI); - assertAugs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion)); - fAssertionValidator.handleEndElement(element, assertAugs); - if (fAugPSVI && fIsAssertProcessingNeededForSTUnion) { - // update PSVI - fValidatedInfo.memberType = ((ElementPSVImpl) assertAugs.getItem(Constants.ELEMENT_PSVI)).fValue.memberType; - } - fIsAssertProcessingNeededForSTUnion = true; + assertionValidatorEndElementDelegate(element); } // Check if we should modify the xsi:type ignore depth @@ -2712,6 +2685,30 @@ public class XMLSchemaValidator return augs; } // handleEndElement(QName,boolean)*/ + /* + * Delegate to assertions validator endElement handler. + */ + private void assertionValidatorEndElementDelegate(QName element) { + + // initialize augmentation information to be passed to assertions processor + Augmentations assertAugs = new AugmentationsImpl(); + ElementPSVImpl assertElemPSVI = new ElementPSVImpl(); + assertElemPSVI.fDeclaration = fCurrentElemDecl; + assertElemPSVI.fTypeDecl = fCurrentType; + assertElemPSVI.fNotation = fNotation; + assertElemPSVI.fGrammars = fGrammarBucket.getGrammars(); + assertAugs.putItem(Constants.ELEMENT_PSVI, assertElemPSVI); + assertAugs.putItem("ASSERT_PROC_NEEDED_FOR_UNION", Boolean.valueOf(fIsAssertProcessingNeededForSTUnion)); + fAssertionValidator.handleEndElement(element, assertAugs); + fFailedAssertions = assertElemPSVI.fFailedAssertions; + if (fAugPSVI && fIsAssertProcessingNeededForSTUnion) { + // update PSVI + fValidatedInfo.memberType = assertElemPSVI.fValue.memberType; + } + fIsAssertProcessingNeededForSTUnion = true; + + } // assertionValidatorEndElementDelegate + final Augmentations endElementPSVI( boolean root, SchemaGrammar[] grammars, @@ -2732,6 +2729,7 @@ public class XMLSchemaValidator inheritedAttributesForPsvi = getInheritedAttributesForPSVI(); } fCurrentPSVI.fInheritedAttributes = inheritedAttributesForPsvi; + fCurrentPSVI.fFailedAssertions = this.fFailedAssertions; // PSVI: validation attempted // nothing below or at the same level has none or partial // (which means this level is strictly assessed, and all chidren Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/ElementPSVI.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/ElementPSVI.java?rev=1128843&r1=1128842&r2=1128843&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/ElementPSVI.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/xs/ElementPSVI.java Sun May 29 09:18:06 2011 @@ -50,5 +50,10 @@ public interface ElementPSVI extends Ite * [inherited attributes]: inherited attributes. */ public ObjectList getInheritedAttributes(); + + /** + * [failed assertions]: failed assertions. + */ + public ObjectList getFailedAssertions(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org