Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractAttributeExtensibleXMLObject.h
1 /*
2  *  Copyright 2001-2007 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 AbstractAttributeExtensibleXMLObject.h
19  * 
20  * AbstractXMLObject mixin that implements AttributeExtensibleXMLObject
21  */
22
23 #ifndef __xmltooling_absattrextxmlobj_h__
24 #define __xmltooling_absattrextxmlobj_h__
25
26 #include <map>
27 #include <xmltooling/AbstractXMLObject.h>
28 #include <xmltooling/AttributeExtensibleXMLObject.h>
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      * AbstractXMLObject mixin that implements AttributeExtensibleXMLObject.
39      * Inherit from this class to add support for attribute wildcarding.
40      */
41     class XMLTOOL_API AbstractAttributeExtensibleXMLObject
42         : public virtual AttributeExtensibleXMLObject, public virtual AbstractXMLObject
43     {
44     public:
45         virtual ~AbstractAttributeExtensibleXMLObject();
46         
47         const XMLCh* getAttribute(const QName& qualifiedName) const {
48             std::map<QName,XMLCh*>::const_iterator i=m_attributeMap.find(qualifiedName);
49             return (i==m_attributeMap.end()) ? NULL : i->second;
50         }
51         
52         void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false);
53     
54         const std::map<QName,XMLCh*>& getExtensionAttributes() const {
55             return m_attributeMap;
56         }
57         
58         const XMLCh* getXMLID() const {
59             return (m_idAttribute == m_attributeMap.end()) ? NULL : m_idAttribute->second;
60         }
61     
62      protected:
63         AbstractAttributeExtensibleXMLObject() {
64             m_idAttribute = m_attributeMap.end();
65         }
66
67         /** Copy constructor. */
68         AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src);
69
70         /**
71          * Assists in the unmarshalling of extension attributes.
72          * 
73          * @param attribute the DOM attribute node being unmarshalled
74          */
75         void unmarshallExtensionAttribute(const DOMAttr* attribute);
76
77         /**
78          * Assists in the marshalling of extension attributes.
79          * 
80          * @param domElement    the DOM element against which to marshall the attributes
81          */
82         void marshallExtensionAttributes(DOMElement* domElement) const;
83     
84     private:
85         /** Map of arbitrary attributes. */
86         std::map<QName,XMLCh*> m_attributeMap;
87         
88         /** Points to the last attribute designated as an XML ID. */
89         std::map<QName,XMLCh*>::const_iterator m_idAttribute;
90     };
91     
92 };
93
94 #if defined (_MSC_VER)
95     #pragma warning( pop )
96 #endif
97
98 #endif /* __xmltooling_absattrextxmlobj_h__ */