Tighten up validator namespace checking, rework registration.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLToolingConfig.cpp
index a9e51b7..7b9d378 100644 (file)
 
 #include <stdexcept>
 
-using namespace log4cpp;
+using namespace xmlsignature;
 using namespace xmltooling;
+using namespace log4cpp;
 using namespace std;
 
-#define REGISTER_ELEMENT(namespaceURI,cname) \
-    q=QName(namespaceURI,cname::LOCAL_NAME); \
-    XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
-    Validator::registerValidator(q,new cname##SchemaValidator())
-    
-#define REGISTER_TYPE(namespaceURI,cname) \
-    q=QName(namespaceURI,cname::TYPE_NAME); \
-    XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
-    Validator::registerValidator(q,new cname##SchemaValidator())
+DECL_EXCEPTION_FACTORY(XMLParserException,xmltooling);
+DECL_EXCEPTION_FACTORY(XMLObjectException,xmltooling);
+DECL_EXCEPTION_FACTORY(MarshallingException,xmltooling);
+DECL_EXCEPTION_FACTORY(UnmarshallingException,xmltooling);
+DECL_EXCEPTION_FACTORY(UnknownElementException,xmltooling);
+DECL_EXCEPTION_FACTORY(UnknownAttributeException,xmltooling);
+DECL_EXCEPTION_FACTORY(UnknownExtensionException,xmltooling);
+DECL_EXCEPTION_FACTORY(ValidationException,xmltooling);
 
-
-DECL_EXCEPTION_FACTORY(XMLParserException);
-DECL_EXCEPTION_FACTORY(XMLObjectException);
-DECL_EXCEPTION_FACTORY(MarshallingException);
-DECL_EXCEPTION_FACTORY(UnmarshallingException);
-DECL_EXCEPTION_FACTORY(UnknownElementException);
-DECL_EXCEPTION_FACTORY(UnknownAttributeException);
-DECL_EXCEPTION_FACTORY(ValidationException);
-DECL_EXCEPTION_FACTORY(SignatureException);
+#ifndef XMLTOOLING_NO_XMLSEC
+    DECL_EXCEPTION_FACTORY(SignatureException,xmlsignature);
+#endif
 
 namespace xmltooling {
    XMLToolingInternalConfig g_config;
@@ -160,33 +154,26 @@ bool XMLToolingInternalConfig::init()
 #endif
 
         m_parserPool=new ParserPool();
+        m_validatingPool=new ParserPool(true,true);
         m_lock=xercesc::XMLPlatformUtils::makeMutex();
 
         // default registrations
         XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder());
-        
-        QName q;
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyInfo);
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyName);
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,MgmtData);
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RSAKeyValue);
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Exponent);
-        REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Modulus);
-        REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyInfo);
-        REGISTER_TYPE(XMLConstants::XMLSIG_NS,RSAKeyValue);
 
+        registerKeyInfoClasses();
+        
+        REGISTER_EXCEPTION_FACTORY(XMLParserException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(XMLObjectException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(MarshallingException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(UnmarshallingException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(UnknownElementException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(UnknownAttributeException,xmltooling);
+        REGISTER_EXCEPTION_FACTORY(ValidationException,xmltooling);
+        
 #ifndef XMLTOOLING_NO_XMLSEC
         XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new SignatureBuilder());
+        REGISTER_EXCEPTION_FACTORY(SignatureException,xmlsignature);
 #endif
-
-        REGISTER_EXCEPTION_FACTORY(XMLParserException);
-        REGISTER_EXCEPTION_FACTORY(XMLObjectException);
-        REGISTER_EXCEPTION_FACTORY(MarshallingException);
-        REGISTER_EXCEPTION_FACTORY(UnmarshallingException);
-        REGISTER_EXCEPTION_FACTORY(UnknownElementException);
-        REGISTER_EXCEPTION_FACTORY(UnknownAttributeException);
-        REGISTER_EXCEPTION_FACTORY(ValidationException);
-        REGISTER_EXCEPTION_FACTORY(SignatureException);
     }
     catch (const xercesc::XMLException&) {
         log.fatal("caught exception while initializing Xerces");
@@ -200,6 +187,8 @@ bool XMLToolingInternalConfig::init()
 void XMLToolingInternalConfig::term()
 {
     XMLObjectBuilder::destroyBuilders();
+    Validator::destroyValidators();
+    XMLToolingException::deregisterFactories();
 
     for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {
 #if defined(WIN32)
@@ -220,6 +209,8 @@ void XMLToolingInternalConfig::term()
     
     delete m_parserPool;
     m_parserPool=NULL;
+    delete m_validatingPool;
+    m_validatingPool=NULL;
 
 #ifndef XMLTOOLING_NO_XMLSEC
     delete m_xsecProvider;
@@ -237,7 +228,7 @@ void XMLToolingInternalConfig::term()
    Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("library shutdown complete");
 }
 
-ILockable& XMLToolingInternalConfig::lock()
+Lockable& XMLToolingInternalConfig::lock()
 {
     xercesc::XMLPlatformUtils::lockMutex(m_lock);
     return *this;