Wrapped encryption schema, also block unknown attributes and handle schemaLocation.
[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 #include <xmltooling/util/DateTime.h>\r
28 \r
29 #if defined (_MSC_VER)\r
30     #pragma warning( push )\r
31     #pragma warning( disable : 4250 4251 )\r
32 #endif\r
33 \r
34 namespace xmltooling {\r
35 \r
36     /**\r
37      * An abstract implementation of XMLObject.\r
38      * This is the primary concrete base class, and supplies basic namespace,\r
39      * type, and parent handling. Most implementation classes should not\r
40      * directly inherit from this class, but rather from the various mixins\r
41      * that supply the rest of the XMLObject interface, as required.\r
42      */\r
43     class XMLTOOL_API AbstractXMLObject : public virtual XMLObject\r
44     {\r
45     public:\r
46         virtual ~AbstractXMLObject() {\r
47             delete m_typeQname;\r
48             XMLString::release(&m_schemaLocation);\r
49         }\r
50 \r
51         const QName& getElementQName() const {\r
52             return m_elementQname;\r
53         }\r
54 \r
55         const std::set<Namespace>& getNamespaces() const {\r
56             return m_namespaces;\r
57         }\r
58     \r
59         void addNamespace(const Namespace& ns) const {\r
60             if (ns.alwaysDeclare() || m_namespaces.find(ns)==m_namespaces.end()) {\r
61                 m_namespaces.insert(ns);\r
62             }\r
63         }\r
64     \r
65         void removeNamespace(const Namespace& ns) {\r
66             m_namespaces.erase(ns);\r
67         }\r
68         \r
69         const QName* getSchemaType() const {\r
70             return m_typeQname;\r
71         }\r
72     \r
73         bool hasParent() const {\r
74             return m_parent != NULL;\r
75         }\r
76      \r
77         XMLObject* getParent() const {\r
78             return m_parent;\r
79         }\r
80     \r
81         void setParent(XMLObject* parent) {\r
82             m_parent = parent;\r
83         }\r
84 \r
85      protected:\r
86         /**\r
87          * Constructor\r
88          * \r
89          * @param nsURI         the namespace of the element\r
90          * @param localName     the local name of the XML element this Object represents\r
91          * @param prefix        the namespace prefix to use\r
92          * @param schemaType    the xsi:type to use\r
93          */\r
94         AbstractXMLObject(\r
95             const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
96             );\r
97 \r
98         /** Copy constructor. */\r
99         AbstractXMLObject(const AbstractXMLObject& src);\r
100         \r
101         /**\r
102          * A helper function for derived classes, for assignment of strings.\r
103          *\r
104          * This 'normalizes' newString, and then if it is different from oldString,\r
105          * it invalidates the DOM, frees the old string, and returns the new.\r
106          * If not different, it frees the new string and just returns the old value.\r
107          * \r
108          * @param oldValue - the current value\r
109          * @param newValue - the new value\r
110          * \r
111          * @return the value that should be assigned\r
112          */\r
113         XMLCh* prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue);\r
114 \r
115         /**\r
116          * A helper function for derived classes, for assignment of date/time data.\r
117          *\r
118          * It invalidates the DOM, frees the old object, and returns the new.\r
119          * \r
120          * @param oldValue - the current value\r
121          * @param newValue - the new value\r
122          * \r
123          * @return the value that should be assigned\r
124          */\r
125         DateTime* prepareForAssignment(DateTime* oldValue, const DateTime* newValue);\r
126 \r
127         /**\r
128          * A helper function for derived classes, for assignment of date/time data.\r
129          *\r
130          * It invalidates the DOM, frees the old object, and returns the new.\r
131          * \r
132          * @param oldValue - the current value\r
133          * @param newValue - the epoch to assign as the new value\r
134          * \r
135          * @return the value that should be assigned\r
136          */\r
137         DateTime* prepareForAssignment(DateTime* oldValue, time_t newValue);\r
138 \r
139         /**\r
140          * A helper function for derived classes, for assignment of date/time data.\r
141          *\r
142          * It invalidates the DOM, frees the old object, and returns the new.\r
143          * \r
144          * @param oldValue - the current value\r
145          * @param newValue - the new value in string form\r
146          * \r
147          * @return the value that should be assigned\r
148          */\r
149         DateTime* prepareForAssignment(DateTime* oldValue, const XMLCh* newValue);\r
150 \r
151         /**\r
152          * A helper function for derived classes, for assignment of QName data.\r
153          *\r
154          * It invalidates the DOM, frees the old object, and returns the new.\r
155          * \r
156          * @param oldValue - the current value\r
157          * @param newValue - the new value\r
158          * \r
159          * @return the value that should be assigned\r
160          */\r
161         QName* prepareForAssignment(QName* oldValue, const QName* newValue);\r
162 \r
163         /**\r
164          * A helper function for derived classes, for assignment of (singleton) XML objects.\r
165          * \r
166          * It is indifferent to whether either the old or the new version of the value is null. \r
167          * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate.\r
168          * Note that since the new value (even if NULL) is always returned, it may be more efficient\r
169          * to discard the return value and just assign independently if a dynamic cast would be involved.\r
170          * \r
171          * @param oldValue - current value\r
172          * @param newValue - proposed new value\r
173          * @return the new value \r
174          * \r
175          * @throws XMLObjectException if the new child already has a parent.\r
176          */\r
177         XMLObject* prepareForAssignment(XMLObject* oldValue, XMLObject* newValue);\r
178 \r
179         /**\r
180          * Set of namespaces associated with the object.\r
181          */\r
182         mutable std::set<Namespace> m_namespaces;\r
183 \r
184         /**\r
185          * Logging object.\r
186          */\r
187         void* m_log;\r
188 \r
189         /**\r
190          * Stores off xsi:schemaLocation attribute.\r
191          */\r
192         XMLCh* m_schemaLocation;\r
193 \r
194     private:\r
195         XMLObject* m_parent;\r
196         QName m_elementQname;\r
197         QName* m_typeQname;\r
198     };\r
199 \r
200 };\r
201 \r
202 #if defined (_MSC_VER)\r
203     #pragma warning( pop )\r
204 #endif\r
205 \r
206 #endif /* __xmltooling_abstractxmlobj_h__ */\r