Integrate parser pools into library.
authorScott Cantor <cantor.2@osu.edu>
Wed, 3 May 2006 22:55:13 +0000 (22:55 +0000)
committerScott Cantor <cantor.2@osu.edu>
Wed, 3 May 2006 22:55:13 +0000 (22:55 +0000)
14 files changed:
xmltooling/XMLToolingConfig.cpp
xmltooling/XMLToolingConfig.h
xmltooling/exceptions.cpp
xmltooling/impl/UnknownElement.cpp
xmltooling/internal.h
xmltooling/signature/impl/XMLSecSignatureImpl.cpp
xmltooling/util/ParserPool.cpp
xmltoolingtest/ComplexXMLObjectTest.h
xmltoolingtest/KeyInfoTest.h
xmltoolingtest/MarshallingTest.h
xmltoolingtest/SignatureTest.h
xmltoolingtest/UnmarshallingTest.h
xmltoolingtest/xmltoolingtest.h
xmltoolingtest/xmltoolingtest.vcproj

index 8e2e48f..e5b1768 100644 (file)
@@ -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;
index e97bb89..5241fe4 100644 (file)
@@ -24,6 +24,7 @@
 #define __xmltooling_config_h__\r
 \r
 #include <xmltooling/Lockable.h>\r
+#include <xmltooling/util/ParserPool.h>\r
 \r
 namespace xmltooling {\r
 \r
@@ -91,7 +92,24 @@ namespace xmltooling {
          * @return true iff configuration was successful\r
          */\r
         virtual bool log_config(const char* config=NULL)=0;\r
-        \r
+\r
+        /**\r
+         * Obtains a non-validating parser pool.\r
+         * Library must be initialized first.\r
+         *\r
+         * @return reference to a non-validating parser pool.\r
+         */\r
+        virtual ParserPool& getParser() const=0;\r
+\r
+        /**\r
+         * Obtains a validating parser pool.\r
+         * Library must be initialized first. Schema/catalog registration must be\r
+         * externally synchronized.\r
+         *\r
+         * @return reference to a validating parser pool.\r
+         */\r
+        virtual ParserPool& getValidatingParser() const=0;\r
+\r
     protected:\r
         XMLToolingConfig() {}\r
     };\r
index 114e1ad..00e9bec 100644 (file)
@@ -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();
index 50c1954..09dbbdd 100644 (file)
@@ -107,7 +107,7 @@ DOMElement* UnknownElementImpl::marshall(DOMDocument* document, MarshallingConte
     MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");\r
     Wrapper4InputSource dsrc(&src,false);\r
     log.debug("parsing XML back into DOM tree");\r
-    DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc);\r
+    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
     if (document) {\r
         // The caller insists on using his own document, so we now have to import the thing\r
         // into it. Then we're just dumping the one we built.\r
@@ -166,7 +166,7 @@ DOMElement* UnknownElementImpl::marshall(DOMElement* parentElement, MarshallingC
     MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");\r
     Wrapper4InputSource dsrc(&src,false);\r
     log.debug("parsing XML back into DOM tree");\r
-    DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc);\r
+    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
     \r
     log.debug("reimporting new DOM into caller-supplied document");\r
     cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(), true));\r
index 973684a..33c771a 100644 (file)
@@ -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<void*> m_libhandles;
         void* m_lock;
+        ParserPool* m_parserPool;
+        ParserPool* m_validatingPool;
     };
     /// @endcond
 
index adc8df5..bf169bb 100644 (file)
@@ -246,7 +246,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, MarshallingCont
         MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"XMLSecSignatureImpl");\r
         Wrapper4InputSource dsrc(&src,false);\r
         log.debug("parsing Signature XML back into DOM tree");\r
-        DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc);\r
+        DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
         if (document) {\r
             // The caller insists on using his own document, so we now have to import the thing\r
             // into it. Then we're just dumping the one we built.\r
@@ -350,7 +350,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, Marshalling
         MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"XMLSecSignatureImpl");\r
         Wrapper4InputSource dsrc(&src,false);\r
         log.debug("parsing XML back into DOM tree");\r
-        DOMDocument* internalDoc=XMLToolingInternalConfig::getInternalConfig().m_parserPool->parse(dsrc);\r
+        DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
         \r
         log.debug("reimporting new DOM into caller-supplied document");\r
         cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(),true));\r
index 1ce146e..4897338 100644 (file)
@@ -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();
index 4b93174..73647b4 100644 (file)
@@ -36,7 +36,7 @@ public:
 \r
         string path=data_path + "ComplexXMLObject.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
