From 5abd16757f109ccf2b6a7c3b40b98ae858bddae8 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 3 May 2006 22:55:13 +0000 Subject: [PATCH] Integrate parser pools into library. --- xmltooling/XMLToolingConfig.cpp | 3 +++ xmltooling/XMLToolingConfig.h | 20 +++++++++++++++++++- xmltooling/exceptions.cpp | 2 +- xmltooling/impl/UnknownElement.cpp | 4 ++-- xmltooling/internal.h | 15 ++++++++++++--- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 4 ++-- xmltooling/util/ParserPool.cpp | 2 +- xmltoolingtest/ComplexXMLObjectTest.h | 2 +- xmltoolingtest/KeyInfoTest.h | 6 +++--- xmltoolingtest/MarshallingTest.h | 6 +++--- xmltoolingtest/SignatureTest.h | 2 +- xmltoolingtest/UnmarshallingTest.h | 10 +++++----- xmltoolingtest/xmltoolingtest.h | 14 ++++---------- xmltoolingtest/xmltoolingtest.vcproj | 8 ++++---- 14 files changed, 61 insertions(+), 37 deletions(-) diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 8e2e48f..e5b1768 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -167,6 +167,7 @@ bool XMLToolingInternalConfig::init() #endif m_parserPool=new ParserPool(); + m_validatingPool=new ParserPool(true,true); m_lock=xercesc::XMLPlatformUtils::makeMutex(); // default registrations @@ -264,6 +265,8 @@ void XMLToolingInternalConfig::term() delete m_parserPool; m_parserPool=NULL; + delete m_validatingPool; + m_validatingPool=NULL; #ifndef XMLTOOLING_NO_XMLSEC delete m_xsecProvider; diff --git a/xmltooling/XMLToolingConfig.h b/xmltooling/XMLToolingConfig.h index e97bb89..5241fe4 100644 --- a/xmltooling/XMLToolingConfig.h +++ b/xmltooling/XMLToolingConfig.h @@ -24,6 +24,7 @@ #define __xmltooling_config_h__ #include +#include namespace xmltooling { @@ -91,7 +92,24 @@ namespace xmltooling { * @return true iff configuration was successful */ virtual bool log_config(const char* config=NULL)=0; - + + /** + * Obtains a non-validating parser pool. + * Library must be initialized first. + * + * @return reference to a non-validating parser pool. + */ + virtual ParserPool& getParser() const=0; + + /** + * Obtains a validating parser pool. + * Library must be initialized first. Schema/catalog registration must be + * externally synchronized. + * + * @return reference to a validating parser pool. + */ + virtual ParserPool& getValidatingParser() const=0; + protected: XMLToolingConfig() {} }; diff --git a/xmltooling/exceptions.cpp b/xmltooling/exceptions.cpp index 114e1ad..00e9bec 100644 --- a/xmltooling/exceptions.cpp +++ b/xmltooling/exceptions.cpp @@ -236,7 +236,7 @@ XMLToolingException* XMLToolingException::fromStream(std::istream& in) static const XMLCh param[] = { chLatin_p, chLatin_a, chLatin_r, chLatin_a, chLatin_m, chNull }; static const XMLCh type[] = { chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull }; - DOMDocument* doc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(in); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in); // Check root element. const DOMElement* root=doc->getDocumentElement(); diff --git a/xmltooling/impl/UnknownElement.cpp b/xmltooling/impl/UnknownElement.cpp index 50c1954..09dbbdd 100644 --- a/xmltooling/impl/UnknownElement.cpp +++ b/xmltooling/impl/UnknownElement.cpp @@ -107,7 +107,7 @@ DOMElement* UnknownElementImpl::marshall(DOMDocument* document, MarshallingConte MemBufInputSource src(reinterpret_cast(m_xml.c_str()),m_xml.length(),"UnknownElementImpl"); Wrapper4InputSource dsrc(&src,false); log.debug("parsing XML back into DOM tree"); - DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc); + DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc); if (document) { // The caller insists on using his own document, so we now have to import the thing // into it. Then we're just dumping the one we built. @@ -166,7 +166,7 @@ DOMElement* UnknownElementImpl::marshall(DOMElement* parentElement, MarshallingC MemBufInputSource src(reinterpret_cast(m_xml.c_str()),m_xml.length(),"UnknownElementImpl"); Wrapper4InputSource dsrc(&src,false); log.debug("parsing XML back into DOM tree"); - DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc); + DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc); log.debug("reimporting new DOM into caller-supplied document"); cachedDOM=static_cast(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(), true)); diff --git a/xmltooling/internal.h b/xmltooling/internal.h index 973684a..33c771a 100644 --- a/xmltooling/internal.h +++ b/xmltooling/internal.h @@ -53,7 +53,7 @@ namespace xmltooling { class XMLToolingInternalConfig : public xmltooling::XMLToolingConfig { public: - XMLToolingInternalConfig() : m_parserPool(NULL), m_lock(NULL) { + XMLToolingInternalConfig() : m_parserPool(NULL), m_validatingPool(NULL), m_lock(NULL) { #ifndef XMLTOOLING_NO_XMLSEC m_xsecProvider=NULL; #endif @@ -73,8 +73,15 @@ namespace xmltooling { bool load_library(const char* path, void* context=NULL); bool log_config(const char* config=NULL); - // internal parser pool - xmltooling::ParserPool* m_parserPool; + // parser access + ParserPool& getParser() const { + return *m_parserPool; + } + + ParserPool& getValidatingParser() const { + return *m_validatingPool; + } + #ifndef XMLTOOLING_NO_XMLSEC XSECProvider* m_xsecProvider; #endif @@ -82,6 +89,8 @@ namespace xmltooling { private: std::vector m_libhandles; void* m_lock; + ParserPool* m_parserPool; + ParserPool* m_validatingPool; }; /// @endcond diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index adc8df5..bf169bb 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -246,7 +246,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, MarshallingCont MemBufInputSource src(reinterpret_cast(m_xml.c_str()),m_xml.length(),"XMLSecSignatureImpl"); Wrapper4InputSource dsrc(&src,false); log.debug("parsing Signature XML back into DOM tree"); - DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc); + DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc); if (document) { // The caller insists on using his own document, so we now have to import the thing // into it. Then we're just dumping the one we built. @@ -350,7 +350,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, Marshalling MemBufInputSource src(reinterpret_cast(m_xml.c_str()),m_xml.length(),"XMLSecSignatureImpl"); Wrapper4InputSource dsrc(&src,false); log.debug("parsing XML back into DOM tree"); - DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc); + DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc); log.debug("reimporting new DOM into caller-supplied document"); cachedDOM=static_cast(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(),true)); diff --git a/xmltooling/util/ParserPool.cpp b/xmltooling/util/ParserPool.cpp index 1ce146e..4897338 100644 --- a/xmltooling/util/ParserPool.cpp +++ b/xmltooling/util/ParserPool.cpp @@ -161,7 +161,7 @@ bool ParserPool::loadCatalog(const XMLCh* pathname) LocalFileInputSource fsrc(NULL,pathname); Wrapper4InputSource domsrc(&fsrc,false); try { - DOMDocument* doc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(domsrc); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(domsrc); // Check root element. const DOMElement* root=doc->getDocumentElement(); diff --git a/xmltoolingtest/ComplexXMLObjectTest.h b/xmltoolingtest/ComplexXMLObjectTest.h index 4b93174..73647b4 100644 --- a/xmltoolingtest/ComplexXMLObjectTest.h +++ b/xmltoolingtest/ComplexXMLObjectTest.h @@ -36,7 +36,7 @@ public: string path=data_path + "ComplexXMLObject.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); diff --git a/xmltoolingtest/KeyInfoTest.h b/xmltoolingtest/KeyInfoTest.h index 7e65639..2d2ec97 100644 --- a/xmltoolingtest/KeyInfoTest.h +++ b/xmltoolingtest/KeyInfoTest.h @@ -38,7 +38,7 @@ public: string path=data_path + "KeyInfo1.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=validatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -67,7 +67,7 @@ public: string path=data_path + "KeyInfo2.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=validatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -92,7 +92,7 @@ public: string path=data_path + "KeyInfo3.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); diff --git a/xmltoolingtest/MarshallingTest.h b/xmltoolingtest/MarshallingTest.h index 55f6f73..0b3e056 100644 --- a/xmltoolingtest/MarshallingTest.h +++ b/xmltoolingtest/MarshallingTest.h @@ -47,7 +47,7 @@ public: string path=data_path + "SimpleXMLObjectWithAttribute.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement())); @@ -67,7 +67,7 @@ public: string path=data_path + "SimpleXMLObjectWithContent.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement())); @@ -107,7 +107,7 @@ public: string path=data_path + "SimpleXMLObjectWithChildren.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement())); diff --git a/xmltoolingtest/SignatureTest.h b/xmltoolingtest/SignatureTest.h index be5c81f..01262bd 100644 --- a/xmltoolingtest/SignatureTest.h +++ b/xmltoolingtest/SignatureTest.h @@ -132,7 +132,7 @@ public: //TS_TRACE(buf.c_str()); istringstream in(buf); - DOMDocument* doc=nonvalidatingPool->parse(in); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in); auto_ptr sxObject2(dynamic_cast(b->buildFromDocument(doc))); TS_ASSERT(sxObject2.get()!=NULL); TS_ASSERT(sxObject2->getSignature()!=NULL); diff --git a/xmltoolingtest/UnmarshallingTest.h b/xmltoolingtest/UnmarshallingTest.h index 574c62a..3687ea3 100644 --- a/xmltoolingtest/UnmarshallingTest.h +++ b/xmltoolingtest/UnmarshallingTest.h @@ -73,7 +73,7 @@ public: string path=data_path + "SimpleXMLObjectWithAttribute.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -93,7 +93,7 @@ public: string path=data_path + "SimpleXMLObjectWithContent.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -113,7 +113,7 @@ public: string path=data_path + "SimpleXMLObjectWithChildren.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -135,7 +135,7 @@ public: string path=data_path + "SimpleXMLObjectWithChildren.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); @@ -160,7 +160,7 @@ public: string path=data_path + "SimpleXMLObjectWithUnknownChild.xml"; ifstream fs(path.c_str()); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement()); diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h index 20450a4..fe1e867 100644 --- a/xmltoolingtest/xmltoolingtest.h +++ b/xmltoolingtest/xmltoolingtest.h @@ -23,8 +23,6 @@ //#define XMLTOOLINGTEST_LEAKCHECK -ParserPool* validatingPool=NULL; -ParserPool* nonvalidatingPool=NULL; std::string data_path = "../xmltoolingtest/data/"; class ToolingFixture : public CxxTest::GlobalFixture @@ -34,17 +32,13 @@ public: XMLToolingConfig::getConfig().log_config(); if (!XMLToolingConfig::getConfig().init()) return false; - validatingPool = new ParserPool(true,true); - nonvalidatingPool = new ParserPool(); if (getenv("XMLTOOLINGTEST_DATA")) data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/"; std::string catpath=data_path + "catalog.xml"; auto_ptr_XMLCh temp(catpath.c_str()); - return validatingPool->loadCatalog(temp.get()); + return XMLToolingConfig::getConfig().getValidatingParser().loadCatalog(temp.get()); } bool tearDownWorld() { - delete validatingPool; - delete nonvalidatingPool; XMLToolingConfig::getConfig().term(); #if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK) _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); @@ -76,7 +70,7 @@ public: void testUnknown() { ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml"); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); string buf1; @@ -104,7 +98,7 @@ public: void testUnknownWithDocChange() { ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml"); - DOMDocument* doc=nonvalidatingPool->parse(fs); + DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs); TS_ASSERT(doc!=NULL); string buf1; @@ -116,7 +110,7 @@ public: auto_ptr xmlObject(b->buildFromDocument(doc)); // bind document TS_ASSERT(xmlObject.get()!=NULL); - DOMDocument* newDoc=nonvalidatingPool->newDocument(); + DOMDocument* newDoc=XMLToolingConfig::getConfig().getParser().newDocument(); DOMElement* rootElement=xmlObject->marshall(newDoc); TS_ASSERT(rootElement!=NULL); diff --git a/xmltoolingtest/xmltoolingtest.vcproj b/xmltoolingtest/xmltoolingtest.vcproj index 843b5ae..5b5b146 100644 --- a/xmltoolingtest/xmltoolingtest.vcproj +++ b/xmltoolingtest/xmltoolingtest.vcproj @@ -40,7 +40,7 @@ @@ -274,7 +274,7 @@ > -- 2.1.4