Shortcuts for unmarshalling in builder interface, adjusted tests
[shibboleth/xmltooling.git] / xmltooling / XMLObjectBuilder.h
index 0c9f069..4426401 100644 (file)
 #define __xmltooling_xmlobjbuilder_h__\r
 \r
 #include <map>\r
-#include <xercesc/dom/DOM.hpp>\r
 #include <xmltooling/QName.h>\r
 #include <xmltooling/XMLObject.h>\r
 \r
-using namespace xercesc;\r
-\r
 #if defined (_MSC_VER)\r
     #pragma warning( push )\r
     #pragma warning( disable : 4250 4251 )\r
@@ -50,21 +47,58 @@ namespace xmltooling {
         /**\r
          * Creates an empty XMLObject.\r
          * \r
-         * @param e     a construction hint based on the eventual unmarshalling source\r
          * @return the empty XMLObject\r
          */\r
-        virtual XMLObject* buildObject(const DOMElement* e=NULL) const=0;\r
+        virtual XMLObject* buildObject() const=0;\r
+\r
+        /**\r
+         * Creates an unmarshalled XMLObject from a DOM Element.\r
+         * \r
+         * @param element       the unmarshalling source\r
+         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document\r
+         * @return the unmarshalled XMLObject\r
+         */\r
+        virtual XMLObject* buildFromElement(DOMElement* element, bool bindDocument=false) const {\r
+            std::auto_ptr<XMLObject> ret(buildObject());\r
+            ret->unmarshall(element,bindDocument);\r
+            return ret.release();\r
+        }\r
+\r
+        /**\r
+         * Creates an unmarshalled XMLObject from the root of a DOM Document.\r
+         * \r
+         * @param doc           the unmarshalling source\r
+         * @param bindDocument  true iff the XMLObject should take ownership of the DOM Document\r
+         * @return the unmarshalled XMLObject\r
+         */\r
+        virtual XMLObject* buildFromDocument(DOMDocument* doc, bool bindDocument=true) const {\r
+            return buildFromElement(doc->getDocumentElement(),bindDocument);\r
+        }\r
 \r
         /**\r
          * Creates an empty XMLObject using the default build method, if a builder can be found.\r
          * \r
          * @param key   the key used to locate a builder\r
-         * @param e     a construction hint based on the eventual unmarshalling source\r
          * @return  the empty object or NULL if no builder is available \r
          */\r
-        static XMLObject* buildObject(const QName& key, const DOMElement* e=NULL) {\r
+        static XMLObject* buildOne(const QName& key) {\r
             const XMLObjectBuilder* b=getBuilder(key);\r
-            return b ? b->buildObject(e) : NULL;\r
+            if (b)\r
+                return b->buildObject();\r
+            b=getDefaultBuilder();\r
+            return b ? b->buildObject() : NULL;\r
+        }\r
+\r
+        /**\r
+         * Creates an unmarshalled XMLObject using the default build method, if a builder can be found.\r
+         * \r
+         * @param element       the unmarshalling source\r
+         * @param bindDocument  true iff the new XMLObject should take ownership of the DOM Document\r
+         * @return  the unmarshalled object or NULL if no builder is available \r
+         */\r
+        static XMLObject* buildOneFromElement(DOMElement* element, bool bindDocument=false) {\r
+            const XMLObjectBuilder* b=getBuilder(element);\r
+            return b ? b->buildFromElement(element,bindDocument) : NULL;\r
         }\r
 \r
         /**\r
@@ -92,7 +126,7 @@ namespace xmltooling {
          * \r
          * @return the default builder or NULL\r
          */\r
-        static const XMLObjectBuilder* getDefaultBuilder(const DOMElement* element) {\r
+        static const XMLObjectBuilder* getDefaultBuilder() {\r
             return m_default;\r
         }\r
 \r