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 #pragma warning( push )
\r
30 #pragma warning( disable : 4250 4251 )
\r
32 namespace xmltooling {
\r
35 * Extension of AbstractXMLObject that implements a DOMCachingXMLObject.
\r
37 class XMLTOOL_API AbstractDOMCachingXMLObject : public virtual AbstractXMLObject, public virtual DOMCachingXMLObject
\r
40 virtual ~AbstractDOMCachingXMLObject();
\r
43 * @see DOMCachingXMLObject::getDOM()
\r
45 const DOMElement* getDOM() const {
\r
50 * @see DOMCachingXMLObject::setDOM()
\r
52 void setDOM(DOMElement* dom) {
\r
57 * @see DOMCachingXMLObject::setDocument()
\r
59 DOMDocument* setDocument(DOMDocument* doc) {
\r
60 DOMDocument* ret=m_document;
\r
66 * @see DOMCachingXMLObject::releaseDOM()
\r
71 * @see DOMCachingXMLObject::releaseParentDOM()
\r
73 void releaseParentDOM(bool propagateRelease=true);
\r
76 * @see DOMCachingXMLObject::releaseChildrenDOM()
\r
78 void releaseChildrenDOM(bool propagateRelease=true);
\r
81 * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).
\r
83 void releaseThisandParentDOM() {
\r
86 releaseParentDOM(true);
\r
91 * A convenience method that is equal to calling releaseDOM() then releaseChildrenDOM(true).
\r
93 void releaseThisAndChildrenDOM() {
\r
96 releaseChildrenDOM(true);
\r
102 * A helper function for derived classes.
\r
103 * This 'normalizes' newString and then if it is different from oldString
\r
104 * invalidates the DOM. It returns the normalized value.
\r
106 * @param oldValue - the current value
\r
107 * @param newValue - the new value
\r
109 * @return the value that should be assigned
\r
111 XMLCh* prepareForAssignment(const XMLCh* oldValue, const XMLCh* newValue) {
\r
112 XMLCh* newString = XMLString::replicate(newValue);
\r
113 XMLString::trim(newString);
\r
115 if (oldValue && !newValue || !oldValue && newValue || XMLString::compareString(oldValue,newValue))
\r
116 releaseThisandParentDOM();
\r
122 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
124 * It is indifferent to whether either the old or the new version of the value is null.
\r
125 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate
\r
127 * @param oldValue - current value
\r
128 * @param newValue - proposed new value
\r
129 * @return The value to assign to the saved Object.
\r
131 * @throws IllegalArgumentException if the child already has a parent.
\r
133 XMLObject* prepareForAssignment(const XMLObject* oldValue, XMLObject* newValue);
\r
138 * @param namespaceURI the namespace the element is in
\r
139 * @param elementLocalName the local name of the XML element this Object represents
\r
141 explicit AbstractDOMCachingXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName)
\r
142 : AbstractXMLObject(namespaceURI,elementLocalName), m_dom(NULL), m_document(NULL) {}
\r
146 DOMDocument* m_document;
\r
151 #pragma warning( pop )
\r
153 #endif /* __xmltooling_abstractdomxmlobj_h__ */
\r