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