2 * Copyright 2001-2007 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 xmltooling/AbstractXMLObject.h
20 * An abstract implementation of XMLObject.
23 #ifndef __xmltooling_abstractxmlobj_h__
24 #define __xmltooling_abstractxmlobj_h__
26 #include <xmltooling/logging.h>
27 #include <xmltooling/XMLObject.h>
28 #include <xmltooling/util/DateTime.h>
30 #if defined (_MSC_VER)
31 #pragma warning( push )
32 #pragma warning( disable : 4250 4251 )
35 namespace xmltooling {
38 * An abstract implementation of XMLObject.
39 * This is the primary concrete base class, and supplies basic namespace,
40 * type, and parent handling. Most implementation classes should not
41 * directly inherit from this class, but rather from the various mixins
42 * that supply the rest of the XMLObject interface, as required.
44 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
47 virtual ~AbstractXMLObject();
51 const QName& getElementQName() const {
52 return m_elementQname;
55 const std::set<Namespace>& getNamespaces() const {
59 void addNamespace(const Namespace& ns) const {
60 std::set<Namespace>::iterator i = m_namespaces.find(ns);
61 if (i == m_namespaces.end())
62 m_namespaces.insert(ns);
63 else if (ns.alwaysDeclare())
64 const_cast<Namespace&>(*i).setAlwaysDeclare(true);
67 void removeNamespace(const Namespace& ns) {
68 m_namespaces.erase(ns);
71 const QName* getSchemaType() const {
75 const XMLCh* getXMLID() const {
79 xmlconstants::xmltooling_bool_t getNil() const {
83 void nil(xmlconstants::xmltooling_bool_t value) {
85 releaseThisandParentDOM();
90 bool hasParent() const {
91 return m_parent != NULL;
94 XMLObject* getParent() const {
98 void setParent(XMLObject* parent) {
106 * @param nsURI the namespace of the element
107 * @param localName the local name of the XML element this Object represents
108 * @param prefix the namespace prefix to use
109 * @param schemaType the xsi:type to use
112 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
115 /** Copy constructor. */
116 AbstractXMLObject(const AbstractXMLObject& src);
119 * A helper function for derived classes, for assignment of strings.
121 * This 'normalizes' newString, and then if it is different from oldString,
122 * it invalidates the DOM, frees the old string, and returns the new.
123 * If not different, it frees the new string and just returns the old value.
125 * @param oldValue the current value
126 * @param newValue the new value
128 * @return the value that should be assigned
130 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
133 * A helper function for derived classes, for assignment of date/time data.
135 * It invalidates the DOM, frees the old object, and returns the new.
137 * @param oldValue the current value
138 * @param newValue the new value
140 * @return the value that should be assigned
142 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
145 * A helper function for derived classes, for assignment of date/time data.
147 * It invalidates the DOM, frees the old object, and returns the new.
149 * @param oldValue the current value
150 * @param newValue the epoch to assign as the new value
151 * @param duration true iff the value is a duration rather than an absolute timestamp
153 * @return the value that should be assigned
155 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration=false);
158 * A helper function for derived classes, for assignment of date/time data.
160 * It invalidates the DOM, frees the old object, and returns the new.
162 * @param oldValue the current value
163 * @param newValue the new value in string form
164 * @param duration true iff the value is a duration rather than an absolute timestamp
166 * @return the value that should be assigned
168 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue, bool duration=false);
171 * A helper function for derived classes, for assignment of QName data.
173 * It invalidates the DOM, frees the old object, and returns the new.
175 * @param oldValue the current value
176 * @param newValue the new value
178 * @return the value that should be assigned
180 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
183 * A helper function for derived classes, for assignment of (singleton) XML objects.
185 * It is indifferent to whether either the old or the new version of the value is null.
186 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
187 * Note that since the new value (even if NULL) is always returned, it may be more efficient
188 * to discard the return value and just assign independently if a dynamic cast would be involved.
190 * @param oldValue current value
191 * @param newValue proposed new value
192 * @return the new value
194 * @throws XMLObjectException if the new child already has a parent.
196 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
199 * Set of namespaces associated with the object.
201 mutable std::set<Namespace> m_namespaces;
206 logging::Category& m_log;
209 * Stores off xsi:schemaLocation attribute.
211 XMLCh* m_schemaLocation;
214 * Stores off xsi:noNamespaceSchemaLocation attribute.
216 XMLCh* m_noNamespaceSchemaLocation;
219 * Stores off xsi:nil attribute.
221 xmlconstants::xmltooling_bool_t m_nil;
225 QName m_elementQname;
231 #if defined (_MSC_VER)
232 #pragma warning( pop )
235 #endif /* __xmltooling_abstractxmlobj_h__ */