Initial DOM handling interfaces.
[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 #pragma warning( push )\r
29 #pragma warning( disable : 4250 4251 )\r
30 \r
31 namespace xmltooling {\r
32 \r
33     /**\r
34      * An abstract implementation of XMLObject.\r
35      */\r
36     class XMLTOOL_API AbstractXMLObject : public virtual XMLObject\r
37     {\r
38     public:\r
39         virtual ~AbstractXMLObject() {\r
40             delete m_typeQname;\r
41         }\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         }\r
56 \r
57         /**\r
58          * @see XMLObject::getNamespaces()\r
59          */\r
60         const std::set<Namespace>& getNamespaces() const {\r
61             return m_namespaces;\r
62         }\r
63     \r
64         /**\r
65          * @see XMLObject::addNamespace()\r
66          */\r
67         void addNamespace(const Namespace& ns) {\r
68             m_namespaces.insert(ns);\r
69         }\r
70     \r
71         /**\r
72          * @see XMLObject::removeNamespace()\r
73          */\r
74         void removeNamespace(const Namespace& ns) {\r
75             m_namespaces.erase(ns);\r
76         }\r
77         \r
78         /**\r
79          * @see XMLObject::getSchemaType()\r
80          */\r
81         const QName* getSchemaType() const {\r
82             return m_typeQname;\r
83         }\r
84     \r
85         /**\r
86          * @see XMLObject::setSchemaType()\r
87          */\r
88         void setSchemaType(const QName* type) {\r
89             delete m_typeQname;\r
90             m_typeQname = NULL;\r
91             if (type) {\r
92                 m_typeQname = new QName(*type);\r
93                 addNamespace(Namespace(type->getNamespaceURI(), type->getPrefix()));\r
94             }\r
95         }\r
96     \r
97         /**\r
98          * @see XMLObject::hasParent()\r
99          */\r
100         bool hasParent() const {\r
101             return m_parent != NULL;\r
102         }\r
103      \r
104         /**\r
105          * @see XMLObject::getParent()\r
106          */\r
107         XMLObject* getParent() const {\r
108             return m_parent;\r
109         }\r
110     \r
111         /**\r
112          * @see XMLObject::setParent()\r
113          */\r
114         void setParent(XMLObject* parent) {\r
115             m_parent = parent;\r
116         }\r
117     \r
118      protected:\r
119         /**\r
120          * Constructor\r
121          * \r
122          * @param namespaceURI the namespace the element is in\r
123          * @param elementLocalName the local name of the XML element this Object represents\r
124          */\r
125         explicit AbstractXMLObject(const XMLCh* namespaceURI, const XMLCh* elementLocalName)\r
126             : m_elementQname(namespaceURI,elementLocalName), m_typeQname(NULL), m_parent(NULL) {}\r
127         \r
128     private:\r
129         XMLObject* m_parent;\r
130         QName m_elementQname;\r
131         QName* m_typeQname;\r
132         std::set<Namespace> m_namespaces;\r
133     };\r
134 \r
135 };\r
136 \r
137 #pragma warning( pop )\r
138 \r
139 #endif /* __xmltooling_abstractxmlobj_h__ */\r