Merged marshalling/unmarshalling methods into core interface.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractDOMCachingXMLObject.cpp
index 7ffc58c..fb4c0f5 100644 (file)
@@ -21,9 +21,9 @@
  */\r
 \r
 #include "internal.h"\r
-#include "exceptions.h"\r
 #include "AbstractDOMCachingXMLObject.h"\r
-#include "io/Unmarshaller.h"\r
+#include "exceptions.h"\r
+#include "XMLObjectBuilder.h"\r
 #include "util/XMLHelper.h"\r
 \r
 #include <algorithm>\r
@@ -40,7 +40,7 @@ AbstractDOMCachingXMLObject::~AbstractDOMCachingXMLObject()
         m_document->release();\r
 }\r
 \r
-void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument)\r
+void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument) const\r
 {\r
     m_dom=dom;\r
     if (dom) {\r
@@ -50,7 +50,7 @@ void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument)
     }\r
 }\r
 \r
-void AbstractDOMCachingXMLObject::releaseDOM()\r
+void AbstractDOMCachingXMLObject::releaseDOM() const\r
 {\r
     if (m_dom) {\r
         Category& log=Category::getInstance(XMLTOOLING_LOGCAT".DOM");\r
@@ -62,7 +62,7 @@ void AbstractDOMCachingXMLObject::releaseDOM()
     }\r
 }\r
 \r
-void AbstractDOMCachingXMLObject::releaseParentDOM(bool propagateRelease)\r
+void AbstractDOMCachingXMLObject::releaseParentDOM(bool propagateRelease) const\r
 {\r
     DOMCachingXMLObject* domCachingParent = dynamic_cast<DOMCachingXMLObject*>(getParent());\r
     if (domCachingParent) {\r
@@ -90,7 +90,7 @@ public:
     }\r
 };\r
 \r
-void AbstractDOMCachingXMLObject::releaseChildrenDOM(bool propagateRelease)\r
+void AbstractDOMCachingXMLObject::releaseChildrenDOM(bool propagateRelease) const\r
 {\r
     if (hasChildren()) {\r
         Category::getInstance(XMLTOOLING_LOGCAT".DOM").debug(\r
@@ -117,20 +117,23 @@ XMLObject* AbstractDOMCachingXMLObject::clone() const
     DOMElement* domCopy=cloneDOM();\r
     if (domCopy) {\r
         // Seemed to work, so now we unmarshall the DOM to produce the clone.\r
-        const Unmarshaller* u=Unmarshaller::getUnmarshaller(domCopy);\r
-        if (!u) {\r
+        const XMLObjectBuilder* b=XMLObjectBuilder::getBuilder(domCopy);\r
+        if (!b) {\r
             auto_ptr<QName> q(XMLHelper::getNodeQName(domCopy));\r
             Category::getInstance(XMLTOOLING_LOGCAT".DOM").error(\r
-                "DOM clone failed, unable to locate unmarshaller for element (%s)", q->toString().c_str()\r
+                "DOM clone failed, unable to locate builder for element (%s)", q->toString().c_str()\r
                 );\r
             domCopy->getOwnerDocument()->release();\r
-            throw UnmarshallingException("Unable to locate unmarshaller for cloned element.");\r
+            throw UnmarshallingException("Unable to locate builder for cloned element.");\r
         }\r
         try {\r
-            return u->unmarshall(domCopy, true);    // bind document\r
+            auto_ptr<XMLObject> objCopy(b->buildObject(domCopy));\r
+            objCopy->unmarshall(domCopy, true);    // bind document\r
+            return objCopy.release();\r
         }\r
         catch (...) {\r
             domCopy->getOwnerDocument()->release();\r
+            throw;\r
         }\r
     }\r
     return NULL;\r