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