2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file AbstractXMLObject.h
20 * An abstract implementation of XMLObject.
23 #if !defined(__xmltooling_abstractxmlobj_h__)
24 #define __xmltooling_abstractxmlobj_h__
26 #include <xmltooling/XMLObject.h>
27 #include <xmltooling/util/DateTime.h>
29 #if defined (_MSC_VER)
30 #pragma warning( push )
31 #pragma warning( disable : 4250 4251 )
34 namespace xmltooling {
37 * An abstract implementation of XMLObject.
38 * This is the primary concrete base class, and supplies basic namespace,
39 * type, and parent handling. Most implementation classes should not
40 * directly inherit from this class, but rather from the various mixins
41 * that supply the rest of the XMLObject interface, as required.
43 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
46 virtual ~AbstractXMLObject() {
48 XMLString::release(&m_schemaLocation);
53 const QName& getElementQName() const {
54 return m_elementQname;
57 const std::set<Namespace>& getNamespaces() const {
61 void addNamespace(const Namespace& ns) const {
62 std::set<Namespace>::iterator i = m_namespaces.find(ns);
63 if (i == m_namespaces.end())
64 m_namespaces.insert(ns);
65 else if (ns.alwaysDeclare())
66 const_cast<Namespace&>(*i).setAlwaysDeclare(true);
69 void removeNamespace(const Namespace& ns) {
70 m_namespaces.erase(ns);
73 const QName* getSchemaType() const {
77 const XMLCh* getXMLID() const {
81 bool hasParent() const {
82 return m_parent != NULL;
85 XMLObject* getParent() const {
89 void setParent(XMLObject* parent) {
97 * @param nsURI the namespace of the element
98 * @param localName the local name of the XML element this Object represents
99 * @param prefix the namespace prefix to use
100 * @param schemaType the xsi:type to use
103 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
106 /** Copy constructor. */
107 AbstractXMLObject(const AbstractXMLObject& src);
110 * A helper function for derived classes, for assignment of strings.
112 * This 'normalizes' newString, and then if it is different from oldString,
113 * it invalidates the DOM, frees the old string, and returns the new.
114 * If not different, it frees the new string and just returns the old value.
116 * @param oldValue - the current value
117 * @param newValue - the new value
119 * @return the value that should be assigned
121 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
124 * A helper function for derived classes, for assignment of date/time data.
126 * It invalidates the DOM, frees the old object, and returns the new.
128 * @param oldValue - the current value
129 * @param newValue - the new value
131 * @return the value that should be assigned
133 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
136 * A helper function for derived classes, for assignment of date/time data.
138 * It invalidates the DOM, frees the old object, and returns the new.
140 * @param oldValue - the current value
141 * @param newValue - the epoch to assign as the new value
143 * @return the value that should be assigned
145 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);
148 * A helper function for derived classes, for assignment of date/time data.
150 * It invalidates the DOM, frees the old object, and returns the new.
152 * @param oldValue - the current value
153 * @param newValue - the new value in string form
155 * @return the value that should be assigned
157 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);
160 * A helper function for derived classes, for assignment of QName data.
162 * It invalidates the DOM, frees the old object, and returns the new.
164 * @param oldValue - the current value
165 * @param newValue - the new value
167 * @return the value that should be assigned
169 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
172 * A helper function for derived classes, for assignment of (singleton) XML objects.
174 * It is indifferent to whether either the old or the new version of the value is null.
175 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
176 * Note that since the new value (even if NULL) is always returned, it may be more efficient
177 * to discard the return value and just assign independently if a dynamic cast would be involved.
179 * @param oldValue - current value
180 * @param newValue - proposed new value
181 * @return the new value
183 * @throws XMLObjectException if the new child already has a parent.
185 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
188 * Set of namespaces associated with the object.
190 mutable std::set<Namespace> m_namespaces;
198 * Stores off xsi:schemaLocation attribute.
200 XMLCh* m_schemaLocation;
204 QName m_elementQname;
210 #if defined (_MSC_VER)
211 #pragma warning( pop )
214 #endif /* __xmltooling_abstractxmlobj_h__ */