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
27 #include <xmltooling/util/DateTime.h>
\r
29 #if defined (_MSC_VER)
\r
30 #pragma warning( push )
\r
31 #pragma warning( disable : 4250 4251 )
\r
34 namespace xmltooling {
\r
37 * An abstract implementation of XMLObject.
\r
38 * This is the primary concrete base class, and supplies basic namespace,
\r
39 * type, and parent handling. Most implementation classes should not
\r
40 * directly inherit from this class, but rather from the various mixins
\r
41 * that supply the rest of the XMLObject interface, as required.
\r
43 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
\r
46 virtual ~AbstractXMLObject() {
\r
48 XMLString::release(&m_schemaLocation);
\r
53 const QName& getElementQName() const {
\r
54 return m_elementQname;
\r
57 const std::set<Namespace>& getNamespaces() const {
\r
58 return m_namespaces;
\r
61 void addNamespace(const Namespace& ns) const {
\r
62 std::set<Namespace>::iterator i = m_namespaces.find(ns);
\r
63 if (i == m_namespaces.end())
\r
64 m_namespaces.insert(ns);
\r
65 else if (ns.alwaysDeclare())
\r
66 i->setAlwaysDeclare(true);
\r
69 void removeNamespace(const Namespace& ns) {
\r
70 m_namespaces.erase(ns);
\r
73 const QName* getSchemaType() const {
\r
77 const XMLCh* getXMLID() const {
\r
81 bool hasParent() const {
\r
82 return m_parent != NULL;
\r
85 XMLObject* getParent() const {
\r
89 void setParent(XMLObject* parent) {
\r
97 * @param nsURI the namespace of the element
\r
98 * @param localName the local name of the XML element this Object represents
\r
99 * @param prefix the namespace prefix to use
\r
100 * @param schemaType the xsi:type to use
\r
103 const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
\r
106 /** Copy constructor. */
\r
107 AbstractXMLObject(const AbstractXMLObject& src);
\r
110 * A helper function for derived classes, for assignment of strings.
\r
112 * This 'normalizes' newString, and then if it is different from oldString,
\r
113 * it invalidates the DOM, frees the old string, and returns the new.
\r
114 * If not different, it frees the new string and just returns the old value.
\r
116 * @param oldValue - the current value
\r
117 * @param newValue - the new value
\r
119 * @return the value that should be assigned
\r
121 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
\r
124 * A helper function for derived classes, for assignment of date/time data.
\r
126 * It invalidates the DOM, frees the old object, and returns the new.
\r
128 * @param oldValue - the current value
\r
129 * @param newValue - the new value
\r
131 * @return the value that should be assigned
\r
133 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
\r
136 * A helper function for derived classes, for assignment of date/time data.
\r
138 * It invalidates the DOM, frees the old object, and returns the new.
\r
140 * @param oldValue - the current value
\r
141 * @param newValue - the epoch to assign as the new value
\r
143 * @return the value that should be assigned
\r
145 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);
\r
148 * A helper function for derived classes, for assignment of date/time data.
\r
150 * It invalidates the DOM, frees the old object, and returns the new.
\r
152 * @param oldValue - the current value
\r
153 * @param newValue - the new value in string form
\r
155 * @return the value that should be assigned
\r
157 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);
\r
160 * A helper function for derived classes, for assignment of QName data.
\r
162 * It invalidates the DOM, frees the old object, and returns the new.
\r
164 * @param oldValue - the current value
\r
165 * @param newValue - the new value
\r
167 * @return the value that should be assigned
\r
169 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
\r
172 * A helper function for derived classes, for assignment of (singleton) XML objects.
\r
174 * It is indifferent to whether either the old or the new version of the value is null.
\r
175 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
\r
176 * Note that since the new value (even if NULL) is always returned, it may be more efficient
\r
177 * to discard the return value and just assign independently if a dynamic cast would be involved.
\r
179 * @param oldValue - current value
\r
180 * @param newValue - proposed new value
\r
181 * @return the new value
\r
183 * @throws XMLObjectException if the new child already has a parent.
\r
185 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
\r
188 * Set of namespaces associated with the object.
\r
190 mutable std::set<Namespace> m_namespaces;
\r
198 * Stores off xsi:schemaLocation attribute.
\r
200 XMLCh* m_schemaLocation;
\r
203 XMLObject* m_parent;
\r
204 QName m_elementQname;
\r
205 QName* m_typeQname;
\r
210 #if defined (_MSC_VER)
\r
211 #pragma warning( pop )
\r
214 #endif /* __xmltooling_abstractxmlobj_h__ */
\r