Moved DOM methods up the tree, add copy c'tors, KeyInfo sample
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractDOMCachingXMLObject.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * @file AbstractDOMCachingXMLObject.h\r
19  * \r
20  * Extension of AbstractXMLObject that adds DOM caching methods\r
21  */\r
22 \r
23 #if !defined(__xmltooling_abstractdomxmlobj_h__)\r
24 #define __xmltooling_abstractdomxmlobj_h__\r
25 \r
26 #include <xmltooling/AbstractXMLObject.h>\r
27 \r
28 #if defined (_MSC_VER)\r
29     #pragma warning( push )\r
30     #pragma warning( disable : 4250 4251 )\r
31 #endif\r
32 \r
33 namespace xmltooling {\r
34 \r
35     /**\r
36      * Extension of AbstractXMLObject that adds DOM caching methods\r
37      */\r
38     class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject\r
39     {\r
40     public:\r
41         virtual ~AbstractDOMCachingXMLObject();\r
42         \r
43         DOMElement* getDOM() const {\r
44             return m_dom;\r
45         }\r
46         \r
47         void setDOM(DOMElement* dom, bool bindDocument=false) const;\r
48         \r
49         void setDocument(DOMDocument* doc) const {\r
50             if (m_document)\r
51                 m_document->release();\r
52             m_document=doc;\r
53         }\r
54     \r
55         virtual void releaseDOM() const;\r
56         \r
57         virtual void releaseParentDOM(bool propagateRelease=true) const;\r
58         \r
59         virtual void releaseChildrenDOM(bool propagateRelease=true) const;\r
60     \r
61         XMLObject* clone() const;\r
62 \r
63      protected:\r
64         AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) {}\r
65 \r
66         /** Copy constructor. */\r
67         AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src)\r
68             : AbstractXMLObject(src), m_dom(NULL), m_document(NULL) {}\r
69 \r
70         /**\r
71          * If a DOM representation exists, this clones it into a new document.\r
72          * \r
73          * @param doc   the document to clone into, or NULL, in which case a new document is created\r
74          * @return  the cloned DOM\r
75          */\r
76         DOMElement* cloneDOM(DOMDocument* doc=NULL) const;\r
77 \r
78     private:\r
79         mutable DOMElement* m_dom;\r
80         mutable DOMDocument* m_document;\r
81     };\r
82     \r
83 };\r
84 \r
85 #if defined (_MSC_VER)\r
86     #pragma warning( pop )\r
87 #endif\r
88 \r
89 #endif /* __xmltooling_abstractdomxmlobj_h__ */\r