knoaman 2003/11/06 11:28:11 Modified: c/src/xercesc/framework/psvi XSAnnotation.cpp XSAnnotation.hpp c/src/xercesc/util Janitor.c Janitor.hpp c/src/xercesc/validators/schema SchemaGrammar.cpp SchemaGrammar.hpp TraverseSchema.cpp TraverseSchema.hpp Log: PSVI support for annotations. Revision Changes Path 1.2 +25 -9 xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.cpp Index: XSAnnotation.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XSAnnotation.cpp 16 Sep 2003 14:33:36 -0000 1.1 +++ XSAnnotation.cpp 6 Nov 2003 19:28:11 -0000 1.2 @@ -56,20 +56,35 @@ /* * $Log$ + * Revision 1.2 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.1 2003/09/16 14:33:36 neilg * PSVI/schema component model classes, with Makefile/configuration changes necessary to build them * */ #include <xercesc/framework/psvi/XSAnnotation.hpp> +#include <xercesc/util/XMLString.hpp> XERCES_CPP_NAMESPACE_BEGIN -XSAnnotation::XSAnnotation( MemoryManager * const manager): - XSObject(XSConstants::ANNOTATION, manager ) +XSAnnotation::XSAnnotation(const XMLCh* const content, + MemoryManager * const manager): + XSObject(XSConstants::ANNOTATION, manager) + , fContents(XMLString::replicate(content, manager)) + , fNext(0) { } +XSAnnotation::~XSAnnotation() +{ + fMemoryManager->deallocate(fContents); + + if (fNext) + delete fNext; +} + // XSAnnotation methods /** @@ -94,14 +109,15 @@ return false; } -/** - * A text representation of annotation. - */ -const XMLCh *XSAnnotation::getAnnotationString() +void XSAnnotation::setNext(XSAnnotation* const nextAnnotation) { - // REVISIT - return 0; + if (fNext) + fNext->setNext(nextAnnotation); + else + fNext = nextAnnotation; } + + XERCES_CPP_NAMESPACE_END 1.2 +26 -8 xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.hpp Index: XSAnnotation.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.hpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XSAnnotation.hpp 16 Sep 2003 14:33:36 -0000 1.1 +++ XSAnnotation.hpp 6 Nov 2003 19:28:11 -0000 1.2 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.2 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.1 2003/09/16 14:33:36 neilg * PSVI/schema component model classes, with Makefile/configuration changes necessary to build them * @@ -106,8 +109,11 @@ * * @param manager The configurable memory manager */ - XSAnnotation( - MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); + XSAnnotation + ( + const XMLCh* const contents + , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager + ); //@}; @@ -131,18 +137,18 @@ * @param target A target pointer to the annotation target object, i.e. * <code>DOMDocument</code>, * <code>DOMElement</code>, - * <code>ContentHandler</code>. + * <code>ContentHandler</code>. * @param targetType A target type. * @return If the <code>target</code> is a recognized type that is supported by * this implementation, and the operation succeeds, return true; otherwise return false. */ - bool writeAnnotation(void *target, - ANNOTATION_TARGET targetType); + bool writeAnnotation(void *target, ANNOTATION_TARGET targetType); /** * A text representation of annotation. */ - const XMLCh *getAnnotationString(); + const XMLCh *getAnnotationString() const; + XMLCh *getAnnotationString(); //@} @@ -150,6 +156,7 @@ // methods needed by implementation // @{ + void setNext(XSAnnotation* const nextAnnotation); //@} private: @@ -165,8 +172,19 @@ // ----------------------------------------------------------------------- // data members // ----------------------------------------------------------------------- + XMLCh* fContents; + XSAnnotation* fNext; }; -inline XSAnnotation::~XSAnnotation() {} + +inline const XMLCh *XSAnnotation::getAnnotationString() const +{ + return fContents; +} + +inline XMLCh *XSAnnotation::getAnnotationString() +{ + return fContents; +} XERCES_CPP_NAMESPACE_END 1.5 +12 -2 xml-xerces/c/src/xercesc/util/Janitor.c Index: Janitor.c =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Janitor.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Janitor.c 21 May 2003 03:34:52 -0000 1.4 +++ Janitor.c 6 Nov 2003 19:28:11 -0000 1.5 @@ -56,6 +56,9 @@ /** * $Log$ + * Revision 1.5 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.4 2003/05/21 03:34:52 jberry * Cast away CodeWarrior complaint of casting away const if we're holding a const obj * @@ -161,8 +164,15 @@ template <class T> void Janitor<T>::reset(T* p) { - delete fData; - fData = p; + if (fData) + delete fData; + + fData = p; +} + +template <class T> bool Janitor<T>::isDataNull() +{ + return (fData == 0); } 1.4 +11 -7 xml-xerces/c/src/xercesc/util/Janitor.hpp Index: Janitor.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/Janitor.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Janitor.hpp 15 May 2003 19:04:35 -0000 1.3 +++ Janitor.hpp 6 Nov 2003 19:28:11 -0000 1.4 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.4 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.3 2003/05/15 19:04:35 knoaman * Partial implementation of the configurable memory manager. * @@ -117,18 +120,19 @@ // ----------------------------------------------------------------------- void orphan(); - // small amount of auto_ptr compatibility - T& operator*() const; - T* operator->() const; - T* get() const; - T* release(); - void reset(T* p = 0); + // small amount of auto_ptr compatibility + T& operator*() const; + T* operator->() const; + T* get() const; + T* release(); + void reset(T* p = 0); + bool isDataNull(); private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators // ----------------------------------------------------------------------- - Janitor(); + Janitor(); Janitor(const Janitor<T>&); // ----------------------------------------------------------------------- 1.14 +29 -3 xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp Index: SchemaGrammar.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- SchemaGrammar.cpp 5 Nov 2003 16:38:08 -0000 1.13 +++ SchemaGrammar.cpp 6 Nov 2003 19:28:11 -0000 1.14 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.14 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.13 2003/11/05 16:38:08 peiyongz * serialize DatatypeValidatorFactory first * @@ -143,6 +146,8 @@ #include <xercesc/validators/schema/XercesAttGroupInfo.hpp> #include <xercesc/validators/schema/XMLSchemaDescriptionImpl.hpp> #include <xercesc/util/OutOfMemoryException.hpp> +#include <xercesc/util/HashPtr.hpp> +#include <xercesc/framework/psvi/XSAnnotation.hpp> #include <xercesc/internal/XTemplateSerializer.hpp> @@ -168,6 +173,7 @@ , fValidated(false) , fDatatypeRegistry(manager) , fGramDesc(0) + , fAnnotations(0) { // // Init all the pool members. @@ -189,6 +195,12 @@ //REVISIT: use grammarPool to create fGramDesc = new (fMemoryManager) XMLSchemaDescriptionImpl(XMLUni::fgXMLNSURIName, fMemoryManager); + // Create annotation table + fAnnotations = new (fMemoryManager) RefHashTableOf<XSAnnotation> + ( + 29, true, new (fMemoryManager) HashPtr(), fMemoryManager + ); + // // Call our own reset method. This lets us have the pool setup stuff // done in just one place (because this stame setup stuff has to be @@ -289,6 +301,7 @@ fElemNonDeclPool->removeAll(); fGroupElemDeclPool->removeAll(); fNotationDeclPool->removeAll(); + fAnnotations->removeAll(); fValidated = false; } @@ -310,7 +323,7 @@ delete fValidSubstitutionGroups; delete fIDRefList; delete fGramDesc; - + delete fAnnotations; } void SchemaGrammar::setGrammarDescription(XMLGrammarDescription* gramDesc) @@ -326,9 +339,22 @@ fGramDesc = (XMLSchemaDescription*) gramDesc; } -XMLGrammarDescription* SchemaGrammar::getGrammarDescription() const +// --------------------------------------------------------------------------- +// SchemaGrammar: Helper methods +// --------------------------------------------------------------------------- +void SchemaGrammar::putAnnotation(void* key, XSAnnotation* const annotation) +{ + fAnnotations->put(key, annotation); +} + +void SchemaGrammar::addAnnotation(XSAnnotation* const annotation) { - return fGramDesc; + XSAnnotation* lAnnot = fAnnotations->get(this); + + if (lAnnot) + lAnnot->setNext(annotation); + else + fAnnotations->put(this, annotation); } /*** 1.11 +67 -0 xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp Index: SchemaGrammar.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/SchemaGrammar.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SchemaGrammar.hpp 14 Oct 2003 15:22:28 -0000 1.10 +++ SchemaGrammar.hpp 6 Nov 2003 19:28:11 -0000 1.11 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.11 2003/11/06 19:28:11 knoaman + * PSVI support for annotations. + * * Revision 1.10 2003/10/14 15:22:28 peiyongz * Implementation of Serialization/Deserialization * @@ -162,6 +165,7 @@ class NamespaceScope; class XercesGroupInfo; class XercesAttGroupInfo; +class XSAnnotation; // --------------------------------------------------------------------------- // typedef declaration @@ -303,6 +307,43 @@ XMLElementDecl* const elemDecl ) const; + // ----------------------------------------------------------------------- + // Annotation management methods + // ----------------------------------------------------------------------- + /** + * Add annotation to the list of annotations for a given key + */ + void putAnnotation(void* key, XSAnnotation* const annotation); + + /** + * Add global annotation + * + * Note: XSAnnotation acts as a linked list + */ + void addAnnotation(XSAnnotation* const annotation); + + /** + * Retrieve the annotation that is associated with the specified key + * + * @param key represents a schema component object (i.e. SchemaGrammar) + * @return XSAnnotation associated with the key object + */ + XSAnnotation* getAnnotation(const void* const key); + + /** + * Retrieve the annotation that is associated with the specified key + * + * @param key represents a schema component object (i.e. SchemaGrammar) + * @return XSAnnotation associated with the key object + */ + const XSAnnotation* getAnnotation(const void* const key) const; + + /** + * Get global annotation + */ + XSAnnotation* getAnnotation(); + const XSAnnotation* getAnnotation() const; + /*** * Support for Serialization/De-serialization ***/ @@ -388,6 +429,7 @@ bool fValidated; DatatypeValidatorFactory fDatatypeRegistry; XMLSchemaDescription* fGramDesc; + RefHashTableOf<XSAnnotation>* fAnnotations; }; @@ -442,6 +484,31 @@ inline RefHashTableOf<XMLRefInfo>* SchemaGrammar::getIDRefList() const { return fIDRefList; +} + +inline XMLGrammarDescription* SchemaGrammar::getGrammarDescription() const +{ + return fGramDesc; +} + +inline XSAnnotation* SchemaGrammar::getAnnotation(const void* const key) +{ + return fAnnotations->get(key); +} + +inline const XSAnnotation* SchemaGrammar::getAnnotation(const void* const key) const +{ + return fAnnotations->get(key); +} + +inline XSAnnotation* SchemaGrammar::getAnnotation() +{ + return fAnnotations->get(this); +} + +inline const XSAnnotation* SchemaGrammar::getAnnotation() const +{ + return fAnnotations->get(this); } // ----------------------------------------------------------------------- 1.91 +248 -51 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp Index: TraverseSchema.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.cpp,v retrieving revision 1.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- TraverseSchema.cpp 6 Nov 2003 15:30:08 -0000 1.90 +++ TraverseSchema.cpp 6 Nov 2003 19:28:11 -0000 1.91 @@ -90,9 +90,11 @@ #include <xercesc/validators/schema/XSDDOMParser.hpp> #include <xercesc/util/HashPtr.hpp> #include <xercesc/dom/DOMNamedNodeMap.hpp> +#include <xercesc/dom/DOMText.hpp> #include <xercesc/dom/impl/XSDElementNSImpl.hpp> #include <xercesc/util/OutOfMemoryException.hpp> #include <xercesc/util/XMLEntityResolver.hpp> +#include <xercesc/framework/psvi/XSAnnotation.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -447,14 +449,15 @@ } -void TraverseSchema::traverseAnnotationDecl(const DOMElement* const annotationElem, - const bool topLevel) { +XSAnnotation* TraverseSchema::traverseAnnotationDecl(const DOMElement* const annotationElem, + const bool topLevel) { // ----------------------------------------------------------------------- // Check Attributes // ----------------------------------------------------------------------- fAttributeCheck.checkAttributes(annotationElem, GeneralAttributeCheck::E_Annotation, this, topLevel); + const XMLCh* contents = 0; for (DOMElement* child = XUtil::getFirstChildElement(annotationElem); child != 0; child = XUtil::getNextSiblingElement(child)) { @@ -462,15 +465,30 @@ const XMLCh* name = child->getLocalName(); if (XMLString::equals(name, SchemaSymbols::fgELT_APPINFO)) { + + DOMNode* textContent = child->getFirstChild(); + if (textContent && textContent->getNodeType() == DOMNode::TEXT_NODE) + contents = ((DOMText*) textContent)->getData(); + fAttributeCheck.checkAttributes(child, GeneralAttributeCheck::E_Appinfo, this); } else if (XMLString::equals(name, SchemaSymbols::fgELT_DOCUMENTATION)) { + + DOMNode* textContent = child->getFirstChild(); + if (textContent && textContent->getNodeType() == DOMNode::TEXT_NODE) + contents = ((DOMText*) textContent)->getData(); + fAttributeCheck.checkAttributes(child, GeneralAttributeCheck::E_Documentation, this); } else { reportSchemaError(child, XMLUni::fgXMLErrDomain, XMLErrs::InvalidAnnotationContent); } } + + if (contents) + return new (fGrammarPoolMemoryManager) XSAnnotation(contents, fGrammarPoolMemoryManager); + + return 0; } @@ -494,9 +512,11 @@ // ------------------------------------------------------------------ // First, handle any ANNOTATION declaration // ------------------------------------------------------------------ - if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { + if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::OnlyAnnotationExpected); - } + + if (fAnnotation) + fSchemaGrammar->addAnnotation(fAnnotation); // ------------------------------------------------------------------ // Get 'schemaLocation' attribute @@ -639,9 +659,11 @@ // ------------------------------------------------------------------ // First, handle any ANNOTATION declaration // ------------------------------------------------------------------ - if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { + if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::OnlyAnnotationExpected); - } + + if (fAnnotation) + fSchemaGrammar->addAnnotation(fAnnotation); // ------------------------------------------------------------------ // Handle 'namespace' attribute @@ -901,6 +923,7 @@ // Process contents // ------------------------------------------------------------------ DOMElement* child = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); ContentSpecNode* left = 0; ContentSpecNode* right = 0; bool hadContent = false; @@ -1007,6 +1030,9 @@ , true , fGrammarPoolMemoryManager ); + + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(left, janAnnot.release()); } return left; @@ -1081,9 +1107,9 @@ int finalSet = parseFinalSet(childElem, S_Final); // annotation?,(list|restriction|union) - DOMElement* content= checkContent(childElem, - XUtil::getFirstChildElement(childElem), - false); + DOMElement* content= checkContent( + childElem, XUtil::getFirstChildElement(childElem), false); + Janitor<XSAnnotation> janAnnot(fAnnotation); if (content == 0) { @@ -1104,27 +1130,26 @@ return 0; } - DatatypeValidator *tmpDV = traverseByList(childElem, content, name, fullName, finalSet); - if(tmpDV && nameEmpty) - tmpDV->setAnonymous(); - return tmpDV; + dv = traverseByList(childElem, content, name, fullName, finalSet, &janAnnot); } else if (XMLString::equals(varietyName, SchemaSymbols::fgELT_RESTRICTION)) { //traverse Restriction - DatatypeValidator *tmpDV = traverseByRestriction(childElem, content, name, fullName, finalSet); - if(tmpDV && nameEmpty) - tmpDV->setAnonymous(); - return tmpDV; + dv = traverseByRestriction(childElem, content, name, fullName, finalSet, &janAnnot); } else if (XMLString::equals(varietyName, SchemaSymbols::fgELT_UNION)) { //traverse union - DatatypeValidator *tmpDV = traverseByUnion(childElem, content, name, fullName, finalSet, baseRefContext); - if(tmpDV && nameEmpty) - tmpDV->setAnonymous(); - return tmpDV; + dv = traverseByUnion(childElem, content, name, fullName, finalSet, baseRefContext, &janAnnot); } else { reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::FeatureUnsupported, varietyName); popCurrentTypeNameStack(); } + + if (dv) { + if (nameEmpty) + dv->setAnonymous(); + + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(dv, janAnnot.release()); + } } return dv; @@ -1249,6 +1274,7 @@ // First, handle any ANNOTATION declaration and get next child // ------------------------------------------------------------------ DOMElement* child = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Process the content of the complex type declaration @@ -1275,7 +1301,7 @@ if (XMLString::equals(childName, SchemaSymbols::fgELT_SIMPLECONTENT)) { // SIMPLE CONTENT element - traverseSimpleContentDecl(name, fullName, child, typeInfo); + traverseSimpleContentDecl(name, fullName, child, typeInfo, &janAnnot); if (XUtil::getNextSiblingElement(child) != 0) { reportSchemaError(child, XMLUni::fgXMLErrDomain, XMLErrs::InvalidChildFollowingSimpleContent); @@ -1284,7 +1310,7 @@ else if (XMLString::equals(childName, SchemaSymbols::fgELT_COMPLEXCONTENT)) { // COMPLEX CONTENT element - traverseComplexContentDecl(name, child, typeInfo, isMixed); + traverseComplexContentDecl(name, child, typeInfo, isMixed, &janAnnot); if (XUtil::getNextSiblingElement(child) != 0) { reportSchemaError(child, XMLUni::fgXMLErrDomain, XMLErrs::InvalidChildFollowingConplexContent); @@ -1330,6 +1356,10 @@ } } + // Store Annotation + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(typeInfo, janAnnot.release()); + // ------------------------------------------------------------------ // Before exiting, restore the scope, mainly for nested anonymous types // ------------------------------------------------------------------ @@ -1382,11 +1412,6 @@ fAttributeCheck.checkAttributes(elem, scope, this, topLevel); // ------------------------------------------------------------------ - // Check for annotations - // ------------------------------------------------------------------ - DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); - - // ------------------------------------------------------------------ // Handle "ref=" // ------------------------------------------------------------------ if (!topLevel) { @@ -1398,9 +1423,6 @@ return processGroupRef(elem, ref); } - // ------------------------------------------------------------------ - // Process contents of global groups - // ------------------------------------------------------------------ // name must be a valid NCName if (!XMLString::isValidNCName(name)) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::InvalidDeclarationName, @@ -1420,6 +1442,15 @@ return groupInfo; } + // ------------------------------------------------------------------ + // Check for annotations + // ------------------------------------------------------------------ + DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); + + // ------------------------------------------------------------------ + // Process contents of global groups + // ------------------------------------------------------------------ int saveScope = fCurrentScope; ContentSpecNode* specNode = 0; XercesGroupInfo* saveGroupInfo = fCurrentGroupInfo; @@ -1479,6 +1510,10 @@ fCurrentGroupInfo = saveGroupInfo; fCurrentScope = saveScope; + // Store Annotation + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(groupInfo, janAnnot.release()); + if (fFullConstraintChecking) { XSDLocator* aLocator = new (fGrammarPoolMemoryManager) XSDLocator(); @@ -1565,6 +1600,7 @@ // Check for annotations // ------------------------------------------------------------------ DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Process contents of global attributeGroups @@ -1638,6 +1674,10 @@ } } + // Store annotation + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(attGroupInfo, janAnnot.release()); + return attGroupInfo; } @@ -1691,6 +1731,7 @@ if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::OnlyAnnotationExpected); } + Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Get attributes @@ -1826,6 +1867,10 @@ delete nameSpaceTokens; } + // Store annotation + if (retSpecNode && !janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(retSpecNode, janAnnot.release()); + return retSpecNode; } @@ -1853,6 +1898,7 @@ // Process contents // ------------------------------------------------------------------ DOMElement* child = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); if (child == 0) { return 0; @@ -1921,6 +1967,9 @@ , true , fGrammarPoolMemoryManager ); + + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(left, janAnnot.release()); } return left; @@ -1982,6 +2031,7 @@ const XMLCh* attForm = getElementAttValue(elem, SchemaSymbols::fgATT_FORM); const XMLCh* dvType = getElementAttValue(elem, SchemaSymbols::fgATT_TYPE); DOMElement* simpleType = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); bool badContent = false; while (simpleType != 0) { @@ -2265,6 +2315,9 @@ attDef->setValue(valueToCheck); } + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(attDef, janAnnot.release()); + if (topLevel) { fAttributeDeclRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), attDef); } @@ -2411,6 +2464,7 @@ // Resolve the type for the element const DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); if (content != 0) { @@ -2707,6 +2761,9 @@ elemDecl->setModelType(contentSpecType); elemDecl->setContentSpec(contentSpecNode); + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(elemDecl, janAnnot.release()); + if (isAnyType) { elemDecl->setAttWildCard(new (fGrammarPoolMemoryManager) SchemaAttDef(XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, @@ -2816,6 +2873,8 @@ //we don't really care if something inside <notation> is wrong.. checkContent(elem, XUtil::getFirstChildElement(elem), true); + if (fAnnotation) + fSchemaGrammar->putAnnotation(decl, fAnnotation); return name; } @@ -2882,7 +2941,8 @@ const DOMElement* const contentElem, const XMLCh* const typeName, const XMLCh* const qualifiedName, - const int finalSet) { + const int finalSet, + Janitor<XSAnnotation>* const janAnnot) { DatatypeValidator* baseValidator = 0; const XMLCh* baseTypeName = getElementAttValue(contentElem, SchemaSymbols::fgATT_ITEMTYPE); @@ -2899,6 +2959,14 @@ content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), false); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } + if (!content) { reportSchemaError(contentElem, XMLUni::fgXMLErrDomain, XMLErrs::ExpectedSimpleTypeInList, typeName); @@ -2922,6 +2990,14 @@ baseValidator = findDTValidator(contentElem, typeName, baseTypeName, SchemaSymbols::XSD_LIST); content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), true); + + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } } DatatypeValidator* newDV = 0; @@ -2969,7 +3045,8 @@ const DOMElement* const contentElem, const XMLCh* const typeName, const XMLCh* const qualifiedName, - const int finalSet) { + const int finalSet, + Janitor<XSAnnotation>* const janAnnot) { DatatypeValidator* baseValidator = 0; DatatypeValidator* newDV = 0; @@ -2987,6 +3064,14 @@ content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), false); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } + if (content == 0) { reportSchemaError(contentElem, XMLUni::fgXMLErrDomain, XMLErrs::ExpectedSimpleTypeInRestriction); @@ -3011,6 +3096,13 @@ baseValidator = findDTValidator(contentElem, typeName, baseTypeName, SchemaSymbols::XSD_RESTRICTION); content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), true); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } } if (baseValidator) { @@ -3019,6 +3111,8 @@ RefHashTableOf<KVStringPair>* facets = 0; RefArrayVectorOf<XMLCh>* enums = 0; XMLBuffer pattern(128, fGrammarPoolMemoryManager); + Janitor<XSAnnotation> janEnumAnnot(0); + Janitor<XSAnnotation> janPatternAnnot(0); XMLCh fixedFlagStr[16]; unsigned int fixedFlag = 0; unsigned short scope = 0; @@ -3044,6 +3138,11 @@ continue; } + // REVISIT + // check for annotation content - we are not checking whether the + // return is empty or not. If not empty we should report an error + checkContent(rootElem, XUtil::getFirstChildElement(content), true); + const XMLCh* attValue = content->getAttribute(SchemaSymbols::fgATT_VALUE); fAttributeCheck.checkAttributes(content, scope, this); @@ -3053,6 +3152,13 @@ if (XMLString::equals(facetName, SchemaSymbols::fgELT_ENUMERATION)) { + if (fAnnotation) { + if (janEnumAnnot.isDataNull()) + janEnumAnnot.reset(fAnnotation); + else + janEnumAnnot.get()->setNext(fAnnotation); + } + // REVISIT // if validator is a notation datatype validator, we need // to get the qualified name first before adding it to the @@ -3083,6 +3189,13 @@ } else if (XMLString::equals(facetName, SchemaSymbols::fgELT_PATTERN)) { + if (fAnnotation) { + if (janPatternAnnot.isDataNull()) + janPatternAnnot.reset(fAnnotation); + else + janPatternAnnot.get()->setNext(fAnnotation); + } + if (isFirstPattern) { // fBuffer.isEmpty() - overhead call isFirstPattern = false; @@ -3097,6 +3210,9 @@ else { if (facets->containsKey(facetName)) { + + if (fAnnotation) + delete fAnnotation; reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::DuplicateFacet, facetName); } else { @@ -3104,29 +3220,35 @@ if (XMLString::equals(facetName, SchemaSymbols::fgELT_WHITESPACE) && baseValidator->getType() != DatatypeValidator::String && !XMLString::equals(attValue, SchemaSymbols::fgWS_COLLAPSE)) { + + if (fAnnotation) + delete fAnnotation; reportSchemaError(content, XMLUni::fgXMLErrDomain, XMLErrs::WS_CollapseExpected, attValue); } else { const XMLCh* facetStr = fStringPool->getValueForId(fStringPool->addOrFind(facetName)); - facets->put((void*) facetStr, new (fGrammarPoolMemoryManager) KVStringPair(facetStr, attValue, fGrammarPoolMemoryManager)); + KVStringPair* kv = new (fGrammarPoolMemoryManager) KVStringPair(facetStr, attValue, fGrammarPoolMemoryManager); + + if (fAnnotation) + fSchemaGrammar->putAnnotation(kv, fAnnotation); + + facets->put((void*) facetStr, kv); checkFixedFacet(content, facetStr, baseValidator, fixedFlag); } } } - - // REVISIT - // check for annotation content - we are not checking whether the - // return is empty or not. If not empty we should report an error - checkContent(rootElem, XUtil::getFirstChildElement(content), true); } content = XUtil::getNextSiblingElement(content); } // end while if (!pattern.isEmpty()) { - facets->put((void*) SchemaSymbols::fgELT_PATTERN, - new (fGrammarPoolMemoryManager) KVStringPair(SchemaSymbols::fgELT_PATTERN, pattern.getRawBuffer(), fGrammarPoolMemoryManager)); + + KVStringPair* kv = new (fGrammarPoolMemoryManager) KVStringPair(SchemaSymbols::fgELT_PATTERN, pattern.getRawBuffer(), fGrammarPoolMemoryManager); + if (!janPatternAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(kv, janPatternAnnot.release()); + facets->put((void*) SchemaSymbols::fgELT_PATTERN, kv); } if (fixedFlag) { @@ -3136,6 +3258,9 @@ new (fGrammarPoolMemoryManager) KVStringPair(SchemaSymbols::fgATT_FIXED, fixedFlagStr, fGrammarPoolMemoryManager)); } + if (enums && !janEnumAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(enums, janEnumAnnot.release()); + try { newDV = fDatatypeRegistry->createDatatypeValidator(qualifiedName, baseValidator, facets, enums, false, finalSet); } @@ -3163,7 +3288,8 @@ const XMLCh* const typeName, const XMLCh* const qualifiedName, const int finalSet, - int baseRefContext) { + int baseRefContext, + Janitor<XSAnnotation>* const janAnnot) { fAttributeCheck.checkAttributes(contentElem, GeneralAttributeCheck::E_Union, this); @@ -3199,10 +3325,24 @@ } content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), true); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } } else { // must 'see' <simpleType> content = checkContent(rootElem, XUtil::getFirstChildElement(contentElem), false); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } if (content == 0) { @@ -3298,7 +3438,8 @@ void TraverseSchema::traverseSimpleContentDecl(const XMLCh* const typeName, const XMLCh* const qualifiedName, const DOMElement* const contentDecl, - ComplexTypeInfo* const typeInfo) + ComplexTypeInfo* const typeInfo, + Janitor<XSAnnotation>* const janAnnot) { // ----------------------------------------------------------------------- // Check Attributes @@ -3310,7 +3451,17 @@ // ----------------------------------------------------------------------- typeInfo->setContentType(SchemaElementDecl::Simple); + // ----------------------------------------------------------------------- + // Process annotation if any + // ----------------------------------------------------------------------- DOMElement* simpleContent = checkContent(contentDecl, XUtil::getFirstChildElement(contentDecl), false); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } // If there are no children, return if (simpleContent == 0) { @@ -3414,6 +3565,13 @@ // ----------------------------------------------------------------------- //Skip over any annotations in the restriction or extension elements DOMElement* content = checkContent(simpleContent, XUtil::getFirstChildElement(simpleContent), true); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } if (typeInfo->getDerivedBy() == SchemaSymbols::XSD_RESTRICTION) { @@ -3657,7 +3815,8 @@ void TraverseSchema::traverseComplexContentDecl(const XMLCh* const typeName, const DOMElement* const contentDecl, ComplexTypeInfo* const typeInfo, - const bool isMixed) + const bool isMixed, + Janitor<XSAnnotation>* const janAnnot) { // ------------------------------------------------------------------ // Check attributes @@ -3690,6 +3849,13 @@ typeInfo->setBaseDatatypeValidator(0); DOMElement* complexContent = checkContent(contentDecl,XUtil::getFirstChildElement(contentDecl),false); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } // If there are no children, return if (complexContent == 0) { @@ -3756,6 +3922,13 @@ // ----------------------------------------------------------------------- //Skip over any annotations in the restriction or extension elements DOMElement* content = checkContent(complexContent, XUtil::getFirstChildElement(complexContent), true); + if (fAnnotation) + { + if (janAnnot->isDataNull()) + janAnnot->reset(fAnnotation); + else + janAnnot->get()->setNext(fAnnotation); + } processComplexContent(complexContent, typeName, content, typeInfo, baseName, localPart, uri, mixedContent, isBaseAnyType); @@ -3787,6 +3960,7 @@ if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { reportSchemaError(elem, XMLUni::fgXMLErrDomain, XMLErrs::AnyAttributeContentError); } + Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Get attributes @@ -3872,6 +4046,8 @@ uriIndex, attType, attDefType, fGrammarPoolMemoryManager); + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(attDef, janAnnot.release()); if (namespaceList.size()) { attDef->setNamespaceList(&namespaceList); @@ -4094,6 +4270,7 @@ // First, handle any ANNOTATION declaration // ------------------------------------------------------------------ DOMElement* elem = checkContent(icElem, XUtil::getFirstChildElement(icElem), false); + Janitor<XSAnnotation> janAnnot(fAnnotation); // ------------------------------------------------------------------ // Get selector @@ -4112,6 +4289,13 @@ fAttributeCheck.checkAttributes(elem, GeneralAttributeCheck::E_Selector, this); checkContent(icElem, XUtil::getFirstChildElement(elem), true); + if (fAnnotation) + { + if (janAnnot.isDataNull()) + janAnnot.reset(fAnnotation); + else + janAnnot.get()->setNext(fAnnotation); + } // ------------------------------------------------------------------ // Get xpath attribute @@ -4183,6 +4367,13 @@ // General Attribute Checking fAttributeCheck.checkAttributes(elem, GeneralAttributeCheck::E_Field, this); checkContent(icElem, XUtil::getFirstChildElement(elem), true); + if (fAnnotation) + { + if (janAnnot.isDataNull()) + janAnnot.reset(fAnnotation); + else + janAnnot.get()->setNext(fAnnotation); + } // xpath expression parsing xpathExpr = getElementAttValue(elem, SchemaSymbols::fgATT_XPATH, true); @@ -4227,6 +4418,9 @@ elem = XUtil::getNextSiblingElement(elem); } + if (!janAnnot.isDataNull()) + fSchemaGrammar->putAnnotation(ic, janAnnot.release()); + if (ic->getFieldCount() == 0) { return false; } @@ -4287,7 +4481,7 @@ const XMLCh* name = child->getLocalName(); if (XMLString::equals(name, SchemaSymbols::fgELT_ANNOTATION)) { - traverseAnnotationDecl(child, true); + fSchemaGrammar->addAnnotation(traverseAnnotationDecl(child, true)); } else if (XMLString::equals(name, SchemaSymbols::fgELT_INCLUDE)) { traverseInclude(child); @@ -4319,7 +4513,7 @@ } if (XMLString::equals(name, SchemaSymbols::fgELT_ANNOTATION)) { - traverseAnnotationDecl(child, true); + fSchemaGrammar->addAnnotation(traverseAnnotationDecl(child, true)); } else if (XMLString::equals(name, SchemaSymbols::fgELT_SIMPLETYPE)) { @@ -4485,6 +4679,7 @@ DOMElement* content = contentElem; const XMLCh* name = getElementAttValue(rootElem,SchemaSymbols::fgATT_NAME); + fAnnotation = 0; if (!content) { if (!isEmpty) { @@ -4496,7 +4691,7 @@ if (XMLString::equals(content->getLocalName(), SchemaSymbols::fgELT_ANNOTATION)) { - traverseAnnotationDecl(content); + fAnnotation = traverseAnnotationDecl(content); content = XUtil::getNextSiblingElement(content); if (!content) { // must be followed by content @@ -4658,10 +4853,10 @@ const XMLCh* const refName) { DOMElement* content = checkContent(elem, XUtil::getFirstChildElement(elem), true); + Janitor<XSAnnotation> janAnnot(fAnnotation); - if (content != 0) { + if (content != 0) reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_ELEMENT); - } const XMLCh* prefix = getPrefix(refName); const XMLCh* localPart = getLocalPart(refName); @@ -6699,6 +6894,7 @@ reportSchemaError(elem, XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_GROUP); } + Janitor<XSAnnotation> janAnnot(fAnnotation); const XMLCh* prefix = getPrefix(refName); const XMLCh* localPart = getLocalPart(refName); const XMLCh* uriStr = resolvePrefixToURI(elem, prefix); @@ -6805,10 +7001,11 @@ const XMLCh* const refName, ComplexTypeInfo* const typeInfo) { -if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { + if (checkContent(elem, XUtil::getFirstChildElement(elem), true) != 0) { reportSchemaError(elem ,XMLUni::fgValidityDomain, XMLValid::NoContentForRef, SchemaSymbols::fgELT_ATTRIBUTEGROUP); } + Janitor<XSAnnotation> janAnnot(fAnnotation); const XMLCh* prefix = getPrefix(refName); const XMLCh* localPart = getLocalPart(refName); const XMLCh* uriStr = resolvePrefixToURI(elem, prefix); 1.28 +13 -7 xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.hpp Index: TraverseSchema.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/schema/TraverseSchema.hpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- TraverseSchema.hpp 30 Oct 2003 21:37:32 -0000 1.27 +++ TraverseSchema.hpp 6 Nov 2003 19:28:11 -0000 1.28 @@ -171,7 +171,7 @@ void preprocessSchema(DOMElement* const schemaRoot, const XMLCh* const schemaURL); void traverseSchemaHeader(const DOMElement* const schemaRoot); - void traverseAnnotationDecl(const DOMElement* const childElem, + XSAnnotation* traverseAnnotationDecl(const DOMElement* const childElem, const bool topLevel = false); void traverseInclude(const DOMElement* const childElem); void traverseImport(const DOMElement* const childElem); @@ -182,11 +182,13 @@ void traverseSimpleContentDecl(const XMLCh* const typeName, const XMLCh* const qualifiedName, const DOMElement* const contentDecl, - ComplexTypeInfo* const typeInfo); + ComplexTypeInfo* const typeInfo, + Janitor<XSAnnotation>* const janAnnot); void traverseComplexContentDecl(const XMLCh* const typeName, const DOMElement* const contentDecl, ComplexTypeInfo* const typeInfo, - const bool isMixed); + const bool isMixed, + Janitor<XSAnnotation>* const janAnnot); DatatypeValidator* traverseSimpleTypeDecl(const DOMElement* const childElem, const bool topLevel = true, int baseRefContext = SchemaSymbols::XSD_EMPTYSET); @@ -197,18 +199,21 @@ const DOMElement* const contentElem, const XMLCh* const typeName, const XMLCh* const qualifiedName, - const int finalSet); + const int finalSet, + Janitor<XSAnnotation>* const janAnnot); DatatypeValidator* traverseByRestriction(const DOMElement* const rootElem, const DOMElement* const contentElem, const XMLCh* const typeName, const XMLCh* const qualifiedName, - const int finalSet); + const int finalSet, + Janitor<XSAnnotation>* const janAnnot); DatatypeValidator* traverseByUnion(const DOMElement* const rootElem, const DOMElement* const contentElem, const XMLCh* const typeName, const XMLCh* const qualifiedName, const int finalSet, - int baseRefContext); + int baseRefContext, + Janitor<XSAnnotation>* const janAnnot); QName* traverseElementDecl(const DOMElement* const childElem, const bool topLevel = false); const XMLCh* traverseNotationDecl(const DOMElement* const childElem); @@ -785,6 +790,7 @@ XSDLocator* fLocator; MemoryManager* fMemoryManager; MemoryManager* fGrammarPoolMemoryManager; + XSAnnotation* fAnnotation; GeneralAttributeCheck fAttributeCheck; friend class GeneralAttributeCheck;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]