2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/AbstractXMLObject.h
24 * An abstract implementation of XMLObject.
27 #ifndef __xmltooling_abstractxmlobj_h__
28 #define __xmltooling_abstractxmlobj_h__
30 #include <xmltooling/logging.h>
31 #include <xmltooling/QName.h>
32 #include <xmltooling/XMLObject.h>
34 #if defined (_MSC_VER)
35 #pragma warning( push )
36 #pragma warning( disable : 4250 4251 )
39 namespace xmltooling {
41 class XMLTOOL_API DateTime;
44 * An abstract implementation of XMLObject.
45 * This is the primary concrete base class, and supplies basic namespace,
46 * type, and parent handling. Most implementation classes should not
47 * directly inherit from this class, but rather from the various mixins
48 * that supply the rest of the XMLObject interface, as required.
50 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
53 virtual ~AbstractXMLObject();
55 // Virtual function overrides.
57 const QName& getElementQName() const;
58 const std::set<Namespace>& getNamespaces() const;
59 void addNamespace(const Namespace& ns) const;
60 void removeNamespace(const Namespace& ns);
61 const QName* getSchemaType() const;
62 const XMLCh* getXMLID() const;
63 xmlconstants::xmltooling_bool_t getNil() const;
64 void nil(xmlconstants::xmltooling_bool_t value);
65 bool hasParent() const;
66 XMLObject* getParent() const;
67 void setParent(XMLObject* parent);
73 * @param nsURI the namespace of the element
74 * @param localName the local name of the XML element this Object represents
75 * @param prefix the namespace prefix to use
76 * @param schemaType the xsi:type to use
79 const XMLCh* nsURI=nullptr, const XMLCh* localName=nullptr, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
82 /** Copy constructor. */
83 AbstractXMLObject(const AbstractXMLObject& src);
86 * A helper function for derived classes, for assignment of strings.
88 * This 'normalizes' newString, and then if it is different from oldString,
89 * it invalidates the DOM, frees the old string, and returns the new.
90 * If not different, it frees the new string and just returns the old value.
92 * @param oldValue the current value
93 * @param newValue the new value
95 * @return the value that should be assigned
97 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
100 * A helper function for derived classes, for assignment of date/time data.
102 * It invalidates the DOM, frees the old object, and returns the new.
104 * @param oldValue the current value
105 * @param newValue the new value
107 * @return the value that should be assigned
109 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
112 * A helper function for derived classes, for assignment of date/time data.
114 * It invalidates the DOM, frees the old object, and returns the new.
116 * @param oldValue the current value
117 * @param newValue the epoch to assign as the new value
118 * @param duration true iff the value is a duration rather than an absolute timestamp
120 * @return the value that should be assigned
122 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration=false);
125 * A helper function for derived classes, for assignment of date/time data.
127 * It invalidates the DOM, frees the old object, and returns the new.
129 * @param oldValue the current value
130 * @param newValue the new value in string form
131 * @param duration true iff the value is a duration rather than an absolute timestamp
133 * @return the value that should be assigned
135 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue, bool duration=false);
138 * A helper function for derived classes, for assignment of QName data.
140 * It invalidates the DOM, frees the old object, and returns the new.
142 * @param oldValue the current value
143 * @param newValue the new value
145 * @return the value that should be assigned
147 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
150 * A helper function for derived classes, for assignment of (singleton) XML objects.
152 * It is indifferent to whether either the old or the new version of the value is null.
153 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
154 * Note that since the new value (even if nullptr) is always returned, it may be more efficient
155 * to discard the return value and just assign independently if a dynamic cast would be involved.
157 * @param oldValue current value
158 * @param newValue proposed new value
159 * @return the new value
161 * @throws XMLObjectException if the new child already has a parent.
163 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
166 * Set of namespaces associated with the object.
168 mutable std::set<Namespace> m_namespaces;
173 logging::Category& m_log;
176 * Stores off xsi:schemaLocation attribute.
178 XMLCh* m_schemaLocation;
181 * Stores off xsi:noNamespaceSchemaLocation attribute.
183 XMLCh* m_noNamespaceSchemaLocation;
186 * Stores off xsi:nil attribute.
188 xmlconstants::xmltooling_bool_t m_nil;
192 QName m_elementQname;
198 #if defined (_MSC_VER)
199 #pragma warning( pop )
202 #endif /* __xmltooling_abstractxmlobj_h__ */