You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2001/11/02 15:20:14 UTC
cvs commit: xml-xerces/c/src/internal XMLScanner.cpp XMLScanner.hpp XMLScanner2.cpp
knoaman 01/11/02 06:20:14
Modified: c/src/internal XMLScanner.cpp XMLScanner.hpp XMLScanner2.cpp
Log:
Add support for identity constraints.
Revision Changes Path
1.72 +203 -16 xml-xerces/c/src/internal/XMLScanner.cpp
Index: XMLScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- XMLScanner.cpp 2001/10/25 21:49:31 1.71
+++ XMLScanner.cpp 2001/11/02 14:20:14 1.72
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner.cpp,v 1.71 2001/10/25 21:49:31 peiyongz Exp $
+ * $Id: XMLScanner.cpp,v 1.72 2001/11/02 14:20:14 knoaman Exp $
*/
@@ -88,8 +88,12 @@
#include <validators/DTD/DocTypeHandler.hpp>
#include <validators/DTD/DTDScanner.hpp>
#include <validators/schema/SchemaSymbols.hpp>
+#include <validators/schema/identity/FieldActivator.hpp>
+#include <validators/schema/identity/XPathMatcherStack.hpp>
+#include <validators/schema/identity/ValueStoreCache.hpp>
+#include <validators/schema/identity/IC_Selector.hpp>
+#include <validators/schema/identity/ValueStore.hpp>
-
// ---------------------------------------------------------------------------
// Local static data
// ---------------------------------------------------------------------------
@@ -208,6 +212,9 @@
, fGrammar(0)
, fEntityDeclPool(0)
, fURIStringPool(0)
+ , fMatcherStack(0)
+ , fValueStoreCache(0)
+ , fFieldActivator(0)
{
commonInit();
@@ -266,6 +273,9 @@
, fGrammar(0)
, fEntityDeclPool(0)
, fURIStringPool(0)
+ , fMatcherStack(0)
+ , fValueStoreCache(0)
+ , fFieldActivator(0)
{
commonInit();
@@ -297,6 +307,10 @@
delete fGrammarResolver;
delete fURIStringPool;
+
+ delete fFieldActivator;
+ delete fMatcherStack;
+ delete fValueStoreCache;
}
@@ -379,6 +393,8 @@
if (fDocHandler)
fDocHandler->startDocument();
+ fValueStoreCache->startDocument();
+
//
// Scan the prolog part, which is everything before the root element
// including the DTD subsets.
@@ -417,6 +433,9 @@
}
}
+ if (fValidate)
+ fValueStoreCache->endDocument();
+
// If we have a document handler, then call the end document
if (fDocHandler)
fDocHandler->endDocument();
@@ -560,16 +579,18 @@
//
fSequenceId++;
- //
+ //
// Reset the scanner and its plugged in stuff for a new run. This
- // resets all the data structures, creates the initial reader and
- // pushes it on the stack, and sets up the base document path
- //
+ // resets all the data structures, creates the initial reader and
+ // pushes it on the stack, and sets up the base document path
+ //
scanReset(src);
+
+ // If we have a document handler, then call the start document
+ if (fDocHandler)
+ fDocHandler->startDocument();
- // If we have a document handler, then call the start document
- if (fDocHandler)
- fDocHandler->startDocument();
+ fValueStoreCache->startDocument();
try
{
@@ -746,11 +767,15 @@
// If we hit the end, then do the miscellaneous part
if (!gotData)
- {
+ {
scanMiscellaneous();
- if (fDocHandler)
- fDocHandler->endDocument();
- }
+
+ if (fValidate)
+ fValueStoreCache->endDocument();
+
+ if (fDocHandler)
+ fDocHandler->endDocument();
+ }
}
}
@@ -917,6 +942,12 @@
initValidator(fDTDValidator);
fSchemaValidator = new SchemaValidator();
initValidator(fSchemaValidator);
+
+ // Create IdentityConstraint info
+ fMatcherStack = new XPathMatcherStack();
+ fValueStoreCache = new ValueStoreCache();
+ fFieldActivator = new FieldActivator(fValueStoreCache, fMatcherStack);
+ fValueStoreCache->setScanner(this);
}
@@ -1738,8 +1769,64 @@
}
// reset xsi:type ComplexTypeInfo
- if (fGrammarType == Grammar::SchemaGrammarType)
+ if (fGrammarType == Grammar::SchemaGrammarType) {
((SchemaElementDecl*)topElem->fThisElement)->setXsiComplexTypeInfo(0);
+
+ // 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));
+ }
+
+ 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)) {
+
+ matcher->endDocumentFragment();
+ fValueStoreCache->transplant(ic);
+ }
+ else if (!ic) {
+ matcher->endDocumentFragment();
+ }
+ }
+
+ // 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);
+
+ if (values) { // nothing to do if nothing matched!
+ values->endDcocumentFragment(fValueStoreCache);
+ }
+
+ matcher->endDocumentFragment();
+ }
+ }
+
+ fValueStoreCache->endElement();
+ }
+ }
}
// If this was the root, then done with content
@@ -3165,6 +3252,34 @@
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);
+
+ for (unsigned int i = 0; i < count; i++) {
+ activateSelectorFor(((SchemaElementDecl*) elemDecl)->getIdentityConstraintAt(i));
+ }
+
+ // call all active identity constraints
+ count = fMatcherStack->getMatcherCount();
+
+ for (unsigned int j = 0; j < count; j++) {
+
+ XPathMatcher* matcher = fMatcherStack->getMatcherAt(j);
+ matcher->startElement(*elemDecl, *fAttrList, attCount);
+ }
+ }
+ }
+
+ //
// If empty, validate content right now if we are validating and then
// pop the element stack top. Else, we have to update the current stack
// top's namespace mapping elements.
@@ -3187,10 +3302,66 @@
, elemDecl->getFormattedContentModel()
);
}
+
+ if (fGrammarType == Grammar::SchemaGrammarType) {
- // reset xsi:type ComplexTypeInfo
- if (fGrammarType == Grammar::SchemaGrammarType)
+ // reset xsi:type ComplexTypeInfo
((SchemaElementDecl*)elemDecl)->setXsiComplexTypeInfo(0);
+
+ // 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);
+ }
+
+ 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)) {
+
+ matcher->endDocumentFragment();
+ fValueStoreCache->transplant(ic);
+ }
+ else if (!ic) {
+ matcher->endDocumentFragment();
+ }
+ }
+
+ // 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);
+
+ if (values) { // nothing to do if nothing matched!
+ values->endDcocumentFragment(fValueStoreCache);
+ }
+
+ matcher->endDocumentFragment();
+ }
+ }
+
+ fValueStoreCache->endElement();
+ }
+ }
}
// If the elem stack is empty, then it was an empty root
@@ -3640,5 +3811,21 @@
delete [] fElemState;
fElemState = newElemState;
fElemStateSize = newSize;
+}
+
+// ---------------------------------------------------------------------------
+// XMLScanner: IC activation methos
+// ---------------------------------------------------------------------------
+void XMLScanner::activateSelectorFor(IdentityConstraint* const ic) {
+
+ IC_Selector* selector = ic->getSelector();
+
+ if (!selector)
+ return;
+
+ XPathMatcher* matcher = selector->createMatcher(fFieldActivator);
+
+ fMatcherStack->addMatcher(matcher);
+ matcher->startDocumentFragment();
}
1.35 +25 -2 xml-xerces/c/src/internal/XMLScanner.hpp
Index: XMLScanner.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.hpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- XMLScanner.hpp 2001/10/12 20:52:18 1.34
+++ XMLScanner.hpp 2001/11/02 14:20:14 1.35
@@ -56,6 +56,9 @@
/*
* $Log: XMLScanner.hpp,v $
+ * Revision 1.35 2001/11/02 14:20:14 knoaman
+ * Add support for identity constraints.
+ *
* Revision 1.34 2001/10/12 20:52:18 tng
* Schema: Find the attributes see if they should be (un)qualified.
*
@@ -207,7 +210,10 @@
class ErrorHandler;
class XMLMsgLoader;
class XMLValidator;
-
+class ValueStoreCache;
+class XPathMatcherStack;
+class FieldActivator;
+class IdentityConstraint;
//
// This is the mondo scanner class, which does the vast majority of the
@@ -644,8 +650,11 @@
// Private helper methods
// -----------------------------------------------------------------------
void resizeElemState();
-
+ // -----------------------------------------------------------------------
+ // IdentityConstraints Activation methods
+ // -----------------------------------------------------------------------
+ void activateSelectorFor(IdentityConstraint* const ic);
// -----------------------------------------------------------------------
// Data members
@@ -839,6 +848,17 @@
// string pool class. This pool is going to be shared by all Grammar.
// Use only if namespace is turned on.
//
+ // 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.
// -----------------------------------------------------------------------
bool fDoNamespaces;
bool fExitOnFirstFatal;
@@ -890,6 +910,9 @@
Grammar::GrammarType fGrammarType;
NameIdPool<DTDEntityDecl>* fEntityDeclPool;
XMLStringPool* fURIStringPool;
+ XPathMatcherStack* fMatcherStack;
+ ValueStoreCache* fValueStoreCache;
+ FieldActivator* fFieldActivator;
};
1.63 +33 -2 xml-xerces/c/src/internal/XMLScanner2.cpp
Index: XMLScanner2.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner2.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- XMLScanner2.cpp 2001/10/12 20:52:18 1.62
+++ XMLScanner2.cpp 2001/11/02 14:20:14 1.63
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner2.cpp,v 1.62 2001/10/12 20:52:18 tng Exp $
+ * $Id: XMLScanner2.cpp,v 1.63 2001/11/02 14:20:14 knoaman Exp $
*/
@@ -97,9 +97,9 @@
#include <validators/schema/SchemaGrammar.hpp>
#include <validators/schema/TraverseSchema.hpp>
#include <validators/schema/SubstitutionGroupComparator.hpp>
+#include <validators/schema/identity/XPathMatcherStack.hpp>
-
// ---------------------------------------------------------------------------
// XMLScanner: Private helper methods
// ---------------------------------------------------------------------------
@@ -1011,6 +1011,9 @@
// Clear out the id reference list
fIDRefList->removeAll();
+ // Reset IdentityConstraints
+ fMatcherStack->clear();
+
//
// Reset the element stack, and give it the latest ids for the special
// URIs it has to know about.
@@ -1121,6 +1124,13 @@
DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator();
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, toFill);
+ // call all active identity constraints
+ unsigned int count = fMatcherStack->getMatcherCount();
+
+ for (unsigned int i = 0; i < count; i++) {
+ fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
+ }
+
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
}
}
@@ -1152,6 +1162,13 @@
DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator();
((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, toFill);
+ // call all active identity constraints
+ unsigned int count = fMatcherStack->getMatcherCount();
+
+ for (unsigned int i = 0; i < count; i++) {
+ fMatcherStack->getMatcherAt(i)->docCharacters(toFill.getRawBuffer(), toFill.getLen());
+ }
+
fDocHandler->docCharacters(toFill.getRawBuffer(), toFill.getLen(), false);
}
}
@@ -1164,6 +1181,13 @@
}
else
{
+ // call all active identity constraints
+ unsigned int count = fMatcherStack->getMatcherCount();
+
+ for (unsigned int i = 0; i < count; i++) {
+ fMatcherStack->getMatcherAt(i)->docCharacters(toSend.getRawBuffer(), toSend.getLen());
+ }
+
// Always assume its just char data if not validating
if (fDocHandler)
fDocHandler->docCharacters(toSend.getRawBuffer(), toSend.getLen(), false);
@@ -2104,6 +2128,13 @@
//
if (nextCh == chCloseSquare && fReaderMgr.skippedString(CDataClose))
{
+ // call all active identity constraints
+ unsigned int count = fMatcherStack->getMatcherCount();
+
+ for (unsigned int i = 0; i < count; i++) {
+ fMatcherStack->getMatcherAt(i)->docCharacters(bbCData.getRawBuffer(), bbCData.getLen());
+ }
+
// If we have a doc handler, call it
if (fDocHandler)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org