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 AbstractXMLObject.h
20 * An abstract implementation of XMLObject.
23 #ifndef __xmltooling_abstractxmlobj_h__
24 #define __xmltooling_abstractxmlobj_h__
26 #include <xmltooling/XMLObject.h>
27 #include <xmltooling/util/DateTime.h>
29 #include <log4cpp/Category.hh>
31 #if defined (_MSC_VER)
32 #pragma warning( push )
33 #pragma warning( disable : 4250 4251 )
36 namespace xmltooling {
39 * An abstract implementation of XMLObject.
40 * This is the primary concrete base class, and supplies basic namespace,
41 * type, and parent handling. Most implementation classes should not
42 * directly inherit from this class, but rather from the various mixins
43 * that supply the rest of the XMLObject interface, as required.
45 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
48 virtual ~AbstractXMLObject() {
50 XMLString::release(&m_schemaLocation);
51 XMLString::release(&m_noNamespaceSchemaLocation);
56 const QName& getElementQName() const {
57 return m_elementQname;
60 const std::set<Namespace>& getNamespaces() const {
64 void addNamespace(const Namespace& ns) const {
65 std::set<Namespace>::iterator i = m_namespaces.find(ns);
66 if (i == m_namespaces.end())
67 m_namespaces.insert(ns);
68 else if (ns.alwaysDeclare())
69 const_cast<Namespace&>(*i).setAlwaysDeclare(true);
72 void removeNamespace(const Namespace& ns) {
73 m_namespaces.erase(ns);
76 const QName* getSchemaType() const {
80 const XMLCh* getXMLID() const {
84 bool hasParent() const {
85 return m_parent != NULL;
88 XMLObject* getParent() const {
92 void setParent(XMLObject* parent) {
100 * @param nsURI the namespace of the element
101 * @param localName the local name of the XML element this Object represents
102 * @param prefix the namespace prefix to use
103 * @param schemaType the xsi:type to use
106 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
109 /** Copy constructor. */
110 AbstractXMLObject(const AbstractXMLObject& src);
113 * A helper function for derived classes, for assignment of strings.
115 * This 'normalizes' newString, and then if it is different from oldString,
116 * it invalidates the DOM, frees the old string, and returns the new.
117 * If not different, it frees the new string and just returns the old value.
119 * @param oldValue - the current value
120 * @param newValue - the new value
122 * @return the value that should be assigned
124 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
127 * A helper function for derived classes, for assignment of date/time data.
129 * It invalidates the DOM, frees the old object, and returns the new.
131 * @param oldValue - the current value
132 * @param newValue - the new value
134 * @return the value that should be assigned
136 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
139 * A helper function for derived classes, for assignment of date/time data.
141 * It invalidates the DOM, frees the old object, and returns the new.
143 * @param oldValue - the current value
144 * @param newValue - the epoch to assign as the new value
146 * @return the value that should be assigned
148 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);
151 * A helper function for derived classes, for assignment of date/time data.
153 * It invalidates the DOM, frees the old object, and returns the new.
155 * @param oldValue - the current value
156 * @param newValue - the new value in string form
158 * @return the value that should be assigned
160 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);
163 * A helper function for derived classes, for assignment of QName data.
165 * It invalidates the DOM, frees the old object, and returns the new.
167 * @param oldValue - the current value
168 * @param newValue - the new value
170 * @return the value that should be assigned
172 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
175 * A helper function for derived classes, for assignment of (singleton) XML objects.
177 * It is indifferent to whether either the old or the new version of the value is null.
178 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
179 * Note that since the new value (even if NULL) is always returned, it may be more efficient
180 * to discard the return value and just assign independently if a dynamic cast would be involved.
182 * @param oldValue - current value
183 * @param newValue - proposed new value
184 * @return the new value
186 * @throws XMLObjectException if the new child already has a parent.
188 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
191 * Set of namespaces associated with the object.
193 mutable std::set<Namespace> m_namespaces;
198 log4cpp::Category& m_log;
201 * Stores off xsi:schemaLocation attribute.
203 XMLCh* m_schemaLocation;
206 * Stores off xsi:noNamespaceSchemaLocation attribute.
208 XMLCh* m_noNamespaceSchemaLocation;
212 QName m_elementQname;
218 #if defined (_MSC_VER)
219 #pragma warning( pop )
222 #endif /* __xmltooling_abstractxmlobj_h__ */