Handle IDness during (un)marshalling, move more work to base class.
[shibboleth/cpp-xmltooling.git] / xmltooling / AttributeExtensibleXMLObject.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 AttributeExtensibleXMLObject.h\r
19  * \r
20  * An XMLObject that supports arbitrary attributes \r
21  */\r
22 \r
23 #if !defined(__xmltooling_attrextxmlobj_h__)\r
24 #define __xmltooling_attrextxmlobj_h__\r
25 \r
26 #include <xmltooling/XMLObject.h>\r
27 \r
28 using namespace xercesc;\r
29 \r
30 #if defined (_MSC_VER)\r
31     #pragma warning( push )\r
32     #pragma warning( disable : 4250 4251 )\r
33 #endif\r
34 \r
35 namespace xmltooling {\r
36 \r
37     /**\r
38      * An XMLObject that supports arbitrary attributes.\r
39      */\r
40     class XMLTOOL_API AttributeExtensibleXMLObject : public virtual XMLObject\r
41     {\r
42     protected:\r
43         AttributeExtensibleXMLObject() {}\r
44         \r
45     public:\r
46         virtual ~AttributeExtensibleXMLObject() {}\r
47         \r
48         /**\r
49          * Gets the value of an XML attribute of the object.\r
50          * \r
51          * @param   qualifiedName   qualified name of the attribute   \r
52          * @return the attribute value, or NULL\r
53          */\r
54         virtual const XMLCh* getAttribute(const QName& qualifiedName) const=0;\r
55         \r
56         /**\r
57          * Sets (or clears) an XML attribute of the object.\r
58          * \r
59          * @param qualifiedName qualified name of the attribute   \r
60          * @param value         value to set, or NULL to clear\r
61          * @param ID            true iff the attribute is an XML ID\r
62          */\r
63         virtual void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false)=0;\r
64 \r
65         /**\r
66          * Gets an immutable map of the extended XML attributes of the object.\r
67          * \r
68          * This set is not guaranteed to (and generally will not) include\r
69          * attributes defined directly on the object's "type".\r
70          */\r
71         virtual const std::map<QName,XMLCh*>& getExtensionAttributes() const=0;\r
72         \r
73         /**\r
74          * Gets an immutable list of all the ID attributes currently registered.\r
75          * \r
76          * @return list of all the ID attributes currently registered\r
77          */\r
78         static const std::set<QName>& getRegisteredIDAttributes() {\r
79             return m_idAttributeSet;\r
80         }\r
81         \r
82         /**\r
83          * Tests whether an XML attribute is registered as an XML ID.\r
84          * \r
85          * @return true iff the attribute name matches a registered XML ID attribute \r
86          */\r
87         static bool isRegisteredIDAttribute(const QName& name) {\r
88             return m_idAttributeSet.find(name)!=m_idAttributeSet.end();\r
89         }\r
90     \r
91         /**\r
92          * Registers a new attribute as being of XML ID type.\r
93          * \r
94          * @param name the qualified attribute name\r
95          */\r
96         static void registerIDAttribute(const QName& name) {\r
97             m_idAttributeSet.insert(name);\r
98         }\r
99 \r
100         /**\r
101          * Deregisters an ID attribute.\r
102          * \r
103          * @param name the qualified attribute name\r
104          */\r
105         static void deregisterIDAttribute(const QName& name) {\r
106             m_idAttributeSet.erase(name);\r
107         }\r
108         \r
109         /**\r
110          * Deregisters all ID attributes.\r
111          */\r
112         static void deregisterIDAttributes() {\r
113             m_idAttributeSet.clear();\r
114         }\r
115 \r
116     private:\r
117         /** Set of attributes to treat as XML IDs. */\r
118         static std::set<QName> m_idAttributeSet;\r
119     };\r
120     \r
121 };\r
122 \r
123 #if defined (_MSC_VER)\r
124     #pragma warning( pop )\r
125 #endif\r
126 \r
127 #endif /* __xmltooling_attrextxmlobj_h__ */\r