Add warning pragma blocks.
[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 implements a DOMCachingXMLObject. \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 #include <xmltooling/DOMCachingXMLObject.h>\r
28 \r
29 #if defined (_MSC_VER)\r
30     #pragma warning( push )\r
31     #pragma warning( disable : 4250 4251 )\r
32 #endif\r
33 \r
34 namespace xmltooling {\r
35 \r
36     /**\r
37      * Extension of AbstractXMLObject that implements a DOMCachingXMLObject.\r
38      */\r
39     class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject, public virtual DOMCachingXMLObject\r
40     {\r
41     public:\r
42         virtual ~AbstractDOMCachingXMLObject();\r
43         \r
44         /**\r
45          * @see DOMCachingXMLObject::getDOM()\r
46          */\r
47         const DOMElement* getDOM() const {\r
48             return m_dom;\r
49         }\r
50         \r
51         /**\r
52          * @see DOMCachingXMLObject::setDOM()\r
53          */\r
54         void setDOM(DOMElement* dom) {\r
55             m_dom=dom;\r
56         }\r
57         \r
58         /**\r
59          * @see DOMCachingXMLObject::setDocument()\r
60          */\r
61         DOMDocument* setDocument(DOMDocument* doc) {\r
62             DOMDocument* ret=m_document;\r
63             m_document=doc;\r
64             return ret;\r
65         }\r
66     \r
67         /**\r
68          * @see DOMCachingXMLObject::releaseDOM()\r
69          */\r
70         void releaseDOM();\r
71         \r
72         /**\r
73          * @see DOMCachingXMLObject::releaseParentDOM()\r
74          */\r
75         void releaseParentDOM(bool propagateRelease=true);\r
76         \r
77         /**\r
78          * @see DOMCachingXMLObject::releaseChildrenDOM()\r
79          */\r
80         void releaseChildrenDOM(bool propagateRelease=true);\r
81     \r
82         /**\r
83          * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).\r
84          */\r
85         void releaseThisandParentDOM() {\r
86             if (m_dom) {\r
87                 releaseDOM();\r
88                 releaseParentDOM(true);\r
89             }\r
90         }\r
91     \r
92         /**\r
93          * A convenience method that is equal to calling releaseDOM() then releaseChildrenDOM(true).\r
94          */\r
95         void releaseThisAndChildrenDOM() {\r
96             if (m_dom) {\r
97                 releaseDOM();\r
98                 releaseChildrenDOM(true);\r
99             }\r
100         }\r
101     \r
102      protected:\r
103         /**\r
104          * A helper function for derived classes.\r
105          * This 'normalizes' newString and then if it is different from oldString\r
106          * invalidates the DOM. It returns the normalized value.\r
107          * \r
108          * @param oldValue - the current value\r
109          * @param newValue - the new value\r
110          * \r
111          * @return the value that should be assigned\r
112          */\r
113         XMLCh* prepareForAssignment(const XMLCh* oldValue, const XMLCh* newValue) {\r
114             XMLCh* newString = XMLString::replicate(newValue);\r
115             XMLString::trim(newString);\r
116 \r
117             if (oldValue && !newValue || !oldValue && newValue || XMLString::compareString(oldValue,newValue))\r
118                 releaseThisandParentDOM();\r
119     \r
120             return newString;\r
121         }\r
122     \r
123         /**\r
124          * A helper function for derived classes, for assignment of (singleton) XML objects.\r
125          * \r
126          * It is indifferent to whether either the old or the new version of the value is null. \r
127          * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate\r
128          * \r
129          * @param oldValue - current value\r
130          * @param newValue - proposed new value\r
131          * @return The value to assign to the saved Object.\r
132          * \r
133          * @throws IllegalArgumentException if the child already has a parent.\r
134          */\r
135         XMLObject* prepareForAssignment(const XMLObject* oldValue, XMLObject* newValue);\r
136 \r
137         /**\r
138          * Constructor\r
139          * \r
140          * @param namespaceURI the namespace the element is in\r
141          * @param elementLocalName the local name of the XML element this Object represents\r
142          */\r
143         explicit AbstractDOMCachingXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName)\r
144             : AbstractXMLObject(namespaceURI,elementLocalName), m_dom(NULL), m_document(NULL) {}\r
145 \r
146     private:\r
147         DOMElement* m_dom;\r
148         DOMDocument* m_document;\r
149     };\r
150     \r
151 };\r
152 \r
153 #if defined (_MSC_VER)\r
154     #pragma warning( pop )\r
155 #endif\r
156 \r
157 #endif /* __xmltooling_abstractdomxmlobj_h__ */\r