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 <algorithm>
\r
27 #include <xmltooling/XMLObject.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
39 class XMLTOOL_API AbstractXMLObject : public virtual XMLObject
\r
42 virtual ~AbstractXMLObject() {
\r
44 std::for_each(m_children.begin(), m_children.end(), cleanup<XMLObject>());
\r
48 * @see XMLObject::getElementQName()
\r
50 const QName& getElementQName() const {
\r
51 return m_elementQname;
\r
55 * @see XMLObject::setElementNamespacePrefix()
\r
57 void setElementNamespacePrefix(const XMLCh* prefix) {
\r
58 m_elementQname.setPrefix(prefix);
\r
62 * @see XMLObject::getNamespaces()
\r
64 const std::set<Namespace>& getNamespaces() const {
\r
65 return m_namespaces;
\r
69 * @see XMLObject::addNamespace()
\r
71 void addNamespace(const Namespace& ns) {
\r
72 if (ns.alwaysDeclare() || m_namespaces.find(ns)==m_namespaces.end()) {
\r
73 m_namespaces.insert(ns);
\r
78 * @see XMLObject::removeNamespace()
\r
80 void removeNamespace(const Namespace& ns) {
\r
81 m_namespaces.erase(ns);
\r
85 * @see XMLObject::getSchemaType()
\r
87 const QName* getSchemaType() const {
\r
92 * @see XMLObject::setSchemaType()
\r
94 void setSchemaType(const QName* type) {
\r
98 m_typeQname = new QName(*type);
\r
99 addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix()));
\r
104 * @see XMLObject::hasParent()
\r
106 bool hasParent() const {
\r
107 return m_parent != NULL;
\r
111 * @see XMLObject::getParent()
\r
113 XMLObject* getParent() const {
\r
118 * @see XMLObject::setParent()
\r
120 void setParent(XMLObject* parent) {
\r
125 * @see XMLObject::hasChildren()
\r
127 bool hasChildren() const {
\r
128 return !m_children.empty();
\r
132 * @see XMLObject::getOrderedChildren()
\r
134 const std::list<XMLObject*>& getOrderedChildren() const {
\r
142 * @param namespaceURI the namespace the element is in
\r
143 * @param elementLocalName the local name of the XML element this Object represents
\r
144 * @param namespacePrefix the namespace prefix to use
\r
146 AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)
\r
147 : m_elementQname(namespaceURI,elementLocalName, namespacePrefix), m_typeQname(NULL), m_parent(NULL) {
\r
148 addNamespace(Namespace(namespaceURI, namespacePrefix));
\r
152 * Underlying list of child objects.
\r
153 * Manages the lifetime of the children.
\r
155 std::list<XMLObject*> m_children;
\r
158 XMLObject* m_parent;
\r
159 QName m_elementQname;
\r
160 QName* m_typeQname;
\r
161 std::set<Namespace> m_namespaces;
\r
166 #if defined (_MSC_VER)
\r
167 #pragma warning( pop )
\r
170 #endif /* __xmltooling_abstractxmlobj_h__ */
\r