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/10/04 17:08:56 UTC
cvs commit: xml-xerces/c/src/validators/schema ComplexTypeInfo.cpp ComplexTypeInfo.hpp SchemaGrammar.hpp SchemaInfo.cpp SchemaInfo.hpp SchemaValidator.cpp SubstitutionGroupComparator.cpp TraverseSchema.cpp TraverseSchema.hpp
knoaman 01/10/04 08:08:56
Modified: c/src/util XMLString.cpp
c/src/validators/common DFAContentModel.cpp
c/src/validators/schema ComplexTypeInfo.cpp
ComplexTypeInfo.hpp SchemaGrammar.hpp
SchemaInfo.cpp SchemaInfo.hpp SchemaValidator.cpp
SubstitutionGroupComparator.cpp TraverseSchema.cpp
TraverseSchema.hpp
Log:
Add support for circular import.
Revision Changes Path
1.27 +2 -2 xml-xerces/c/src/util/XMLString.cpp
Index: XMLString.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLString.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- XMLString.cpp 2001/08/10 16:23:06 1.26
+++ XMLString.cpp 2001/10/04 15:08:55 1.27
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLString.cpp,v 1.26 2001/08/10 16:23:06 peiyongz Exp $
+ * $Id: XMLString.cpp,v 1.27 2001/10/04 15:08:55 knoaman Exp $
*/
@@ -727,7 +727,7 @@
if (colonPos != -1)
{
XMLCh *prefix = new XMLCh[colonPos+1];
- XMLString::subString(prefix, name, 0, colonPos-1);
+ XMLString::subString(prefix, name, 0, colonPos);
ArrayJanitor<XMLCh> janName(prefix);
if (XMLString::isValidNCName(prefix)==false)
return false;
1.25 +8 -1 xml-xerces/c/src/validators/common/DFAContentModel.cpp
Index: DFAContentModel.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/common/DFAContentModel.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- DFAContentModel.cpp 2001/09/14 14:50:22 1.24
+++ DFAContentModel.cpp 2001/10/04 15:08:55 1.25
@@ -56,6 +56,9 @@
/*
* $Log: DFAContentModel.cpp,v $
+ * Revision 1.25 2001/10/04 15:08:55 knoaman
+ * Add support for circular import.
+ *
* Revision 1.24 2001/09/14 14:50:22 tng
* Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems.
*
@@ -1151,8 +1154,12 @@
// Rename the URI back
for (i = 0; i < fElemMapSize; i++) {
+
unsigned int orgURIIndex = fElemMap[i]->getURI();
- fElemMap[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
+
+ if (orgURIIndex != XMLContentModel::gEOCFakeId) {
+ fElemMap[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
+ }
}
// Unique Particle Attribution
1.19 +57 -72 xml-xerces/c/src/validators/schema/ComplexTypeInfo.cpp
Index: ComplexTypeInfo.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/ComplexTypeInfo.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ComplexTypeInfo.cpp 2001/09/05 20:49:11 1.18
+++ ComplexTypeInfo.cpp 2001/10/04 15:08:56 1.19
@@ -56,6 +56,9 @@
/*
* $Log: ComplexTypeInfo.cpp,v $
+ * Revision 1.19 2001/10/04 15:08:56 knoaman
+ * Add support for circular import.
+ *
* Revision 1.18 2001/09/05 20:49:11 knoaman
* Fix for complexTypes with mixed content model.
*
@@ -136,6 +139,7 @@
, fFinalSet(0)
, fScopeDefined(Grammar::TOP_LEVEL_SCOPE)
, fElementId(XMLElementDecl::fgInvalidElemId)
+ , fContentType(SchemaElementDecl::Empty)
, fTypeName(0)
, fBaseDatatypeValidator(0)
, fDatatypeValidator(0)
@@ -150,6 +154,7 @@
, fContentSpecOrgURI(0)
, fUniqueURI(0)
, fContentSpecOrgURISize(16)
+ , fSpecNodesToDelete(0)
{
}
@@ -167,6 +172,7 @@
delete fAttDefs;
delete fAttList;
delete fElements;
+ delete fSpecNodesToDelete;
delete fContentModel;
delete [] fFormattedModel;
@@ -296,13 +302,14 @@
{
if (fContentSpec) {
ContentSpecNode* specNode = new ContentSpecNode(*fContentSpec);
- Janitor<ContentSpecNode> janSpecNode(0);
- XMLContentModel* cm = makeContentModel(true, specNode, &janSpecNode);
+ XMLContentModel* cm = makeContentModel(true, specNode);
if (cm) {
cm->checkUniqueParticleAttribution(pGrammarResolver, pStringPool, pValidator, fContentSpecOrgURI);
delete cm;
}
+
+ fSpecNodesToDelete->removeAllElements();
}
}
@@ -347,27 +354,29 @@
return newValue;
}
-XMLContentModel* ComplexTypeInfo::makeContentModel(const bool checkUPA, ContentSpecNode* specNode,
- Janitor<ContentSpecNode>* const janSpecNode)
+XMLContentModel* ComplexTypeInfo::makeContentModel(const bool checkUPA, ContentSpecNode* const specNode)
{
- // expand the content spec first
- fContentSpecOrgURI = new unsigned int[fContentSpecOrgURISize];
- if (specNode) {
- specNode = convertContentSpecTree(specNode, true, checkUPA);
+ if ((specNode || fContentSpec) && !fSpecNodesToDelete) {
+ fSpecNodesToDelete = new RefVectorOf<ContentSpecNode>(8);
+ }
- if (janSpecNode) {
- janSpecNode->reset(specNode);
- }
+ // expand the content spec first
+ ContentSpecNode* aSpecNode = specNode;
+ if (aSpecNode) {
+
+ fContentSpecOrgURI = new unsigned int[fContentSpecOrgURISize];
+ aSpecNode = convertContentSpecTree(aSpecNode, checkUPA);
+ fSpecNodesToDelete->addElement(aSpecNode);
}
else {
- specNode = convertContentSpecTree(fContentSpec, fAdoptContentSpec, checkUPA);
- if (specNode != fContentSpec) {
- if (specNode == fContentSpec->getFirst() && !fAdoptContentSpec)
+ aSpecNode = convertContentSpecTree(fContentSpec, checkUPA);
+ if (aSpecNode != fContentSpec) {
+ if (aSpecNode == fContentSpec->getFirst() && !fAdoptContentSpec)
fAdoptContentSpec = false;
else
fAdoptContentSpec = true;
- fContentSpec = specNode;
+ fContentSpec = aSpecNode;
}
}
@@ -382,11 +391,11 @@
// Just create a mixel content model object. This type of
// content model is optimized for mixed content validation.
//
- cmRet = new MixedContentModel(false, specNode);
+ cmRet = new MixedContentModel(false, aSpecNode);
}
else if (fContentType == SchemaElementDecl::Mixed_Complex) {
- cmRet = createChildModel(specNode, true);
+ cmRet = createChildModel(aSpecNode, true);
}
else if (fContentType == SchemaElementDecl::Children)
{
@@ -397,12 +406,13 @@
// create a SimpleListContentModel object. If its complex, it
// will create a DFAContentModel object.
//
- cmRet = createChildModel(specNode, false);
+ cmRet = createChildModel(aSpecNode, false);
}
else
{
ThrowXML(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren);
}
+
return cmRet;
}
@@ -515,11 +525,15 @@
return new DFAContentModel(false, specNode, isMixed);
}
-ContentSpecNode* ComplexTypeInfo::convertContentSpecTree(ContentSpecNode* const curNode, const bool toAdoptSpecNode, const bool checkUPA) {
+ContentSpecNode*
+ComplexTypeInfo::convertContentSpecTree(ContentSpecNode* const curNode,
+ const bool checkUPA) {
if (!curNode)
return 0;
+ const ContentSpecNode::NodeTypes curType = curNode->getType();
+
// When checking Unique Particle Attribution, rename leaf elements
if (checkUPA) {
fContentSpecOrgURI[fUniqueURI] = curNode->getElement()->getURI();
@@ -532,7 +546,6 @@
// Get the spec type of the passed node
int minOccurs = curNode->getMinOccurs();
int maxOccurs = curNode->getMaxOccurs();
- const ContentSpecNode::NodeTypes curType = curNode->getType();
ContentSpecNode* retNode = curNode;
if ((curType & 0x0f) == ContentSpecNode::Any
@@ -540,60 +553,42 @@
|| (curType & 0x0f) == ContentSpecNode::Any_NS
|| curType == ContentSpecNode::Leaf)
{
- retNode = expandContentModel(curNode, minOccurs, maxOccurs, toAdoptSpecNode);
+ retNode = expandContentModel(curNode, minOccurs, maxOccurs);
}
else if ((curType == ContentSpecNode::Choice)
|| (curType == ContentSpecNode::All)
|| (curType == ContentSpecNode::Sequence))
{
- bool toAdoptLeft = toAdoptSpecNode? curNode->isFirstAdopted() : false;
- ContentSpecNode* leftNode = convertContentSpecTree(curNode->getFirst(), toAdoptLeft, checkUPA);
+ ContentSpecNode* childNode = curNode->getFirst();
+ ContentSpecNode* leftNode = convertContentSpecTree(childNode, checkUPA);
ContentSpecNode* rightNode = curNode->getSecond();
- if (leftNode != curNode->getFirst()) {
- if (leftNode == curNode->getFirst()->getFirst() && !curNode->isFirstAdopted())
- toAdoptLeft = false;
- else
- toAdoptLeft = true;
+ if (!rightNode) {
+ retNode = expandContentModel(leftNode, minOccurs, maxOccurs);
curNode->setAdoptFirst(false);
- curNode->setFirst(leftNode);
-
- if (rightNode) {
- curNode->setAdoptFirst(toAdoptLeft);
- }
+ delete curNode;
+ return retNode;
}
- if (!rightNode) {
+ if (leftNode != childNode) {
- if (toAdoptSpecNode) {
- retNode = expandContentModel(leftNode, minOccurs, maxOccurs, toAdoptLeft);
- curNode->setAdoptFirst(false);
- delete curNode;
- }
- else {
- retNode = expandContentModel(leftNode, minOccurs, maxOccurs, false);
- }
-
- return retNode;
+ curNode->setAdoptFirst(false);
+ curNode->setFirst(leftNode);
+ curNode->setAdoptFirst(true);
}
-
- bool toAdoptRight = toAdoptSpecNode? curNode->isSecondAdopted() : false;
- rightNode = convertContentSpecTree(curNode->getSecond(), toAdoptRight, checkUPA);
- if (rightNode != curNode->getSecond()) {
+ childNode = rightNode;
+ rightNode = convertContentSpecTree(childNode, checkUPA);
- if (rightNode == curNode->getSecond()->getFirst() && !curNode->isSecondAdopted())
- toAdoptRight = false;
- else
- toAdoptRight = true;
+ if (rightNode != childNode) {
curNode->setAdoptSecond(false);
curNode->setSecond(rightNode);
- curNode->setAdoptSecond(toAdoptRight);
+ curNode->setAdoptSecond(true);
}
- retNode = expandContentModel(curNode, minOccurs, maxOccurs, toAdoptSpecNode);
+ retNode = expandContentModel(curNode, minOccurs, maxOccurs);
}
return retNode;
@@ -601,8 +596,7 @@
ContentSpecNode* ComplexTypeInfo::expandContentModel(ContentSpecNode* const specNode,
const int minOccurs,
- const int maxOccurs,
- const bool toAdoptSpecNode)
+ const int maxOccurs)
{
if (!specNode) {
return 0;
@@ -615,21 +609,17 @@
}
else if (minOccurs == 0 && maxOccurs == 1) {
- retNode = new ContentSpecNode(ContentSpecNode::ZeroOrOne,
- retNode, 0, toAdoptSpecNode);
+ retNode = new ContentSpecNode(ContentSpecNode::ZeroOrOne, retNode, 0);
}
else if (minOccurs == 0 && maxOccurs == -1) {
- retNode = new ContentSpecNode(ContentSpecNode::ZeroOrMore,
- retNode, 0, toAdoptSpecNode);
+ retNode = new ContentSpecNode(ContentSpecNode::ZeroOrMore, retNode, 0);
}
else if (minOccurs == 1 && maxOccurs == -1) {
- retNode = new ContentSpecNode(ContentSpecNode::OneOrMore,
- retNode, 0, toAdoptSpecNode);
+ retNode = new ContentSpecNode(ContentSpecNode::OneOrMore, retNode, 0);
}
else if (maxOccurs == -1) {
- retNode = new ContentSpecNode(ContentSpecNode::OneOrMore,
- retNode, 0, toAdoptSpecNode);
+ retNode = new ContentSpecNode(ContentSpecNode::OneOrMore, retNode, 0);
for (int i=0; i < (int)(minOccurs-1); i++) {
retNode = new ContentSpecNode(ContentSpecNode::Sequence,
@@ -641,7 +631,7 @@
if (minOccurs == 0) {
ContentSpecNode* optional =
- new ContentSpecNode(ContentSpecNode::ZeroOrOne, saveNode, 0, toAdoptSpecNode);
+ new ContentSpecNode(ContentSpecNode::ZeroOrOne, saveNode, 0);
retNode = optional;
@@ -652,19 +642,15 @@
}
else {
- bool isRetAdopted = toAdoptSpecNode;
-
if (minOccurs > 1) {
retNode = new ContentSpecNode(ContentSpecNode::Sequence,
- retNode, saveNode, toAdoptSpecNode, false);
+ retNode, saveNode, true, false);
for (int i=1; i < (int)(minOccurs-1); i++) {
retNode = new ContentSpecNode(ContentSpecNode::Sequence,
retNode, saveNode, true, false);
}
-
- isRetAdopted = true;
}
int counter = maxOccurs-minOccurs;
@@ -673,8 +659,7 @@
ContentSpecNode* optional = new ContentSpecNode(ContentSpecNode::ZeroOrOne, saveNode, 0, false);
- retNode = new ContentSpecNode(ContentSpecNode::Sequence,
- retNode, optional, isRetAdopted, true);
+ retNode = new ContentSpecNode(ContentSpecNode::Sequence, retNode, optional);
for (int j=1; j < counter; j++) {
1.10 +5 -5 xml-xerces/c/src/validators/schema/ComplexTypeInfo.hpp
Index: ComplexTypeInfo.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/ComplexTypeInfo.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ComplexTypeInfo.hpp 2001/08/27 23:04:02 1.9
+++ ComplexTypeInfo.hpp 2001/10/04 15:08:56 1.10
@@ -55,7 +55,7 @@
*/
/*
- * $Id: ComplexTypeInfo.hpp,v 1.9 2001/08/27 23:04:02 knoaman Exp $
+ * $Id: ComplexTypeInfo.hpp,v 1.10 2001/10/04 15:08:56 knoaman Exp $
*/
#if !defined(COMPLEXTYPEINFO_HPP)
@@ -183,11 +183,10 @@
// -----------------------------------------------------------------------
void faultInAttDefList() const;
XMLContentModel* createChildModel(ContentSpecNode* specNode, const bool isMixed);
- XMLContentModel* makeContentModel(const bool checkUPA = false, ContentSpecNode* specNode = 0,
- Janitor<ContentSpecNode>* const janSpecNode = 0);
+ XMLContentModel* makeContentModel(const bool checkUPA = false, ContentSpecNode* const specNode = 0);
XMLCh* formatContentModel () const ;
- ContentSpecNode* expandContentModel(ContentSpecNode* const curNode, const int minOccurs, const int maxOccurs, const bool toAdoptSpecNode = true);
- ContentSpecNode* convertContentSpecTree(ContentSpecNode* const curNode, const bool toAdoptSpecNode = true, const bool checkUPA = false);
+ ContentSpecNode* expandContentModel(ContentSpecNode* const curNode, const int minOccurs, const int maxOccurs);
+ ContentSpecNode* convertContentSpecTree(ContentSpecNode* const curNode, const bool checkUPA = false);
void resizeContentSpecOrgURI();
// -----------------------------------------------------------------------
@@ -215,6 +214,7 @@
unsigned int* fContentSpecOrgURI;
unsigned int fUniqueURI;
unsigned int fContentSpecOrgURISize;
+ RefVectorOf<ContentSpecNode>* fSpecNodesToDelete;
};
// ---------------------------------------------------------------------------
1.11 +4 -1 xml-xerces/c/src/validators/schema/SchemaGrammar.hpp
Index: SchemaGrammar.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaGrammar.hpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SchemaGrammar.hpp 2001/09/14 14:50:22 1.10
+++ SchemaGrammar.hpp 2001/10/04 15:08:56 1.11
@@ -56,6 +56,9 @@
/*
* $Log: SchemaGrammar.hpp,v $
+ * Revision 1.11 2001/10/04 15:08:56 knoaman
+ * Add support for circular import.
+ *
* Revision 1.10 2001/09/14 14:50:22 tng
* Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems.
*
@@ -123,7 +126,7 @@
// ---------------------------------------------------------------------------
// typedef declaration
// ---------------------------------------------------------------------------
-typedef RefVectorOf<SchemaElementDecl> ElemVector;
+typedef ValueVectorOf<SchemaElementDecl*> ElemVector;
class VALIDATORS_EXPORT SchemaGrammar : public Grammar
1.5 +135 -13 xml-xerces/c/src/validators/schema/SchemaInfo.cpp
Index: SchemaInfo.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaInfo.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SchemaInfo.cpp 2001/07/31 15:26:54 1.4
+++ SchemaInfo.cpp 2001/10/04 15:08:56 1.5
@@ -56,6 +56,9 @@
/*
* $Log: SchemaInfo.cpp,v $
+ * Revision 1.5 2001/10/04 15:08:56 knoaman
+ * Add support for circular import.
+ *
* Revision 1.4 2001/07/31 15:26:54 knoaman
* Added support for <attributeGroup>.
*
@@ -74,41 +77,160 @@
// Includes
// ---------------------------------------------------------------------------
#include <validators/schema/SchemaInfo.hpp>
+#include <validators/schema/XUtil.hpp>
+#include <validators/schema/SchemaSymbols.hpp>
#include <util/XMLString.hpp>
-
// ---------------------------------------------------------------------------
// SchemaInfo: Constructors and Destructor
// ---------------------------------------------------------------------------
-SchemaInfo::SchemaInfo(const bool elemDefaultQualified,
- const bool attrDefaultQualified,
+SchemaInfo::SchemaInfo(const unsigned short elemAttrDefaultQualified,
const int blockDefault,
const int finalDefault,
+ const int targetNSURI,
+ const int currentScope,
+ const int scopeCount,
const unsigned int namespaceScopeLevel,
XMLCh* const schemaURL,
- const DOM_Element& root,
- SchemaInfo* const nextRoot,
- SchemaInfo* const prevRoot)
- : fElementDefaultQualified(elemDefaultQualified)
- , fAttributeDefaultQualified(attrDefaultQualified)
+ const XMLCh* const targetNSURIString,
+ XMLStringPool* const stringPool,
+ const DOM_Element& root)
+ : fElemAttrDefaultQualified(elemAttrDefaultQualified)
, fBlockDefault(blockDefault)
, fFinalDefault(finalDefault)
+ , fTargetNSURI(targetNSURI)
+ , fCurrentScope(currentScope)
+ , fScopeCount(scopeCount)
, fNamespaceScopeLevel(namespaceScopeLevel)
- , fCurrentSchemaURL(XMLString::replicate(schemaURL))
+ , fCurrentSchemaURL(schemaURL)
+ , fTargetNSURIString(targetNSURIString)
+ , fStringPool(stringPool)
, fSchemaRootElement(root)
- , fNext(nextRoot)
- , fPrev(prevRoot)
+ , fIncludeList(0)
+ , fImportList(0)
+ , fImportingList(0)
+ , fRedefineList(0)
{
+ fImportingList = new RefVectorOf<SchemaInfo>(4, false);
}
SchemaInfo::~SchemaInfo()
{
delete [] fCurrentSchemaURL;
- delete fNext;
- fNext = 0;
+ delete fImportList;
+ delete fIncludeList;
+ delete fImportingList;
+
+ fImportList = fIncludeList = fImportingList = 0;
+}
+
+// ---------------------------------------------------------------------------
+// SchemaInfo:
+// ---------------------------------------------------------------------------
+DOM_Element
+SchemaInfo::getTopLevelComponent(const XMLCh* const compCategory,
+ const XMLCh* const name,
+ SchemaInfo** enclosingSchema) {
+
+ SchemaInfo* currentInfo = this;
+ DOM_Element child = getTopLevelComponent(compCategory, name);
+
+ if (child == 0) {
+
+ unsigned int listSize = (fIncludeList) ? fIncludeList->size() : 0;
+
+ for (unsigned int i=0; i < listSize; i++) {
+
+ currentInfo = fIncludeList->elementAt(i);
+
+ child = currentInfo->getTopLevelComponent(compCategory, name);
+
+ if (child != 0) {
+
+ *enclosingSchema = currentInfo;
+ break;
+ }
+ }
+
+ if (child == 0 && fRedefineList) { // try redefine list
+
+ currentInfo = fRedefineList->get(compCategory, fStringPool->addOrFind(name));
+
+ if (currentInfo) {
+ child = currentInfo->getTopLevelComponent(compCategory, name);
+
+ if (child != 0) {
+ *enclosingSchema = currentInfo;
+ }
+ }
+ }
+ }
+
+ return child;
+}
+
+
+DOM_Element
+SchemaInfo::getTopLevelComponent(const XMLCh* const compCategory,
+ const XMLCh* const name) {
+
+ DOM_Element child = XUtil::getFirstChildElement(fSchemaRootElement);
+
+ while (child != 0) {
+
+ if (child.getLocalName().equals(compCategory)) {
+
+ if (child.getAttribute(SchemaSymbols::fgATT_NAME).equals(name)) {
+ break;
+ }
+ }
+ else if (child.getLocalName().equals(SchemaSymbols::fgELT_REDEFINE)) { // if redefine
+
+ DOM_Element redefineChild = XUtil::getFirstChildElement(child);
+
+ while (redefineChild != 0) {
+
+ if (redefineChild.getLocalName().equals(compCategory)) {
+
+ if (redefineChild.getAttribute(SchemaSymbols::fgATT_NAME).equals(name)) {
+ break;
+ }
+ }
+
+ redefineChild = XUtil::getNextSiblingElement(redefineChild);
+ }
+
+ if (redefineChild != 0) {
+
+ child = redefineChild;
+ break;
+ }
+ }
+
+ child = XUtil::getNextSiblingElement(child);
+ }
+
+ return child;
}
+void SchemaInfo::updateImportingInfo(SchemaInfo* const importingInfo) {
+
+ if (!fImportingList->containsElement(importingInfo)) {
+ fImportingList->addElement(importingInfo);
+ }
+
+ unsigned int listSize = importingInfo->fImportingList->size();
+
+ for (unsigned int i=0; i < listSize; i++) {
+
+ SchemaInfo* tmpInfo = importingInfo->fImportingList->elementAt(i);
+
+ if (tmpInfo != this && !fImportingList->containsElement(tmpInfo)) {
+ fImportingList->addElement(tmpInfo);
+ }
+ }
+}
/**
* End of file SchemaInfo.cpp
1.5 +177 -35 xml-xerces/c/src/validators/schema/SchemaInfo.hpp
Index: SchemaInfo.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaInfo.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SchemaInfo.hpp 2001/07/31 15:26:54 1.4
+++ SchemaInfo.hpp 2001/10/04 15:08:56 1.5
@@ -55,7 +55,7 @@
*/
/*
- * $Id: SchemaInfo.hpp,v 1.4 2001/07/31 15:26:54 knoaman Exp $
+ * $Id: SchemaInfo.hpp,v 1.5 2001/10/04 15:08:56 knoaman Exp $
*/
#if !defined(SCHEMAINFO_HPP)
@@ -78,72 +78,105 @@
// Includes
// ---------------------------------------------------------------------------
#include <dom/DOM_Element.hpp>
+#include <util/RefVectorOf.hpp>
+#include <util/RefHash2KeysTableOf.hpp>
+#include <util/StringPool.hpp>
class SchemaInfo
{
public:
+
+ enum ListType {
+ // Redefine is treated as an include
+ IMPORT = 1,
+ INCLUDE = 2
+ };
+
// -----------------------------------------------------------------------
// Constructor/Destructor
// -----------------------------------------------------------------------
- SchemaInfo(const bool elemDefaultQualified,
- const bool attrDefaultQualified,
+ SchemaInfo(const unsigned short fElemAttrDefaultQualified,
const int blockDefault,
const int finalDefault,
+ const int targetNSURI,
+ const int currentScope,
+ const int scopeCount,
const unsigned int namespaceScopeLevel,
XMLCh* const schemaURL,
- const DOM_Element& root,
- SchemaInfo* const nextRoot,
- SchemaInfo* const prevRoot);
+ const XMLCh* const targetNSURIString,
+ XMLStringPool* const stringPool,
+ const DOM_Element& root);
~SchemaInfo();
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
- SchemaInfo* getNext() const;
- SchemaInfo* getPrev() const;
- XMLCh* getCurrentSchemaURL() const;
- DOM_Element getRoot() const;
- int getBlockDefault() const;
- int getFinalDefault() const;
- unsigned int getNamespaceScopeLevel() const;
- bool isElementDefaultQualified() const;
- bool isAttributeDefaultQualified() const;
+ XMLCh* getCurrentSchemaURL() const;
+ const XMLCh* const getTargetNSURIString() const;
+ DOM_Element getRoot() const;
+ int getBlockDefault() const;
+ int getFinalDefault() const;
+ int getTargetNSURI() const;
+ int getCurrentScope() const;
+ int getScopeCount() const;
+ unsigned int getNamespaceScopeLevel() const;
+ unsigned short getElemAttrDefaultQualified() const;
+ RefVectorEnumerator<SchemaInfo> getImportingListEnumerator() const;
// -----------------------------------------------------------------------
// Setter methods
+ // -----------------------------------------------------------------------
+ void setCurrentScope(const int aValue);
+ void setScopeCount(const int aValue);
+
+ // -----------------------------------------------------------------------
+ // Access methods
// -----------------------------------------------------------------------
- void setNext(SchemaInfo* const nextInfo);
+ void addSchemaInfo(SchemaInfo* const toAdd, const ListType aListType);
+ void addRedefineInfo(const XMLCh* const categName, const XMLCh* const typeName,
+ SchemaInfo* const toAdd);
+ bool containsInfo(const SchemaInfo* const toCheck, const ListType aListType) const;
+ SchemaInfo* getImportInfo(const unsigned int namespaceURI) const;
+ SchemaInfo* getRedefInfo(const XMLCh* const categName,
+ const XMLCh* const typeName);
+ DOM_Element getTopLevelComponent(const XMLCh* const compCategory,
+ const XMLCh* const name);
+ DOM_Element getTopLevelComponent(const XMLCh* const compCategory,
+ const XMLCh* const name,
+ SchemaInfo** enclosingSchema);
+ void updateImportingInfo(SchemaInfo* const importingInfo);
+ bool circularImportExist(const unsigned int nameSpaceURI);
private:
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
- bool fElementDefaultQualified;
- bool fAttributeDefaultQualified;
+ unsigned short fElemAttrDefaultQualified;
int fBlockDefault;
int fFinalDefault;
+ int fTargetNSURI;
+ int fCurrentScope;
+ int fScopeCount;
unsigned int fNamespaceScopeLevel;
XMLCh* fCurrentSchemaURL;
+ const XMLCh* fTargetNSURIString;
+ XMLStringPool* fStringPool;
DOM_Element fSchemaRootElement;
- SchemaInfo* fNext;
- SchemaInfo* fPrev;
+ RefVectorOf<SchemaInfo>* fIncludeList;
+ RefVectorOf<SchemaInfo>* fImportList;
+ RefVectorOf<SchemaInfo>* fImportingList;
+ RefHash2KeysTableOf<SchemaInfo>* fRedefineList;
};
// ---------------------------------------------------------------------------
// SchemaInfo: Getter methods
// ---------------------------------------------------------------------------
-inline bool SchemaInfo::isAttributeDefaultQualified() const {
+inline unsigned short SchemaInfo::getElemAttrDefaultQualified() const {
- return fAttributeDefaultQualified;
+ return fElemAttrDefaultQualified;
}
-
-inline bool SchemaInfo::isElementDefaultQualified() const {
-
- return fElementDefaultQualified;
-}
-
inline int SchemaInfo::getBlockDefault() const {
return fBlockDefault;
@@ -163,28 +196,137 @@
return fCurrentSchemaURL;
}
+inline const XMLCh* const SchemaInfo::getTargetNSURIString() const {
+
+ return fTargetNSURIString;
+}
+
inline DOM_Element SchemaInfo::getRoot() const {
return fSchemaRootElement;
}
-inline SchemaInfo* SchemaInfo::getNext() const {
+inline int SchemaInfo::getTargetNSURI() const {
- return fNext;
+ return fTargetNSURI;
}
-inline SchemaInfo* SchemaInfo::getPrev() const {
+inline int SchemaInfo::getCurrentScope() const {
- return fPrev;
+ return fCurrentScope;
}
+inline int SchemaInfo::getScopeCount() const {
+
+ return fScopeCount;
+}
+inline RefVectorEnumerator<SchemaInfo>
+SchemaInfo::getImportingListEnumerator() const {
+
+ return RefVectorEnumerator<SchemaInfo>(fImportingList);
+}
+
+// ---------------------------------------------------------------------------
+// Setter methods
+// ---------------------------------------------------------------------------
+inline void SchemaInfo::setCurrentScope(const int aValue) {
+
+ fCurrentScope = aValue;
+}
+
+inline void SchemaInfo::setScopeCount(const int aValue) {
+
+ fScopeCount = aValue;
+}
+
// ---------------------------------------------------------------------------
-// SchemaInfo: Setter methods
+// SchemaInfo: Access methods
// ---------------------------------------------------------------------------
-inline void SchemaInfo::setNext(SchemaInfo* const nextInfo) {
+inline void SchemaInfo::addSchemaInfo(SchemaInfo* const toAdd,
+ const ListType aListType) {
+
+ if (aListType == IMPORT) {
+
+ if (!fImportList)
+ fImportList = new RefVectorOf<SchemaInfo>(8, false);
+
+ if (!fImportList->containsElement(toAdd)) {
+ fImportList->addElement(toAdd);
+ toAdd->updateImportingInfo(this);
+ }
+ }
+ else {
+
+ if (!fIncludeList)
+ fIncludeList = new RefVectorOf<SchemaInfo>(8, false);
+
+ if (!fIncludeList->containsElement(toAdd))
+ fIncludeList->addElement(toAdd);
+ }
+}
+
+inline void SchemaInfo::addRedefineInfo(const XMLCh* const categName,
+ const XMLCh* const typeName,
+ SchemaInfo* const toAdd) {
+
+ if (!fRedefineList) {
+ fRedefineList = new RefHash2KeysTableOf<SchemaInfo>(8, false);
+ }
+
+ fRedefineList->put((void*) categName, fStringPool->addOrFind(typeName), toAdd);
+}
+
+inline SchemaInfo* SchemaInfo::getImportInfo(const unsigned int namespaceURI) const {
+
+ unsigned int importSize = (fImportList) ? fImportList->size() : 0;
+ SchemaInfo* currInfo = 0;
+
+ for (unsigned int i=0; i < importSize; i++) {
+
+ currInfo = fImportList->elementAt(i);
+
+ if (currInfo->getTargetNSURI() == (int) namespaceURI)
+ break;
+ }
+
+ return currInfo;
+}
+
+inline SchemaInfo* SchemaInfo::getRedefInfo(const XMLCh* const categName,
+ const XMLCh* const typeName) {
+
+ if (fRedefineList) {
+ return fRedefineList->get(categName, fStringPool->addOrFind(typeName));
+ }
+
+ return 0;
+}
+
+inline bool SchemaInfo::containsInfo(const SchemaInfo* const toCheck,
+ const ListType aListType) const {
+
+ if ((aListType == INCLUDE) && fIncludeList) {
+ return fIncludeList->containsElement(toCheck);
+ }
+ else if ((aListType == IMPORT) && fImportList) {
+ return fImportList->containsElement(toCheck);
+ }
+
+ return false;
+}
+
+inline bool SchemaInfo::circularImportExist(const unsigned int namespaceURI) {
+
+ unsigned int importSize = fImportingList->size();
+
+ for (unsigned int i=0; i < importSize; i++) {
+ if (fImportingList->elementAt(i)->getTargetNSURI() == (int) namespaceURI) {
+ return true;
+ }
+ }
- fNext = nextInfo;
+ return false;
}
#endif
1.19 +4 -1 xml-xerces/c/src/validators/schema/SchemaValidator.cpp
Index: SchemaValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaValidator.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- SchemaValidator.cpp 2001/09/10 14:06:22 1.18
+++ SchemaValidator.cpp 2001/10/04 15:08:56 1.19
@@ -56,6 +56,9 @@
/*
* $Log: SchemaValidator.cpp,v $
+ * Revision 1.19 2001/10/04 15:08:56 knoaman
+ * Add support for circular import.
+ *
* Revision 1.18 2001/09/10 14:06:22 tng
* Schema: AnyAttribute support in Scanner and Validator.
*
@@ -468,7 +471,7 @@
else {
// retrieve complexType registry and DatatypeValidator registry
RefHashTableOf<ComplexTypeInfo>* complexTypeRegistry = sGrammar->getComplexTypeRegistry();
- DatatypeValidatorFactory* dataTypeReg = sGrammar->getDatatypeRegistry();
+ DatatypeValidatorFactory* dataTypeReg = fGrammarResolver->getDatatypeRegistry();
if (!complexTypeRegistry || !dataTypeReg)
emitError(XMLValid::BadXsiType, fXsiType->getRawName());
1.7 +4 -1 xml-xerces/c/src/validators/schema/SubstitutionGroupComparator.cpp
Index: SubstitutionGroupComparator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SubstitutionGroupComparator.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SubstitutionGroupComparator.cpp 2001/08/21 15:57:51 1.6
+++ SubstitutionGroupComparator.cpp 2001/10/04 15:08:56 1.7
@@ -56,6 +56,9 @@
/*
* $Log: SubstitutionGroupComparator.cpp,v $
+ * Revision 1.7 2001/10/04 15:08:56 knoaman
+ * Add support for circular import.
+ *
* Revision 1.6 2001/08/21 15:57:51 tng
* Schema: Add isAllowedByWildcard. Help from James Murphy.
*
@@ -242,7 +245,7 @@
if (!theValidSubstitutionGroups)
return false;
- RefVectorOf<SchemaElementDecl>* subsElements = theValidSubstitutionGroups->get(element->getLocalPart(), uriId);
+ ValueVectorOf<SchemaElementDecl*>* subsElements = theValidSubstitutionGroups->get(element->getLocalPart(), uriId);
if (!subsElements)
return false;
1.51 +895 -882 xml-xerces/c/src/validators/schema/TraverseSchema.cpp
Index: TraverseSchema.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/TraverseSchema.cpp,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- TraverseSchema.cpp 2001/09/18 14:41:56 1.50
+++ TraverseSchema.cpp 2001/10/04 15:08:56 1.51
@@ -55,7 +55,7 @@
*/
/*
- * $Id: TraverseSchema.cpp,v 1.50 2001/09/18 14:41:56 knoaman Exp $
+ * $Id: TraverseSchema.cpp,v 1.51 2001/10/04 15:08:56 knoaman Exp $
*/
// ---------------------------------------------------------------------------
@@ -64,8 +64,6 @@
#include <validators/schema/TraverseSchema.hpp>
#include <validators/datatype/DatatypeValidatorFactory.hpp>
#include <dom/DOM_NamedNodeMap.hpp>
-#include <util/RefVectorOf.hpp>
-#include <util/RefHashTableOf.hpp>
#include <util/Janitor.hpp>
#include <util/KVStringPair.hpp>
#include <util/XMLStringTokenizer.hpp>
@@ -85,13 +83,11 @@
#include <internal/XMLInternalErrorHandler.hpp>
#include <framework/XMLValidator.hpp>
#include <sax/EntityResolver.hpp>
-#include <util/XMLURL.hpp>
#include <sax/InputSource.hpp>
#include <framework/LocalFileInputSource.hpp>
#include <framework/URLInputSource.hpp>
#include <parsers/DOMParser.hpp>
#include <dom/DOM_DOMException.hpp>
-#include <validators/schema/SchemaInfo.hpp>
#include <validators/datatype/InvalidDatatypeValueException.hpp>
#include <validators/datatype/InvalidDatatypeFacetException.hpp>
#include <validators/schema/GeneralAttributeCheck.hpp>
@@ -169,23 +165,17 @@
, XMLValidator* const xmlValidator
, const XMLCh* const schemaURL
, EntityResolver* const entityResolver
- , ErrorHandler* const errorHandler
- , ValueVectorOf<unsigned int>* const importLocations)
- : fElementDefaultQualified(false)
- , fAttributeDefaultQualified(false)
- , fAdoptImportLocations(false)
+ , ErrorHandler* const errorHandler)
+ : fFullConstraintChecking(false)
+ , fElemAttrDefaultQualified(0)
, fTargetNSURI(-1)
, fEmptyNamespaceURI(-1)
, fCurrentScope(Grammar::TOP_LEVEL_SCOPE)
- , fSimpleTypeAnonCount(0)
- , fComplexTypeAnonCount(0)
+ , fAnonXSTypeCount(0)
, fFinalDefault(0)
, fBlockDefault(0)
, fScopeCount(0)
- , fCurrentNamespaceLevel(0)
- , fSchemaRootElement(schemaRoot)
, fTargetNSURIString(0)
- , fCurrentSchemaURL(XMLString::replicate(schemaURL))
, fDatatypeRegistry(0)
, fGrammarResolver(grammarResolver)
, fSchemaGrammar(schemaGrammar)
@@ -200,13 +190,11 @@
, fComplexTypeRegistry(0)
, fGroupRegistry(0)
, fAttGroupRegistry(0)
- , fIncludeLocations(0)
- , fSchemaInfoRoot(0)
- , fCurrentSchemaInfo(0)
+ , fSchemaInfoList(0)
+ , fSchemaInfo(0)
, fCurrentGroupInfo(0)
, fCurrentAttGroupInfo(0)
, fCurrentComplexType(0)
- , fImportLocations(importLocations)
, fCurrentTypeNameStack(0)
, fCurrentGroupStack(0)
, fAttributeCheck(0)
@@ -222,7 +210,12 @@
{
try {
- doTraverseSchema();
+
+ if (fGrammarResolver && !schemaRoot.isNull()) {
+
+ init();
+ doTraverseSchema(schemaRoot, schemaURL);
+ }
}
catch(...) {
@@ -241,178 +234,153 @@
// ---------------------------------------------------------------------------
// TraverseSchema: Traversal methods
// ---------------------------------------------------------------------------
-void TraverseSchema::doTraverseSchema() {
-
- fDatatypeRegistry = fGrammarResolver->getDatatypeRegistry();
- fDatatypeRegistry->expandRegistryToFullSchemaSet();
-
- if (!fImportLocations) {
- fAdoptImportLocations = true;
- fImportLocations = new ValueVectorOf<unsigned int>(8);
- }
-
- unsigned int schemaURLId = fURIStringPool->addOrFind(fCurrentSchemaURL);
- fImportLocations->addElement(schemaURLId);
-
- if (fSchemaRootElement.isNull()) {
- // REVISIT: Anything to do?
- return;
- }
-
- fStringPool = fGrammarResolver->getStringPool();
- fEmptyNamespaceURI = fURIStringPool->addOrFind(XMLUni::fgZeroLenString);
- fAttributeCheck = GeneralAttributeCheck::instance();
- fCurrentTypeNameStack = new ValueVectorOf<unsigned int>(8);
- fCurrentGroupStack = new ValueVectorOf<unsigned int>(8);
- fGlobalTypes = new RefHash2KeysTableOf<XMLCh>(29, false);
- fGlobalAttributes = new RefHash2KeysTableOf<XMLCh>(13, false);
- fGlobalGroups = new RefHash2KeysTableOf<XMLCh>(13, false);
- fGlobalAttGroups = new RefHash2KeysTableOf<XMLCh>(13, false);
- fSubstitutionGroups = new RefHash2KeysTableOf<SchemaElementDecl>(29, false);
- fRefElements = new RefVectorOf<SchemaElementDecl>(32, false);
- fRefElemScope = new ValueVectorOf<int>(32);
+void TraverseSchema::doTraverseSchema(const DOM_Element& schemaRoot,
+ const XMLCh* const schemaURL) {
// Make sure namespace binding is defaulted
- DOMString rootPrefix = fSchemaRootElement.getPrefix();
+ DOM_Element rootElem = schemaRoot;
+ DOMString rootPrefix = schemaRoot.getPrefix();
if (rootPrefix == 0 || rootPrefix.length() == 0) {
- DOMString xmlns = fSchemaRootElement.getAttribute(XMLUni::fgXMLNSString);
+ DOMString xmlns = rootElem.getAttribute(XMLUni::fgXMLNSString);
if (xmlns.length() == 0) {
- fSchemaRootElement.setAttribute(
- XMLUni::fgXMLNSString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
+ rootElem.setAttribute(XMLUni::fgXMLNSString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
}
}
-
- //Retrieve the targetnamespace URI information
- DOMString targetNSURIStr = fSchemaRootElement.getAttribute(
- SchemaSymbols::fgATT_TARGETNAMESPACE);
- if (targetNSURIStr == 0) {
- fTargetNSURIString = XMLString::replicate(XMLUni::fgZeroLenString);
- }
- else {
+ if (fFullConstraintChecking) {
- fBuffer.set(targetNSURIStr.rawBuffer(), targetNSURIStr.length());
- fTargetNSURIString = XMLString::replicate(fBuffer.getRawBuffer());
+ fRefElements = new RefVectorOf<QName>(32);
+ fRefElemScope = new ValueVectorOf<int>(32);
}
- fTargetNSURI = fURIStringPool->addOrFind(fTargetNSURIString);
-
// Set schemaGrammar data and add it to GrammarResolver
- if (fGrammarResolver == 0) {
+ // For complex type registry, attribute decl registry , group/attGroup
+ // and namespace mapping, needs to check whether the passed in
+ // Grammar was a newly instantiated one.
+ fComplexTypeRegistry = fSchemaGrammar->getComplexTypeRegistry();
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoGrammarResolver);
- return;
+ if (fComplexTypeRegistry == 0 ) {
+
+ fComplexTypeRegistry = new RefHashTableOf<ComplexTypeInfo>(29);
+ fSchemaGrammar->setComplexTypeRegistry(fComplexTypeRegistry);
}
- else{
- // for complex type registry, attribute decl registry , group/attGroup
- // and namespace mapping, needs to check whether the passed in
- // Grammar was a newly instantiated one.
- fComplexTypeRegistry = fSchemaGrammar->getComplexTypeRegistry();
+ fGroupRegistry = fSchemaGrammar->getGroupInfoRegistry();
- if (fComplexTypeRegistry == 0 ) {
+ if (fGroupRegistry == 0 ) {
- fComplexTypeRegistry = new RefHashTableOf<ComplexTypeInfo>(109);
- fSchemaGrammar->setComplexTypeRegistry(fComplexTypeRegistry);
- }
+ fGroupRegistry = new RefHashTableOf<XercesGroupInfo>(13);
+ fSchemaGrammar->setGroupInfoRegistry(fGroupRegistry);
+ }
- fGroupRegistry = fSchemaGrammar->getGroupInfoRegistry();
+ fAttGroupRegistry = fSchemaGrammar->getAttGroupInfoRegistry();
- if (fGroupRegistry == 0 ) {
+ if (fAttGroupRegistry == 0 ) {
- fGroupRegistry = new RefHashTableOf<XercesGroupInfo>(13);
- fSchemaGrammar->setGroupInfoRegistry(fGroupRegistry);
- }
+ fAttGroupRegistry = new RefHashTableOf<XercesAttGroupInfo>(13);
+ fSchemaGrammar->setAttGroupInfoRegistry(fAttGroupRegistry);
+ }
- fAttGroupRegistry = fSchemaGrammar->getAttGroupInfoRegistry();
+ fAttributeDeclRegistry = fSchemaGrammar->getAttributeDeclRegistry();
- if (fAttGroupRegistry == 0 ) {
+ if (fAttributeDeclRegistry == 0) {
- fAttGroupRegistry = new RefHashTableOf<XercesAttGroupInfo>(13);
- fSchemaGrammar->setAttGroupInfoRegistry(fAttGroupRegistry);
- }
+ fAttributeDeclRegistry = new RefHashTableOf<XMLAttDef>(29);
+ fSchemaGrammar->setAttributeDeclRegistry(fAttributeDeclRegistry);
+ }
- fAttributeDeclRegistry = fSchemaGrammar->getAttributeDeclRegistry();
+ fNamespaceScope = fSchemaGrammar->getNamespaceScope();
- if (fAttributeDeclRegistry == 0) {
+ if (fNamespaceScope == 0) {
- fAttributeDeclRegistry = new RefHashTableOf<XMLAttDef>(29, true);
- fSchemaGrammar->setAttributeDeclRegistry(fAttributeDeclRegistry);
- }
+ fNamespaceScope = new NamespaceScope();
+ fNamespaceScope->reset(fEmptyNamespaceURI);
+ fSchemaGrammar->setNamespaceScope(fNamespaceScope);
+ }
- fNamespaceScope = fSchemaGrammar->getNamespaceScope();
+ unsigned int namespaceDepth = fNamespaceScope->increaseDepth();
- if (fNamespaceScope == 0) {
+ fValidSubstitutionGroups = fSchemaGrammar->getValidSubstitutionGroups();
- fNamespaceScope = new NamespaceScope();
- fNamespaceScope->reset(fEmptyNamespaceURI);
- fCurrentNamespaceLevel = fNamespaceScope->increaseDepth();
- fSchemaGrammar->setNamespaceScope(fNamespaceScope);
- }
+ if (!fValidSubstitutionGroups) {
- fValidSubstitutionGroups = fSchemaGrammar->getValidSubstitutionGroups();
+ fValidSubstitutionGroups = new RefHash2KeysTableOf<ElemVector>(29);
+ fSchemaGrammar->setValidSubstitutionGroups(fValidSubstitutionGroups);
+ }
- if (!fValidSubstitutionGroups) {
+ //Retrieve the targetnamespace URI information
+ DOMString targetNSURIStr = schemaRoot.getAttribute(SchemaSymbols::fgATT_TARGETNAMESPACE);
- fValidSubstitutionGroups = new RefHash2KeysTableOf<ElemVector>(29);
- fSchemaGrammar->setValidSubstitutionGroups(fValidSubstitutionGroups);
- }
+ if (targetNSURIStr == 0) {
+ fSchemaGrammar->setTargetNamespace(XMLUni::fgZeroLenString);
+ }
+ else {
+
+ fBuffer.set(targetNSURIStr.rawBuffer(), targetNSURIStr.length());
+ fSchemaGrammar->setTargetNamespace(fBuffer.getRawBuffer());
+ }
- fSchemaGrammar->setDatatypeRegistry(fDatatypeRegistry);
- fSchemaGrammar->setTargetNamespace(fTargetNSURIString);
- fGrammarResolver->putGrammar(fSchemaGrammar->getTargetNamespace(),
- fSchemaGrammar);
- } // end else
+ fTargetNSURIString = fSchemaGrammar->getTargetNamespace();
+ fTargetNSURI = fURIStringPool->addOrFind(fTargetNSURIString);
+ fGrammarResolver->putGrammar(fTargetNSURIString, fSchemaGrammar);
- traverseSchemaHeader();
+ traverseSchemaHeader(rootElem);
// Save current schema info
- fIncludeLocations = new RefHashTableOf<SchemaInfo>(13, false);
- fSchemaInfoRoot = new SchemaInfo(fElementDefaultQualified,
- fAttributeDefaultQualified,
- fBlockDefault,
- fFinalDefault,
- fCurrentNamespaceLevel,
- fCurrentSchemaURL,
- fSchemaRootElement,
- 0, 0);
- fCurrentSchemaInfo = fSchemaInfoRoot;
- fIncludeLocations->put((void*) fCurrentSchemaInfo->getCurrentSchemaURL(), fCurrentSchemaInfo);
+ SchemaInfo* currInfo = new SchemaInfo(fElemAttrDefaultQualified, fBlockDefault,
+ fFinalDefault, fTargetNSURI, fCurrentScope,
+ fScopeCount, namespaceDepth,
+ XMLString::replicate(schemaURL),
+ fTargetNSURIString, fStringPool, schemaRoot);
+
+ if (fSchemaInfo) {
+ fSchemaInfo->addSchemaInfo(currInfo, SchemaInfo::IMPORT);
+ }
+
+ fSchemaInfo = currInfo;
+ fSchemaInfoList->put((void*) fSchemaInfo->getCurrentSchemaURL(), fSchemaInfo);
// process children nodes
- processChildren(fSchemaRootElement);
+ fCurrentScope = Grammar::TOP_LEVEL_SCOPE;
+ fScopeCount = 0;
+ processChildren(schemaRoot);
// Handle identity constraints
// TO DO
// Element consistency checks - substitution groups
- checkRefElementConsistency();
+ if (fFullConstraintChecking) {
+ checkRefElementConsistency();
+ }
}
-void TraverseSchema::traverseSchemaHeader() {
+void TraverseSchema::traverseSchemaHeader(const DOM_Element& schemaRoot) {
// -----------------------------------------------------------------------
// Check Attributes
// -----------------------------------------------------------------------
unsigned short scope = GeneralAttributeCheck::GlobalContext;
- fAttributeCheck->checkAttributes(fSchemaRootElement, scope, this);
+ fAttributeCheck->checkAttributes(schemaRoot, scope, this);
+
+ retrieveNamespaceMapping(schemaRoot);
+ fElemAttrDefaultQualified = 0;
- retrieveNamespaceMapping();
+ if (schemaRoot.getAttribute(SchemaSymbols::fgATT_ELEMENTFORMDEFAULT).equals(SchemaSymbols::fgATTVAL_QUALIFIED)) {
+ fElemAttrDefaultQualified |= Elem_Def_Qualified;
+ }
- fElementDefaultQualified =
- fSchemaRootElement.getAttribute(SchemaSymbols::fgATT_ELEMENTFORMDEFAULT).equals(SchemaSymbols::fgATTVAL_QUALIFIED);
- fAttributeDefaultQualified =
- fSchemaRootElement.getAttribute(SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT).equals(SchemaSymbols::fgATTVAL_QUALIFIED);
+ if (schemaRoot.getAttribute(SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT).equals(SchemaSymbols::fgATTVAL_QUALIFIED)) {
+ fElemAttrDefaultQualified |= Attr_Def_Qualified;
+ }
// Get finalDefault/blockDefault values
- const XMLCh* defaultVal = getElementAttValue(fSchemaRootElement,
- SchemaSymbols::fgATT_BLOCKDEFAULT);
- const XMLCh* finalVal = getElementAttValue(fSchemaRootElement,
- SchemaSymbols::fgATT_FINALDEFAULT);
+ const XMLCh* defaultVal = getElementAttValue(schemaRoot, SchemaSymbols::fgATT_BLOCKDEFAULT);
+ const XMLCh* finalVal = getElementAttValue(schemaRoot, SchemaSymbols::fgATT_FINALDEFAULT);
+
fBlockDefault = parseBlockSet(defaultVal, ES_Block);
fFinalDefault = parseFinalSet(finalVal, ECS_Final);
}
@@ -474,8 +442,7 @@
// ------------------------------------------------------------------
// Get 'schemaLocation' attribute
// ------------------------------------------------------------------
- const XMLCh* schemaLocation =
- getElementAttValue(elem, SchemaSymbols::fgATT_SCHEMALOCATION);
+ const XMLCh* schemaLocation = getElementAttValue(elem, SchemaSymbols::fgATT_SCHEMALOCATION);
if (XMLString::stringLen(schemaLocation) == 0) {
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNoSchemaLocation, SchemaSymbols::fgELT_INCLUDE);
@@ -494,8 +461,11 @@
}
const XMLCh* includeURL = srcToFill->getSystemId();
+ SchemaInfo* includeSchemaInfo = fSchemaInfoList->get(includeURL);
+
+ if (includeSchemaInfo) {
- if (fIncludeLocations->containsKey(includeURL)) {
+ fSchemaInfo->addSchemaInfo(includeSchemaInfo, SchemaInfo::INCLUDE);
return;
}
@@ -526,48 +496,47 @@
if (!root.isNull()) {
- const XMLCh* targetNSURIString =
- getElementAttValue(root,SchemaSymbols::fgATT_TARGETNAMESPACE);
+ const XMLCh* targetNSURIString = getElementAttValue(root,SchemaSymbols::fgATT_TARGETNAMESPACE);
+ unsigned int targetNSLength = XMLString::stringLen(targetNSURIString);
- if (XMLString::stringLen(targetNSURIString) != 0
- && XMLString::compareString(targetNSURIString,
- fTargetNSURIString) != 0){
+ // check to see if targetNameSpace is right
+ if (targetNSLength != 0
+ && XMLString::compareString(targetNSURIString,fTargetNSURIString) != 0){
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::IncludeNamespaceDifference,
schemaLocation, targetNSURIString);
+ return;
}
- else {
- // --------------------------------------------------------
- // Update schema information with included schema
- // --------------------------------------------------------
- fCurrentNamespaceLevel = fNamespaceScope->increaseDepth();
- fSchemaRootElement = root;
- setCurrentSchemaURL(includeURL);
- traverseSchemaHeader();
-
- // and now we'd better save this stuff!
- fCurrentSchemaInfo =
- new SchemaInfo(fElementDefaultQualified,
- fAttributeDefaultQualified,
- fBlockDefault,
- fFinalDefault,
- fCurrentNamespaceLevel,
- fCurrentSchemaURL,
- fSchemaRootElement,
- fCurrentSchemaInfo->getNext(),
- fCurrentSchemaInfo);
-
- fIncludeLocations->put((void*) fCurrentSchemaInfo->getCurrentSchemaURL(),
- fCurrentSchemaInfo);
-
- (fCurrentSchemaInfo->getPrev())->setNext(fCurrentSchemaInfo);
- processChildren(fSchemaRootElement);
-
- // --------------------------------------------------------
- // Restore old schema information
- // --------------------------------------------------------
- restoreSchemaInfo(fCurrentSchemaInfo->getPrev());
- }
+ // if targetNamespace is empty, change it to includ'g schema
+ // targetNamespace
+ if (targetNSLength == 0 && root.getAttributeNode(XMLUni::fgXMLNSString) == 0
+ && fTargetNSURI != fEmptyNamespaceURI) {
+ root.setAttribute(XMLUni::fgXMLNSString, fTargetNSURIString);
+ }
+
+ // --------------------------------------------------------
+ // Update schema information with included schema
+ // --------------------------------------------------------
+ unsigned int namespaceDepth = fNamespaceScope->increaseDepth();
+ fElemAttrDefaultQualified = 0;
+ traverseSchemaHeader(root);
+
+ // and now we'd better save this stuff!
+ SchemaInfo* saveInfo = fSchemaInfo;
+ fSchemaInfo = new SchemaInfo(fElemAttrDefaultQualified, fBlockDefault,
+ fFinalDefault, fTargetNSURI, fCurrentScope,
+ fScopeCount, namespaceDepth,
+ XMLString::replicate(includeURL),
+ fTargetNSURIString, fStringPool, root);
+
+ fSchemaInfoList->put((void*) fSchemaInfo->getCurrentSchemaURL(), fSchemaInfo);
+ saveInfo->addSchemaInfo(fSchemaInfo, SchemaInfo::INCLUDE);
+ processChildren(root);
+
+ // --------------------------------------------------------
+ // Restore old schema information
+ // --------------------------------------------------------
+ restoreSchemaInfo(saveInfo);
}
}
}
@@ -609,32 +578,18 @@
return;
}
- if (!XMLString::stringLen(nameSpace)
- && fTargetNSURI == fEmptyNamespaceURI) {
+ if (!XMLString::stringLen(nameSpace) && fTargetNSURI == fEmptyNamespaceURI) {
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::Import_1_2);
return;
}
- SchemaGrammar* importedGrammar = 0;
-
- if (nameSpace) {
-
- importedGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(nameSpace);
-
- if (importedGrammar) {
- return;
- }
- }
-
// ------------------------------------------------------------------
// Get 'schemaLocation' attribute
// ------------------------------------------------------------------
- const XMLCh* schemaLocation =
- getElementAttValue(elem, SchemaSymbols::fgATT_SCHEMALOCATION);
+ const XMLCh* schemaLocation = getElementAttValue(elem, SchemaSymbols::fgATT_SCHEMALOCATION);
if (XMLString::stringLen(schemaLocation) == 0) {
-// reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNoSchemaLocation, SchemaSymbols::fgELT_IMPORT);
return;
}
@@ -650,12 +605,25 @@
}
const XMLCh* importURL = srcToFill->getSystemId();
- unsigned int locationId = fURIStringPool->addOrFind(importURL);
+ SchemaInfo* importSchemaInfo = fSchemaInfoList->get(importURL);
+
+ if (importSchemaInfo) {
- if (fImportLocations->containsElement(locationId)) {
+ fSchemaInfo->addSchemaInfo(importSchemaInfo, SchemaInfo::IMPORT);
return;
}
+ SchemaGrammar* importedGrammar = 0;
+
+ if (nameSpace) {
+
+ importedGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(nameSpace);
+
+ if (importedGrammar) {
+ return;
+ }
+ }
+
// ------------------------------------------------------------------
// Parse input source
// ------------------------------------------------------------------
@@ -666,13 +634,11 @@
parser.setDoNamespaces(true);
parser.setErrorHandler((ErrorHandler*) &internalErrorHandler);
parser.setEntityResolver(fEntityResolver);
-
parser.parse(*srcToFill);
if (internalErrorHandler.getSawFatal() && fScanner->getExitOnFirstFatal())
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::SchemaScanFatalError);
-
// ------------------------------------------------------------------
// Get root element
// ------------------------------------------------------------------
@@ -681,29 +647,46 @@
if (!document.isNull()) {
DOM_Element root = document.getDocumentElement();
-
- if (!root.isNull()) {
- const XMLCh* targetNSURIString =
- getElementAttValue(root,SchemaSymbols::fgATT_TARGETNAMESPACE);
+ if (root.isNull()) {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::ImportRootError, schemaLocation);
+ return;
+ }
- if (XMLString::compareString(targetNSURIString, nameSpace) != 0) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::ImportNamespaceDifference,
- schemaLocation, targetNSURIString, nameSpace);
- }
- else {
+ const XMLCh* targetNSURIString = getElementAttValue(root,SchemaSymbols::fgATT_TARGETNAMESPACE);
- importedGrammar = new SchemaGrammar();
+ if (XMLString::compareString(targetNSURIString, nameSpace) != 0) {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::ImportNamespaceDifference,
+ schemaLocation, targetNSURIString, nameSpace);
+ }
+ else {
- TraverseSchema traverseSchema(root, fURIStringPool, importedGrammar,
- fGrammarResolver, fScanner, fValidator,
- importURL, fEntityResolver, fErrorHandler,
- fImportLocations);
- }
- }
- else {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::ImportRootError, schemaLocation);
- }
+ // --------------------------------------------------------
+ // Traverse new schema
+ // --------------------------------------------------------
+ SchemaInfo* saveInfo = fSchemaInfo;
+ fSchemaGrammar = new SchemaGrammar();
+ Janitor<RefVectorOf<QName> > janElem(fRefElements);
+ Janitor<ValueVectorOf<int> > janElemScope(fRefElemScope);
+ doTraverseSchema(root, importURL);
+
+ // --------------------------------------------------------
+ // Restore old schema information
+ // --------------------------------------------------------
+ restoreSchemaInfo(saveInfo, SchemaInfo::IMPORT);
+
+ // reset fRefElements && fRefElemScope
+ if (fFullConstraintChecking) {
+
+ RefVectorOf<QName>* tmpElems = fRefElements;
+ ValueVectorOf<int>* tmpElemScope = fRefElemScope;
+
+ fRefElements = janElem.release();
+ fRefElemScope = janElemScope.release();
+ janElem.reset(tmpElems);
+ janElemScope.reset(tmpElemScope);
+ }
+ }
}
}
@@ -733,7 +716,7 @@
// actually go through the schema being redefined and convert it to a
// grammar. Only then do we run through redefineDecl's kids and put them
// in the grammar.
- SchemaInfo* redefiningInfo = fCurrentSchemaInfo;
+ SchemaInfo* redefiningInfo = fSchemaInfo;
if (!openRedefinedSchema(redefineElem)) {
return;
@@ -743,14 +726,14 @@
fRedefineComponents = new RefHash2KeysTableOf<XMLCh>(13, false);
}
- SchemaInfo* redefinedInfo = fCurrentSchemaInfo;
+ SchemaInfo* redefinedInfo = fSchemaInfo;
renameRedefinedComponents(redefineElem, redefiningInfo, redefinedInfo);
// Now we have to march through our nicely-renamed schemas. When
// we do these traversals other <redefine>'s may perhaps be
// encountered; we leave recursion to sort this out.
restoreSchemaInfo(redefinedInfo);
- processChildren(fSchemaRootElement);
+ processChildren(fSchemaInfo->getRoot());
// Now traverse our own <redefine>
restoreSchemaInfo(redefiningInfo);
@@ -770,8 +753,7 @@
*/
ContentSpecNode*
TraverseSchema::traverseChoiceSequence(const DOM_Element& elem,
- const int modelGroupType,
- bool& toAdoptSpecNode)
+ const int modelGroupType)
{
// ------------------------------------------------------------------
@@ -787,25 +769,26 @@
ContentSpecNode* left = 0;
ContentSpecNode* right = 0;
bool hadContent = false;
- bool toAdoptLeft = true;
- bool toAdoptRight = true;
for (; child != 0; child = XUtil::getNextSiblingElement(child)) {
ContentSpecNode* contentSpecNode = 0;
- ContentSpecNode* expandedSpecNode = 0;
bool seeParticle = false;
- bool adoptSpecNode = true;
DOMString childName = child.getLocalName();
if (childName.equals(SchemaSymbols::fgELT_ELEMENT)) {
- QName* eltQName = traverseElementDecl(child);
- Janitor<QName> janQName(eltQName);
+ bool toDelete = true;
+ Janitor<QName> janQName(0);
+ QName* eltQName = traverseElementDecl(child, toDelete);
if (eltQName == 0) {
continue;
}
+
+ if (toDelete) {
+ janQName.reset(eltQName);
+ }
contentSpecNode = new ContentSpecNode(eltQName);
seeParticle = true;
@@ -835,13 +818,11 @@
}
else if (childName.equals(SchemaSymbols::fgELT_CHOICE)) {
- contentSpecNode =
- traverseChoiceSequence(child,ContentSpecNode::Choice, adoptSpecNode);
+ contentSpecNode = traverseChoiceSequence(child,ContentSpecNode::Choice);
seeParticle = true;
}
else if (childName.equals(SchemaSymbols::fgELT_SEQUENCE)) {
- contentSpecNode =
- traverseChoiceSequence(child,ContentSpecNode::Sequence, adoptSpecNode);
+ contentSpecNode = traverseChoiceSequence(child,ContentSpecNode::Sequence);
seeParticle = true;
}
else if (childName.equals(SchemaSymbols::fgELT_ANY)) {
@@ -863,32 +844,22 @@
checkMinMax(contentSpecNode, child, Not_All_Context);
}
- expandedSpecNode = contentSpecNode;
-
if (left == 0) {
- left = expandedSpecNode;
- toAdoptLeft = adoptSpecNode;
+ left = contentSpecNode;
}
else if (right == 0) {
- right = expandedSpecNode;
- toAdoptRight = adoptSpecNode;
+ right = contentSpecNode;
}
else {
- left = new ContentSpecNode((ContentSpecNode::NodeTypes) modelGroupType,
- left, right, toAdoptLeft, toAdoptRight);
- right = expandedSpecNode;
- toAdoptLeft = true;
- toAdoptRight = adoptSpecNode;
+ left = new ContentSpecNode((ContentSpecNode::NodeTypes) modelGroupType, left, right);
+ right = contentSpecNode;
}
}
if (hadContent) {
- left = new ContentSpecNode((ContentSpecNode::NodeTypes) modelGroupType,
- left, right, toAdoptLeft, toAdoptRight);
- toAdoptLeft = true;
+ left = new ContentSpecNode((ContentSpecNode::NodeTypes) modelGroupType, left, right);
}
- toAdoptSpecNode = toAdoptLeft;
return left;
}
@@ -926,7 +897,7 @@
}
if (XMLString::stringLen(name) == 0) { // anonymous simpleType
- name = genAnonTypeName(fgAnonSNamePrefix, fSimpleTypeAnonCount);
+ name = genAnonTypeName(fgAnonSNamePrefix);
}
fBuffer.set(fTargetNSURIString);
@@ -934,7 +905,7 @@
fBuffer.append(name);
XMLCh* fullName = fBuffer.getRawBuffer();
- int fullTypeName = fStringPool->addOrFind(fullName);
+ int fullTypeNameId = fStringPool->addOrFind(fullName);
//check if we have already traversed the same simpleType decl
if (fDatatypeRegistry->getDatatypeValidator(fullName)!= 0) {
@@ -942,13 +913,13 @@
}
// Circular constraint checking
- if (fCurrentTypeNameStack->containsElement(fullTypeName)){
+ if (fCurrentTypeNameStack->containsElement(fullTypeNameId)){
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, name);
return -1;
}
- fCurrentTypeNameStack->addElement(fullTypeName);
+ fCurrentTypeNameStack->addElement(fullTypeNameId);
// Get 'final' values
const XMLCh* finalVal = getElementAttValue(childElem, SchemaSymbols::fgATT_FINAL);
@@ -1028,7 +999,7 @@
return -1;
}
- name = genAnonTypeName(fgAnonCNamePrefix, fComplexTypeAnonCount);
+ name = genAnonTypeName(fgAnonCNamePrefix);
}
if (!XMLString::isValidNCName(name)) {
@@ -1250,13 +1221,13 @@
}
int saveScope = fCurrentScope;
- unsigned int fullNameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer());
- const XMLCh* fullName = fStringPool->getValueForId(fullNameIndex);
+// unsigned int fullNameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer());
+ const XMLCh* fullName = fStringPool->getValueForId(nameIndex);
ContentSpecNode* specNode = 0;
XercesGroupInfo* saveGroupInfo = fCurrentGroupInfo;
groupInfo = new XercesGroupInfo();
- fCurrentGroupStack->addElement(fullNameIndex);
+ fCurrentGroupStack->addElement(nameIndex);
fCurrentGroupInfo = groupInfo;
if (!saveGroupInfo && !fCurrentComplexType) {
@@ -1276,14 +1247,13 @@
}
bool illegalChild = false;
- bool adoptSpecNode = true;
DOMString childName = content.getLocalName();
if (childName.equals(SchemaSymbols::fgELT_SEQUENCE)) {
- specNode = traverseChoiceSequence(content, ContentSpecNode::Sequence, adoptSpecNode);
+ specNode = traverseChoiceSequence(content, ContentSpecNode::Sequence);
}
else if (childName.equals(SchemaSymbols::fgELT_CHOICE)) {
- specNode = traverseChoiceSequence(content, ContentSpecNode::Choice, adoptSpecNode);
+ specNode = traverseChoiceSequence(content, ContentSpecNode::Choice);
}
else if (childName.equals(SchemaSymbols::fgELT_ALL)) {
specNode = traverseAll(content);
@@ -1314,35 +1284,6 @@
return groupInfo;
}
-XercesGroupInfo*
-TraverseSchema::traverseGroupDeclNS(const XMLCh* const uriStr,
- const XMLCh* const name) {
-
- // ------------------------------------------------------------------
- // Get grammar information
- // ------------------------------------------------------------------
- SchemaGrammar* aGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(uriStr);
-
- if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
-
- reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uriStr);
- return 0;
- }
-
- fBuffer.set(uriStr);
- fBuffer.append(chComma);
- fBuffer.append(name);
-
- XercesGroupInfo* groupInfo = aGrammar->getGroupInfoRegistry()->get(fBuffer.getRawBuffer());
-
- if (!groupInfo) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_GROUP, uriStr, name);
- }
-
- return groupInfo;
-}
-
/**
* Traverse attributeGroup Declaration.
@@ -1463,14 +1404,14 @@
}
-XercesAttGroupInfo*
+inline XercesAttGroupInfo*
TraverseSchema::traverseAttributeGroupDeclNS(const XMLCh* const uriStr,
const XMLCh* const name) {
// ------------------------------------------------------------------
// Get grammar information
// ------------------------------------------------------------------
- SchemaGrammar* aGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(uriStr);
+ Grammar* aGrammar = fGrammarResolver->getGrammar(uriStr);
if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
@@ -1478,17 +1419,11 @@
return 0;
}
- XercesAttGroupInfo* attGroupInfo = aGrammar->getAttGroupInfoRegistry()->get(name);
+ XercesAttGroupInfo* attGroupInfo = ((SchemaGrammar*)aGrammar)->getAttGroupInfoRegistry()->get(name);
- if (!attGroupInfo) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, name);
- }
-
return attGroupInfo;
}
-
/**
* Traverse Any declaration
*
@@ -1658,13 +1593,18 @@
if (childName.equals(SchemaSymbols::fgELT_ELEMENT)) {
- QName* eltQName = traverseElementDecl(child);
- Janitor<QName> janQName(eltQName);
+ bool toDelete = true;
+ Janitor<QName> janQName(0);
+ QName* eltQName = traverseElementDecl(child, toDelete);
if (eltQName == 0) {
continue;
}
+ if (toDelete) {
+ janQName.reset(eltQName);
+ }
+
contentSpecNode = new ContentSpecNode(eltQName);
checkMinMax(contentSpecNode, child, All_Element);
}
@@ -1806,7 +1746,7 @@
if (XMLString::stringLen(fTargetNSURIString) != 0
&& (topLevel || XMLString::compareString(attForm, qualified) == 0
- || (fAttributeDefaultQualified
+ || ((fSchemaInfo->getElemAttrDefaultQualified() & Attr_Def_Qualified)
&& XMLString::stringLen(attForm) == 0))) {
uriIndex = fTargetNSURI;
}
@@ -1826,6 +1766,7 @@
DatatypeValidator* dv = 0;
XMLAttDef::AttTypes attType;
DOMString contentName;
+ SchemaInfo* saveInfo = fSchemaInfo;
while (simpleType != 0) {
@@ -1865,7 +1806,8 @@
const XMLCh* localPart = getLocalPart(typeAttr);
const XMLCh* prefix = getPrefix(typeAttr);
- const XMLCh* typeURI = resolvePrefixToURI(prefix);
+ const XMLCh* typeURI = resolvePrefixToURI(prefix);
+
if (XMLString::compareString(typeURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) == 0) {
dv = getDatatypeValidator(SchemaSymbols::fgURI_SCHEMAFORSCHEMA, localPart);
@@ -1900,21 +1842,13 @@
if (dv == 0 && XMLString::stringLen(typeURI) == 0) {
- // save current schema information
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element topLevelType =
- getTopLevelComponentByName(SchemaSymbols::fgELT_SIMPLETYPE, localPart);
+ DOM_Element topLevelType =
+ fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
if (topLevelType != 0) {
traverseSimpleTypeDecl(topLevelType);
dv = getDatatypeValidator(typeURI, localPart);
-
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
-
}
else {
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::AttributeSimpleTypeNotFound,
@@ -1928,27 +1862,19 @@
// check if the type is from the same Schema
dv = getDatatypeValidator(typeURI, localPart);
- if (dv == 0
- && XMLString::compareString(typeURI, fTargetNSURIString) == 0) {
+ if (dv == 0 && !XMLString::compareString(typeURI, fTargetNSURIString)) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
DOM_Element topLevelType =
- getTopLevelComponentByName(SchemaSymbols::fgELT_SIMPLETYPE,
- localPart);
+ fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
if (topLevelType != 0) {
traverseSimpleTypeDecl(topLevelType);
dv = getDatatypeValidator(typeURI, localPart);
-
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
}
else {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::AttributeSimpleTypeNotFound,
- typeURI, localPart, name);
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::AttributeSimpleTypeNotFound,
+ typeURI, localPart, name);
}
}
@@ -1960,24 +1886,24 @@
}
}
+ // restore schema information, if necessary
+ fSchemaInfo = saveInfo;
+
bool required = false;
bool prohibited = false;
if (XMLString::stringLen(useVal) != 0) {
- if (XMLString::compareString(useVal,
- SchemaSymbols::fgATTVAL_REQUIRED) == 0) {
+ if (!XMLString::compareString(useVal, SchemaSymbols::fgATTVAL_REQUIRED)) {
required = true;
}
- else if (XMLString::compareString(useVal,
- SchemaSymbols::fgATTVAL_PROHIBITED) == 0) {
+ else if (!XMLString::compareString(useVal, SchemaSymbols::fgATTVAL_PROHIBITED)) {
prohibited = true;
}
}
// validate fixed/default values
- const XMLCh* valueToCheck = XMLString::stringLen(defaultVal) != 0
- ? defaultVal : fixedVal;
+ const XMLCh* valueToCheck = XMLString::stringLen(defaultVal) ? defaultVal : fixedVal;
if (attType == XMLAttDef::Simple && dv != 0
&& XMLString::stringLen(valueToCheck) != 0) {
@@ -2000,8 +1926,7 @@
}
// create SchemaAttDef
- SchemaAttDef* attDef =
- new SchemaAttDef(XMLUni::fgZeroLenString, name, uriIndex, attType);
+ SchemaAttDef* attDef = new SchemaAttDef(XMLUni::fgZeroLenString, name, uriIndex, attType);
attDef->setDatatypeValidator(dv);
@@ -2075,7 +2000,7 @@
*
* @param elem: the declaration of the element under consideration
*/
-QName* TraverseSchema::traverseElementDecl(const DOM_Element& elem) {
+QName* TraverseSchema::traverseElementDecl(const DOM_Element& elem, bool& toDelete) {
bool topLevel = isTopLevelComponent(elem);
const XMLCh* name = getElementAttValue(elem, SchemaSymbols::fgATT_NAME);
@@ -2120,7 +2045,7 @@
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::BadAttWithRef);
}
- return processElementDeclRef(elem, ref);
+ return processElementDeclRef(elem, ref, toDelete);
}
// Name is notEmpty
@@ -2278,8 +2203,7 @@
if (XMLString::stringLen(subsGroupName) != 0) {
- SchemaElementDecl* subsElemDecl =
- getSubstituteGroupElemDecl(subsGroupName, noErrorFound);
+ SchemaElementDecl* subsElemDecl = getSubstituteGroupElemDecl(subsGroupName, noErrorFound);
if (subsElemDecl != 0) {
@@ -2317,16 +2241,50 @@
elemDecl->setSubstitutionGroupName(fBuffer.getRawBuffer());
fSubstitutionGroups->put((void*) elemBaseName, elemURI, subsElemDecl);
- RefVectorOf<SchemaElementDecl>* subsElements =
+ ValueVectorOf<SchemaElementDecl*>* subsElements =
fValidSubstitutionGroups->get(subsElemBaseName, subsElemURI);
- if (!subsElements) {
+ if (!subsElements && fTargetNSURI != subsElemURI) {
+
+ SchemaGrammar* aGrammar = (SchemaGrammar*)
+ fGrammarResolver->getGrammar(fURIStringPool->getValueForId(subsElemURI));
+
+ if (aGrammar) {
+ subsElements = aGrammar->getValidSubstitutionGroups()->get(subsElemBaseName, subsElemURI);
- subsElements = new RefVectorOf<SchemaElementDecl>(8, false);
+ if (subsElements) {
+ subsElements = new ValueVectorOf<SchemaElementDecl*>(*subsElements);
+ }
+ else if (fSchemaInfo->circularImportExist(subsElemURI)) {
+ aGrammar->getValidSubstitutionGroups()->put(
+ subsElemBaseName, subsElemURI, new ValueVectorOf<SchemaElementDecl*>(8));
+ }
+ }
+ }
+
+ if (!subsElements) {
+ subsElements = new ValueVectorOf<SchemaElementDecl*>(8);
fValidSubstitutionGroups->put(subsElemBaseName, subsElemURI, subsElements);
}
subsElements->addElement(elemDecl);
+
+ // update related subs. info in case of circular import
+ RefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator();
+
+ while (importingEnum.hasMoreElements()) {
+
+ const SchemaInfo& curRef = importingEnum.nextElement();
+ SchemaGrammar* aGrammar = (SchemaGrammar*)
+ fGrammarResolver->getGrammar(curRef.getTargetNSURIString());
+ ValueVectorOf<SchemaElementDecl*>* subsElemList =
+ aGrammar->getValidSubstitutionGroups()->get(subsElemBaseName, subsElemURI);
+
+ if (subsElemList && !subsElemList->containsElement(elemDecl)) {
+ subsElemList->addElement(elemDecl);
+ }
+ }
+
buildValidSubstitutionListB(elemDecl, subsElemDecl);
buildValidSubstitutionListF(elemDecl, subsElemDecl);
}
@@ -3438,9 +3396,9 @@
// ---------------------------------------------------------------------------
// TraverseSchema: Helper methods
// ---------------------------------------------------------------------------
-void TraverseSchema::retrieveNamespaceMapping() {
+void TraverseSchema::retrieveNamespaceMapping(const DOM_Element& schemaRoot) {
- DOM_NamedNodeMap schemaEltAttrs = fSchemaRootElement.getAttributes();
+ DOM_NamedNodeMap schemaEltAttrs = schemaRoot.getAttributes();
bool seenXMLNS = false;
int attrCount = schemaEltAttrs.getLength();
@@ -3467,24 +3425,20 @@
XMLString::subString(prefix, name, offsetIndex + 1, XMLString::stringLen(name));
fBuffer.set(attValue.rawBuffer(), attValue.length());
- fNamespaceScope->addPrefix(prefix,
- fURIStringPool->addOrFind(fBuffer.getRawBuffer()));
+ fNamespaceScope->addPrefix(prefix, fURIStringPool->addOrFind(fBuffer.getRawBuffer()));
}
else if (attName.equals(XMLUni::fgXMLNSString)) { // == 'xmlns'
DOMString attValue = attribute.getNodeValue();
fBuffer.set(attValue.rawBuffer(), attValue.length());
- fNamespaceScope->addPrefix( XMLUni::fgZeroLenString,
- fURIStringPool->addOrFind(fBuffer.getRawBuffer()));
-
+ fNamespaceScope->addPrefix( XMLUni::fgZeroLenString, fURIStringPool->addOrFind(fBuffer.getRawBuffer()));
seenXMLNS = true;
}
- } // end for
+ } // end for
if (!seenXMLNS && XMLString::stringLen(fTargetNSURIString) == 0 ) {
- fNamespaceScope->addPrefix( XMLUni::fgZeroLenString,
- fEmptyNamespaceURI);
+ fNamespaceScope->addPrefix(XMLUni::fgZeroLenString, fEmptyNamespaceURI);
}
}
@@ -3556,8 +3510,9 @@
}
else if (name.equals(SchemaSymbols::fgELT_ELEMENT)) {
- QName* elmQName = traverseElementDecl(child);
- Janitor<QName> janQName(elmQName);
+ bool toDelete = true;
+ QName* elmQName = traverseElementDecl(child, toDelete);
+ delete elmQName;
}
else if (name.equals(SchemaSymbols::fgELT_ATTRIBUTEGROUP)) {
@@ -3744,9 +3699,9 @@
if (baseValidator == 0) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
+ SchemaInfo* saveInfo = fSchemaInfo;
DOM_Element baseTypeNode =
- getTopLevelComponentByName(SchemaSymbols::fgELT_SIMPLETYPE, localPart);
+ fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
if (baseTypeNode != 0) {
@@ -3754,9 +3709,7 @@
baseValidator = getDatatypeValidator(uri, localPart);
// restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ fSchemaInfo = saveInfo;
}
}
@@ -3779,91 +3732,9 @@
}
-DOM_Element
-TraverseSchema::getTopLevelComponentByName(const XMLCh* const compCategory,
- const XMLCh* const name) {
-
- DOM_Element child = getTopLevelComponentByName(compCategory, name, fCurrentSchemaInfo);
-
- if (child == 0) {
-
- SchemaInfo* saveCurrentInfo = fCurrentSchemaInfo;
- SchemaInfo* currentInfo = fSchemaInfoRoot;
-
- for (; currentInfo; currentInfo = currentInfo->getNext()) {
-
- if (currentInfo == saveCurrentInfo) {
- continue;
- }
-
- child = getTopLevelComponentByName(compCategory, name, currentInfo);
-
- if (child != 0) {
- break;
- }
- }
-
- if (child == 0 && saveCurrentInfo) {
- restoreSchemaInfo(saveCurrentInfo);
- }
- }
-
- return child;
-}
-
-
-DOM_Element
-TraverseSchema::getTopLevelComponentByName(const XMLCh* const compCategory,
- const XMLCh* const name,
- SchemaInfo* const currentInfo) {
-
- // REVISIT - need to update to accomodate 'redefine'
- if (currentInfo && currentInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(currentInfo);
- }
-
- DOM_Element child = XUtil::getFirstChildElement(fSchemaRootElement);
-
- while (child != 0) {
-
- if (child.getLocalName().equals(compCategory)) {
-
- if (child.getAttribute(SchemaSymbols::fgATT_NAME).equals(name)) {
- break;
- }
- }
- else if (child.getLocalName().equals(SchemaSymbols::fgELT_REDEFINE)) { // if redefine
-
- DOM_Element redefineChild = XUtil::getFirstChildElement(child);
-
- while (redefineChild != 0) {
-
- if (redefineChild.getLocalName().equals(compCategory)) {
-
- if (redefineChild.getAttribute(SchemaSymbols::fgATT_NAME).equals(name)) {
- break;
- }
- }
-
- redefineChild = XUtil::getNextSiblingElement(redefineChild);
- }
-
- if (redefineChild != 0) {
-
- child = redefineChild;
- break;
- }
- }
-
- child = XUtil::getNextSiblingElement(child);
- }
-
- return child;
-}
-
const XMLCh* TraverseSchema::resolvePrefixToURI(const XMLCh* const prefix) {
- int nameSpaceIndex = fNamespaceScope->getNamespaceForPrefix(prefix, fCurrentNamespaceLevel);
+ int nameSpaceIndex = fNamespaceScope->getNamespaceForPrefix(prefix, fSchemaInfo->getNamespaceScopeLevel());
const XMLCh* uriStr = fURIStringPool->getValueForId(nameSpaceIndex);
if (!XMLString::stringLen(uriStr) && XMLString::stringLen(prefix)) {
@@ -3887,7 +3758,8 @@
}
QName* TraverseSchema::processElementDeclRef(const DOM_Element& elem,
- const XMLCh* const refName) {
+ const XMLCh* const refName,
+ bool& toDelete) {
DOM_Element content = checkContent(elem, XUtil::getFirstChildElement(elem),
true);
@@ -3915,8 +3787,8 @@
//if not found, traverse the top level element that is referenced
if (!refElemDecl) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element targetElem = getTopLevelComponentByName(SchemaSymbols::fgELT_ELEMENT, localPart);
+ SchemaInfo* saveInfo = fSchemaInfo;
+ DOM_Element targetElem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_ELEMENT, localPart, &fSchemaInfo);
if (targetElem == 0) {
@@ -3926,30 +3798,23 @@
}
else {
+ // problems with recursive declarations
+/*
delete eltName;
eltName = traverseElementDecl(targetElem);
refElemDecl = (SchemaElementDecl*)
fSchemaGrammar->getElemDecl(uriID, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
+*/
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ // restore schema information
+ fSchemaInfo = saveInfo;
}
}
-
- const SchemaElementDecl* other = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(uriID, localPart, 0, fCurrentScope);
-
- if (refElemDecl && other
- && (refElemDecl->getComplexTypeInfo() != other->getComplexTypeInfo()
- || refElemDecl->getDatatypeValidator() != other->getDatatypeValidator())) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, localPart);
- }
- if (refElemDecl) {
+ if (fFullConstraintChecking) {
- fRefElements->addElement(refElemDecl);
+ toDelete = false;
+ fRefElements->addElement(eltName);
fRefElemScope->addElement(fCurrentScope);
}
@@ -4163,22 +4028,18 @@
if (dv == 0) {
- if (XMLString::compareString(typeURI,
- SchemaSymbols::fgURI_SCHEMAFORSCHEMA) != 0
- || XMLString::compareString(fTargetNSURIString,
- SchemaSymbols::fgURI_SCHEMAFORSCHEMA) == 0) {
+ if (XMLString::compareString(typeURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) != 0
+ || XMLString::compareString(fTargetNSURIString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) == 0) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element elem = getTopLevelComponentByName(SchemaSymbols::fgELT_SIMPLETYPE, localPart);
+ SchemaInfo* saveInfo = fSchemaInfo;
+ DOM_Element elem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
if (elem != 0 && traverseSimpleTypeDecl(elem) != -1) {
dv = getDatatypeValidator(typeURI, localPart);
}
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ // restore schema information
+ fSchemaInfo = saveInfo;
}
}
}
@@ -4197,49 +4058,65 @@
bool& noErrorDetected,
const XMLCh* const otherSchemaURI)
{
- const XMLCh* localPart = getLocalPart(typeStr);
- const XMLCh* typeURI = otherSchemaURI;
- ComplexTypeInfo* typeInfo = 0;
+ const XMLCh* localPart = getLocalPart(typeStr);
+ const XMLCh* prefix = getPrefix(typeStr);
+ const XMLCh* typeURI = (otherSchemaURI) ? otherSchemaURI : resolvePrefixToURI(prefix);
+ ComplexTypeInfo* typeInfo = 0;
+ SchemaInfo* saveInfo = fSchemaInfo;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
+
+ fBuffer.set(typeURI);
+ fBuffer.append(chComma);
+ fBuffer.append(localPart);
if (otherSchemaURI != 0) {
- typeInfo = getTypeInfoFromNS(typeURI, localPart);
+
+ Grammar* aGrammar = fGrammarResolver->getGrammar(typeURI);
+
+ typeInfo = ((SchemaGrammar*)aGrammar)->getComplexTypeRegistry()->get(fBuffer.getRawBuffer());
+
+ if (typeInfo) {
+ return typeInfo;
+ }
+
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(typeURI));
+
+ if (!impInfo) {
+
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::UnresolvedPrefix, prefix);
+ noErrorDetected = false;
+ return 0;
+ }
+
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
}
else {
+ typeInfo = fComplexTypeRegistry->get(fBuffer.getRawBuffer());
+ }
- const XMLCh* prefix = getPrefix(typeStr);
+ if (!typeInfo) {
- typeURI = resolvePrefixToURI(prefix);
- fBuffer.set(typeURI);
- fBuffer.append(chComma);
- fBuffer.append(localPart);
- typeInfo = fComplexTypeRegistry->get(fBuffer.getRawBuffer());
+ if (XMLString::compareString(typeURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) != 0 ||
+ XMLString::compareString(fTargetNSURIString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA) == 0) {
- if (typeInfo == 0) {
+ DOM_Element elem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_COMPLEXTYPE, localPart, &fSchemaInfo);
- if (XMLString::compareString(typeURI,
- SchemaSymbols::fgURI_SCHEMAFORSCHEMA) != 0
- || XMLString::compareString(fTargetNSURIString,
- SchemaSymbols::fgURI_SCHEMAFORSCHEMA) == 0) {
-
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element elem = getTopLevelComponentByName(
- SchemaSymbols::fgELT_COMPLEXTYPE, localPart);
-
- if (elem != 0) {
-
- int typeIndex = traverseComplexTypeDecl(elem);
- typeInfo = fComplexTypeRegistry->get(
- fStringPool->getValueForId(typeIndex));
+ if (elem != 0) {
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
- }
+ int typeIndex = traverseComplexTypeDecl(elem);
+ typeInfo = fComplexTypeRegistry->get(fStringPool->getValueForId(typeIndex));
}
}
}
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
+
return typeInfo;
}
@@ -4248,72 +4125,76 @@
TraverseSchema::getSubstituteGroupElemDecl(const XMLCh* const name,
bool& noErrorDetected) {
- const XMLCh* nameURI = resolvePrefixToURI(getPrefix(name));
- const XMLCh* localPart = getLocalPart(name);
- SchemaElementDecl* elemDecl = 0;
+ const XMLCh* nameURI = resolvePrefixToURI(getPrefix(name));
+ const XMLCh* localPart = getLocalPart(name);
+ SchemaElementDecl* elemDecl = 0;
+ SchemaInfo* saveInfo = fSchemaInfo;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
if (XMLString::compareString(nameURI, fTargetNSURIString) != 0) {
- elemDecl = getElementDeclFromNS(nameURI, localPart);
- }
- else {
- elemDecl = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(fTargetNSURI, localPart,
- 0, Grammar::TOP_LEVEL_SCOPE);
+ Grammar* grammar = fGrammarResolver->getGrammar(nameURI);
+ unsigned int uriId = fURIStringPool->addOrFind(nameURI);
- if (elemDecl == 0) {
+ if (grammar && grammar->getGrammarType() == Grammar::SchemaGrammarType) {
+ elemDecl = (SchemaElementDecl*)
+ grammar->getElemDecl(uriId, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
+ }
+ else {
- DOM_Element subsGroupElem =
- getTopLevelComponentByName(SchemaSymbols::fgELT_ELEMENT,
- localPart);
+ reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, nameURI);
+ return 0;
+ }
- if (subsGroupElem != 0) {
+ if (!elemDecl) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- QName* subsGroupQName = traverseElementDecl(subsGroupElem);
- Janitor<QName> janQName(subsGroupQName);
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(uriId);
- if (subsGroupQName != 0) {
- elemDecl = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(fTargetNSURI, localPart,
- 0, Grammar::TOP_LEVEL_SCOPE);
- }
+ if (!impInfo) {
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, nameURI, localPart);
+ return 0;
}
+
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
}
}
+ else {
+ elemDecl = (SchemaElementDecl*)
+ fSchemaGrammar->getElemDecl(fTargetNSURI, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
+ }
- if (elemDecl == 0
- || (elemDecl->getDatatypeValidator() == 0
- && elemDecl->getComplexTypeInfo() == 0)) {
+ if (!elemDecl) {
- noErrorDetected = false;
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, nameURI, localPart);
- }
+ DOM_Element subsGroupElem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_ELEMENT,localPart, &fSchemaInfo);
- return elemDecl;
-}
+ if (subsGroupElem != 0) {
-SchemaElementDecl*
-TraverseSchema::getElementDeclFromNS(const XMLCh* const nameUri,
- const XMLCh* const localPart) {
+ bool toDelete = true;
+ QName* subsGroupQName = traverseElementDecl(subsGroupElem, toDelete);
+ Janitor<QName> janQName(subsGroupQName);
- // REVISIT:
- Grammar* grammar = fGrammarResolver->getGrammar(nameUri);
- unsigned int uriId = fURIStringPool->addOrFind(nameUri);
+ if (subsGroupQName) {
+ elemDecl = (SchemaElementDecl*) fSchemaGrammar->getElemDecl(fTargetNSURI, localPart,0, Grammar::TOP_LEVEL_SCOPE);
+ }
- if (grammar != 0 && grammar->getGrammarType() == Grammar::SchemaGrammarType) {
- return (SchemaElementDecl*)
- grammar->getElemDecl(uriId, localPart, 0, Grammar::TOP_LEVEL_SCOPE);
+ if (!elemDecl) {
+
+ noErrorDetected = false;
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, nameURI, localPart);
+ }
+ }
}
- reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, nameUri);
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
- return 0;
+ return elemDecl;
}
bool
@@ -4425,7 +4306,8 @@
uriIndex = fTargetNSURI;
enclosingScope = Grammar::TOP_LEVEL_SCOPE;
}
- else if ((XMLString::stringLen(elemForm) == 0 && fElementDefaultQualified)
+ else if ((XMLString::stringLen(elemForm) == 0 &&
+ (fSchemaInfo->getElemAttrDefaultQualified() & Elem_Def_Qualified))
|| XMLString::compareString(elemForm,SchemaSymbols::fgATTVAL_QUALIFIED) == 0) {
uriIndex = fTargetNSURI;
@@ -4523,47 +4405,52 @@
}
// check for different namespace
+ SchemaInfo* saveInfo = fSchemaInfo;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
+
if (XMLString::compareString(uriStr, fTargetNSURIString) != 0) {
- addAttributeDeclFromAnotherSchema(localPart, uriStr, typeInfo);
- return;
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(attURI);
+
+ if (!impInfo) {
+
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TopLevelAttributeNotFound, refName);
+ return;
+ }
+
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
}
// if Global attribute registry does not contain the ref attribute, get
// the referred attribute declaration and traverse it.
if (fAttributeDeclRegistry->containsKey(localPart) == false) {
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
DOM_Element referredAttribute =
- getTopLevelComponentByName(SchemaSymbols::fgELT_ATTRIBUTE, localPart);
-
- if (referredAttribute == 0) {
+ fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_ATTRIBUTE, localPart, &fSchemaInfo);
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TopLevelAttributeNotFound, refName);
- return;
+ if (referredAttribute != 0) {
+ traverseAttributeDecl(referredAttribute, 0);
}
+ }
- traverseAttributeDecl(referredAttribute, 0);
+ SchemaAttDef* refAttDef = (SchemaAttDef*) fAttributeDeclRegistry->get(localPart);
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ // restore schema information, if necessary
+ if (fSchemaInfo != saveInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
}
- SchemaAttDef* refAttDef = (SchemaAttDef*)
- fAttributeDeclRegistry->get(localPart);
+ if (!refAttDef) {
- if (refAttDef == 0) {
-
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TopLevelAttributeNotFound, refName);
return;
}
- bool required = (XMLString::compareString(useAttr,
- SchemaSymbols::fgATTVAL_REQUIRED) == 0);
- bool prohibited = (XMLString::compareString(useAttr,
- SchemaSymbols::fgATTVAL_PROHIBITED) == 0);
+ bool required = (XMLString::compareString(useAttr,SchemaSymbols::fgATTVAL_REQUIRED) == 0);
+ bool prohibited = (XMLString::compareString(useAttr,SchemaSymbols::fgATTVAL_PROHIBITED) == 0);
QName* attQName = refAttDef->getAttName();
SchemaAttDef* attDef = new SchemaAttDef(attQName->getPrefix(),
attQName->getLocalPart(),
@@ -4645,6 +4532,10 @@
}
}
+ if (minOccurs == 0 && maxOccurs == 0){
+ return;
+ }
+
// Constraint checking for min/max value
if (!isMaxUnbounded) {
@@ -4711,7 +4602,6 @@
ContentSpecNode* specNode = 0;
DOM_Element attrNode;
int typeDerivedBy = SchemaSymbols::EMPTY_SET;
- bool adoptSpecNode = true;
ComplexTypeInfo* baseTypeInfo = typeInfo->getBaseComplexTypeInfo();
if (baseTypeInfo) {
@@ -4785,13 +4675,13 @@
}
else if (childName.equals(SchemaSymbols::fgELT_SEQUENCE)) {
- specNode = traverseChoiceSequence(childElem, ContentSpecNode::Sequence, adoptSpecNode);
+ specNode = traverseChoiceSequence(childElem, ContentSpecNode::Sequence);
checkMinMax(specNode, childElem);
attrNode = XUtil::getNextSiblingElement(childElem);
}
else if (childName.equals(SchemaSymbols::fgELT_CHOICE)) {
- specNode = traverseChoiceSequence(childElem, ContentSpecNode::Choice, adoptSpecNode);
+ specNode = traverseChoiceSequence(childElem, ContentSpecNode::Choice);
checkMinMax(specNode, childElem);
attrNode = XUtil::getNextSiblingElement(childElem);
}
@@ -4815,7 +4705,7 @@
}
typeInfo->setContentSpec(specNode);
- typeInfo->setAdoptContentSpec(adoptSpecNode);
+ typeInfo->setAdoptContentSpec(true);
// -----------------------------------------------------------------------
// Merge in information from base, if it exists
@@ -4844,18 +4734,18 @@
// the current in sequence
if (!specNode) {
- typeInfo->setContentSpec(baseSpecNode);
- typeInfo->setAdoptContentSpec(false);
+ if (baseSpecNode) {
+ typeInfo->setContentSpec(new ContentSpecNode(*baseSpecNode));
+ typeInfo->setAdoptContentSpec(true);
+ }
}
else if (baseSpecNode != 0) {
- bool toAdoptSpecNode = typeInfo->getAdoptContentSpec();
-
typeInfo->setAdoptContentSpec(false);
typeInfo->setContentSpec(
- new ContentSpecNode(ContentSpecNode::Sequence, baseSpecNode,
- specNode, false,
- toAdoptSpecNode));
+ new ContentSpecNode(ContentSpecNode::Sequence,
+ new ContentSpecNode(*baseSpecNode),
+ specNode));
typeInfo->setAdoptContentSpec(true);
}
}
@@ -4921,8 +4811,10 @@
const XMLCh* const uriStr,
ComplexTypeInfo* const typeInfo) {
- ComplexTypeInfo* baseComplexTypeInfo = 0;
- DatatypeValidator* baseDTValidator = 0;
+ SchemaInfo* saveInfo = fSchemaInfo;
+ ComplexTypeInfo* baseComplexTypeInfo = 0;
+ DatatypeValidator* baseDTValidator = 0;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
// -------------------------------------------------------------
// check if the base type is from another schema
@@ -4930,22 +4822,22 @@
if (isBaseFromAnotherSchema(uriStr)) {
baseComplexTypeInfo = getTypeInfoFromNS(uriStr, localPart);
-
- if (baseComplexTypeInfo == 0) {
- baseDTValidator = getDatatypeValidator(uriStr, localPart);
+ if (!baseComplexTypeInfo) {
- if (baseDTValidator == 0) {
-
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, uriStr, localPart);
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
+
+ if (!impInfo) {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::BaseTypeNotFound, baseName);
throw TraverseSchema::InvalidComplexTypeInfo;
}
+
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
}
}
-
- // -------------------------------------------------------------
- // type must be from same schema
- // -------------------------------------------------------------
else {
fBuffer.set(uriStr);
@@ -4963,67 +4855,62 @@
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, fullBaseName);
throw TraverseSchema::InvalidComplexTypeInfo;
}
+ }
- // if not found, 2 possibilities:
- // 1: ComplexType in question has not been compiled yet;
- // 2: base is SimpleTYpe;
- if (baseComplexTypeInfo == 0) {
-
- baseDTValidator = getDatatypeValidator(uriStr, localPart);
-
- if (baseDTValidator == 0) {
-
- int baseTypeSymbol;
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element baseTypeNode = getTopLevelComponentByName(
- SchemaSymbols::fgELT_COMPLEXTYPE, localPart);
+ // if not found, 2 possibilities:
+ // 1: ComplexType in question has not been compiled yet;
+ // 2: base is SimpleTYpe;
+ if (!baseComplexTypeInfo) {
- if (baseTypeNode != 0) {
+ baseDTValidator = getDatatypeValidator(uriStr, localPart);
- baseTypeSymbol = traverseComplexTypeDecl(baseTypeNode);
- baseComplexTypeInfo = fComplexTypeRegistry->get(
- fStringPool->getValueForId(baseTypeSymbol));
+ if (baseDTValidator == 0) {
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
- }
- else {
+ DOM_Element baseTypeNode =
+ fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_COMPLEXTYPE, localPart, &fSchemaInfo);
- baseTypeNode = getTopLevelComponentByName(
- SchemaSymbols::fgELT_SIMPLETYPE, localPart);
+ if (baseTypeNode != 0) {
- if (baseTypeNode != 0) {
+ int baseTypeSymbol = traverseComplexTypeDecl(baseTypeNode);
+ baseComplexTypeInfo = fComplexTypeRegistry->get(fStringPool->getValueForId(baseTypeSymbol));
+ }
+ else {
- baseTypeSymbol = traverseSimpleTypeDecl(baseTypeNode);
- baseDTValidator = getDatatypeValidator(uriStr, localPart);
+ baseTypeNode = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_SIMPLETYPE, localPart, &fSchemaInfo);
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ if (baseTypeNode != 0) {
- if (baseDTValidator == 0) {
+ int baseTypeSymbol = traverseSimpleTypeDecl(baseTypeNode);
+ baseDTValidator = getDatatypeValidator(uriStr, localPart);
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, uriStr, localPart, uriStr);
- throw TraverseSchema::InvalidComplexTypeInfo;
- }
- }
- else {
+ if (baseDTValidator == 0) {
// restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
}
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::BaseTypeNotFound, baseName);
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::TypeNotFound, uriStr, localPart, uriStr);
throw TraverseSchema::InvalidComplexTypeInfo;
}
}
+ else {
+
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::BaseTypeNotFound, baseName);
+ throw TraverseSchema::InvalidComplexTypeInfo;
+ }
}
}
- } // end else (type must be from same schema)
+ } // end if
+
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
typeInfo->setBaseComplexTypeInfo(baseComplexTypeInfo);
typeInfo->setBaseDatatypeValidator(baseDTValidator);
@@ -5095,6 +4982,7 @@
SchemaAttDef* attWildCard = 0;
Janitor<SchemaAttDef> janAttWildCard(0);
XercesAttGroupInfo* attGroupInfo = 0;
+ ValueVectorOf<XercesAttGroupInfo*> attGroupList(4);
for (; child != 0; child = XUtil::getNextSiblingElement(child)) {
@@ -5105,6 +4993,9 @@
}
else if (childName.equals(SchemaSymbols::fgELT_ATTRIBUTEGROUP)) {
attGroupInfo = traverseAttributeGroupDecl(child, typeInfo);
+ if (attGroupInfo && !attGroupList.containsElement(attGroupInfo)) {
+ attGroupList.addElement(attGroupInfo);
+ }
}
else if (childName.equals(SchemaSymbols::fgELT_ANYATTRIBUTE) ) {
attWildCard = traverseAnyAttribute(child);
@@ -5124,39 +5015,67 @@
ComplexTypeInfo* baseTypeInfo = typeInfo->getBaseComplexTypeInfo();
SchemaAttDef* baseAttWildCard = (baseTypeInfo) ? baseTypeInfo->getAttWildCard() : 0;
int derivedBy = typeInfo->getDerivedBy();
+ unsigned int attGroupListSize = attGroupList.size();
- if (attGroupInfo) {
+ if (attGroupListSize) {
- unsigned int anyAttCount = attGroupInfo->anyAttributeCount();
+ SchemaAttDef* completeWildCard = 0;
+ Janitor<SchemaAttDef> janCompleteWildCard(0);
+ XMLAttDef::DefAttTypes defAttType;
+ bool defAttTypeSet = false;
- if (anyAttCount) {
+ for (unsigned int i=0; i < attGroupListSize; i++) {
- SchemaAttDef* attCompleteWildCard = attGroupInfo->getCompleteWildCard();
- XMLAttDef::DefAttTypes defAttType = (attWildCard)
- ? attWildCard->getDefaultType() : attGroupInfo->anyAttributeAt(0)->getDefaultType();
+ attGroupInfo = attGroupList.elementAt(i);
+ unsigned int anyAttCount = attGroupInfo->anyAttributeCount();
- if (!attCompleteWildCard) {
+ if (anyAttCount) {
- attCompleteWildCard = new SchemaAttDef(attGroupInfo->anyAttributeAt(0));
+ if (!defAttTypeSet) {
- for (unsigned int i= 1; i < anyAttCount; i++) {
- attWildCardIntersection(attCompleteWildCard, attGroupInfo->anyAttributeAt(i));
+ defAttType = (attWildCard) ? attWildCard->getDefaultType()
+ : attGroupInfo->anyAttributeAt(0)->getDefaultType();
+ defAttTypeSet = true;
}
+
+ SchemaAttDef* attGroupWildCard = attGroupInfo->getCompleteWildCard();
+
+ if (!attGroupWildCard) {
+
+ attGroupWildCard = new SchemaAttDef(attGroupInfo->anyAttributeAt(0));
+
+ for (unsigned int i= 1; i < anyAttCount; i++) {
+ attWildCardIntersection(attGroupWildCard, attGroupInfo->anyAttributeAt(i));
+ }
- attGroupInfo->setCompleteWildCard(attCompleteWildCard);
+ attGroupInfo->setCompleteWildCard(attGroupWildCard);
+ }
+
+ if (completeWildCard) {
+ attWildCardIntersection(completeWildCard, attGroupWildCard);
+ }
+ else {
+ completeWildCard = new SchemaAttDef(attGroupWildCard);
+ janCompleteWildCard.reset(completeWildCard);
+ }
}
+ }
+
+ if (completeWildCard) {
+
if (attWildCard) {
- attWildCardIntersection(attWildCard, attCompleteWildCard);
+ attWildCardIntersection(attWildCard, completeWildCard);
}
else {
- attWildCard = new SchemaAttDef(attCompleteWildCard);
+ attWildCard = completeWildCard;
+ janCompleteWildCard.orphan();
janAttWildCard.reset(attWildCard);
}
attWildCard->setDefaultType(defAttType);
- }
+ }
}
if (derivedBy == SchemaSymbols::EXTENSION && baseAttWildCard && attWildCard) {
@@ -5197,7 +5116,7 @@
}
else {
checkAttDerivationOK(baseTypeInfo, typeInfo);
- }
+ }
}
// -------------------------------------------------------------
@@ -5239,73 +5158,6 @@
}
-int
-TraverseSchema::addAttributeDeclFromAnotherSchema(const XMLCh* const name,
- const XMLCh* const uri,
- ComplexTypeInfo* const typeInfo)
-{
- SchemaGrammar* aGrammar = (SchemaGrammar*)
- fGrammarResolver->getGrammar(uri);
-
- if (XMLString::stringLen(uri) == 0 || aGrammar == 0
- || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
-
- reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uri);
- return -1;
- }
-
- if (aGrammar->getAttributeDeclRegistry() == 0) {
-
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoAttributeInSchema, name, uri);
- return -1;
- }
-
- SchemaAttDef* tempAtt = (SchemaAttDef*)
- aGrammar->getAttributeDeclRegistry()->get(name);
-
- if (tempAtt == 0) {
-
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoAttributeInSchema, name, uri);
- return -1;
- }
-
- if (typeInfo || fCurrentAttGroupInfo) {
-
- QName* attName = tempAtt->getAttName();
-
- if (typeInfo->getAttDef(attName->getLocalPart(), attName->getURI()) != 0) {
-
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DuplicateRefAttribute, uri, name);
- return -1;
- }
-
- SchemaAttDef* newAtt = new SchemaAttDef(attName->getPrefix(),
- attName->getLocalPart(),
- attName->getURI(),
- tempAtt->getValue(),
- tempAtt->getType(),
- tempAtt->getDefaultType(),
- tempAtt->getEnumeration());
-
- newAtt->setDatatypeValidator(tempAtt->getDatatypeValidator());
-
- bool toClone = false;
-
- if (typeInfo) {
-
- toClone = true;
- typeInfo->addAttDef(newAtt);
- }
-
- if (fCurrentGroupInfo) {
- fCurrentAttGroupInfo->addAttDef(newAtt, toClone);
- }
- }
-
- return 0;
-}
-
-
void TraverseSchema::defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo) {
if (typeInfo) {
@@ -5336,7 +5188,7 @@
try {
- XMLURL urlTmp(fCurrentSchemaURL, loc);
+ XMLURL urlTmp(fSchemaInfo->getCurrentSchemaURL(), loc);
if (urlTmp.isRelative()) {
ThrowXML(MalformedURLException,
@@ -5347,31 +5199,53 @@
}
catch(const MalformedURLException&) {
// Its not a URL, so lets assume its a local file name.
- srcToFill = new LocalFileInputSource(fCurrentSchemaURL,loc);
+ srcToFill = new LocalFileInputSource(fSchemaInfo->getCurrentSchemaURL(),loc);
}
}
return srcToFill;
}
+
+void TraverseSchema::restoreSchemaInfo(SchemaInfo* const toRestore,
+ SchemaInfo::ListType const aListType) {
+
+
+ if (aListType == SchemaInfo::IMPORT) { // restore grammar info
-void TraverseSchema::restoreSchemaInfo(SchemaInfo* const toRestore) {
+ int targetNSURI = toRestore->getTargetNSURI();
+ fSchemaGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(toRestore->getTargetNSURIString());
+
+ if (!fSchemaGrammar) {
+
+ reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, fURIStringPool->getValueForId(targetNSURI));
+ return;
+ }
+
+ fTargetNSURI = targetNSURI;
+ fCurrentScope = toRestore->getCurrentScope();
+ fScopeCount = toRestore->getScopeCount();
+ fTargetNSURIString = fSchemaGrammar->getTargetNamespace();
+ fGroupRegistry = fSchemaGrammar->getGroupInfoRegistry();
+ fAttGroupRegistry = fSchemaGrammar->getAttGroupInfoRegistry();
+ fAttributeDeclRegistry = fSchemaGrammar->getAttributeDeclRegistry();
+ fComplexTypeRegistry = fSchemaGrammar->getComplexTypeRegistry();
+ fValidSubstitutionGroups = fSchemaGrammar->getValidSubstitutionGroups();
+ fNamespaceScope = fSchemaGrammar->getNamespaceScope();
+ }
- fCurrentSchemaInfo = toRestore;
- setCurrentSchemaURL(fCurrentSchemaInfo->getCurrentSchemaURL());
- fElementDefaultQualified = fCurrentSchemaInfo->isElementDefaultQualified();
- fAttributeDefaultQualified = fCurrentSchemaInfo->isAttributeDefaultQualified();
- fBlockDefault = fCurrentSchemaInfo->getBlockDefault();
- fFinalDefault = fCurrentSchemaInfo->getFinalDefault();
- fCurrentNamespaceLevel = fCurrentSchemaInfo->getNamespaceScopeLevel();
- fSchemaRootElement = fCurrentSchemaInfo->getRoot();
+ fSchemaInfo = toRestore;
+ fElemAttrDefaultQualified = fSchemaInfo->getElemAttrDefaultQualified();
+ fBlockDefault = fSchemaInfo->getBlockDefault();
+ fFinalDefault = fSchemaInfo->getFinalDefault();
}
bool
TraverseSchema::emptiableParticle(const ContentSpecNode* const specNode) {
- if (getMinTotalRange(specNode) == 0) {
+ if (!fFullConstraintChecking ||
+ (getMinTotalRange(specNode) == 0)) {
return true;
}
@@ -5517,24 +5391,42 @@
for (unsigned int i=0; i < refElemSize; i++) {
int elemScope = fRefElemScope->elementAt(i);
- SchemaElementDecl* elem = fRefElements->elementAt(i);
- RefVectorOf<SchemaElementDecl>* subsElements =
- fValidSubstitutionGroups->get(elem->getBaseName(), elem->getURI());
-
- if (subsElements) {
- unsigned subsElemSize = subsElements->size();
-
- for (unsigned int j=0; j < subsElemSize; j++) {
-
- SchemaElementDecl* subsElem = subsElements->elementAt(j);
- const XMLCh* subsElemName = subsElem->getBaseName();
- SchemaElementDecl* sameScopeElem = (SchemaElementDecl*)
- fSchemaGrammar->getElemDecl(subsElem->getURI(), subsElemName, 0, elemScope);
-
- if (sameScopeElem
- && (subsElem->getComplexTypeInfo() != sameScopeElem->getComplexTypeInfo()
- || subsElem->getDatatypeValidator() != sameScopeElem->getDatatypeValidator())) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, subsElemName);
+ QName* elemQName = fRefElements->elementAt(i);
+ unsigned int elemURI = elemQName->getURI();
+ const XMLCh* elemName = elemQName->getLocalPart();
+ const SchemaElementDecl* elemDecl = (SchemaElementDecl*)
+ fSchemaGrammar->getElemDecl(elemURI, elemName, 0, Grammar::TOP_LEVEL_SCOPE);
+
+ if (elemDecl) {
+
+ const SchemaElementDecl* other = (SchemaElementDecl*)
+ fSchemaGrammar->getElemDecl(elemURI, elemName, 0, elemScope);
+
+ if (other
+ && (elemDecl->getComplexTypeInfo() != other->getComplexTypeInfo() ||
+ elemDecl->getDatatypeValidator() != other->getDatatypeValidator())) {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, elemName);
+ continue;
+ }
+
+ ValueVectorOf<SchemaElementDecl*>* subsElements = fValidSubstitutionGroups->get(elemName, elemURI);
+
+ if (subsElements) {
+
+ unsigned subsElemSize = subsElements->size();
+
+ for (unsigned int j=0; j < subsElemSize; j++) {
+
+ SchemaElementDecl* subsElem = subsElements->elementAt(j);
+ const XMLCh* subsElemName = subsElem->getBaseName();
+ SchemaElementDecl* sameScopeElem = (SchemaElementDecl*)
+ fSchemaGrammar->getElemDecl(subsElem->getURI(), subsElemName, 0, elemScope);
+
+ if (sameScopeElem
+ && (subsElem->getComplexTypeInfo() != sameScopeElem->getComplexTypeInfo()
+ || subsElem->getDatatypeValidator() != sameScopeElem->getDatatypeValidator())) {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DuplicateElementDeclaration, subsElemName);
+ }
}
}
}
@@ -5545,29 +5437,68 @@
TraverseSchema::buildValidSubstitutionListB(SchemaElementDecl* const elemDecl,
SchemaElementDecl* const subsElemDecl) {
- int elemURI = subsElemDecl->getURI();
- XMLCh* elemName = subsElemDecl->getBaseName();
+ SchemaElementDecl* tmpElemDecl = subsElemDecl;
- SchemaElementDecl* chainElem = fSubstitutionGroups->get(elemName, elemURI);
+ while (true) {
- if (!chainElem || (chainElem == elemDecl)) {
- return;
- }
+ int elemURI = tmpElemDecl->getURI();
+ XMLCh* elemName = tmpElemDecl->getBaseName();
+ SchemaElementDecl* chainElem = fSubstitutionGroups->get(elemName, elemURI);
- RefVectorOf<SchemaElementDecl>* validSubsElements =
- fValidSubstitutionGroups->get(chainElem->getBaseName(), chainElem->getURI());
+ if (!chainElem || (chainElem == elemDecl)) {
+ break;
+ }
- if (validSubsElements->containsElement(elemDecl)) {
- return;
- }
+ int chainElemURI = chainElem->getURI();
+ XMLCh* chainElemName = chainElem->getBaseName();
+ ValueVectorOf<SchemaElementDecl*>* validSubsElements =
+ fValidSubstitutionGroups->get(chainElemName, chainElemURI);
+
+ if (!validSubsElements) {
+
+ if (fTargetNSURI == chainElemURI) {
+ break; // an error must have occured
+ }
+
+ SchemaGrammar* aGrammar = (SchemaGrammar*)
+ fGrammarResolver->getGrammar(fURIStringPool->getValueForId(chainElemURI));
- if (isSubstitutionGroupValid(chainElem, elemDecl->getComplexTypeInfo(),
- elemDecl->getDatatypeValidator(), 0, false)) {
+ if (!aGrammar)
+ break;
+
+ validSubsElements = aGrammar->getValidSubstitutionGroups()->get(chainElemName, chainElemURI);
+
+ if (!validSubsElements) {
+ break;
+ }
+
+ validSubsElements = new ValueVectorOf<SchemaElementDecl*>(*validSubsElements);
+ fValidSubstitutionGroups->put((void*) chainElemName, chainElemURI, validSubsElements);
+ }
+ if (validSubsElements->containsElement(elemDecl) ||
+ !isSubstitutionGroupValid(chainElem, elemDecl->getComplexTypeInfo(),
+ elemDecl->getDatatypeValidator(), 0, false)) {
+ break;
+ }
+
validSubsElements->addElement(elemDecl);
- }
+
+ // update related subs. info in case of circular import
+ RefVectorEnumerator<SchemaInfo> importingEnum = fSchemaInfo->getImportingListEnumerator();
- buildValidSubstitutionListB(elemDecl, chainElem);
+ while (importingEnum.hasMoreElements()) {
+
+ const SchemaInfo& curRef = importingEnum.nextElement();
+ SchemaGrammar* aGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(curRef.getTargetNSURIString());
+ ValueVectorOf<SchemaElementDecl*>* subsElemList =
+ aGrammar->getValidSubstitutionGroups()->get(chainElemName, chainElemURI);
+
+ if (subsElemList && !subsElemList->containsElement(elemDecl)) {
+ subsElemList->addElement(elemDecl);
+ }
+ }
+ }
}
void
@@ -5576,33 +5507,50 @@
int elemURI = elemDecl->getURI();
XMLCh* elemName = elemDecl->getBaseName();
- RefVectorOf<SchemaElementDecl>* validSubsElements =
- fValidSubstitutionGroups->get(elemName, elemURI);
+ ValueVectorOf<SchemaElementDecl*>* validSubsElements =fValidSubstitutionGroups->get(elemName, elemURI);
if (validSubsElements) {
- unsigned int elemSize = validSubsElements->size();
- for (unsigned int i=0; i<elemSize; i++) {
+ int subsElemURI = subsElemDecl->getURI();
+ XMLCh* subsElemName = subsElemDecl->getBaseName();
+ ValueVectorOf<SchemaElementDecl*>* validSubs = fValidSubstitutionGroups->get(subsElemName, subsElemURI);
- SchemaElementDecl* chainElem = validSubsElements->elementAt(i);
+ if (!validSubs) {
- if (chainElem == subsElemDecl) {
- continue;
+ if (fTargetNSURI == subsElemURI) {
+ return; // an error must have occured
+ }
+
+ SchemaGrammar* aGrammar = (SchemaGrammar*)
+ fGrammarResolver->getGrammar(fURIStringPool->getValueForId(subsElemURI));
+
+ if (!aGrammar)
+ return;
+
+ validSubs = aGrammar->getValidSubstitutionGroups()->get(subsElemName, subsElemURI);
+
+ if (!validSubs) {
+ return;
}
+
+ validSubs = new ValueVectorOf<SchemaElementDecl*>(*validSubs);
+ fValidSubstitutionGroups->put((void*) subsElemName, subsElemURI, validSubs);
+ }
+
+ unsigned int elemSize = validSubsElements->size();
+ for (unsigned int i=0; i<elemSize; i++) {
- RefVectorOf<SchemaElementDecl>* validSubs =
- fValidSubstitutionGroups->get(subsElemDecl->getBaseName(), subsElemDecl->getURI());
+ SchemaElementDecl* chainElem = validSubsElements->elementAt(i);
- if (validSubs->containsElement(chainElem)) {
+ if (chainElem == subsElemDecl ||
+ validSubs->containsElement(chainElem)) {
continue;
}
if (isSubstitutionGroupValid(subsElemDecl, chainElem->getComplexTypeInfo(),
chainElem->getDatatypeValidator(), 0, false)) {
- validSubsElements->addElement(chainElem);
+ validSubs->addElement(chainElem);
}
-
- buildValidSubstitutionListF(chainElem, subsElemDecl);
}
}
}
@@ -5640,49 +5588,79 @@
return 0;
}
- XercesGroupInfo* groupInfo = 0;
+ XercesGroupInfo* groupInfo = 0;
+ SchemaInfo* saveInfo = fSchemaInfo;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
//if from another schema
if (XMLString::compareString(uriStr, fTargetNSURIString) != 0) {
- groupInfo = traverseGroupDeclNS(uriStr, localPart);
- }
- else {
- groupInfo = fGroupRegistry->get(fStringPool->getValueForId(nameIndex));
+ Grammar* aGrammar = fGrammarResolver->getGrammar(uriStr);
+ if (!aGrammar || aGrammar->getGrammarType() != Grammar::SchemaGrammarType) {
+
+ reportSchemaError(XMLUni::fgValidityDomain, XMLValid::GrammarNotFound, uriStr);
+ return 0;
+ }
+
+ groupInfo = ((SchemaGrammar*)aGrammar)->getGroupInfoRegistry()->get(fStringPool->getValueForId(nameIndex));
+
if (!groupInfo) {
+
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
+
+ if (!impInfo) {
+
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
+ SchemaSymbols::fgELT_GROUP, uriStr, localPart);
+ return 0;
+ }
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element groupElem =
- getTopLevelComponentByName(SchemaSymbols::fgELT_GROUP, localPart);
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
+ }
+ }
+ else {
+ groupInfo = fGroupRegistry->get(fStringPool->getValueForId(nameIndex));
+ }
- if (groupElem != 0) {
+ if (!groupInfo) {
- groupInfo = traverseGroupDecl(groupElem);
+ DOM_Element groupElem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_GROUP, localPart, &fSchemaInfo);
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ if (groupElem != 0) {
- if (groupInfo && fCurrentGroupInfo
- && groupInfo->getScope() == fCurrentGroupInfo->getScope()) {
- copyGroupElements(groupInfo, fCurrentGroupInfo, 0);
- }
+ groupInfo = traverseGroupDecl(groupElem);
- return groupInfo;
+ if (groupInfo && fCurrentGroupInfo
+ && groupInfo->getScope() == fCurrentGroupInfo->getScope()) {
+ copyGroupElements(groupInfo, fCurrentGroupInfo, 0);
}
- else {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_GROUP, uriStr, localPart);
+
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
}
+
+ return groupInfo;
}
+ else {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
+ SchemaSymbols::fgELT_GROUP, uriStr, localPart);
+ }
}
if (groupInfo) {
copyGroupElements(groupInfo, fCurrentGroupInfo, fCurrentComplexType);
}
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
+
return groupInfo;
}
@@ -5696,13 +5674,32 @@
reportSchemaError(XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_ATTRIBUTEGROUP);
}
- const XMLCh* prefix = getPrefix(refName);
- const XMLCh* localPart = getLocalPart(refName);
- const XMLCh* uriStr = resolvePrefixToURI(prefix);
- XercesAttGroupInfo* attGroupInfo = 0;
+ const XMLCh* prefix = getPrefix(refName);
+ const XMLCh* localPart = getLocalPart(refName);
+ const XMLCh* uriStr = resolvePrefixToURI(prefix);
+ XercesAttGroupInfo* attGroupInfo = 0;
+ SchemaInfo* saveInfo = fSchemaInfo;
+ SchemaInfo::ListType infoType = SchemaInfo::INCLUDE;
if (XMLString::compareString(uriStr, fTargetNSURIString) != 0) {
- attGroupInfo = traverseAttributeGroupDeclNS(uriStr, localPart);
+
+ attGroupInfo = traverseAttributeGroupDeclNS(uriStr, localPart);
+
+ if (!attGroupInfo) {
+ SchemaInfo* impInfo = fSchemaInfo->getImportInfo(fURIStringPool->addOrFind(uriStr));
+
+ if (!impInfo) {
+
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
+ SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, localPart);
+ return 0;
+ }
+
+ infoType = SchemaInfo::IMPORT;
+ fSchemaInfo->setCurrentScope(fCurrentScope);
+ fSchemaInfo->setScopeCount(fScopeCount);
+ restoreSchemaInfo(impInfo, infoType);
+ }
}
else {
@@ -5718,40 +5715,43 @@
}
attGroupInfo = fAttGroupRegistry->get(localPart);
-
- if (!attGroupInfo) {
+ }
- // traverse top level attributeGroup - if found
- SchemaInfo* saveInfo = fCurrentSchemaInfo;
- DOM_Element attGroupElem =
- getTopLevelComponentByName(SchemaSymbols::fgELT_ATTRIBUTEGROUP, localPart);
+ if (!attGroupInfo) {
- if (attGroupElem != 0) {
+ // traverse top level attributeGroup - if found
+ DOM_Element attGroupElem = fSchemaInfo->getTopLevelComponent(SchemaSymbols::fgELT_ATTRIBUTEGROUP, localPart, &fSchemaInfo);
- attGroupInfo = traverseAttributeGroupDecl(attGroupElem, typeInfo);
+ if (attGroupElem != 0) {
- // restore schema information, if necessary
- if (saveInfo != fCurrentSchemaInfo) {
- restoreSchemaInfo(saveInfo);
- }
+ attGroupInfo = traverseAttributeGroupDecl(attGroupElem, typeInfo);
- if (attGroupInfo && fCurrentAttGroupInfo) {
- copyAttGroupAttributes(attGroupInfo, fCurrentAttGroupInfo, 0);
- }
-
- return attGroupInfo;
+ if (attGroupInfo && fCurrentAttGroupInfo) {
+ copyAttGroupAttributes(attGroupInfo, fCurrentAttGroupInfo, 0);
}
- else {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
- SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, localPart);
+
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
}
+
+ return attGroupInfo;
}
+ else {
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNotFound,
+ SchemaSymbols::fgELT_ATTRIBUTEGROUP, uriStr, localPart);
+ }
}
if (attGroupInfo) {
copyAttGroupAttributes(attGroupInfo, fCurrentAttGroupInfo, typeInfo);
}
+ // restore schema information, if necessary
+ if (saveInfo != fSchemaInfo) {
+ restoreSchemaInfo(saveInfo, infoType);
+ }
+
return attGroupInfo;
}
@@ -6295,8 +6295,7 @@
// ------------------------------------------------------------------
// Get 'schemaLocation' attribute
// ------------------------------------------------------------------
- const XMLCh* schemaLocation =
- getElementAttValue(redefineElem, SchemaSymbols::fgATT_SCHEMALOCATION);
+ const XMLCh* schemaLocation = getElementAttValue(redefineElem, SchemaSymbols::fgATT_SCHEMALOCATION);
if (XMLString::stringLen(schemaLocation) == 0) {
reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::DeclarationNoSchemaLocation, SchemaSymbols::fgELT_REDEFINE);
@@ -6316,13 +6315,16 @@
const XMLCh* includeURL = srcToFill->getSystemId();
- if (!XMLString::compareString(includeURL, fCurrentSchemaURL)) {
+ if (!XMLString::compareString(includeURL, fSchemaInfo->getCurrentSchemaURL())) {
return false;
}
+
+ SchemaInfo* redefSchemaInfo = fSchemaInfoList->get(includeURL);
- if (fIncludeLocations->containsKey(includeURL)) {
+ if (redefSchemaInfo) {
- restoreSchemaInfo(fIncludeLocations->get(includeURL));
+ fSchemaInfo->addSchemaInfo(redefSchemaInfo, SchemaInfo::INCLUDE);
+ restoreSchemaInfo(redefSchemaInfo);
return true;
}
@@ -6379,25 +6381,20 @@
// --------------------------------------------------------
// Update schema information with redefined schema
// --------------------------------------------------------
- fCurrentNamespaceLevel = fNamespaceScope->increaseDepth();
- fSchemaRootElement = root;
- setCurrentSchemaURL(includeURL);
- traverseSchemaHeader();
+ unsigned int namespaceDepth = fNamespaceScope->increaseDepth();
+ fElemAttrDefaultQualified = 0;
+ traverseSchemaHeader(root);
// and now we'd better save this stuff!
- fCurrentSchemaInfo = new SchemaInfo(fElementDefaultQualified,
- fAttributeDefaultQualified,
- fBlockDefault,
- fFinalDefault,
- fCurrentNamespaceLevel,
- fCurrentSchemaURL,
- fSchemaRootElement,
- fCurrentSchemaInfo->getNext(),
- fCurrentSchemaInfo);
-
- (fCurrentSchemaInfo->getPrev())->setNext(fCurrentSchemaInfo);
- fIncludeLocations->put((void*) fCurrentSchemaInfo->getCurrentSchemaURL(),
- fCurrentSchemaInfo);
+ redefSchemaInfo = fSchemaInfo;
+ fSchemaInfo = new SchemaInfo(fElemAttrDefaultQualified, fBlockDefault,
+ fFinalDefault, fTargetNSURI, fCurrentScope,
+ fScopeCount, namespaceDepth,
+ XMLString::replicate(includeURL),
+ fTargetNSURIString, fStringPool, root);
+
+ fSchemaInfoList->put((void*) fSchemaInfo->getCurrentSchemaURL(), fSchemaInfo);
+ redefSchemaInfo->addSchemaInfo(fSchemaInfo, SchemaInfo::INCLUDE);
}
return true;
@@ -6418,17 +6415,22 @@
}
// if component already redefined skip
- const XMLCh* typeName = getElementAttValue(child, SchemaSymbols::fgATT_NAME);
fBuffer.set(childName.rawBuffer(), childName.length());
unsigned int childNameId = fStringPool->addOrFind(fBuffer.getRawBuffer());
const XMLCh* tmpChildName = fStringPool->getValueForId(childNameId);
+ const XMLCh* typeName = getElementAttValue(child, SchemaSymbols::fgATT_NAME);
- if (fRedefineComponents->containsKey(tmpChildName, fStringPool->addOrFind(typeName))) {
+ fBuffer.set(fTargetNSURIString);
+ fBuffer.append(chComma);
+ fBuffer.append(typeName);
+
+ if (fRedefineComponents->containsKey(tmpChildName, fStringPool->addOrFind(fBuffer.getRawBuffer()))) {
continue;
}
if (validateRedefineNameChange(child, tmpChildName, typeName, 1, redefiningSchemaInfo)) {
+ redefinedSchemaInfo->addRedefineInfo(tmpChildName, typeName, redefiningSchemaInfo);
fixRedefinedSchema(redefinedSchemaInfo, tmpChildName, typeName, 1);
}
}
@@ -6442,15 +6444,19 @@
const XMLCh* baseTypeName = 0;
unsigned int typeNameId = fStringPool->addOrFind(redefineChildTypeName);
-
- restoreSchemaInfo(redefiningSchemaInfo);
+
fBuffer.set(fTargetNSURIString);
fBuffer.append(chComma);
fBuffer.append(redefineChildTypeName);
+ int fullTypeNameId = fStringPool->addOrFind(fBuffer.getRawBuffer());
+ const XMLCh* typeNameStr = fStringPool->getValueForId(fullTypeNameId);
+
+ restoreSchemaInfo(redefiningSchemaInfo);
+
if (!XMLString::compareString(redefineChildComponentName,SchemaSymbols::fgELT_SIMPLETYPE)) {
- if (fDatatypeRegistry->getDatatypeValidator(fBuffer.getRawBuffer())) {
+ if (fDatatypeRegistry->getDatatypeValidator(typeNameStr)) {
return false;
}
@@ -6484,10 +6490,12 @@
// now we have to do the renaming...
getRedefineNewTypeName(baseTypeName, redefineNameCounter, fBuffer);
grandKid.setAttribute(SchemaSymbols::fgATT_BASE, fBuffer.getRawBuffer());
+ fRedefineComponents->put((void*) SchemaSymbols::fgELT_SIMPLETYPE,
+ fullTypeNameId, 0);
}
else if (!XMLString::compareString(redefineChildComponentName,SchemaSymbols::fgELT_COMPLEXTYPE)) {
- if (fComplexTypeRegistry->containsKey(fBuffer.getRawBuffer())) {
+ if (fComplexTypeRegistry->containsKey(typeNameStr)) {
return false;
}
@@ -6538,12 +6546,14 @@
// now we have to do the renaming...
getRedefineNewTypeName(baseTypeName, redefineNameCounter, fBuffer);
greatGrandKid.setAttribute(SchemaSymbols::fgATT_BASE, fBuffer.getRawBuffer());
+ fRedefineComponents->put((void*) SchemaSymbols::fgELT_COMPLEXTYPE,
+ fullTypeNameId, 0);
}
}
}
else if (!XMLString::compareString(redefineChildComponentName, SchemaSymbols::fgELT_GROUP)) {
- if (fGroupRegistry->containsKey(fBuffer.getRawBuffer())) {
+ if (fGroupRegistry->containsKey(typeNameStr)) {
return false;
}
@@ -6560,13 +6570,15 @@
// when processing groups, we will check that table, if a value
// is found, we need to do a particle derivation check.
fRedefineComponents->put((void*) SchemaSymbols::fgELT_GROUP,
- typeNameId, fTargetNSURIString);
+ fullTypeNameId, fSchemaInfo->getCurrentSchemaURL());
}
-
+ else {
+ fRedefineComponents->put((void*) SchemaSymbols::fgELT_GROUP, fullTypeNameId, 0);
+ }
}
else if (!XMLString::compareString(redefineChildComponentName, SchemaSymbols::fgELT_ATTRIBUTEGROUP)) {
- if (fAttributeDeclRegistry->containsKey(redefineChildTypeName)) {
+ if (fAttGroupRegistry->containsKey(redefineChildTypeName)) {
return false;
}
@@ -6584,7 +6596,10 @@
// a value is found, we need to check for attribute derivation ok
// (by restriction)
fRedefineComponents->put((void*) SchemaSymbols::fgELT_ATTRIBUTEGROUP,
- typeNameId, fTargetNSURIString);
+ fullTypeNameId, fSchemaInfo->getCurrentSchemaURL());
+ }
+ else {
+ fRedefineComponents->put((void*) SchemaSymbols::fgELT_ATTRIBUTEGROUP, fullTypeNameId, 0);
}
}
@@ -6696,8 +6711,14 @@
}
foundIt = true;
+
+ SchemaInfo* reRedefinedSchemaInfo = fSchemaInfo;
+
+ SchemaInfo* redefInfo =
+ redefinedSchemaInfo->getRedefInfo(redefineChildComponentName, redefineChildTypeName);
- SchemaInfo* reRedefinedSchemaInfo = fCurrentSchemaInfo;
+ reRedefinedSchemaInfo->addRedefineInfo(redefineChildComponentName,
+ redefineChildTypeName, redefInfo);
if (validateRedefineNameChange(redefChild, redefineChildComponentName, redefineChildTypeName, redefineNameCounter + 1, redefinedSchemaInfo)) {
fixRedefinedSchema(reRedefinedSchemaInfo, redefineChildComponentName, redefineChildTypeName, redefineNameCounter + 1);
@@ -6708,12 +6729,16 @@
// now we have to do the renaming...
getRedefineNewTypeName(infoItemName, redefineNameCounter, fBuffer);
- const XMLCh* newInfoItemName = fBuffer.getRawBuffer();
+ const XMLCh* newInfoItemName = fStringPool->getValueForId(fStringPool->addOrFind(fBuffer.getRawBuffer()));
redefChild.setAttribute(SchemaSymbols::fgATT_NAME, newInfoItemName);
// and we now know we will traverse this, so set fRedefineComponents appropriately...
- unsigned int infoItemNameId = fStringPool->addOrFind(newInfoItemName);
+ fBuffer.set(fTargetNSURIString);
+ fBuffer.append(chComma);
+ fBuffer.append(newInfoItemName);
+ unsigned int infoItemNameId = fStringPool->addOrFind(fBuffer.getRawBuffer());
+
if (!fRedefineComponents->containsKey(redefineChildComponentName, infoItemNameId)) {
fRedefineComponents->put((void*) redefineChildComponentName, infoItemNameId, 0);
}
@@ -6766,14 +6791,32 @@
}
// ---------------------------------------------------------------------------
-// TraverseSchema: CleanUp methods
+// TraverseSchema: Init/CleanUp methods
// ---------------------------------------------------------------------------
+void TraverseSchema::init() {
+
+ if (fScanner && fScanner->getValidationSchemaFullChecking()) {
+ fFullConstraintChecking = true;
+ }
+
+ fDatatypeRegistry = fGrammarResolver->getDatatypeRegistry();
+ fDatatypeRegistry->expandRegistryToFullSchemaSet();
+ fStringPool = fGrammarResolver->getStringPool();
+ fEmptyNamespaceURI = fScanner->getEmptyNamespaceId();
+ fAttributeCheck = GeneralAttributeCheck::instance();
+ fCurrentTypeNameStack = new ValueVectorOf<unsigned int>(8);
+ fCurrentGroupStack = new ValueVectorOf<unsigned int>(8);
+ fGlobalTypes = new RefHash2KeysTableOf<XMLCh>(29, false);
+ fGlobalAttributes = new RefHash2KeysTableOf<XMLCh>(13, false);
+ fGlobalGroups = new RefHash2KeysTableOf<XMLCh>(13, false);
+ fGlobalAttGroups = new RefHash2KeysTableOf<XMLCh>(13, false);
+ fSubstitutionGroups = new RefHash2KeysTableOf<SchemaElementDecl>(29, false);
+ fSchemaInfoList = new RefHashTableOf<SchemaInfo>(29);
+}
+
void TraverseSchema::cleanUp() {
- delete [] fTargetNSURIString;
- delete [] fCurrentSchemaURL;
- delete fIncludeLocations;
- delete fSchemaInfoRoot;
+ delete fSchemaInfoList;
delete fCurrentTypeNameStack;
delete fCurrentGroupStack;
delete fGlobalTypes;
@@ -6784,39 +6827,9 @@
delete fSubstitutionGroups;
delete fRefElements;
delete fRefElemScope;
-
- if (fAdoptImportLocations) {
- delete fImportLocations;
- }
}
/**
* End of file TraverseSchema.cpp
*/
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1.22 +38 -76 xml-xerces/c/src/validators/schema/TraverseSchema.hpp
Index: TraverseSchema.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/TraverseSchema.hpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TraverseSchema.hpp 2001/08/27 20:14:42 1.21
+++ TraverseSchema.hpp 2001/10/04 15:08:56 1.22
@@ -55,7 +55,7 @@
*/
/*
- * $Id: TraverseSchema.hpp,v 1.21 2001/08/27 20:14:42 knoaman Exp $
+ * $Id: TraverseSchema.hpp,v 1.22 2001/10/04 15:08:56 knoaman Exp $
*/
#if !defined(TRAVERSESCHEMA_HPP)
@@ -76,6 +76,7 @@
#include <util/ValueVectorOf.hpp>
#include <util/RefHash2KeysTableOf.hpp>
#include <validators/schema/SchemaGrammar.hpp>
+#include <validators/schema/SchemaInfo.hpp>
// ---------------------------------------------------------------------------
// Forward Declarations
@@ -92,7 +93,6 @@
class ContentSpecNode;
class NamespaceScope;
class SchemaAttDef;
-class SchemaInfo;
class InputSource;
class ErrorHandler;
class GeneralAttributeCheck;
@@ -117,16 +117,10 @@
, const XMLCh* const schemaURL
, EntityResolver* const entityResolver
, ErrorHandler* const errorHandler
- , ValueVectorOf<unsigned int>* const importLocations = 0
);
~TraverseSchema();
- // -----------------------------------------------------------------------
- // Setter methods
- // -----------------------------------------------------------------------
- void setCurrentSchemaURL(const XMLCh* const urlStr);
-
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
@@ -135,8 +129,9 @@
void operator=(const TraverseSchema&);
// -----------------------------------------------------------------------
- // CleanUp methods
+ // Init/CleanUp methods
// -----------------------------------------------------------------------
+ void init();
void cleanUp();
// -----------------------------------------------------------------------
@@ -145,8 +140,9 @@
/**
* Traverse the Schema DOM tree
*/
- void doTraverseSchema();
- void traverseSchemaHeader();
+ void doTraverseSchema(const DOM_Element& schemaRoot,
+ const XMLCh* const schemaURL);
+ void traverseSchemaHeader(const DOM_Element& schemaRoot);
void traverseAnnotationDecl(const DOM_Element& childElem);
void traverseInclude(const DOM_Element& childElem);
void traverseImport(const DOM_Element& childElem);
@@ -176,20 +172,17 @@
const int typeNameIndex,
const int finalSet,
int baseRefContext);
- QName* traverseElementDecl(const DOM_Element& childElem);
+ QName* traverseElementDecl(const DOM_Element& childElem, bool& toDelete);
XMLCh* traverseNotationDecl(const DOM_Element& childElem);
ContentSpecNode* traverseChoiceSequence(const DOM_Element& elemDecl,
- const int modelGroupType,
- bool& toAdoptSpecNode);
+ const int modelGroupType);
ContentSpecNode* traverseAny(const DOM_Element& anyDecl);
ContentSpecNode* traverseAll(const DOM_Element& allElem);
XercesGroupInfo* traverseGroupDecl(const DOM_Element& childElem);
- XercesGroupInfo* traverseGroupDeclNS(const XMLCh* const uriStr,
- const XMLCh* const groupName);
XercesAttGroupInfo* traverseAttributeGroupDecl(const DOM_Element& elem,
ComplexTypeInfo* const typeInfo);
XercesAttGroupInfo* traverseAttributeGroupDeclNS(const XMLCh* const uriStr,
- const XMLCh* const attGroupName);
+ const XMLCh* const name);
SchemaAttDef* traverseAnyAttribute(const DOM_Element& elem);
// -----------------------------------------------------------------------
@@ -209,7 +202,7 @@
/**
* Retrived the Namespace mapping from the schema element
*/
- void retrieveNamespaceMapping();
+ void retrieveNamespaceMapping(const DOM_Element& schemaRoot);
/**
* Loop through the children, and traverse the corresponding schema type
@@ -271,23 +264,6 @@
const XMLCh* const baseTypeStr,
const int baseRefContext);
- /**
- * Return a compenent defined as a top level in a schema grammar
- *
- * In redefine we've not only got to look at the space of the thing we
- * are redefining but at the original schema too. The idea is to start
- * from the top, then go down through our list of schemas until we find
- * what we want. This should not often be necessary, because we've
- * processed all redefined schemas, but there are conditions in which not
- * all elements so redefined may have been promoted to the topmost level.
- */
- DOM_Element getTopLevelComponentByName(const XMLCh* const compCategory,
- const XMLCh* const name);
-
- DOM_Element getTopLevelComponentByName(const XMLCh* const compCategory,
- const XMLCh* const name,
- SchemaInfo* const currentInfo);
-
const XMLCh* resolvePrefixToURI(const XMLCh* const prefix);
/**
@@ -315,7 +291,8 @@
* Process a 'ref' of an Element declaration
*/
QName* processElementDeclRef(const DOM_Element& elem,
- const XMLCh* const refName);
+ const XMLCh* const refName,
+ bool& toDelete);
/**
* Process a 'ref' of an Attribute declaration
@@ -386,13 +363,6 @@
bool& noErrorDetected);
/**
- * Return a Schema element declared in another schema
- */
- SchemaElementDecl* getElementDeclFromNS(const XMLCh* const nameUri,
- const XMLCh* const localPart);
-
-
- /**
* Check validity constraint of a substitutionGroup attribute in
* an element declaration
*/
@@ -472,12 +442,7 @@
/**
* Generate a name for an anonymous type
*/
- const XMLCh* genAnonTypeName(const XMLCh* const prefix,
- int& anonCount);
-
- int addAttributeDeclFromAnotherSchema(const XMLCh* const name,
- const XMLCh* const uri,
- ComplexTypeInfo* const typeInfo);
+ const XMLCh* genAnonTypeName(const XMLCh* const prefix);
void defaultComplexTypeInfo(ComplexTypeInfo* const typeInfo);
@@ -487,7 +452,8 @@
*/
InputSource* resolveSchemaLocation(const XMLCh* const loc);
- void restoreSchemaInfo(SchemaInfo* const toRestore);
+ void restoreSchemaInfo(SchemaInfo* const toRestore,
+ SchemaInfo::ListType const aListType = SchemaInfo::INCLUDE);
int resetCurrentTypeNameStack(const int);
/**
@@ -650,6 +616,12 @@
*/
void preprocessRedefineInclude(SchemaInfo* const currSchemaInfo);
+ /**
+ * Update the list of valid substitution groups in the case of circular
+ * import.
+ */
+ void updateCircularSubstitutionList(SchemaInfo* const aSchemaInfo);
+
// -----------------------------------------------------------------------
// Private constants
// -----------------------------------------------------------------------
@@ -667,6 +639,12 @@
InvalidComplexTypeInfo = 1
};
+ enum
+ {
+ Elem_Def_Qualified = 1,
+ Attr_Def_Qualified = 2
+ };
+
// Flags indicate any special restrictions on minOccurs and maxOccurs
// relating to "all".
// Not_All_Context - not processing an <all>
@@ -684,21 +662,16 @@
// -----------------------------------------------------------------------
// Private data members
// -----------------------------------------------------------------------
- bool fElementDefaultQualified;
- bool fAttributeDefaultQualified;
- bool fAdoptImportLocations;
+ bool fFullConstraintChecking;
+ unsigned short fElemAttrDefaultQualified;
int fTargetNSURI;
int fEmptyNamespaceURI;
int fCurrentScope;
- int fSimpleTypeAnonCount;
- int fComplexTypeAnonCount;
int fFinalDefault;
int fBlockDefault;
int fScopeCount;
- unsigned int fCurrentNamespaceLevel;
- DOM_Element fSchemaRootElement;
- XMLCh* fTargetNSURIString;
- XMLCh* fCurrentSchemaURL;
+ unsigned int fAnonXSTypeCount;
+ const XMLCh* fTargetNSURIString;
DatatypeValidatorFactory* fDatatypeRegistry;
GrammarResolver* fGrammarResolver;
SchemaGrammar* fSchemaGrammar;
@@ -714,13 +687,11 @@
RefHashTableOf<ComplexTypeInfo>* fComplexTypeRegistry;
RefHashTableOf<XercesGroupInfo>* fGroupRegistry;
RefHashTableOf<XercesAttGroupInfo>* fAttGroupRegistry;
- RefHashTableOf<SchemaInfo>* fIncludeLocations;
- SchemaInfo* fSchemaInfoRoot;
- SchemaInfo* fCurrentSchemaInfo;
+ RefHashTableOf<SchemaInfo>* fSchemaInfoList;
+ SchemaInfo* fSchemaInfo;
XercesGroupInfo* fCurrentGroupInfo;
XercesAttGroupInfo* fCurrentAttGroupInfo;
ComplexTypeInfo* fCurrentComplexType;
- ValueVectorOf<unsigned int>* fImportLocations;
ValueVectorOf<unsigned int>* fCurrentTypeNameStack;
ValueVectorOf<unsigned int>* fCurrentGroupStack;
GeneralAttributeCheck* fAttributeCheck;
@@ -731,7 +702,8 @@
RefHash2KeysTableOf<XMLCh>* fRedefineComponents;
RefHash2KeysTableOf<SchemaElementDecl>* fSubstitutionGroups;
RefHash2KeysTableOf<ElemVector>* fValidSubstitutionGroups;
- RefVectorOf<SchemaElementDecl>* fRefElements;
+ RefHash2KeysTableOf<ElemVector>* fGrammarSubstitutionGroups;
+ RefVectorOf<QName>* fRefElements;
ValueVectorOf<int>* fRefElemScope;
friend class GeneralAttributeCheck;
@@ -739,15 +711,6 @@
// ---------------------------------------------------------------------------
-// TraverseSchema: Setter methods
-// ---------------------------------------------------------------------------
-inline void TraverseSchema::setCurrentSchemaURL(const XMLCh* const urlStr) {
-
- delete [] fCurrentSchemaURL;
- fCurrentSchemaURL = XMLString::replicate(urlStr);
-}
-
-// ---------------------------------------------------------------------------
// TraverseSchema: Helper methods
// ---------------------------------------------------------------------------
inline const XMLCh* TraverseSchema::getPrefix(const XMLCh* const rawName) {
@@ -857,12 +820,11 @@
return false;
}
-inline const XMLCh* TraverseSchema::genAnonTypeName(const XMLCh* const prefix,
- int& anonCount) {
+inline const XMLCh* TraverseSchema::genAnonTypeName(const XMLCh* const prefix) {
XMLCh anonCountStr[16]; // a count of 15 digits should be enough
- XMLString::binToText(anonCount++, anonCountStr, 15, 10);
+ XMLString::binToText(fAnonXSTypeCount++, anonCountStr, 15, 10);
fBuffer.set(prefix);
fBuffer.append(anonCountStr);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org