2 * Copyright 2001-2006 Internet2
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 * @file AbstractDOMCachingXMLObject.h
\r
20 * Extension of AbstractXMLObject that implements a DOMCachingXMLObject.
\r
23 #if !defined(__xmltooling_abstractdomxmlobj_h__)
\r
24 #define __xmltooling_abstractdomxmlobj_h__
\r
26 #include <xmltooling/AbstractXMLObject.h>
\r
27 #include <xmltooling/DOMCachingXMLObject.h>
\r
29 #if defined (_MSC_VER)
\r
30 #pragma warning( push )
\r
31 #pragma warning( disable : 4250 4251 )
\r
34 namespace xmltooling {
\r
37 * Extension of AbstractXMLObject that implements a DOMCachingXMLObject.
\r
39 class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject, public virtual DOMCachingXMLObject
\r
42 virtual ~AbstractDOMCachingXMLObject();
\r
45 * @see DOMCachingXMLObject::getDOM()
\r
47 DOMElement* getDOM() const {
\r
52 * @see DOMCachingXMLObject::setDOM()
\r
54 void setDOM(DOMElement* dom, bool bindDocument=false) const;
\r
57 * @see DOMCachingXMLObject::setDocument()
\r
59 void setDocument(DOMDocument* doc) const {
\r
61 m_document->release();
\r
66 * @see DOMCachingXMLObject::releaseDOM()
\r
68 virtual void releaseDOM() const;
\r
71 * @see DOMCachingXMLObject::releaseParentDOM()
\r
73 virtual void releaseParentDOM(bool propagateRelease=true) const;
\r
76 * @see DOMCachingXMLObject::releaseChildrenDOM()
\r
78 virtual void releaseChildrenDOM(bool propagateRelease=true) const;
\r
81 * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).
\r
83 void releaseThisandParentDOM() const {
\r
86 releaseParentDOM(true);
\r
91 * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM().
\r
93 void releaseThisAndChildrenDOM() const {
\r
95 releaseChildrenDOM(true);
\r
101 * @see XMLObject::clone()
\r
103 XMLObject* clone() const;
\r
106 AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) {}
\r
109 * If a DOM representation exists, this clones it into a new document.
\r
111 * @param doc the document to clone into, or NULL, in which case a new document is created
\r
112 * @return the cloned DOM
\r
114 DOMElement* cloneDOM(DOMDocument* doc=NULL) const;
\r
117 * A helper function for derived classes.
\r
118 * This 'normalizes' newString, and then if it is different from oldString,
\r
119 * it invalidates the DOM, frees the old string, and return the new.
\r
120 * If not different, it frees the new string and just returns the old value.
\r
122 * @param oldValue - the current value
\r
123 * @param newValue - the new value
\r
125 * @return the value that should be assigned
\r
127 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) {
\r
128 XMLCh* newString = XMLString::replicate(newValue);
\r
129 XMLString::trim(newString);
\r
130 if (!XMLString::equals(oldValue,newValue)) {
\r
131 releaseThisandParentDOM();
\r
132 XMLString::release(&oldValue);
\r
135 XMLString::release(&newString);
\r
140 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
142 * It is indifferent to whether either the old or the new version of the value is null.
\r
143 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate
\r
145 * @param oldValue - current value
\r
146 * @param newValue - proposed new value
\r
147 * @return the value to assign
\r
149 * @throws XMLObjectException if the new child already has a parent.
\r
151 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
154 mutable DOMElement* m_dom;
\r
155 mutable DOMDocument* m_document;
\r
160 #if defined (_MSC_VER)
\r
161 #pragma warning( pop )
\r
164 #endif /* __xmltooling_abstractdomxmlobj_h__ */
\r