2 * Copyright 2001-2010 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/QName.h>
28 #include <xmltooling/XMLObject.h>
30 #if defined (_MSC_VER)
31 #pragma warning( push )
32 #pragma warning( disable : 4250 4251 )
35 namespace xmltooling {
37 class XMLTOOL_API DateTime;
40 * An abstract implementation of XMLObject.
41 * This is the primary concrete base class, and supplies basic namespace,
42 * type, and parent handling. Most implementation classes should not
43 * directly inherit from this class, but rather from the various mixins
44 * that supply the rest of the XMLObject interface, as required.
46 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
49 virtual ~AbstractXMLObject();
51 // Virtual function overrides.
53 const QName& getElementQName() const;
54 const std::set<Namespace>& getNamespaces() const;
55 void addNamespace(const Namespace& ns) const;
56 void removeNamespace(const Namespace& ns);
57 const QName* getSchemaType() const;
58 const XMLCh* getXMLID() const;
59 xmlconstants::xmltooling_bool_t getNil() const;
60 void nil(xmlconstants::xmltooling_bool_t value);
61 bool hasParent() const;
62 XMLObject* getParent() const;
63 void setParent(XMLObject* parent);
69 * @param nsURI the namespace of the element
70 * @param localName the local name of the XML element this Object represents
71 * @param prefix the namespace prefix to use
72 * @param schemaType the xsi:type to use
75 const XMLCh* nsURI=nullptr, const XMLCh* localName=nullptr, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
78 /** Copy constructor. */
79 AbstractXMLObject(const AbstractXMLObject& src);
82 * A helper function for derived classes, for assignment of strings.
84 * This 'normalizes' newString, and then if it is different from oldString,
85 * it invalidates the DOM, frees the old string, and returns the new.
86 * If not different, it frees the new string and just returns the old value.
88 * @param oldValue the current value
89 * @param newValue the new value
91 * @return the value that should be assigned
93 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
96 * A helper function for derived classes, for assignment of date/time data.
98 * It invalidates the DOM, frees the old object, and returns the new.
100 * @param oldValue the current value
101 * @param newValue the new value
103 * @return the value that should be assigned
105 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
108 * A helper function for derived classes, for assignment of date/time data.
110 * It invalidates the DOM, frees the old object, and returns the new.
112 * @param oldValue the current value
113 * @param newValue the epoch to assign as the new value
114 * @param duration true iff the value is a duration rather than an absolute timestamp
116 * @return the value that should be assigned
118 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration=false);
121 * A helper function for derived classes, for assignment of date/time data.
123 * It invalidates the DOM, frees the old object, and returns the new.
125 * @param oldValue the current value
126 * @param newValue the new value in string form
127 * @param duration true iff the value is a duration rather than an absolute timestamp
129 * @return the value that should be assigned
131 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue, bool duration=false);
134 * A helper function for derived classes, for assignment of QName data.
136 * It invalidates the DOM, frees the old object, and returns the new.
138 * @param oldValue the current value
139 * @param newValue the new value
141 * @return the value that should be assigned
143 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
146 * A helper function for derived classes, for assignment of (singleton) XML objects.
148 * It is indifferent to whether either the old or the new version of the value is null.
149 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
150 * Note that since the new value (even if nullptr) is always returned, it may be more efficient
151 * to discard the return value and just assign independently if a dynamic cast would be involved.
153 * @param oldValue current value
154 * @param newValue proposed new value
155 * @return the new value
157 * @throws XMLObjectException if the new child already has a parent.
159 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
162 * Set of namespaces associated with the object.
164 mutable std::set<Namespace> m_namespaces;
169 logging::Category& m_log;
172 * Stores off xsi:schemaLocation attribute.
174 XMLCh* m_schemaLocation;
177 * Stores off xsi:noNamespaceSchemaLocation attribute.
179 XMLCh* m_noNamespaceSchemaLocation;
182 * Stores off xsi:nil attribute.
184 xmlconstants::xmltooling_bool_t m_nil;
188 QName m_elementQname;
194 #if defined (_MSC_VER)
195 #pragma warning( pop )
198 #endif /* __xmltooling_abstractxmlobj_h__ */