Handle variant element names, merge in wildcard class, add test cases.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.h
1 /*\r
2 *  Copyright 2001-2006 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 /**\r
18  * @file AbstractXMLObject.h\r
19  * \r
20  * An abstract implementation of XMLObject.\r
21  */\r
22 \r
23 #if !defined(__xmltooling_abstractxmlobj_h__)\r
24 #define __xmltooling_abstractxmlobj_h__\r
25 \r
26 #include <xmltooling/XMLObject.h>\r
27 \r
28 #if defined (_MSC_VER)\r
29     #pragma warning( push )\r
30     #pragma warning( disable : 4250 4251 )\r
31 #endif\r
32 \r
33 namespace xmltooling {\r
34 \r
35     /**\r
36      * An abstract implementation of XMLObject.\r
37      */\r
38     class XMLTOOL_API AbstractXMLObject : public virtual XMLObject\r
39     {\r
40     public:\r
41         virtual ~AbstractXMLObject();\r
42 \r
43         /**\r
44          * @see XMLObject::getElementQName()\r
45          */\r
46         const QName& getElementQName() const {\r
47             return m_elementQname;\r
48         }\r
49 \r
50         /**\r
51          * @see XMLObject::setElementNamespacePrefix()\r
52          */\r
53         void setElementNamespacePrefix(const XMLCh* prefix) {\r
54             m_elementQname.setPrefix(prefix);\r
55             addNamespace(Namespace(m_elementQname.getNamespaceURI(),prefix));\r
56         }\r
57 \r
58         /**\r
59          * @see XMLObject::getNamespaces()\r
60          */\r
61         const std::set<Namespace>& getNamespaces() const {\r
62             return m_namespaces;\r
63         }\r
64     \r
65         /**\r
66          * @see XMLObject::addNamespace()\r
67          */\r
68         void addNamespace(const Namespace& ns) const {\r
69             if (ns.alwaysDeclare() || m_namespaces.find(ns)==m_namespaces.end()) {\r
70                 m_namespaces.insert(ns);\r
71             }\r
72         }\r
73     \r
74         /**\r
75          * @see XMLObject::removeNamespace()\r
76          */\r
77         void removeNamespace(const Namespace& ns) {\r
78             m_namespaces.erase(ns);\r
79         }\r
80         \r
81         /**\r
82          * @see XMLObject::getSchemaType()\r
83          */\r
84         const QName* getSchemaType() const {\r
85             return m_typeQname;\r
86         }\r
87     \r
88         /**\r
89          * @see XMLObject::setSchemaType()\r
90          */\r
91         void setSchemaType(const QName* type) {\r
92             delete m_typeQname;\r
93             m_typeQname = NULL;\r
94             if (type) {\r
95                 m_typeQname = new QName(*type);\r
96                 addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix()));\r
97             }\r
98         }\r
99     \r
100         /**\r
101          * @see XMLObject::hasParent()\r
102          */\r
103         bool hasParent() const {\r
104             return m_parent != NULL;\r
105         }\r
106      \r
107         /**\r
108          * @see XMLObject::getParent()\r
109          */\r
110         XMLObject* getParent() const {\r
111             return m_parent;\r
112         }\r
113     \r
114         /**\r
115          * @see XMLObject::setParent()\r
116          */\r
117         void setParent(XMLObject* parent) {\r
118             m_parent = parent;\r
119         }\r
120 \r
121         /**\r
122          * @see XMLObject::hasChildren()\r
123          */\r
124         bool hasChildren() const {\r
125             return !m_children.empty();\r
126         }\r
127 \r
128         /**\r
129          * @see XMLObject::getOrderedChildren()\r
130          */\r
131         const std::list<XMLObject*>& getOrderedChildren() const {\r
132             return m_children;\r
133         }\r
134 \r
135      protected:\r
136         /**\r
137          * Constructor\r
138          * \r
139          * @param namespaceURI the namespace the element is in\r
140          * @param elementLocalName the local name of the XML element this Object represents\r
141          * @param namespacePrefix the namespace prefix to use\r
142          */\r
143         AbstractXMLObject(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL);\r
144 \r
145         /**\r
146          * Underlying list of child objects.\r
147          * Manages the lifetime of the children.\r
148          */\r
149         std::list<XMLObject*> m_children;\r
150 \r
151         /**\r
152          * Set of namespaces associated with the object.\r
153          */\r
154         mutable std::set<Namespace> m_namespaces;\r
155 \r
156         /**\r
157          * Logging object.\r
158          */\r
159         void* m_log;\r
160 \r
161     private:\r
162         XMLObject* m_parent;\r
163         QName m_elementQname;\r
164         QName* m_typeQname;\r
165     };\r
166 \r
167 };\r
168 \r
169 #if defined (_MSC_VER)\r
170     #pragma warning( pop )\r
171 #endif\r
172 \r
173 #endif /* __xmltooling_abstractxmlobj_h__ */\r