index 7e65639..2d2ec97 100644 (file)
@@ -38,7 +38,7 @@ public:
 \r
         string path=data_path + "KeyInfo1.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=validatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -67,7 +67,7 @@ public:
 \r
         string path=data_path + "KeyInfo2.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=validatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getValidatingParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -92,7 +92,7 @@ public:
 \r
         string path=data_path + "KeyInfo3.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
index 55f6f73..0b3e056 100644 (file)
@@ -47,7 +47,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithAttribute.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
@@ -67,7 +67,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithContent.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
@@ -107,7 +107,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         TS_ASSERT(rootElement->isEqualNode(doc->getDocumentElement()));\r
index be5c81f..01262bd 100644 (file)
@@ -132,7 +132,7 @@ public:
         //TS_TRACE(buf.c_str());\r
 \r
         istringstream in(buf);\r
-        DOMDocument* doc=nonvalidatingPool->parse(in);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);\r
         auto_ptr<SimpleXMLObject> sxObject2(dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc)));\r
         TS_ASSERT(sxObject2.get()!=NULL);\r
         TS_ASSERT(sxObject2->getSignature()!=NULL);\r
index 574c62a..3687ea3 100644 (file)
@@ -73,7 +73,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithAttribute.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -93,7 +93,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithContent.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -113,7 +113,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -135,7 +135,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
@@ -160,7 +160,7 @@ public:
 \r
         string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";\r
         ifstream fs(path.c_str());\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
index 20450a4..fe1e867 100644 (file)
@@ -23,8 +23,6 @@
 \r
 //#define XMLTOOLINGTEST_LEAKCHECK\r
 \r
-ParserPool* validatingPool=NULL;\r
-ParserPool* nonvalidatingPool=NULL;\r
 std::string data_path = "../xmltoolingtest/data/";\r
 \r
 class ToolingFixture : public CxxTest::GlobalFixture\r
@@ -34,17 +32,13 @@ public:
         XMLToolingConfig::getConfig().log_config();\r
         if (!XMLToolingConfig::getConfig().init())\r
             return false;\r
-        validatingPool = new ParserPool(true,true);\r
-        nonvalidatingPool = new ParserPool();\r
         if (getenv("XMLTOOLINGTEST_DATA"))\r
             data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/";\r
         std::string catpath=data_path + "catalog.xml";\r
         auto_ptr_XMLCh temp(catpath.c_str());\r
-        return validatingPool->loadCatalog(temp.get());\r
+        return XMLToolingConfig::getConfig().getValidatingParser().loadCatalog(temp.get());\r
     }\r
     bool tearDownWorld() {\r
-        delete validatingPool;\r
-        delete nonvalidatingPool;\r
         XMLToolingConfig::getConfig().term();\r
 #if defined(_MSC_VER ) && defined(XMLTOOLINGTEST_LEAKCHECK)\r
        _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );\r
@@ -76,7 +70,7 @@ public:
 \r
     void testUnknown() {\r
         ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         string buf1;\r
@@ -104,7 +98,7 @@ public:
 \r
     void testUnknownWithDocChange() {\r
         ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithChildren.xml");\r
-        DOMDocument* doc=nonvalidatingPool->parse(fs);\r
+        DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);\r
         TS_ASSERT(doc!=NULL);\r
 \r
         string buf1;\r
@@ -116,7 +110,7 @@ public:
         auto_ptr<XMLObject> xmlObject(b->buildFromDocument(doc)); // bind document\r
         TS_ASSERT(xmlObject.get()!=NULL);\r
 \r
-        DOMDocument* newDoc=nonvalidatingPool->newDocument();\r
+        DOMDocument* newDoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
         DOMElement* rootElement=xmlObject->marshall(newDoc);\r
         TS_ASSERT(rootElement!=NULL);\r
 \r
index 843b5ae..5b5b146 100644 (file)
@@ -40,7 +40,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories=".."\r
+                               AdditionalIncludeDirectories="$(SolutionDir)"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories=".."\r
+                               AdditionalIncludeDirectories="$(SolutionDir)"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
                                RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                        >\r
                                        <Tool\r
                                                Name="VCCustomBuildTool"\r
-                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;&#x0D;&#x0A;"\r
                                                Outputs="&quot;$(InputName)&quot;.cpp"\r
                                        />\r
                                </FileConfiguration>\r
                                        >\r
                                        <Tool\r
                                                Name="VCCustomBuildTool"\r
-                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;"\r
+                                               CommandLine="\perl\bin\perl.exe -w \cxxtest\cxxtestgen.pl --part --have-eh --have-std --abort-on-fail -o &quot;$(InputName)&quot;.cpp &quot;$(InputPath)&quot;&#x0D;&#x0A;"\r
                                                Outputs="&quot;$(InputName)&quot;.cpp"\r
                                        />\r
                                </FileConfiguration>\r