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 void setSchemaType(const QName* type) {
\r
69 m_typeQname = new QName(*type);
\r
70 addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix()));
\r
74 bool hasParent() const {
\r
75 return m_parent != NULL;
\r
78 XMLObject* getParent() const {
\r
82 void setParent(XMLObject* parent) {
\r
86 bool hasChildren() const {
\r
87 return !m_children.empty();
\r
90 const std::list<XMLObject*>& getOrderedChildren() const {
\r
98 * @param namespaceURI the namespace the element is in
\r
99 * @param elementLocalName the local name of the XML element this Object represents
\r
100 * @param namespacePrefix the namespace prefix to use
\r
102 AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL);
\r
104 /** Copy constructor. */
\r
105 AbstractXMLObject(const AbstractXMLObject& src);
\r
108 * A helper function for derived classes.
\r
109 * This 'normalizes' newString, and then if it is different from oldString,
\r
110 * it invalidates the DOM, frees the old string, and return the new.
\r
111 * If not different, it frees the new string and just returns the old value.
\r
113 * @param oldValue - the current value
\r
114 * @param newValue - the new value
\r
116 * @return the value that should be assigned
\r
118 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) {
\r
119 XMLCh* newString = XMLString::replicate(newValue);
\r
120 XMLString::trim(newString);
\r
121 if (!XMLString::equals(oldValue,newValue)) {
\r
122 releaseThisandParentDOM();
\r
123 XMLString::release(&oldValue);
\r
126 XMLString::release(&newString);
\r
131 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
133 * It is indifferent to whether either the old or the new version of the value is null.
\r
134 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate
\r
136 * @param oldValue - current value
\r
137 * @param newValue - proposed new value
\r
138 * @return the value to assign
\r
140 * @throws XMLObjectException if the new child already has a parent.
\r
142 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
145 * Underlying list of child objects.
\r
146 * Manages the lifetime of the children.
\r
148 std::list<XMLObject*> m_children;
\r
151 * Set of namespaces associated with the object.
\r
153 mutable std::set<Namespace> m_namespaces;
\r
161 XMLObject* m_parent;
\r
162 QName m_elementQname;
\r
163 QName* m_typeQname;
\r
168 #if defined (_MSC_VER)
\r
169 #pragma warning( pop )
\r
172 #endif /* __xmltooling_abstractxmlobj_h__ */
\r