Tighten up validator namespace checking, rework registration.
[shibboleth/xmltooling.git] / xmltooling / XMLToolingConfig.cpp
index 9bd8b3e..7b9d378 100644 (file)
  */
 
 #include "internal.h"
+#include "exceptions.h"
 #include "XMLToolingConfig.h"
 #include "impl/UnknownElement.h"
-#include "signature/impl/XMLSecSignature.h"
+#include "signature/KeyInfo.h"
+#include "signature/Signature.h"
 #include "util/NDC.h"
+#include "util/XMLConstants.h"
+#include "validation/Validator.h"
 
 #ifdef HAVE_DLFCN_H
 # include <dlfcn.h>
 
 #include <stdexcept>
 
-using namespace log4cpp;
+using namespace xmlsignature;
 using namespace xmltooling;
+using namespace log4cpp;
 using namespace std;
 
-namespace {
+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;
 }
 
@@ -136,17 +154,25 @@ 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());
-        Marshaller::registerDefaultMarshaller(new UnknownElementMarshaller());
-        Unmarshaller::registerDefaultUnmarshaller(new UnknownElementUnmarshaller());
+
+        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
-        QName dsig(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME);
-        XMLObjectBuilder::registerBuilder(dsig,new XMLSecSignatureBuilder());
-        Marshaller::registerMarshaller(dsig,new XMLSecSignatureMarshaller());
-        Unmarshaller::registerUnmarshaller(dsig,new XMLSecSignatureUnmarshaller());
+        XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new SignatureBuilder());
+        REGISTER_EXCEPTION_FACTORY(SignatureException,xmlsignature);
 #endif
     }
     catch (const xercesc::XMLException&) {
@@ -161,8 +187,8 @@ bool XMLToolingInternalConfig::init()
 void XMLToolingInternalConfig::term()
 {
     XMLObjectBuilder::destroyBuilders();
-    Marshaller::destroyMarshallers();
-    Unmarshaller::destroyUnmarshallers();
+    Validator::destroyValidators();
+    XMLToolingException::deregisterFactories();
 
     for (vector<void*>::reverse_iterator i=m_libhandles.rbegin(); i!=m_libhandles.rend(); i++) {
 #if defined(WIN32)
@@ -183,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;
@@ -200,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;