peiyongz 2004/04/13 09:56:59 Modified: c/src/xercesc/internal IGXMLScanner.cpp IGXMLScanner.hpp IGXMLScanner2.cpp SGXMLScanner.cpp SGXMLScanner.hpp XMLScanner.cpp XMLScanner.hpp Log: IdentityConstraintHandler Revision Changes Path 1.61 +41 -145 xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp Index: IGXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v retrieving revision 1.60 retrieving revision 1.61 diff -u -r1.60 -r1.61 --- IGXMLScanner.cpp 7 Apr 2004 14:15:12 -0000 1.60 +++ IGXMLScanner.cpp 13 Apr 2004 16:56:58 -0000 1.61 @@ -81,11 +81,8 @@ #include <xercesc/validators/DTD/DTDScanner.hpp> #include <xercesc/validators/DTD/DTDValidator.hpp> #include <xercesc/validators/schema/SchemaValidator.hpp> -#include <xercesc/validators/schema/identity/FieldActivator.hpp> -#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp> -#include <xercesc/validators/schema/identity/ValueStoreCache.hpp> +#include <xercesc/validators/schema/identity/IdentityConstraintHandler.hpp> #include <xercesc/validators/schema/identity/IC_Selector.hpp> -#include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/util/OutOfMemoryException.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -107,9 +104,7 @@ , fDTDValidator(0) , fSchemaValidator(0) , fDTDGrammar(0) - , fMatcherStack(0) - , fValueStoreCache(0) - , fFieldActivator(0) + , fICHandler(0) , fLocationPairs(0) , fDTDElemNonDeclPool(0) , fSchemaElemNonDeclPool(0) @@ -159,9 +154,7 @@ , fDTDValidator(0) , fSchemaValidator(0) , fDTDGrammar(0) - , fMatcherStack(0) - , fValueStoreCache(0) - , fFieldActivator(0) + , fICHandler(0) , fLocationPairs(0) , fDTDElemNonDeclPool(0) , fSchemaElemNonDeclPool(0) @@ -455,8 +448,8 @@ // That went ok, so scan for any miscellaneous stuff scanMiscellaneous(); - if (fValidate) - fValueStoreCache->endDocument(); + if (toCheckIdentityConstraint()) + fICHandler->endDocument(); if (fDocHandler) fDocHandler->endDocument(); @@ -571,10 +564,11 @@ initValidator(fSchemaValidator); // Create IdentityConstraint info - fMatcherStack = new (fMemoryManager) XPathMatcherStack(fMemoryManager); - fValueStoreCache = new (fMemoryManager) ValueStoreCache(fMemoryManager); - fFieldActivator = new (fMemoryManager) FieldActivator(fValueStoreCache, fMatcherStack, fMemoryManager); - fValueStoreCache->setScanner(this); + /*** + todo: to auto sense if grammar has ic or not, probably do it + at reset() or parse() + ***/ + fICHandler = new (fMemoryManager) IdentityConstraintHandler(this, fMemoryManager); // Create schemaLocation pair info fLocationPairs = new (fMemoryManager) ValueVectorOf<XMLCh*>(8, fMemoryManager); @@ -602,9 +596,7 @@ delete fRawAttrList; delete fDTDValidator; delete fSchemaValidator; - delete fFieldActivator; - delete fMatcherStack; - delete fValueStoreCache; + delete fICHandler; delete fLocationPairs; delete fDTDElemNonDeclPool; delete fSchemaElemNonDeclPool; @@ -1153,51 +1145,15 @@ } // call matchers and de-activate context - int oldCount = fMatcherStack->getMatcherCount(); - - if (oldCount || - ((SchemaElementDecl*)topElem->fThisElement)->getIdentityConstraintCount()) { - - for (int i = oldCount - 1; i >= 0; i--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(i); - matcher->endElement(*(topElem->fThisElement), fContent.getRawBuffer()); - } - - if (fMatcherStack->size() > 0) { - fMatcherStack->popContext(); - } - - // handle everything *but* keyref's. - int newCount = fMatcherStack->getMatcherCount(); - - for (int j = oldCount - 1; j >= newCount; j--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() != IdentityConstraint::KEYREF)) - fValueStoreCache->transplant(ic, matcher->getInitialDepth()); - } - - // now handle keyref's... - for (int k = oldCount - 1; k >= newCount; k--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(k); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() == IdentityConstraint::KEYREF)) { - - ValueStore* values = fValueStoreCache->getValueStoreFor(ic, matcher->getInitialDepth()); - - if (values) { // nothing to do if nothing matched! - values->endDcocumentFragment(fValueStoreCache); - } - } - } - - fValueStoreCache->endElement(); + if (toCheckIdentityConstraint()) + { + fICHandler->deactivateContext + ( + (SchemaElementDecl *) topElem->fThisElement + , fContent.getRawBuffer() + ); } + } } @@ -2841,28 +2797,19 @@ attCount = buildAttList(*fRawAttrList, attCount, elemDecl, *fAttrList); // activate identity constraints - if (fValidate && fGrammar && fGrammarType == Grammar::SchemaGrammarType) { - - unsigned int count = ((SchemaElementDecl*) elemDecl)->getIdentityConstraintCount(); - - if (count || fMatcherStack->getMatcherCount()) { - - fValueStoreCache->startElement(); - fMatcherStack->pushContext(); - fValueStoreCache->initValueStoresFor((SchemaElementDecl*) elemDecl, (int) elemDepth); - - for (unsigned int i = 0; i < count; i++) { - activateSelectorFor(((SchemaElementDecl*) elemDecl)->getIdentityConstraintAt(i), (int) elemDepth); - } - - // call all active identity constraints - count = fMatcherStack->getMatcherCount(); - - for (unsigned int j = 0; j < count; j++) { - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - matcher->startElement(*elemDecl, uriId, fPrefixBuf.getRawBuffer(), *fAttrList, attCount); - } - } + if (fGrammar && + fGrammarType == Grammar::SchemaGrammarType && + toCheckIdentityConstraint()) + { + fICHandler->activateIdentityConstraint + ( + (SchemaElementDecl*) elemDecl + , (int) elemDepth + , uriId + , fPrefixBuf.getRawBuffer() + , *fAttrList + , attCount + ); } // Since the element may have default values, call start tag now regardless if it is empty or not @@ -2964,50 +2911,15 @@ } // call matchers and de-activate context - int oldCount = fMatcherStack->getMatcherCount(); - - if (oldCount || ((SchemaElementDecl*) elemDecl)->getIdentityConstraintCount()) { - - for (int i = oldCount - 1; i >= 0; i--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(i); - matcher->endElement(*elemDecl, fContent.getRawBuffer()); - } - - if (fMatcherStack->size() > 0) { - fMatcherStack->popContext(); - } - - // handle everything *but* keyref's. - int newCount = fMatcherStack->getMatcherCount(); - - for (int j = oldCount - 1; j >= newCount; j--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() != IdentityConstraint::KEYREF)) - fValueStoreCache->transplant(ic, matcher->getInitialDepth()); - } - - // now handle keyref's... - for (int k = oldCount - 1; k >= newCount; k--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(k); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() == IdentityConstraint::KEYREF)) { - - ValueStore* values = fValueStoreCache->getValueStoreFor(ic, matcher->getInitialDepth()); - - if (values) { // nothing to do if nothing matched! - values->endDcocumentFragment(fValueStoreCache); - } - } - } - - fValueStoreCache->endElement(); + if (toCheckIdentityConstraint()) + { + fICHandler->deactivateContext + ( + (SchemaElementDecl *) elemDecl + , fContent.getRawBuffer() + ); } + } } @@ -3199,22 +3111,6 @@ fMemoryManager->deallocate(fElemState); //delete [] fElemState; fElemState = newElemState; fElemStateSize = newSize; -} - -// --------------------------------------------------------------------------- -// IGXMLScanner: IC activation methos -// --------------------------------------------------------------------------- -void IGXMLScanner::activateSelectorFor(IdentityConstraint* const ic, const int initialDepth) { - - IC_Selector* selector = ic->getSelector(); - - if (!selector) - return; - - XPathMatcher* matcher = selector->createMatcher(fFieldActivator, initialDepth, fMemoryManager); - - fMatcherStack->addMatcher(matcher); - matcher->startDocumentFragment(); } // --------------------------------------------------------------------------- 1.20 +22 -30 xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp Index: IGXMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- IGXMLScanner.hpp 7 Apr 2004 14:14:08 -0000 1.19 +++ IGXMLScanner.hpp 13 Apr 2004 16:56:58 -0000 1.20 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.20 2004/04/13 16:56:58 peiyongz + * IdentityConstraintHandler + * * Revision 1.19 2004/04/07 14:14:08 peiyongz * make resolveSystemId virutal * @@ -135,9 +138,7 @@ class DTDGrammar; class DTDValidator; class SchemaValidator; -class ValueStoreCache; -class XPathMatcherStack; -class FieldActivator; +class IdentityConstraintHandler; class IdentityConstraint; class ContentLeafNameTypeVector; class SchemaAttDef; @@ -310,7 +311,7 @@ // ----------------------------------------------------------------------- // IdentityConstraints Activation methods // ----------------------------------------------------------------------- - void activateSelectorFor(IdentityConstraint* const ic, const int initialDepth); + inline bool toCheckIdentityConstraint() const; // ----------------------------------------------------------------------- // Grammar preparsing methods @@ -347,17 +348,6 @@ // Stores an element next state from DFA content model - used for // wildcard validation // - // fMatcherStack - // Stack of active XPath matchers for identity constraints. All - // active XPath matchers are notified of startElement, characters - // and endElement callbacks in order to perform their matches. - // - // fValueStoreCache - // Cache of value stores for identity constraint fields. - // - // fFieldActivator - // Activates fields within a certain scope when a selector matches - // its xpath. // fDTDElemNonDeclPool // registry of "faulted-in" DTD element decls // fSchemaElemNonDeclPool @@ -378,21 +368,19 @@ // filled when a PSVIHandler is registered // // ----------------------------------------------------------------------- - bool fSeeXsi; - Grammar::GrammarType fGrammarType; - unsigned int fElemStateSize; - unsigned int* fElemState; - XMLBuffer fContent; - RefVectorOf<KVStringPair>* fRawAttrList; - DTDValidator* fDTDValidator; - SchemaValidator* fSchemaValidator; - DTDGrammar* fDTDGrammar; - XPathMatcherStack* fMatcherStack; - ValueStoreCache* fValueStoreCache; - FieldActivator* fFieldActivator; - ValueVectorOf<XMLCh*>* fLocationPairs; - NameIdPool<DTDElementDecl>* fDTDElemNonDeclPool; - RefHash3KeysIdPool<SchemaElementDecl>* fSchemaElemNonDeclPool; + bool fSeeXsi; + Grammar::GrammarType fGrammarType; + unsigned int fElemStateSize; + unsigned int* fElemState; + XMLBuffer fContent; + RefVectorOf<KVStringPair>* fRawAttrList; + DTDValidator* fDTDValidator; + SchemaValidator* fSchemaValidator; + DTDGrammar* fDTDGrammar; + IdentityConstraintHandler* fICHandler; + ValueVectorOf<XMLCh*>* fLocationPairs; + NameIdPool<DTDElementDecl>* fDTDElemNonDeclPool; + RefHash3KeysIdPool<SchemaElementDecl>* fSchemaElemNonDeclPool; unsigned int fElemCount; RefHashTableOf<unsigned int>* fAttDefRegistry; RefHashTableOf<unsigned int>* fUndeclaredAttrRegistry; @@ -409,6 +397,10 @@ return XMLUni::fgIGXMLScanner; } +inline bool IGXMLScanner::toCheckIdentityConstraint() const +{ + return fValidate && fIdentityConstraintChecking && fICHandler; +} XERCES_CPP_NAMESPACE_END 1.60 +10 -9 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp Index: IGXMLScanner2.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- IGXMLScanner2.cpp 29 Jan 2004 11:46:30 -0000 1.59 +++ IGXMLScanner2.cpp 13 Apr 2004 16:56:58 -0000 1.60 @@ -90,9 +90,8 @@ #include <xercesc/validators/schema/SchemaValidator.hpp> #include <xercesc/validators/schema/TraverseSchema.hpp> #include <xercesc/validators/schema/SubstitutionGroupComparator.hpp> -#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp> #include <xercesc/validators/schema/XSDDOMParser.hpp> -#include <xercesc/validators/schema/identity/ValueStoreCache.hpp> +#include <xercesc/validators/schema/identity/IdentityConstraintHandler.hpp> #include <xercesc/util/XMLResourceIdentifier.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -1252,8 +1251,8 @@ fRootElemName = 0; // Reset IdentityConstraints - fValueStoreCache->startDocument(); - fMatcherStack->clear(); + if (fICHandler) + fICHandler->reset(); // Reset the element stack, and give it the latest ids for the special // URIs it has to know about. @@ -1434,7 +1433,7 @@ schemaValidator->setDatatypeBuffer(rawBuf); // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(rawBuf, len); if (fDocHandler) @@ -1476,7 +1475,7 @@ schemaValidator->setDatatypeBuffer(rawBuf); // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(rawBuf, len); if (fDocHandler) @@ -1503,7 +1502,7 @@ // call all active identity constraints if (fGrammarType == Grammar::SchemaGrammarType) { - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(toSend.getRawBuffer(), toSend.getLen()); } @@ -2520,8 +2519,10 @@ } } - if (fMatcherStack->getMatcherCount()) + // call all active identity constraints + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(bbCData.getRawBuffer(), bbCData.getLen()); + } else { if (fValidate) { 1.77 +46 -155 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp Index: SGXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v retrieving revision 1.76 retrieving revision 1.77 diff -u -r1.76 -r1.77 --- SGXMLScanner.cpp 11 Feb 2004 12:43:44 -0000 1.76 +++ SGXMLScanner.cpp 13 Apr 2004 16:56:58 -0000 1.77 @@ -81,11 +81,8 @@ #include <xercesc/validators/schema/TraverseSchema.hpp> #include <xercesc/validators/schema/XSDDOMParser.hpp> #include <xercesc/validators/schema/SubstitutionGroupComparator.hpp> -#include <xercesc/validators/schema/identity/FieldActivator.hpp> -#include <xercesc/validators/schema/identity/XPathMatcherStack.hpp> -#include <xercesc/validators/schema/identity/ValueStoreCache.hpp> +#include <xercesc/validators/schema/identity/IdentityConstraintHandler.hpp> #include <xercesc/validators/schema/identity/IC_Selector.hpp> -#include <xercesc/validators/schema/identity/ValueStore.hpp> #include <xercesc/util/OutOfMemoryException.hpp> #include <xercesc/util/XMLResourceIdentifier.hpp> #include <xercesc/util/HashPtr.hpp> @@ -111,9 +108,7 @@ , fRawAttrList(0) , fSchemaGrammar(0) , fSchemaValidator(0) - , fMatcherStack(0) - , fValueStoreCache(0) - , fFieldActivator(0) + , fICHandler(0) , fElemNonDeclPool(0) , fElemCount(0) , fAttDefRegistry(0) @@ -166,9 +161,7 @@ , fRawAttrList(0) , fSchemaGrammar(0) , fSchemaValidator(0) - , fMatcherStack(0) - , fValueStoreCache(0) - , fFieldActivator(0) + , fICHandler(0) , fElemNonDeclPool(0) , fElemCount(0) , fAttDefRegistry(0) @@ -455,8 +448,8 @@ // That went ok, so scan for any miscellaneous stuff scanMiscellaneous(); - if (fValidate) - fValueStoreCache->endDocument(); + if (toCheckIdentityConstraint()) + fICHandler->endDocument(); if (fDocHandler) fDocHandler->endDocument(); @@ -1056,52 +1049,17 @@ if(fPSVIElemContext.fIsSpecified) fPSVIElemContext.fNormalizedValue = ((SchemaElementDecl *)topElem->fThisElement)->getDefaultValue(); } - // call matchers and de-activate context - int oldCount = fMatcherStack->getMatcherCount(); - - if (oldCount || - ((SchemaElementDecl*)topElem->fThisElement)->getIdentityConstraintCount()) { - - for (int i = oldCount - 1; i >= 0; i--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(i); - matcher->endElement(*(topElem->fThisElement), fContent.getRawBuffer()); - } - - if (fMatcherStack->size() > 0) { - fMatcherStack->popContext(); - } - - // handle everything *but* keyref's. - int newCount = fMatcherStack->getMatcherCount(); - - for (int j = oldCount - 1; j >= newCount; j--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() != IdentityConstraint::KEYREF)) - fValueStoreCache->transplant(ic, matcher->getInitialDepth()); - } - - // now handle keyref's... - for (int k = oldCount - 1; k >= newCount; k--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(k); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() == IdentityConstraint::KEYREF)) { - - ValueStore* values = fValueStoreCache->getValueStoreFor(ic, matcher->getInitialDepth()); - - if (values) { // nothing to do if nothing matched! - values->endDcocumentFragment(fValueStoreCache); - } - } - } - fValueStoreCache->endElement(); + // call matchers and de-activate context + if (toCheckIdentityConstraint()) + { + fICHandler->deactivateContext + ( + (SchemaElementDecl *) topElem->fThisElement + , fContent.getRawBuffer() + ); } + } if(!isRoot) ((SchemaElementDecl *)fElemStack.topElement()->fThisElement)->updateValidityFromElement(topElem->fThisElement, fGrammarType); @@ -1752,29 +1710,18 @@ attCount = buildAttList(*fRawAttrList, attCount, elemDecl, *fAttrList); // activate identity constraints - if (fValidate) { - - unsigned int count = ((SchemaElementDecl*) elemDecl)->getIdentityConstraintCount(); - - if (count || fMatcherStack->getMatcherCount()) { - - fValueStoreCache->startElement(); - fMatcherStack->pushContext(); - fValueStoreCache->initValueStoresFor((SchemaElementDecl*) elemDecl, (int) elemDepth); - - for (unsigned int i = 0; i < count; i++) { - activateSelectorFor(((SchemaElementDecl*) elemDecl)->getIdentityConstraintAt(i), (int) elemDepth); - } - - // call all active identity constraints - count = fMatcherStack->getMatcherCount(); - - for (unsigned int j = 0; j < count; j++) { + if (toCheckIdentityConstraint()) + { + fICHandler->activateIdentityConstraint + ( + (SchemaElementDecl*) elemDecl + , (int) elemDepth + , uriId + , fPrefixBuf.getRawBuffer() + , *fAttrList + , attCount + ); - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - matcher->startElement(*elemDecl, uriId, fPrefixBuf.getRawBuffer(), *fAttrList, attCount); - } - } } // Since the element may have default values, call start tag now regardless if it is empty or not @@ -1874,49 +1821,15 @@ } // call matchers and de-activate context - int oldCount = fMatcherStack->getMatcherCount(); - if (oldCount || ((SchemaElementDecl*) elemDecl)->getIdentityConstraintCount()) { - - for (int i = oldCount - 1; i >= 0; i--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(i); - matcher->endElement(*elemDecl, fContent.getRawBuffer()); - } - - if (fMatcherStack->size() > 0) { - fMatcherStack->popContext(); - } - - // handle everything *but* keyref's. - int newCount = fMatcherStack->getMatcherCount(); - - for (int j = oldCount - 1; j >= newCount; j--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(j); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() != IdentityConstraint::KEYREF)) - fValueStoreCache->transplant(ic, matcher->getInitialDepth()); - } - - // now handle keyref's... - for (int k = oldCount - 1; k >= newCount; k--) { - - XPathMatcher* matcher = fMatcherStack->getMatcherAt(k); - IdentityConstraint* ic = matcher->getIdentityConstraint(); - - if (ic && (ic->getType() == IdentityConstraint::KEYREF)) { - - ValueStore* values = fValueStoreCache->getValueStoreFor(ic, matcher->getInitialDepth()); - - if (values) { // nothing to do if nothing matched! - values->endDcocumentFragment(fValueStoreCache); - } - } - } - - fValueStoreCache->endElement(); + if (toCheckIdentityConstraint()) + { + fICHandler->deactivateContext + ( + (SchemaElementDecl *) elemDecl + , fContent.getRawBuffer() + ); } + } if(!isRoot) @@ -2061,27 +1974,6 @@ } // --------------------------------------------------------------------------- -// SGXMLScanner: IC activation methos -// --------------------------------------------------------------------------- -void SGXMLScanner::activateSelectorFor(IdentityConstraint* const ic, const int initialDepth) { - - IC_Selector* selector = ic->getSelector(); - - if (!selector) - return; - - XPathMatcher* matcher = selector->createMatcher - ( - fFieldActivator - , initialDepth - , fMemoryManager - ); - - fMatcherStack->addMatcher(matcher); - matcher->startDocumentFragment(); -} - -// --------------------------------------------------------------------------- // SGXMLScanner: Grammar preparsing // --------------------------------------------------------------------------- Grammar* SGXMLScanner::loadGrammar(const InputSource& src @@ -2214,10 +2106,11 @@ initValidator(fSchemaValidator); // Create IdentityConstraint info - fMatcherStack = new (fMemoryManager) XPathMatcherStack(fMemoryManager); - fValueStoreCache = new (fMemoryManager) ValueStoreCache(fMemoryManager); - fFieldActivator = new (fMemoryManager) FieldActivator(fValueStoreCache, fMatcherStack, fMemoryManager); - fValueStoreCache->setScanner(this); + /*** + todo: to auto sense if grammar has ic or not, probably do it + at reset() or parse() + ***/ + fICHandler = new (fMemoryManager) IdentityConstraintHandler(this, fMemoryManager); // Add the default entity entries for the character refs that must always // be present. @@ -2246,9 +2139,7 @@ delete fEntityTable; delete fRawAttrList; delete fSchemaValidator; - delete fFieldActivator; - delete fMatcherStack; - delete fValueStoreCache; + delete fICHandler; delete fElemNonDeclPool; delete fAttDefRegistry; delete fUndeclaredAttrRegistryNS; @@ -3311,8 +3202,8 @@ resetValidationContext(); // Reset IdentityConstraints - fValueStoreCache->startDocument(); - fMatcherStack->clear(); + if (fICHandler) + fICHandler->reset(); // Reset the element stack, and give it the latest ids for the special // URIs it has to know about. @@ -3483,7 +3374,7 @@ ((SchemaValidator*)fValidator)->setDatatypeBuffer(toFill.getRawBuffer()); // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(toFill.getRawBuffer(), toFill.getLen()); if (fDocHandler) @@ -3521,7 +3412,7 @@ ((SchemaValidator*)fValidator)->setDatatypeBuffer(toFill.getRawBuffer()); // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(toFill.getRawBuffer(), toFill.getLen()); if (fDocHandler) @@ -3542,7 +3433,7 @@ else { // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(toSend.getRawBuffer(), toSend.getLen()); // Always assume its just char data if not validating @@ -4296,7 +4187,7 @@ } // call all active identity constraints - if (fMatcherStack->getMatcherCount()) + if (toCheckIdentityConstraint() && fICHandler->getMatcherCount()) fContent.append(bbCData.getRawBuffer(), bbCData.getLen()); // If we have a doc handler, call it 1.18 +21 -28 xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp Index: SGXMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- SGXMLScanner.hpp 7 Apr 2004 14:14:08 -0000 1.17 +++ SGXMLScanner.hpp 13 Apr 2004 16:56:58 -0000 1.18 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.18 2004/04/13 16:56:58 peiyongz + * IdentityConstraintHandler + * * Revision 1.17 2004/04/07 14:14:08 peiyongz * make resolveSystemId virutal * @@ -126,9 +129,7 @@ class SchemaGrammar; class SchemaValidator; -class ValueStoreCache; -class XPathMatcherStack; -class FieldActivator; +class IdentityConstraintHandler; class IdentityConstraint; class ContentLeafNameTypeVector; class SchemaAttDef; @@ -297,7 +298,7 @@ // ----------------------------------------------------------------------- // IdentityConstraints Activation methods // ----------------------------------------------------------------------- - void activateSelectorFor(IdentityConstraint* const ic, const int initialDepth); + inline bool toCheckIdentityConstraint() const; // ----------------------------------------------------------------------- // Grammar preparsing methods @@ -330,17 +331,6 @@ // Stores an element next state from DFA content model - used for // wildcard validation // - // fMatcherStack - // Stack of active XPath matchers for identity constraints. All - // active XPath matchers are notified of startElement, characters - // and endElement callbacks in order to perform their matches. - // - // fValueStoreCache - // Cache of value stores for identity constraint fields. - // - // fFieldActivator - // Activates fields within a certain scope when a selector matches - // its xpath. // fElemNonDeclPool // registry for elements without decls in the grammar // fElemCount @@ -357,19 +347,17 @@ // filled when a PSVIHandler is registered // // ----------------------------------------------------------------------- - bool fSeeXsi; - Grammar::GrammarType fGrammarType; - unsigned int fElemStateSize; - unsigned int* fElemState; - XMLBuffer fContent; - ValueHashTableOf<XMLCh>* fEntityTable; - RefVectorOf<KVStringPair>* fRawAttrList; - SchemaGrammar* fSchemaGrammar; - SchemaValidator* fSchemaValidator; - XPathMatcherStack* fMatcherStack; - ValueStoreCache* fValueStoreCache; - FieldActivator* fFieldActivator; - RefHash3KeysIdPool<SchemaElementDecl>* fElemNonDeclPool; + bool fSeeXsi; + Grammar::GrammarType fGrammarType; + unsigned int fElemStateSize; + unsigned int* fElemState; + XMLBuffer fContent; + ValueHashTableOf<XMLCh>* fEntityTable; + RefVectorOf<KVStringPair>* fRawAttrList; + SchemaGrammar* fSchemaGrammar; + SchemaValidator* fSchemaValidator; + IdentityConstraintHandler* fICHandler; + RefHash3KeysIdPool<SchemaElementDecl>* fElemNonDeclPool; unsigned int fElemCount; RefHashTableOf<unsigned int>* fAttDefRegistry; RefHash2KeysTableOf<unsigned int>* fUndeclaredAttrRegistryNS; @@ -383,6 +371,11 @@ inline const XMLCh* SGXMLScanner::getName() const { return XMLUni::fgSGXMLScanner; +} + +inline bool SGXMLScanner::toCheckIdentityConstraint() const +{ + return fValidate && fIdentityConstraintChecking && fICHandler; } XERCES_CPP_NAMESPACE_END 1.64 +4 -1 xml-xerces/c/src/xercesc/internal/XMLScanner.cpp Index: XMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v retrieving revision 1.63 retrieving revision 1.64 diff -u -r1.63 -r1.64 --- XMLScanner.cpp 7 Apr 2004 14:15:12 -0000 1.63 +++ XMLScanner.cpp 13 Apr 2004 16:56:58 -0000 1.64 @@ -175,6 +175,7 @@ , fValidatorFromUser(false) , fDoSchema(false) , fSchemaFullChecking(false) + , fIdentityConstraintChecking(true) , fToCacheGrammar(false) , fUseCachedGrammar(false) , fLoadExternalDTD(true) @@ -252,6 +253,7 @@ , fValidatorFromUser(false) , fDoSchema(false) , fSchemaFullChecking(false) + , fIdentityConstraintChecking(true) , fToCacheGrammar(false) , fUseCachedGrammar(false) , fLoadExternalDTD(true) @@ -698,6 +700,7 @@ setStandardUriConformant(refScanner->getStandardUriConformant()); setExitOnFirstFatal(refScanner->getExitOnFirstFatal()); setValidationConstraintFatal(refScanner->getValidationConstraintFatal()); + setIdentityConstraintChecking(refScanner->getIdentityConstraintChecking()); setValidationSchemaFullChecking(refScanner->getValidationSchemaFullChecking()); cacheGrammarFromParse(refScanner->isCachingGrammarFromParse()); useCachedGrammarInParse(refScanner->isUsingCachedGrammarInParse()); 1.34 +25 -0 xml-xerces/c/src/xercesc/internal/XMLScanner.hpp Index: XMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.hpp,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- XMLScanner.hpp 7 Apr 2004 14:15:12 -0000 1.33 +++ XMLScanner.hpp 13 Apr 2004 16:56:58 -0000 1.34 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.34 2004/04/13 16:56:58 peiyongz + * IdentityConstraintHandler + * * Revision 1.33 2004/04/07 14:15:12 peiyongz * allow internalDTD (conditionally) with grammar reusing * @@ -490,6 +493,7 @@ ValSchemes getValidationScheme() const; bool getDoSchema() const; bool getValidationSchemaFullChecking() const; + bool getIdentityConstraintChecking() const; const XMLEntityHandler* getEntityHandler() const; XMLEntityHandler* getEntityHandler(); const XMLErrorReporter* getErrorReporter() const; @@ -617,6 +621,7 @@ void setValidator(XMLValidator* const valToAdopt); void setDoSchema(const bool doSchema); void setValidationSchemaFullChecking(const bool schemaFullChecking); + void setIdentityConstraintChecking(const bool identityConstraintChecking); void setHasNoDTD(const bool hasNoDTD); void cacheGrammarFromParse(const bool newValue); void useCachedGrammarInParse(const bool newValue); @@ -797,6 +802,10 @@ // This indicates whether we treat validation constraint errors as // fatal errors or not. It defaults to false, but it can be changed. // + // fValidateConstraint + // This indicates whether we perform identity constraint validation. + // It defaults to false, but it can be changed. + // // fIDRefList // This is a list of XMLRefInfo objects. This member lets us do all // needed ID-IDREF balancing checks. @@ -854,6 +863,11 @@ // This flag indicates whether the client code wants full Schema // constraint checking. // + // fIdentityConstraintChecking + // This flag indicates whether the client code wants Identity + // Constraint checking, defaulted to true to maintain backward + // compatibility (to minimize supprise) + // // fAttName // fAttValue // fCDataBuf @@ -973,6 +987,7 @@ bool fValidatorFromUser; bool fDoSchema; bool fSchemaFullChecking; + bool fIdentityConstraintChecking; bool fToCacheGrammar; bool fUseCachedGrammar; bool fLoadExternalDTD; @@ -1197,6 +1212,11 @@ return fSchemaFullChecking; } +inline bool XMLScanner::getIdentityConstraintChecking() const +{ + return fIdentityConstraintChecking; +} + inline int XMLScanner::getErrorCount() { return fErrorCount; @@ -1387,6 +1407,11 @@ inline void XMLScanner::setValidationSchemaFullChecking(const bool schemaFullChecking) { fSchemaFullChecking = schemaFullChecking; +} + +inline void XMLScanner::setIdentityConstraintChecking(const bool identityConstraintChecking) +{ + fIdentityConstraintChecking = identityConstraintChecking; } inline void XMLScanner::setHasNoDTD(const bool hasNoDTD)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]