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>
36 #if defined (_MSC_VER)
37 #pragma warning( push )
38 #pragma warning( disable : 4250 4251 )
41 namespace xmltooling {
43 class XMLTOOL_API DateTime;
46 * An abstract implementation of XMLObject.
47 * This is the primary concrete base class, and supplies basic namespace,
48 * type, and parent handling. Most implementation classes should not
49 * directly inherit from this class, but rather from the various mixins
50 * that supply the rest of the XMLObject interface, as required.
52 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
55 virtual ~AbstractXMLObject();
57 // Virtual function overrides.
59 const QName& getElementQName() const;
60 const std::set<Namespace>& getNamespaces() const;
61 void addNamespace(const Namespace& ns) const;
62 void removeNamespace(const Namespace& ns);
63 const QName* getSchemaType() const;
64 const XMLCh* getXMLID() const;
65 xmlconstants::xmltooling_bool_t getNil() const;
66 void nil(xmlconstants::xmltooling_bool_t value);
67 bool hasParent() const;
68 XMLObject* getParent() const;
69 void setParent(XMLObject* parent);
75 * @param nsURI the namespace of the element
76 * @param localName the local name of the XML element this Object represents
77 * @param prefix the namespace prefix to use
78 * @param schemaType the xsi:type to use
81 const XMLCh* nsURI=nullptr, const XMLCh* localName=nullptr, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
84 /** Copy constructor. */
85 AbstractXMLObject(const AbstractXMLObject& src);
88 * A helper function for derived classes, for assignment of strings.
90 * This 'normalizes' newString, and then if it is different from oldString,
91 * it invalidates the DOM, frees the old string, and returns the new.
92 * If not different, it frees the new string and just returns the old value.
94 * @param oldValue the current value
95 * @param newValue the new value
97 * @return the value that should be assigned
99 XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);
102 * A helper function for derived classes, for assignment of date/time data.
104 * It invalidates the DOM, frees the old object, and returns the new.
106 * @param oldValue the current value
107 * @param newValue the new value
109 * @return the value that should be assigned
111 DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);
114 * A helper function for derived classes, for assignment of date/time data.
116 * It invalidates the DOM, frees the old object, and returns the new.
118 * @param oldValue the current value
119 * @param newValue the epoch to assign as the new value
120 * @param duration true iff the value is a duration rather than an absolute timestamp
122 * @return the value that should be assigned
124 DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue, bool duration=false);
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 in string form
133 * @param duration true iff the value is a duration rather than an absolute timestamp
135 * @return the value that should be assigned
137 DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue, bool duration=false);
140 * A helper function for derived classes, for assignment of QName data.
142 * It invalidates the DOM, frees the old object, and returns the new.
144 * @param oldValue the current value
145 * @param newValue the new value
147 * @return the value that should be assigned
149 QName* prepareForAssignment(QName* oldValue, const QName* newValue);
152 * A helper function for derived classes, for assignment of (singleton) XML objects.
154 * It is indifferent to whether either the old or the new version of the value is null.
155 * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.
156 * Note that since the new value (even if nullptr) is always returned, it may be more efficient
157 * to discard the return value and just assign independently if a dynamic cast would be involved.
159 * @param oldValue current value
160 * @param newValue proposed new value
161 * @return the new value
163 * @throws XMLObjectException if the new child already has a parent.
165 XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);
168 * Set of namespaces associated with the object.
170 mutable std::set<Namespace> m_namespaces;
175 logging::Category& m_log;
178 * Stores off xsi:schemaLocation attribute.
180 XMLCh* m_schemaLocation;
183 * Stores off xsi:noNamespaceSchemaLocation attribute.
185 XMLCh* m_noNamespaceSchemaLocation;
188 * Stores off xsi:nil attribute.
190 xmlconstants::xmltooling_bool_t m_nil;
194 QName m_elementQname;
195 std::auto_ptr<QName> m_typeQname;
200 #if defined (_MSC_VER)
201 #pragma warning( pop )
204 #endif /* __xmltooling_abstractxmlobj_h__ */