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() {
49 xercesc::XMLString::release(&m_schemaLocation);
50 xercesc::XMLString::release(&m_noNamespaceSchemaLocation);
55 const QName& getElementQName() const {
56 return m_elementQname;
59 const std::set<Namespace>& getNamespaces() const {
63 void addNamespace(const Namespace& ns) const {
64 std::set<Namespace>::iterator i = m_namespaces.find(ns);
65 if (i == m_namespaces.end())
66 m_namespaces.insert(ns);
67 else if (ns.alwaysDeclare())
68 const_cast<Namespace&>(*i).setAlwaysDeclare(true);
71 void removeNamespace(const Namespace& ns) {
72 m_namespaces.erase(ns);
75 const QName* getSchemaType() const {
79 const XMLCh* getXMLID() const {
83 bool hasParent() const {
84 return m_parent != NULL;
87 XMLObject* getParent() const {
91 void setParent(XMLObject* parent) {
99 * @param nsURI the namespace of the element
100 * @param localName the local name of the XML element this Object represents
101 * @param prefix the namespace prefix to use
102 * @param schemaType the xsi:type to use
105 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
108 /** Copy constructor. */
109 AbstractXMLObject(const AbstractXMLObject& src);
112 * A helper function for derived classes, for assignment of strings.
114 * This 'normalizes' newString, and then if it is different from oldString,
115 * it invalidates the DOM, frees the old string, and returns the new.
116 * If not different, it frees the new string and just returns the old value.
118 * @param oldValue - the current value
119 * @param newValue - the new value
121 * @return the value that should be assigned
123 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
126 * A helper function for derived classes, for assignment of date/time data.
128 * It invalidates the DOM, frees the old object, and returns the new.
130 * @param oldValue - the current value
131 * @param newValue - the new value
133 * @return the value that should be assigned
135 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
138 * A helper function for derived classes, for assignment of date/time data.
140 * It invalidates the DOM, frees the old object, and returns the new.
142 * @param oldValue - the current value
143 * @param newValue - the epoch to assign as the new value
145 * @return the value that should be assigned
147 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);
150 * A helper function for derived classes, for assignment of date/time data.
152 * It invalidates the DOM, frees the old object, and returns the new.
154 * @param oldValue - the current value
155 * @param newValue - the new value in string form
157 * @return the value that should be assigned
159 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);
162 * A helper function for derived classes, for assignment of QName data.
164 * It invalidates the DOM, frees the old object, and returns the new.
166 * @param oldValue - the current value
167 * @param newValue - the new value
169 * @return the value that should be assigned
171 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
174 * A helper function for derived classes, for assignment of (singleton) XML objects.
176 * It is indifferent to whether either the old or the new version of the value is null.
177 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
178 * Note that since the new value (even if NULL) is always returned, it may be more efficient
179 * to discard the return value and just assign independently if a dynamic cast would be involved.
181 * @param oldValue - current value
182 * @param newValue - proposed new value
183 * @return the new value
185 * @throws XMLObjectException if the new child already has a parent.
187 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
190 * Set of namespaces associated with the object.
192 mutable std::set<Namespace> m_namespaces;
197 logging::Category& m_log;
200 * Stores off xsi:schemaLocation attribute.
202 XMLCh* m_schemaLocation;
205 * Stores off xsi:noNamespaceSchemaLocation attribute.
207 XMLCh* m_noNamespaceSchemaLocation;
211 QName m_elementQname;
217 #if defined (_MSC_VER)
218 #pragma warning( pop )
221 #endif /* __xmltooling_abstractxmlobj_h__ */