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
37 * This is the primary concrete base class, and supplies basic namespace,
\r
38 * type, and parent handling. Most implementation classes should not
\r
39 * directly inherit from this class, but rather from the various mixins
\r
40 * that supply the rest of the XMLObject interface, as required.
\r
42 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
\r
45 virtual ~AbstractXMLObject() {
\r
49 const QName& getElementQName() const {
\r
50 return m_elementQname;
\r
53 const std::set<Namespace>& getNamespaces() const {
\r
54 return m_namespaces;
\r
57 void addNamespace(const Namespace& ns) const {
\r
58 if (ns.alwaysDeclare() || m_namespaces.find(ns)==m_namespaces.end()) {
\r
59 m_namespaces.insert(ns);
\r
63 void removeNamespace(const Namespace& ns) {
\r
64 m_namespaces.erase(ns);
\r
67 const QName* getSchemaType() const {
\r
71 bool hasParent() const {
\r
72 return m_parent != NULL;
\r
75 XMLObject* getParent() const {
\r
79 void setParent(XMLObject* parent) {
\r
87 * @param nsURI the namespace of the element
\r
88 * @param localName the local name of the XML element this Object represents
\r
89 * @param prefix the namespace prefix to use
\r
90 * @param schemaType the xsi:type to use
\r
93 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
\r
96 /** Copy constructor. */
\r
97 AbstractXMLObject(const AbstractXMLObject& src);
\r
100 * A helper function for derived classes.
\r
101 * This 'normalizes' newString, and then if it is different from oldString,
\r
102 * it invalidates the DOM, frees the old string, and return the new.
\r
103 * If not different, it frees the new string and just returns the old value.
\r
105 * @param oldValue - the current value
\r
106 * @param newValue - the new value
\r
108 * @return the value that should be assigned
\r
110 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
\r
113 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
115 * It is indifferent to whether either the old or the new version of the value is null.
\r
116 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
\r
117 * Note that since the new value (even if NULL) is always returned, it may be more efficient
\r
118 * to discard the return value and just assign independently if a dynamic cast would be involved.
\r
120 * @param oldValue - current value
\r
121 * @param newValue - proposed new value
\r
122 * @return the new value
\r
124 * @throws XMLObjectException if the new child already has a parent.
\r
126 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
129 * Set of namespaces associated with the object.
\r
131 mutable std::set<Namespace> m_namespaces;
\r
139 XMLObject* m_parent;
\r
140 QName m_elementQname;
\r
141 QName* m_typeQname;
\r
146 #if defined (_MSC_VER)
\r
147 #pragma warning( pop )
\r
150 #endif /* __xmltooling_abstractxmlobj_h__ */
\r