Manage document while setting DOM.
authorScott Cantor <cantor.2@osu.edu>
Tue, 21 Feb 2006 19:48:50 +0000 (19:48 +0000)
committerScott Cantor <cantor.2@osu.edu>
Tue, 21 Feb 2006 19:48:50 +0000 (19:48 +0000)
xmltooling/AbstractDOMCachingXMLObject.cpp
xmltooling/AbstractDOMCachingXMLObject.h
xmltooling/DOMCachingXMLObject.h

index 0b9f064..62ea3e9 100644 (file)
@@ -38,6 +38,22 @@ AbstractDOMCachingXMLObject::~AbstractDOMCachingXMLObject()
         m_document->release();\r
 }\r
 \r
+void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument)\r
+{\r
+    m_dom=dom;\r
+    if (dom) {\r
+        if (bindDocument) {\r
+            DOMDocument* tmp=setDocument(dom->getOwnerDocument());\r
+            if (tmp)\r
+                tmp->release();\r
+        }\r
+    }\r
+    else if (m_document) {\r
+        m_document->release();\r
+        m_document=NULL;\r
+    }\r
+}\r
+\r
 void AbstractDOMCachingXMLObject::releaseDOM()\r
 {\r
     Category& log=Category::getInstance(XMLTOOLING_LOGCAT".DOM");\r
index 3959b22..4c90d81 100644 (file)
@@ -51,9 +51,7 @@ namespace xmltooling {
         /**\r
          * @see DOMCachingXMLObject::setDOM()\r
          */\r
-        void setDOM(DOMElement* dom) {\r
-            m_dom=dom;\r
-        }\r
+        void setDOM(DOMElement* dom, bool bindDocument=false);\r
         \r
         /**\r
          * @see DOMCachingXMLObject::setDocument()\r
index b850531..bf14c8c 100644 (file)
@@ -49,9 +49,10 @@ namespace xmltooling {
         /**\r
          * Sets the DOM representation of this XMLObject.\r
          * \r
-         * @param dom DOM representation of this XMLObject\r
+         * @param dom       DOM representation of this XMLObject\r
+         * @param bindDocument  true if the object should take ownership of the associated Document\r
          */\r
-        virtual void setDOM(DOMElement* dom)=0;\r
+        virtual void setDOM(DOMElement* dom, bool bindDocument=false)=0;\r
     \r
         /**\r
          * Assigns ownership of a DOM document to the XMLObject.\r