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 2002/01/15 20:09:17 UTC
cvs commit: xml-xerces/c/src/validators/schema ComplexTypeInfo.cpp ComplexTypeInfo.hpp TraverseSchema.cpp TraverseSchema.hpp
knoaman 02/01/15 11:09:17
Modified: c/src/validators/schema ComplexTypeInfo.cpp
ComplexTypeInfo.hpp TraverseSchema.cpp
TraverseSchema.hpp
Log:
Fix for bug 5807.
Revision Changes Path
1.27 +5 -0 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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- ComplexTypeInfo.cpp 2 Jan 2002 15:20:22 -0000 1.26
+++ ComplexTypeInfo.cpp 15 Jan 2002 19:09:16 -0000 1.27
@@ -56,6 +56,9 @@
/*
* $Log: ComplexTypeInfo.cpp,v $
+ * Revision 1.27 2002/01/15 19:09:16 knoaman
+ * Fix for bug 5807.
+ *
* Revision 1.26 2002/01/02 15:20:22 tng
* Schema Fix: should not store a temp value as the key in the element pool and the attribute pool.
*
@@ -156,12 +159,14 @@
: fAbstract(false)
, fAdoptContentSpec(true)
, fAttWithTypeId(false)
+ , fPreprocessed(false)
, fDerivedBy(0)
, fBlockSet(0)
, fFinalSet(0)
, fScopeDefined(Grammar::TOP_LEVEL_SCOPE)
, fElementId(XMLElementDecl::fgInvalidElemId)
, fContentType(SchemaElementDecl::Empty)
+ , fRecursingTypeIndex(-1)
, fTypeName(0)
, fBaseDatatypeValidator(0)
, fDatatypeValidator(0)
1.13 +27 -2 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- ComplexTypeInfo.hpp 21 Nov 2001 14:30:13 -0000 1.12
+++ ComplexTypeInfo.hpp 15 Jan 2002 19:09:16 -0000 1.13
@@ -55,7 +55,7 @@
*/
/*
- * $Id: ComplexTypeInfo.hpp,v 1.12 2001/11/21 14:30:13 knoaman Exp $
+ * $Id: ComplexTypeInfo.hpp,v 1.13 2002/01/15 19:09:16 knoaman Exp $
*/
#if !defined(COMPLEXTYPEINFO_HPP)
@@ -104,6 +104,7 @@
bool getAbstract() const;
bool getAdoptContentSpec() const;
bool containsAttWithTypeId() const;
+ bool getPreprocessed() const;
int getDerivedBy() const;
int getBlockSet() const;
int getFinalSet() const;
@@ -127,7 +128,7 @@
SchemaElementDecl* elementAt(const unsigned int index);
XMLContentModel* getContentModel(const bool checkUPA = false);
const XMLCh* getFormattedContentModel () const;
-
+ int getRecursingTypeIndex() const;
// -----------------------------------------------------------------------
// Setter methods
@@ -135,6 +136,7 @@
void setAbstract(const bool isAbstract);
void setAdoptContentSpec(const bool toAdopt);
void setAttWithTypeId(const bool value);
+ void setPreprocessed(const bool aValue = true);
void setDerivedBy(const int derivedBy);
void setBlockSet(const int blockSet);
void setFinalSet(const int finalSet);
@@ -150,6 +152,7 @@
void addAttDef(SchemaAttDef* const toAdd);
void addElement(SchemaElementDecl* const toAdd);
void setContentModel(XMLContentModel* const newModelToAdopt);
+ void setRecursingTypeIndex(const int anIndex);
// -----------------------------------------------------------------------
// Helper methods
@@ -198,12 +201,14 @@
bool fAbstract;
bool fAdoptContentSpec;
bool fAttWithTypeId;
+ bool fPreprocessed;
int fDerivedBy;
int fBlockSet;
int fFinalSet;
int fScopeDefined;
unsigned int fElementId;
int fContentType;
+ int fRecursingTypeIndex;
XMLCh* fTypeName;
DatatypeValidator* fBaseDatatypeValidator;
DatatypeValidator* fDatatypeValidator;
@@ -239,6 +244,11 @@
return fAttWithTypeId;
}
+inline bool ComplexTypeInfo::getPreprocessed() const {
+
+ return fPreprocessed;
+}
+
inline int ComplexTypeInfo::getDerivedBy() const {
return fDerivedBy;
@@ -361,6 +371,11 @@
return fContentModel;
}
+inline int ComplexTypeInfo::getRecursingTypeIndex() const {
+
+ return fRecursingTypeIndex;
+}
+
// ---------------------------------------------------------------------------
// ComplexTypeInfo: Setter methods
// ---------------------------------------------------------------------------
@@ -379,6 +394,11 @@
fAttWithTypeId = value;
}
+inline void ComplexTypeInfo::setPreprocessed(const bool aValue) {
+
+ fPreprocessed = aValue;
+}
+
inline void ComplexTypeInfo::setDerivedBy(const int derivedBy) {
fDerivedBy = derivedBy;
@@ -460,6 +480,11 @@
{
delete fContentModel;
fContentModel = newModelToAdopt;
+}
+
+inline void ComplexTypeInfo::setRecursingTypeIndex(const int anIndex) {
+
+ fRecursingTypeIndex = anIndex;
}
// ---------------------------------------------------------------------------
1.76 +116 -47 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.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- TraverseSchema.cpp 10 Jan 2002 17:44:49 -0000 1.75
+++ TraverseSchema.cpp 15 Jan 2002 19:09:16 -0000 1.76
@@ -55,7 +55,7 @@
*/
/*
- * $Id: TraverseSchema.cpp,v 1.75 2002/01/10 17:44:49 knoaman Exp $
+ * $Id: TraverseSchema.cpp,v 1.76 2002/01/15 19:09:16 knoaman Exp $
*/
// ---------------------------------------------------------------------------
@@ -189,11 +189,12 @@
, fTargetNSURI(-1)
, fEmptyNamespaceURI(-1)
, fCurrentScope(Grammar::TOP_LEVEL_SCOPE)
- , fAnonXSTypeCount(0)
- , fCircularCheckIndex(0)
, fFinalDefault(0)
, fBlockDefault(0)
, fScopeCount(0)
+ , fRecursingElemIndex(0)
+ , fAnonXSTypeCount(0)
+ , fCircularCheckIndex(0)
, fTargetNSURIString(0)
, fDatatypeRegistry(0)
, fGrammarResolver(grammarResolver)
@@ -229,6 +230,8 @@
, fIC_NodeListNS(0)
, fIC_ElementsNS(0)
, fIC_NamespaceDepthNS(0)
+ , fRecursingAnonTypes(0)
+ , fRecursingTypeNames(0)
{
try {
@@ -1060,7 +1063,8 @@
* ( (attribute | attributeGroup)* , anyAttribute?))))
* </complexType>
*/
-int TraverseSchema::traverseComplexTypeDecl(const DOM_Element& elem) {
+int TraverseSchema::traverseComplexTypeDecl(const DOM_Element& elem,
+ const XMLCh* const recursingTypeName) {
// Get the attributes of the complexType
const XMLCh* name = getElementAttValue(elem, SchemaSymbols::fgATT_NAME);
@@ -1074,7 +1078,10 @@
return -1;
}
- name = genAnonTypeName(fgAnonCNamePrefix);
+ if (recursingTypeName)
+ name = recursingTypeName;
+ else
+ name = genAnonTypeName(fgAnonCNamePrefix);
}
if (!XMLString::isValidNCName(name)) {
@@ -1094,11 +1101,13 @@
int typeNameIndex = fStringPool->addOrFind(fBuffer.getRawBuffer());
const XMLCh* fullName = fStringPool->getValueForId(typeNameIndex);
- if (topLevel) {
+ ComplexTypeInfo* typeInfo = 0;
- ComplexTypeInfo* temp = fComplexTypeRegistry->get(fullName);
+ if (topLevel || recursingTypeName) {
- if (temp != 0 ) {
+ typeInfo = fComplexTypeRegistry->get(fullName);
+
+ if (typeInfo && !typeInfo->getPreprocessed()) {
return typeNameIndex;
}
}
@@ -1113,10 +1122,30 @@
// -----------------------------------------------------------------------
// Create a new instance
// -----------------------------------------------------------------------
- ComplexTypeInfo* typeInfo = new ComplexTypeInfo();
+ bool preProcessFlag = (typeInfo) ? typeInfo->getPreprocessed() : false;
unsigned int previousCircularCheckIndex = fCircularCheckIndex;
int previousScope = fCurrentScope;
- fCurrentScope = fScopeCount++;
+
+ if (preProcessFlag) {
+
+ fCurrentScope = typeInfo->getScopeDefined();
+ typeInfo->setPreprocessed(false);
+ }
+ else {
+
+ // ------------------------------------------------------------------
+ // Register the type
+ // ------------------------------------------------------------------
+ typeInfo = new ComplexTypeInfo();
+ fCurrentScope = fScopeCount++;
+ fComplexTypeRegistry->put((void*) fullName, typeInfo);
+ typeInfo->setTypeName(fullName);
+ typeInfo->setScopeDefined(fCurrentScope);
+ }
+
+ fCurrentTypeNameStack->addElement(typeNameIndex);
+ ComplexTypeInfo* saveTypeInfo = fCurrentComplexType;
+ fCurrentComplexType = typeInfo;
// ------------------------------------------------------------------
// First, handle any ANNOTATION declaration and get next child
@@ -1125,18 +1154,6 @@
true);
// ------------------------------------------------------------------
- // Register the type
- // ------------------------------------------------------------------
- // Register the type first, so that in case of a recursive element type
- // declaration, we can retrieve the complexType info (though the rest of
- fComplexTypeRegistry->put((void*) fullName, typeInfo);
- typeInfo->setTypeName(fullName);
- typeInfo->setScopeDefined(fCurrentScope);
- fCurrentTypeNameStack->addElement(typeNameIndex);
- ComplexTypeInfo* saveTypeInfo = fCurrentComplexType;
- fCurrentComplexType = typeInfo;
-
- // ------------------------------------------------------------------
// Process the content of the complex type declaration
// ------------------------------------------------------------------
try {
@@ -1182,39 +1199,62 @@
}
}
}
- catch(TraverseSchema::ExceptionCodes) {
- defaultComplexTypeInfo(typeInfo);
+ catch(const TraverseSchema::ExceptionCodes aCode) {
+ if (aCode == TraverseSchema::InvalidComplexTypeInfo)
+ defaultComplexTypeInfo(typeInfo);
+ else if (aCode == TraverseSchema::RecursingElement)
+ typeInfo->setPreprocessed();
}
// ------------------------------------------------------------------
// Finish the setup of the typeInfo
// ------------------------------------------------------------------
- const XMLCh* blockAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_BLOCK);
- const XMLCh* finalAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_FINAL);
- const XMLCh* abstractAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_ABSTRACT);
- int blockSet = parseBlockSet(blockAttVal, C_Block);
- int finalSet = parseFinalSet(finalAttVal, EC_Final);
-
- typeInfo->setBlockSet(blockSet);
- typeInfo->setFinalSet(finalSet);
-
- if (XMLString::stringLen(abstractAttVal)
- && (!XMLString::compareString(abstractAttVal, SchemaSymbols::fgATTVAL_TRUE)
- || !XMLString::compareString(abstractAttVal, fgValueOne))) {
- typeInfo->setAbstract(true);
- }
- else {
- typeInfo->setAbstract(false);
+ if (!preProcessFlag) {
+
+ const XMLCh* blockAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_BLOCK);
+ const XMLCh* finalAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_FINAL);
+ const XMLCh* abstractAttVal = getElementAttValue(elem, SchemaSymbols::fgATT_ABSTRACT);
+ int blockSet = parseBlockSet(blockAttVal, C_Block);
+ int finalSet = parseFinalSet(finalAttVal, EC_Final);
+
+ typeInfo->setBlockSet(blockSet);
+ typeInfo->setFinalSet(finalSet);
+
+ if (XMLString::stringLen(abstractAttVal)
+ && (!XMLString::compareString(abstractAttVal, SchemaSymbols::fgATTVAL_TRUE)
+ || !XMLString::compareString(abstractAttVal, fgValueOne))) {
+ typeInfo->setAbstract(true);
+ }
+ else {
+ typeInfo->setAbstract(false);
+ }
}
// ------------------------------------------------------------------
+ // Traverse anonymous complex types for recursing elements
+ // ------------------------------------------------------------------
+ resetCurrentTypeNameStack(0);
+ fCircularCheckIndex = previousCircularCheckIndex;
+
+ int i = fRecursingElemIndex - 1;
+ int recursingTypeIndex = typeInfo->getRecursingTypeIndex();
+
+ for (; i >= recursingTypeIndex && recursingTypeIndex != -1; i--) {
+
+ DOM_Element elem = fRecursingAnonTypes->elementAt(i);
+ const XMLCh* typeName = fRecursingTypeNames->elementAt(i);
+
+ fRecursingAnonTypes->removeElementAt(i);
+ fRecursingTypeNames->removeElementAt(i);
+ fRecursingElemIndex--;
+ traverseComplexTypeDecl(elem, typeName);
+ }
+
+ // ------------------------------------------------------------------
// Before exiting, restore the scope, mainly for nested anonymous types
// ------------------------------------------------------------------
fCurrentScope = previousScope;
fCurrentComplexType = saveTypeInfo;
- fCircularCheckIndex = previousCircularCheckIndex;
- resetCurrentTypeNameStack(0);
-
return typeNameIndex;
}
@@ -2280,7 +2320,24 @@
noErrorFound = false;
}
else if (!isDuplicate) {
+
typeInfo->setElementId(elemDecl->getId());
+
+ //Recursing element
+ if (typeInfo->getPreprocessed()) {
+
+ const XMLCh* typeInfoName = typeInfo->getTypeName();
+
+ if (!fRecursingAnonTypes) {
+ fRecursingAnonTypes = new ValueVectorOf<DOM_Element>(8);
+ fRecursingTypeNames = new ValueVectorOf<const XMLCh*>(8);
+ }
+
+ fRecursingAnonTypes->addElement(content);
+ fRecursingTypeNames->addElement(typeInfoName + XMLString::indexOf(typeInfoName, chComma) + 1);
+ typeInfo->getBaseComplexTypeInfo()->setRecursingTypeIndex(fRecursingElemIndex);
+ fRecursingElemIndex++;
+ }
}
anonymousType = true;
@@ -5621,11 +5678,21 @@
baseComplexTypeInfo = fComplexTypeRegistry->get(fullBaseName);
// Circular check
- if (baseComplexTypeInfo &&
- fCurrentTypeNameStack->containsElement(fStringPool->addOrFind(fullBaseName), fCircularCheckIndex)) {
+ if (baseComplexTypeInfo) {
- reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, fullBaseName);
- throw TraverseSchema::InvalidComplexTypeInfo;
+ if (fCurrentTypeNameStack->containsElement(fStringPool->addOrFind(fullBaseName), fCircularCheckIndex)) {
+
+ reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::NoCircularDefinition, fullBaseName);
+ throw TraverseSchema::InvalidComplexTypeInfo;
+ }
+ else if (fCurrentTypeNameStack->containsElement(fStringPool->addOrFind(fullBaseName))) {
+
+ typeInfo->setBaseComplexTypeInfo(baseComplexTypeInfo);
+ throw TraverseSchema::RecursingElement;
+ }
+ else if (baseComplexTypeInfo->getPreprocessed()) {
+ baseComplexTypeInfo = 0;
+ }
}
}
@@ -8502,6 +8569,8 @@
delete fIC_ElementsNS;
delete fIC_NamespaceDepthNS;
delete fIC_NodeListNS;
+ delete fRecursingAnonTypes;
+ delete fRecursingTypeNames;
}
/**
1.31 +7 -5 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.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- TraverseSchema.hpp 10 Jan 2002 17:44:49 -0000 1.30
+++ TraverseSchema.hpp 15 Jan 2002 19:09:17 -0000 1.31
@@ -55,7 +55,7 @@
*/
/*
- * $Id: TraverseSchema.hpp,v 1.30 2002/01/10 17:44:49 knoaman Exp $
+ * $Id: TraverseSchema.hpp,v 1.31 2002/01/15 19:09:17 knoaman Exp $
*/
#if !defined(TRAVERSESCHEMA_HPP)
@@ -181,7 +181,7 @@
const bool isMixed);
int traverseSimpleTypeDecl(const DOM_Element& childElem,
int baseRefContext = SchemaSymbols::EMPTY_SET);
- int traverseComplexTypeDecl(const DOM_Element& childElem);
+ int traverseComplexTypeDecl(const DOM_Element& childElem, const XMLCh* const recursingTypeName = 0);
int traverseByList(const DOM_Element& rootElem,
const DOM_Element& contentElem,
const int typeNameIndex,
@@ -757,8 +757,7 @@
{
NoException = 0,
InvalidComplexTypeInfo = 1,
- ParticleDerivationNotOK = 2,
- InvalidContentSpecType = 3
+ RecursingElement = 2
};
enum
@@ -777,7 +776,8 @@
int fCurrentScope;
int fFinalDefault;
int fBlockDefault;
- int fScopeCount;
+ int fScopeCount;
+ int fRecursingElemIndex;
unsigned int fAnonXSTypeCount;
unsigned int fCircularCheckIndex;
const XMLCh* fTargetNSURIString;
@@ -817,6 +817,8 @@
RefHashTableOf<ValueVectorOf<DOM_Element> >* fIC_NodeListNS;
RefHashTableOf<ElemVector>* fIC_ElementsNS;
RefHashTableOf<ValueVectorOf<unsigned int> >* fIC_NamespaceDepthNS;
+ ValueVectorOf<DOM_Element>* fRecursingAnonTypes;
+ ValueVectorOf<const XMLCh*>* fRecursingTypeNames;
friend class GeneralAttributeCheck;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org