Tighten up validator namespace checking, rework registration.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLToolingConfig.cpp
index 3cfbe79..7b9d378 100644 (file)
  */
 
 #include "internal.h"
-
-#define XMLTOOLING_DEFINE_CONSTANTS
-#include <xercesc/util/XMLUniDefs.hpp>
-
 #include "exceptions.h"
 #include "XMLToolingConfig.h"
 #include "impl/UnknownElement.h"
-#include "signature/impl/KeyInfoImpl.h"
-#include "signature/impl/XMLSecSignatureImpl.h"
+#include "signature/KeyInfo.h"
+#include "signature/Signature.h"
 #include "util/NDC.h"
 #include "util/XMLConstants.h"
 #include "validation/Validator.h"
 
 #include <stdexcept>
 
-using namespace log4cpp;
+using namespace xmlsignature;
 using namespace xmltooling;
+using namespace log4cpp;
 using namespace std;
 
-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);
+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);
+
+#ifndef XMLTOOLING_NO_XMLSEC
+    DECL_EXCEPTION_FACTORY(SignatureException,xmlsignature);
+#endif
 
 namespace xmltooling {
    XMLToolingInternalConfig g_config;
@@ -153,38 +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(XMLConstants::XMLSIG_NS,KeyInfo::LOCAL_NAME);
-        XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl());
-        Validator::registerValidator(q,new KeyInfoSchemaValidator());
-        q=QName(XMLConstants::XMLSIG_NS,KeyInfo::TYPE_NAME);
-        XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl());
-        Validator::registerValidator(q,new KeyInfoSchemaValidator());
-
-        q=QName(XMLConstants::XMLSIG_NS,KeyName::LOCAL_NAME);
-        XMLObjectBuilder::registerBuilder(q,new KeyNameBuilderImpl());
-        Validator::registerValidator(q,new KeyNameSchemaValidator());
-
-        q=QName(XMLConstants::XMLSIG_NS,MgmtData::LOCAL_NAME);
-        XMLObjectBuilder::registerBuilder(q,new MgmtDataBuilderImpl());
-        Validator::registerValidator(q,new MgmtDataSchemaValidator());
 
+        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 XMLSecSignatureBuilder());
+        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");
@@ -198,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)
@@ -218,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;
@@ -235,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;