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 AbstractXMLObject.h
\r
20 * An abstract implementation of XMLObject.
\r
23 #if !defined(__xmltooling_abstractxmlobj_h__)
\r
24 #define __xmltooling_abstractxmlobj_h__
\r
26 #include <xmltooling/XMLObject.h>
\r
28 #if defined (_MSC_VER)
\r
29 #pragma warning( push )
\r
30 #pragma warning( disable : 4250 4251 )
\r
33 namespace xmltooling {
\r
36 * An abstract implementation of XMLObject.
\r
38 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
\r
41 virtual ~AbstractXMLObject();
\r
43 const QName& getElementQName() const {
\r
44 return m_elementQname;
\r
47 const std::set<Namespace>& getNamespaces() const {
\r
48 return m_namespaces;
\r
51 void addNamespace(const Namespace& ns) const {
\r
52 if (ns.alwaysDeclare() || m_namespaces.find(ns)==m_namespaces.end()) {
\r
53 m_namespaces.insert(ns);
\r
57 void removeNamespace(const Namespace& ns) {
\r
58 m_namespaces.erase(ns);
\r
61 const QName* getSchemaType() const {
\r
65 bool hasParent() const {
\r
66 return m_parent != NULL;
\r
69 XMLObject* getParent() const {
\r
73 void setParent(XMLObject* parent) {
\r
77 bool hasChildren() const {
\r
78 return !m_children.empty();
\r
81 const std::list<XMLObject*>& getOrderedChildren() const {
\r
89 * @param nsURI the namespace of the element
\r
90 * @param localName the local name of the XML element this Object represents
\r
91 * @param prefix the namespace prefix to use
\r
92 * @param schemaType the xsi:type to use
\r
95 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
\r
98 /** Copy constructor. */
\r
99 AbstractXMLObject(const AbstractXMLObject& src);
\r
102 * A helper function for derived classes.
\r
103 * This 'normalizes' newString, and then if it is different from oldString,
\r
104 * it invalidates the DOM, frees the old string, and return the new.
\r
105 * If not different, it frees the new string and just returns the old value.
\r
107 * @param oldValue - the current value
\r
108 * @param newValue - the new value
\r
110 * @return the value that should be assigned
\r
112 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) {
\r
113 XMLCh* newString = XMLString::replicate(newValue);
\r
114 XMLString::trim(newString);
\r
115 if (!XMLString::equals(oldValue,newValue)) {
\r
116 releaseThisandParentDOM();
\r
117 XMLString::release(&oldValue);
\r
120 XMLString::release(&newString);
\r
125 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
127 * It is indifferent to whether either the old or the new version of the value is null.
\r
128 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
\r
129 * Note that since the new value (even if NULL) is always returned, it may be more efficient
\r
130 * to discard the return value and just assign independently if a dynamic cast would be involved.
\r
132 * @param oldValue - current value
\r
133 * @param newValue - proposed new value
\r
134 * @return the new value
\r
136 * @throws XMLObjectException if the new child already has a parent.
\r
138 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
141 * Underlying list of child objects.
\r
142 * Manages the lifetime of the children.
\r
144 std::list<XMLObject*> m_children;
\r
147 * Set of namespaces associated with the object.
\r
149 mutable std::set<Namespace> m_namespaces;
\r
157 XMLObject* m_parent;
\r
158 QName m_elementQname;
\r
159 QName* m_typeQname;
\r
164 #if defined (_MSC_VER)
\r
165 #pragma warning( pop )
\r
168 #endif /* __xmltooling_abstractxmlobj_h__ */
\r