diff --git a/src/xercesc/framework/MemBufInputSource.cpp b/src/xercesc/framework/MemBufInputSource.cpp index e043875edc11a4efca931188d880f6750a735fed..5dd88a04206c054f70ce307d323134119fa58fdd 100644 --- a/src/xercesc/framework/MemBufInputSource.cpp +++ b/src/xercesc/framework/MemBufInputSource.cpp @@ -16,6 +16,9 @@ /** * $Log$ + * Revision 1.7 2004/09/28 02:14:13 cargilld + * Add support for validating annotations. + * * Revision 1.6 2004/09/08 13:55:57 peiyongz * Apache License Version 2.0 * @@ -93,6 +96,12 @@ MemBufInputSource::~MemBufInputSource() delete [] (XMLByte*)fSrcBytes; } +void MemBufInputSource::resetMemBufInputSource(const XMLByte* const srcDocBytes + , const unsigned int byteCount) +{ + fByteCount = byteCount; + fSrcBytes = srcDocBytes; +} // --------------------------------------------------------------------------- // MemBufInputSource: InputSource interface implementation diff --git a/src/xercesc/framework/MemBufInputSource.hpp b/src/xercesc/framework/MemBufInputSource.hpp index 4533b0dcaad4a704f3972fd51c5d19f0c62a42ce..880460b6ecc1c0008c6d34d7403707b63b8d47a7 100644 --- a/src/xercesc/framework/MemBufInputSource.hpp +++ b/src/xercesc/framework/MemBufInputSource.hpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.9 2004/09/28 02:14:13 cargilld + * Add support for validating annotations. + * * Revision 1.8 2004/09/08 13:55:57 peiyongz * Apache License Version 2.0 * @@ -217,6 +220,17 @@ public : */ void setCopyBufToStream(const bool newState); + /** + * This methods allows the MemBufInputSource to be used for more than + * one input source, instead of destructing/constructing another + * MemBufInputSource. + * + * @param srcDocBytes The actual data buffer to be parsed from. + * @param byteCount The count of bytes (not characters, bytes!) + * in the buffer. + */ + void resetMemBufInputSource(const XMLByte* const srcDocBytes + , const unsigned int byteCount); //@} diff --git a/src/xercesc/framework/psvi/XSAnnotation.cpp b/src/xercesc/framework/psvi/XSAnnotation.cpp index 6581c42f39ed94aa38bf2fe27c67052499bfff9e..3e3692f70017448cc34150f6cfc012d6bdf719d8 100644 --- a/src/xercesc/framework/psvi/XSAnnotation.cpp +++ b/src/xercesc/framework/psvi/XSAnnotation.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.11 2004/09/28 02:14:13 cargilld + * Add support for validating annotations. + * * Revision 1.10 2004/09/08 13:56:07 peiyongz * Apache License Version 2.0 * @@ -114,6 +117,7 @@ void XSAnnotation::writeAnnotation(DOMNode* node, ANNOTATION_TARGET targetType) , fMemoryManager ); memBufIS->setEncoding(XMLUni::fgXMLChEncodingString); + memBufIS->setCopyBufToStream(false); try { @@ -148,6 +152,7 @@ void XSAnnotation::writeAnnotation(ContentHandler* handler) , fMemoryManager ); memBufIS->setEncoding(XMLUni::fgXMLChEncodingString); + memBufIS->setCopyBufToStream(false); try { diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp index b1d26efaac87f54567601d1043ebacdf94a56bdc..a650e38458fcfc2d8114c4a51dcc517fa8b9208f 100644 --- a/src/xercesc/internal/XMLScanner.cpp +++ b/src/xercesc/internal/XMLScanner.cpp @@ -141,6 +141,7 @@ XMLScanner::XMLScanner(XMLValidator* const valToAdopt, , fLoadExternalDTD(true) , fNormalizeData(true) , fGenerateSyntheticAnnotations(false) + , fValidateAnnotations(false) , fErrorCount(0) , fEntityExpansionLimit(0) , fEntityExpansionCount(0) @@ -220,6 +221,7 @@ XMLScanner::XMLScanner( XMLDocumentHandler* const docHandler , fLoadExternalDTD(true) , fNormalizeData(true) , fGenerateSyntheticAnnotations(false) + , fValidateAnnotations(false) , fErrorCount(0) , fEntityExpansionLimit(0) , fEntityExpansionCount(0) diff --git a/src/xercesc/internal/XMLScanner.hpp b/src/xercesc/internal/XMLScanner.hpp index c42dc6729b891993dbfa5e680fc0f4c441803974..59d2eb012b6595110528d3fcd5ecf75e1728e02d 100644 --- a/src/xercesc/internal/XMLScanner.hpp +++ b/src/xercesc/internal/XMLScanner.hpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.39 2004/09/28 02:14:13 cargilld + * Add support for validating annotations. + * * Revision 1.38 2004/09/23 01:09:55 cargilld * Add support for generating synthetic XSAnnotations. When a schema component has non-schema attributes and no child attributes create a synthetic XSAnnotation (under feature control) so the non-schema attributes can be recovered under PSVI. * @@ -517,6 +520,7 @@ public : const XMLCh* getPrefixForId(unsigned int prefId) const; bool getGenerateSyntheticAnnotations() const; + bool getValidateAnnotations() const; // ----------------------------------------------------------------------- // Getter methods @@ -612,6 +616,7 @@ public : void setStandardUriConformant(const bool newValue); void setGenerateSyntheticAnnotations(const bool newValue); + void setValidateAnnotations(const bool newValue); // ----------------------------------------------------------------------- // Mutator methods @@ -965,6 +970,7 @@ protected: bool fLoadExternalDTD; bool fNormalizeData; bool fGenerateSyntheticAnnotations; + bool fValidateAnnotations; int fErrorCount; unsigned int fEntityExpansionLimit; unsigned int fEntityExpansionCount; @@ -1315,6 +1321,11 @@ inline bool XMLScanner::getGenerateSyntheticAnnotations() const return fGenerateSyntheticAnnotations; } +inline bool XMLScanner::getValidateAnnotations() const +{ + return fValidateAnnotations; +} + // --------------------------------------------------------------------------- // XMLScanner: Setter methods // --------------------------------------------------------------------------- @@ -1473,6 +1484,11 @@ inline void XMLScanner::setGenerateSyntheticAnnotations(const bool newValue) fGenerateSyntheticAnnotations = newValue; } +inline void XMLScanner::setValidateAnnotations(const bool newValue) +{ + fValidateAnnotations = newValue; +} + // --------------------------------------------------------------------------- // XMLScanner: Mutator methods // --------------------------------------------------------------------------- diff --git a/src/xercesc/parsers/AbstractDOMParser.cpp b/src/xercesc/parsers/AbstractDOMParser.cpp index 9957364f9cfb747291d1a0cef275d9ce587c910f..03160f96f499435d729371d731243edaa4f531b9 100644 --- a/src/xercesc/parsers/AbstractDOMParser.cpp +++ b/src/xercesc/parsers/AbstractDOMParser.cpp @@ -235,6 +235,11 @@ bool AbstractDOMParser::getGenerateSyntheticAnnotations() const return fScanner->getGenerateSyntheticAnnotations(); } +bool AbstractDOMParser::getValidateAnnotations() const +{ + return fScanner->getValidateAnnotations(); +} + bool AbstractDOMParser::getExitOnFirstFatalError() const { return fScanner->getExitOnFirstFatal(); @@ -333,6 +338,11 @@ void AbstractDOMParser::setGenerateSyntheticAnnotations(const bool newState) fScanner->setGenerateSyntheticAnnotations(newState); } +void AbstractDOMParser::setValidateAnnotations(const bool newState) +{ + fScanner->setValidateAnnotations(newState); +} + void AbstractDOMParser::setExitOnFirstFatalError(const bool newState) { fScanner->setExitOnFirstFatal(newState); diff --git a/src/xercesc/parsers/AbstractDOMParser.hpp b/src/xercesc/parsers/AbstractDOMParser.hpp index ddb558412e5175ce080b3ad0d6ecaa49fab85378..ebe739295b7f44c0c5eab0a32fb7f258d314a696 100644 --- a/src/xercesc/parsers/AbstractDOMParser.hpp +++ b/src/xercesc/parsers/AbstractDOMParser.hpp @@ -408,7 +408,7 @@ public : */ bool getCreateSchemaInfo() const; - /** Get the 'generate synthetic validations' flag + /** Get the 'generate synthetic annotations' flag * * @return true, if the parser is currently configured to * generate synthetic annotations, false otherwise. @@ -421,6 +421,15 @@ public : */ bool getGenerateSyntheticAnnotations() const; + /** Get the 'validate annotations' flag + * + * @return true, if the parser is currently configured to + * validate annotations, false otherwise. + * + * @see #setValidateAnnotations + */ + bool getValidateAnnotations() const; + //@} @@ -430,7 +439,7 @@ public : /** @name Setter methods */ //@{ - /** set the 'generate synthetic validations' flag + /** set the 'generate synthetic annotations' flag * * @param newValue The value for specifying whether Synthetic Annotations * should be generated or not. @@ -443,6 +452,15 @@ public : */ void setGenerateSyntheticAnnotations(const bool newValue); + /** set the 'validlate annotations' flag + * + * @param newValue The value for specifying whether Annotations + * should be validated or not. + * + * @see #getValidateAnnotations + */ + void setValidateAnnotations(const bool newValue); + /** Set the 'do namespaces' flag * * This method allows users to enable or disable the parser's diff --git a/src/xercesc/parsers/DOMBuilderImpl.cpp b/src/xercesc/parsers/DOMBuilderImpl.cpp index 552e1b82746debff36fe9b7affcdc62cd71872e2..454f164ce5b93fc2f4eecc57368cf3d6d6f04f61 100644 --- a/src/xercesc/parsers/DOMBuilderImpl.cpp +++ b/src/xercesc/parsers/DOMBuilderImpl.cpp @@ -235,6 +235,10 @@ void DOMBuilderImpl::setFeature(const XMLCh* const name, const bool state) { getScanner()->setGenerateSyntheticAnnotations(state); } + else if (XMLString::compareIString(name, XMLUni::fgXercesValidateAnnotations) == 0) + { + getScanner()->setValidateAnnotations(state); + } else { throw DOMException(DOMException::NOT_FOUND_ERR, 0, getMemoryManager()); } @@ -329,6 +333,10 @@ bool DOMBuilderImpl::getFeature(const XMLCh* const name) const { return getScanner()->getGenerateSyntheticAnnotations(); } + else if (XMLString::compareIString(name, XMLUni::fgXercesValidateAnnotations) == 0) + { + return getScanner()->getValidateAnnotations(); + } else { throw DOMException(DOMException::NOT_FOUND_ERR, 0, getMemoryManager()); } diff --git a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp index 000b280f776a89bd621c0e16a2cec26199bebf68..e82f7411891ffe8fc2e5aeaf1b9d10138a891630 100644 --- a/src/xercesc/parsers/SAX2XMLReaderImpl.cpp +++ b/src/xercesc/parsers/SAX2XMLReaderImpl.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.37 2004/09/28 02:14:14 cargilld + * Add support for validating annotations. + * * Revision 1.36 2004/09/23 01:09:55 cargilld * Add support for generating synthetic XSAnnotations. When a schema component has non-schema attributes and no child attributes create a synthetic XSAnnotation (under feature control) so the non-schema attributes can be recovered under PSVI. * @@ -1564,6 +1567,10 @@ void SAX2XMLReaderImpl::setFeature(const XMLCh* const name, const bool value) { fScanner->setGenerateSyntheticAnnotations(value); } + else if (XMLString::compareIString(name, XMLUni::fgXercesValidateAnnotations) == 0) + { + fScanner->setValidateAnnotations(value); + } else throw SAXNotRecognizedException("Unknown Feature", fMemoryManager); } @@ -1600,6 +1607,8 @@ bool SAX2XMLReaderImpl::getFeature(const XMLCh* const name) const return fScanner->getStandardUriConformant(); else if (XMLString::compareIString(name, XMLUni::fgXercesGenerateSyntheticAnnotations) == 0) return fScanner->getGenerateSyntheticAnnotations(); + else if (XMLString::compareIString(name, XMLUni::fgXercesValidateAnnotations) == 0) + return fScanner->getValidateAnnotations(); else throw SAXNotRecognizedException("Unknown Feature", fMemoryManager); diff --git a/src/xercesc/parsers/SAXParser.cpp b/src/xercesc/parsers/SAXParser.cpp index 96f54e8684d311292742a59b83e57ef31869e8c5..7d85ff1338f81f2b82b8365caf0997a1698fedc4 100644 --- a/src/xercesc/parsers/SAXParser.cpp +++ b/src/xercesc/parsers/SAXParser.cpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.35 2004/09/28 02:14:14 cargilld + * Add support for validating annotations. + * * Revision 1.34 2004/09/23 01:09:55 cargilld * Add support for generating synthetic XSAnnotations. When a schema component has non-schema attributes and no child attributes create a synthetic XSAnnotation (under feature control) so the non-schema attributes can be recovered under PSVI. * @@ -454,6 +457,11 @@ bool SAXParser::getGenerateSyntheticAnnotations() const return fScanner->getGenerateSyntheticAnnotations(); } +bool SAXParser::getValidateAnnotations() const +{ + return fScanner->getValidateAnnotations(); +} + bool SAXParser::getExitOnFirstFatalError() const { return fScanner->getExitOnFirstFatal(); @@ -570,6 +578,11 @@ void SAXParser::setGenerateSyntheticAnnotations(const bool newState) fScanner->setGenerateSyntheticAnnotations(newState); } +void SAXParser::setValidateAnnotations(const bool newState) +{ + fScanner->setValidateAnnotations(newState); +} + void SAXParser::setExitOnFirstFatalError(const bool newState) { fScanner->setExitOnFirstFatal(newState); diff --git a/src/xercesc/parsers/SAXParser.hpp b/src/xercesc/parsers/SAXParser.hpp index f67f2cf411ff3013f0f5b38160bc8377622efb2b..e7bf9ee4efbfca82761bff8f5818d908b0055dae 100644 --- a/src/xercesc/parsers/SAXParser.hpp +++ b/src/xercesc/parsers/SAXParser.hpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.34 2004/09/28 02:14:14 cargilld + * Add support for validating annotations. + * * Revision 1.33 2004/09/23 01:09:55 cargilld * Add support for generating synthetic XSAnnotations. When a schema component has non-schema attributes and no child attributes create a synthetic XSAnnotation (under feature control) so the non-schema attributes can be recovered under PSVI. * @@ -645,7 +648,7 @@ public : */ unsigned int getSrcOffset() const; - /** Get the 'generate synthetic validations' flag + /** Get the 'generate synthetic annotations' flag * * @return true, if the parser is currently configured to * generate synthetic annotations, false otherwise. @@ -658,6 +661,15 @@ public : */ bool getGenerateSyntheticAnnotations() const; + /** Get the 'validate annotations' flag + * + * @return true, if the parser is currently configured to + * validate annotations, false otherwise. + * + * @see #setValidateAnnotations + */ + bool getValidateAnnotations() const; + //@} @@ -667,7 +679,7 @@ public : /** @name Setter methods */ //@{ - /** set the 'generate synthetic validations' flag + /** set the 'generate synthetic annotations' flag * * @param newValue The value for specifying whether Synthetic Annotations * should be generated or not. @@ -679,6 +691,15 @@ public : */ void setGenerateSyntheticAnnotations(const bool newValue); + /** set the 'validate annotations' flag + * + * @param newValue The value for specifying whether annotations + * should be validate or not. + * + * @see #getValidateAnnotations + */ + void setValidateAnnotations(const bool newValue); + /** * This method allows users to enable or disable the parser's * namespace processing. When set to true, parser starts enforcing diff --git a/src/xercesc/util/XMLUni.cpp b/src/xercesc/util/XMLUni.cpp index df76173607d65775992225441e0b9d950fa953f3..ab082301569190dbd0d3f10071118762c108c445 100644 --- a/src/xercesc/util/XMLUni.cpp +++ b/src/xercesc/util/XMLUni.cpp @@ -683,6 +683,13 @@ const XMLCh XMLUni::fgDGXMLScanner[] = , chLatin_c, chLatin_a, chLatin_n, chLatin_n, chLatin_e, chLatin_r, chNull }; +const XMLCh XMLUni::fgXSAXMLScanner[] = +{ + chLatin_X, chLatin_S, chLatin_A + , chLatin_X, chLatin_M, chLatin_L, chLatin_S + , chLatin_c, chLatin_a, chLatin_n, chLatin_n, chLatin_e, chLatin_r, chNull +}; + const XMLCh XMLUni::fgCDataStart[] = { chOpenAngle, chBang, chOpenSquare, chLatin_C, chLatin_D @@ -1110,6 +1117,20 @@ const XMLCh XMLUni::fgXercesGenerateSyntheticAnnotations[] = , chLatin_i, chLatin_o, chLatin_n, chLatin_s, chNull }; +const XMLCh XMLUni::fgXercesValidateAnnotations[] = +//Xerces: http://apache.org/xml/features/validate-annotations +{ + chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash + , chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h + , chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash + , chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_f, chLatin_e + , chLatin_a, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chLatin_s + , chForwardSlash, chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d + , chLatin_a, chLatin_t, chLatin_e, chDash + , chLatin_a, chLatin_n, chLatin_n, chLatin_o, chLatin_t, chLatin_a, chLatin_t + , chLatin_i, chLatin_o, chLatin_n, chLatin_s, chNull +}; + //Property //Xerces: http://apache.org/xml/properties/schema/external-schemaLocation const XMLCh XMLUni::fgXercesSchemaExternalSchemaLocation[] = diff --git a/src/xercesc/util/XMLUni.hpp b/src/xercesc/util/XMLUni.hpp index 9f4837043175efcbf56330a48fdd1a180d41dce3..db029d422c21078a510d5273ef310f4d1d53e346 100644 --- a/src/xercesc/util/XMLUni.hpp +++ b/src/xercesc/util/XMLUni.hpp @@ -164,6 +164,7 @@ public : static const XMLCh fgIGXMLScanner[]; static const XMLCh fgSGXMLScanner[]; static const XMLCh fgDGXMLScanner[]; + static const XMLCh fgXSAXMLScanner[]; static const XMLCh fgCDataStart[]; static const XMLCh fgCDataEnd[]; @@ -221,6 +222,8 @@ public : static const XMLCh fgXercesStandardUriConformant[]; static const XMLCh fgXercesDOMHasPSVIInfo[]; static const XMLCh fgXercesGenerateSyntheticAnnotations[]; + static const XMLCh fgXercesValidateAnnotations[]; + // SAX2 features/properties names static const XMLCh fgSAX2CoreValidation[]; diff --git a/src/xercesc/validators/schema/SchemaGrammar.hpp b/src/xercesc/validators/schema/SchemaGrammar.hpp index e820e2a3a2fc90db3d73de8419cc6e43f92af2fd..8990c6588d8db976ae23cd238c8bc07669e7e20c 100644 --- a/src/xercesc/validators/schema/SchemaGrammar.hpp +++ b/src/xercesc/validators/schema/SchemaGrammar.hpp @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.17 2004/09/28 02:14:14 cargilld + * Add support for validating annotations. + * * Revision 1.16 2004/09/08 13:56:56 peiyongz * Apache License Version 2.0 * @@ -325,6 +328,12 @@ public: XSAnnotation* getAnnotation(); const XSAnnotation* getAnnotation() const; + /** + * Get annotation hash table, to enumerate through them + */ + RefHashTableOf<XSAnnotation>* getAnnotations(); + const RefHashTableOf<XSAnnotation>* getAnnotations() const; + /*** * Support for Serialization/De-serialization ***/ @@ -508,6 +517,15 @@ inline const XSAnnotation* SchemaGrammar::getAnnotation() const return fAnnotations->get(this); } +inline RefHashTableOf<XSAnnotation>* SchemaGrammar::getAnnotations() +{ + return fAnnotations; +} + +inline const RefHashTableOf<XSAnnotation>* SchemaGrammar::getAnnotations() const +{ + return fAnnotations; +} // ----------------------------------------------------------------------- // Setter methods // ----------------------------------------------------------------------- diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp index afd4a04c67dc0faac0c2d6db8960ba57b941ba9e..557a33591f9a799bfb78b8cb76a04b177d430ffe 100644 --- a/src/xercesc/validators/schema/TraverseSchema.cpp +++ b/src/xercesc/validators/schema/TraverseSchema.cpp @@ -56,6 +56,8 @@ #include <xercesc/util/XMLEntityResolver.hpp> #include <xercesc/util/XMLUri.hpp> #include <xercesc/framework/psvi/XSAnnotation.hpp> +#include <xercesc/framework/MemBufInputSource.hpp> +#include <xercesc/internal/XSAXMLScanner.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -141,19 +143,6 @@ const XMLCh* fgIdentityConstraints[] = SchemaSymbols::fgELT_KEYREF }; -const XMLCh fgAnnotation[] = -{ - chLatin_a, chLatin_n, chLatin_n, chLatin_o, chLatin_t, chLatin_a, chLatin_t - , chLatin_i, chLatin_o, chLatin_n, chNull -}; - -const XMLCh fgDocumentation[] = -{ - chLatin_d, chLatin_o, chLatin_c, chLatin_u, chLatin_m, chLatin_e - , chLatin_n, chLatin_t, chLatin_a, chLatin_t - , chLatin_i, chLatin_o, chLatin_n, chNull -}; - const XMLCh fgSynthetic_Annotation[] = { chLatin_S, chLatin_y, chLatin_n, chLatin_t, chLatin_h, chLatin_e, chLatin_t @@ -293,6 +282,10 @@ void TraverseSchema::doTraverseSchema(const DOMElement* const schemaRoot) { } } + if (fScanner->getValidateAnnotations() && !fSchemaGrammar->getAnnotations()->isEmpty()) + { + validateAnnotations(); + } fSchemaInfo->setProcessed(); } @@ -4655,7 +4648,7 @@ void TraverseSchema::processChildren(const DOMElement* const root) { } // for each child node - if (fSchemaInfo->getNonXSAttList()->size() && !sawAnnotation) + if (fScanner->getGenerateSyntheticAnnotations() && fSchemaInfo->getNonXSAttList()->size() && !sawAnnotation) { // synthesize a global annotation here. fSchemaGrammar->addAnnotation( @@ -8743,7 +8736,7 @@ XSAnnotation* TraverseSchema::generateSyntheticAnnotation(const DOMElement* cons fBuffer.append(prefix); fBuffer.append(chColon); } - fBuffer.append(fgAnnotation); + fBuffer.append(SchemaSymbols::fgELT_ANNOTATION); // next is the nonXSAttList names & values unsigned int nonXSAttSize = nonXSAttList->size(); @@ -8841,7 +8834,7 @@ XSAnnotation* TraverseSchema::generateSyntheticAnnotation(const DOMElement* cons fBuffer.append(prefix); fBuffer.append(chColon); } - fBuffer.append(fgDocumentation); + fBuffer.append(SchemaSymbols::fgELT_DOCUMENTATION); fBuffer.append(chCloseAngle); fBuffer.append(fgSynthetic_Annotation); fBuffer.append(chOpenAngle); @@ -8851,7 +8844,7 @@ XSAnnotation* TraverseSchema::generateSyntheticAnnotation(const DOMElement* cons fBuffer.append(prefix); fBuffer.append(chColon); } - fBuffer.append(fgDocumentation); + fBuffer.append(SchemaSymbols::fgELT_DOCUMENTATION); fBuffer.append(chCloseAngle); fBuffer.append(chLF); fBuffer.append(chOpenAngle); @@ -8861,7 +8854,7 @@ XSAnnotation* TraverseSchema::generateSyntheticAnnotation(const DOMElement* cons fBuffer.append(prefix); fBuffer.append(chColon); } - fBuffer.append(fgAnnotation); + fBuffer.append(SchemaSymbols::fgELT_ANNOTATION); fBuffer.append(chCloseAngle); XSAnnotation* annot = new (fGrammarPoolMemoryManager) XSAnnotation(fBuffer.getRawBuffer(), fGrammarPoolMemoryManager); @@ -8871,6 +8864,134 @@ XSAnnotation* TraverseSchema::generateSyntheticAnnotation(const DOMElement* cons return annot; } +void TraverseSchema::validateAnnotations() { + + MemoryManager *memMgr = fMemoryManager; + RefHashTableOfEnumerator<XSAnnotation> xsAnnotationEnum = RefHashTableOfEnumerator<XSAnnotation> (fSchemaGrammar->getAnnotations(), false, memMgr); + XSAnnotation& xsAnnot = xsAnnotationEnum.nextElement(); + + // create schema grammar + SchemaGrammar *grammar = new (memMgr) SchemaGrammar(memMgr); + NamespaceScope *nsScope; + grammar->setComplexTypeRegistry(new (memMgr) RefHashTableOf<ComplexTypeInfo>(29, memMgr)); + grammar->setGroupInfoRegistry(new (memMgr) RefHashTableOf<XercesGroupInfo>(13, memMgr)); + grammar->setAttGroupInfoRegistry(new (memMgr) RefHashTableOf<XercesAttGroupInfo>(13, memMgr)); + grammar->setAttributeDeclRegistry(new (memMgr) RefHashTableOf<XMLAttDef>(29, memMgr)); + nsScope = new (memMgr) NamespaceScope(memMgr); + nsScope->reset(fEmptyNamespaceURI); + grammar->setNamespaceScope(nsScope); + grammar->setValidSubstitutionGroups(new (memMgr) RefHash2KeysTableOf<ElemVector>(29, memMgr)); + grammar->setTargetNamespace(SchemaSymbols::fgURI_SCHEMAFORSCHEMA); + XMLSchemaDescription* gramDesc = (XMLSchemaDescription*) grammar->getGrammarDescription(); + gramDesc->setTargetNamespace(SchemaSymbols::fgURI_SCHEMAFORSCHEMA); + + // setup components of annotation grammar + SchemaElementDecl* annotElemDecl = new (memMgr) SchemaElementDecl + ( + XMLUni::fgZeroLenString , SchemaSymbols::fgELT_ANNOTATION + , fURIStringPool->addOrFind(SchemaSymbols::fgURI_SCHEMAFORSCHEMA) + , SchemaElementDecl::Mixed_Complex, Grammar::TOP_LEVEL_SCOPE , memMgr + ); + annotElemDecl->setCreateReason(XMLElementDecl::Declared); + grammar->putElemDecl(annotElemDecl); + + ComplexTypeInfo* complexType = new (memMgr) ComplexTypeInfo(memMgr); + complexType->setAnonymous(); + complexType->setContentType(SchemaElementDecl::Mixed_Complex); + annotElemDecl->setComplexTypeInfo(complexType); + + // Revisit: is this okay for a key? + fBuffer.set(SchemaSymbols::fgURI_SCHEMAFORSCHEMA); + fBuffer.append(chComma); + fBuffer.append(chLatin_C); + fBuffer.append(chDigit_0); + grammar->getComplexTypeRegistry()->put((void*) fBuffer.getRawBuffer(), complexType); + + SchemaElementDecl* appInfoElemDecl = new (memMgr) SchemaElementDecl + ( + XMLUni::fgZeroLenString , SchemaSymbols::fgELT_APPINFO + , fURIStringPool->addOrFind(SchemaSymbols::fgURI_SCHEMAFORSCHEMA) + , SchemaElementDecl::Any, Grammar::TOP_LEVEL_SCOPE , memMgr + ); + + appInfoElemDecl->setCreateReason(XMLElementDecl::Declared); + appInfoElemDecl->setAttWildCard + ( + new (memMgr) SchemaAttDef + ( + XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, + fEmptyNamespaceURI, XMLAttDef::Any_Any, + XMLAttDef::ProcessContents_Lax, memMgr + ) + ); + grammar->putElemDecl(appInfoElemDecl); + complexType->addElement(appInfoElemDecl); + + SchemaElementDecl* docElemDecl = new (memMgr) SchemaElementDecl + ( + XMLUni::fgZeroLenString , SchemaSymbols::fgELT_DOCUMENTATION + , fURIStringPool->addOrFind(SchemaSymbols::fgURI_SCHEMAFORSCHEMA) + , SchemaElementDecl::Any, Grammar::TOP_LEVEL_SCOPE , memMgr + ); + + docElemDecl->setCreateReason(XMLElementDecl::Declared); + docElemDecl->setAttWildCard + ( + new (memMgr) SchemaAttDef + ( + XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, + fEmptyNamespaceURI, XMLAttDef::Any_Any, + XMLAttDef::ProcessContents_Lax, memMgr + ) + ); + grammar->putElemDecl(docElemDecl); + complexType->addElement(docElemDecl); + + ContentSpecNode* left = new (memMgr) ContentSpecNode(appInfoElemDecl, memMgr); + ContentSpecNode* right = new (memMgr) ContentSpecNode(docElemDecl, memMgr); + ContentSpecNode* root = new (memMgr) ContentSpecNode(ContentSpecNode::ModelGroupChoice + , left + , right + , true + , true + , memMgr); + root->setMinOccurs(0); + root->setMaxOccurs(SchemaSymbols::XSD_UNBOUNDED); + complexType->setContentSpec(root); + + // create input source to scan + MemBufInputSource* memBufIS = new (memMgr) MemBufInputSource + ( + (const XMLByte*)xsAnnot.getAnnotationString() + , XMLString::stringLen(xsAnnot.getAnnotationString())*sizeof(XMLCh) + , SchemaSymbols::fgELT_ANNOTATION + , false + , memMgr + ); + memBufIS->setEncoding(XMLUni::fgXMLChEncodingString); + memBufIS->setCopyBufToStream(false); + + XSAXMLScanner *scanner = new (memMgr) XSAXMLScanner + ( + fGrammarResolver, fURIStringPool, grammar, memMgr + ); + + scanner->setErrorReporter(fErrorReporter); + + scanner->scanDocument(*memBufIS); + + while (xsAnnotationEnum.hasMoreElements()) + { + XSAnnotation& xsAnnot = xsAnnotationEnum.nextElement(); + memBufIS->resetMemBufInputSource((const XMLByte*)xsAnnot.getAnnotationString() + , XMLString::stringLen(xsAnnot.getAnnotationString())*sizeof(XMLCh)); + //scanner->scanDocument(*memBufIS); + } + + delete scanner; + delete memBufIS; +} + XERCES_CPP_NAMESPACE_END /** diff --git a/src/xercesc/validators/schema/TraverseSchema.hpp b/src/xercesc/validators/schema/TraverseSchema.hpp index 551351677d62ec28e2781a422a873950f3ccf857..e7b87e65b977fb3c6a4bb8656aa1d5e03fc14265 100644 --- a/src/xercesc/validators/schema/TraverseSchema.hpp +++ b/src/xercesc/validators/schema/TraverseSchema.hpp @@ -686,6 +686,10 @@ private: // routine to generate synthetic annotations XSAnnotation* generateSyntheticAnnotation(const DOMElement* const elem , ValueVectorOf<DOMNode*>* nonXSAttList); + + // routine to validate annotations + void validateAnnotations(); + // ----------------------------------------------------------------------- // Private constants // -----------------------------------------------------------------------