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
38 * This is the primary base class for XMLObject implementation classes to use.
\r
40 class XMLTOOL_API AbstractDOMCachingXMLObject : public AbstractXMLObject, public DOMCachingXMLObject
\r
43 virtual ~AbstractDOMCachingXMLObject();
\r
46 * @see DOMCachingXMLObject::getDOM()
\r
48 DOMElement* getDOM() const {
\r
53 * @see DOMCachingXMLObject::setDOM()
\r
55 void setDOM(DOMElement* dom, bool bindDocument=false);
\r
58 * @see DOMCachingXMLObject::setDocument()
\r
60 void setDocument(DOMDocument* doc) {
\r
62 m_document->release();
\r
67 * @see DOMCachingXMLObject::releaseDOM()
\r
69 virtual void releaseDOM();
\r
72 * @see DOMCachingXMLObject::releaseParentDOM()
\r
74 virtual void releaseParentDOM(bool propagateRelease=true);
\r
77 * @see DOMCachingXMLObject::releaseChildrenDOM()
\r
79 virtual void releaseChildrenDOM(bool propagateRelease=true);
\r
82 * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).
\r
84 void releaseThisandParentDOM() {
\r
87 releaseParentDOM(true);
\r
92 * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM().
\r
94 void releaseThisAndChildrenDOM() {
\r
96 releaseChildrenDOM(true);
\r
102 * @see XMLObject::clone()
\r
104 XMLObject* clone() const;
\r
110 * @param namespaceURI the namespace the element is in
\r
111 * @param elementLocalName the local name of the XML element this Object represents
\r
112 * @param namespacePrefix the namespace prefix to use
\r
114 AbstractDOMCachingXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)
\r
115 : AbstractXMLObject(namespaceURI,elementLocalName, namespacePrefix), m_dom(NULL), m_document(NULL) {}
\r
118 * If a DOM representation exists, this clones it into a new document.
\r
120 * @param doc the document to clone into, or NULL, in which case a new document is created
\r
121 * @return the cloned DOM
\r
123 DOMElement* cloneDOM(DOMDocument* doc=NULL) const;
\r
126 * A helper function for derived classes.
\r
127 * This 'normalizes' newString, and then if it is different from oldString,
\r
128 * it invalidates the DOM, frees the old string, and return the new.
\r
129 * If not different, it frees the new string and just returns the old value.
\r
131 * @param oldValue - the current value
\r
132 * @param newValue - the new value
\r
134 * @return the value that should be assigned
\r
136 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) {
\r
137 XMLCh* newString = XMLString::replicate(newValue);
\r
138 XMLString::trim(newString);
\r
139 if (!XMLString::equals(oldValue,newValue)) {
\r
140 releaseThisandParentDOM();
\r
141 XMLString::release(&oldValue);
\r
144 XMLString::release(&newString);
\r
149 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
151 * It is indifferent to whether either the old or the new version of the value is null.
\r
152 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate
\r
154 * @param oldValue - current value
\r
155 * @param newValue - proposed new value
\r
156 * @return the value to assign
\r
158 * @throws XMLObjectException if the new child already has a parent.
\r
160 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
164 DOMDocument* m_document;
\r
169 #if defined (_MSC_VER)
\r
170 #pragma warning( pop )
\r
173 #endif /* __xmltooling_abstractdomxmlobj_h__ */
\r