gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / AttributeExtensibleXMLObject.h
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file AttributeExtensibleXMLObject.h
19  * 
20  * An XMLObject that supports arbitrary attributes 
21  */
22
23 #if !defined(__xmltooling_attrextxmlobj_h__)
24 #define __xmltooling_attrextxmlobj_h__
25
26 #include <xmltooling/XMLObject.h>
27
28 using namespace xercesc;
29
30 #if defined (_MSC_VER)
31     #pragma warning( push )
32     #pragma warning( disable : 4250 4251 )
33 #endif
34
35 namespace xmltooling {
36
37     /**
38      * An XMLObject that supports arbitrary attributes.
39      */
40     class XMLTOOL_API AttributeExtensibleXMLObject : public virtual XMLObject
41     {
42     protected:
43         AttributeExtensibleXMLObject() {}
44         
45     public:
46         virtual ~AttributeExtensibleXMLObject() {}
47         
48         /**
49          * Gets the value of an XML attribute of the object.
50          * 
51          * @param   qualifiedName   qualified name of the attribute   
52          * @return the attribute value, or NULL
53          */
54         virtual const XMLCh* getAttribute(const QName& qualifiedName) const=0;
55         
56         /**
57          * Sets (or clears) an XML attribute of the object.
58          * 
59          * @param qualifiedName qualified name of the attribute   
60          * @param value         value to set, or NULL to clear
61          * @param ID            true iff the attribute is an XML ID
62          */
63         virtual void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false)=0;
64
65         /**
66          * Gets an immutable map of the extended XML attributes of the object.
67          * 
68          * This set is not guaranteed to (and generally will not) include
69          * attributes defined directly on the object's "type".
70          */
71         virtual const std::map<QName,XMLCh*>& getExtensionAttributes() const=0;
72         
73         /**
74          * Gets an immutable list of all the ID attributes currently registered.
75          * 
76          * @return list of all the ID attributes currently registered
77          */
78         static const std::set<QName>& getRegisteredIDAttributes() {
79             return m_idAttributeSet;
80         }
81         
82         /**
83          * Tests whether an XML attribute is registered as an XML ID.
84          * 
85          * @return true iff the attribute name matches a registered XML ID attribute 
86          */
87         static bool isRegisteredIDAttribute(const QName& name) {
88             return m_idAttributeSet.find(name)!=m_idAttributeSet.end();
89         }
90     
91         /**
92          * Registers a new attribute as being of XML ID type.
93          * 
94          * @param name the qualified attribute name
95          */
96         static void registerIDAttribute(const QName& name) {
97             m_idAttributeSet.insert(name);
98         }
99
100         /**
101          * Deregisters an ID attribute.
102          * 
103          * @param name the qualified attribute name
104          */
105         static void deregisterIDAttribute(const QName& name) {
106             m_idAttributeSet.erase(name);
107         }
108         
109         /**
110          * Deregisters all ID attributes.
111          */
112         static void deregisterIDAttributes() {
113             m_idAttributeSet.clear();
114         }
115
116     private:
117         /** Set of attributes to treat as XML IDs. */
118         static std::set<QName> m_idAttributeSet;
119     };
120     
121 };
122
123 #if defined (_MSC_VER)
124     #pragma warning( pop )
125 #endif
126
127 #endif /* __xmltooling_attrextxmlobj_h__ */