First cut at signing support.
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.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 UnknownElement.h\r
19  * \r
20  * Basic implementations suitable for use as defaults for unrecognized content\r
21  */\r
22 \r
23 #if !defined(__xmltooling_unkelement_h__)\r
24 #define __xmltooling_unkelement_h__\r
25 \r
26 #include "internal.h"\r
27 #include "AbstractDOMCachingXMLObject.h"\r
28 #include "XMLObjectBuilder.h"\r
29 #include "io/Marshaller.h"\r
30 #include "io/Unmarshaller.h"\r
31 \r
32 #include <string>\r
33 \r
34 #if defined (_MSC_VER)\r
35     #pragma warning( push )\r
36     #pragma warning( disable : 4250 4251 )\r
37 #endif\r
38 \r
39 namespace xmltooling {\r
40 \r
41     /**\r
42      * Implementation class for unrecognized DOM elements.\r
43      * Purpose is to wrap the DOM and do any necessary caching/reconstruction\r
44      * when a DOM has to cross into a new document.\r
45      */\r
46     class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractDOMCachingXMLObject\r
47     {\r
48     public:\r
49         UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)\r
50             : AbstractDOMCachingXMLObject(namespaceURI, elementLocalName, namespacePrefix) {}\r
51     \r
52         /**\r
53          * Overridden to ensure XML content of DOM isn't lost.\r
54          * \r
55          * @see DOMCachingXMLObject::releaseDOM()\r
56          */\r
57         void releaseDOM();\r
58 \r
59         /**\r
60           * @see XMLObject::clone()\r
61           */\r
62         XMLObject* clone() const;\r
63 \r
64     protected:\r
65         /**\r
66          * When needed, we can serialize the DOM into XML form and preserve it here.\r
67          */\r
68         std::string m_xml;\r
69 \r
70         void serialize(std::string& s) const;\r
71     private:\r
72         friend class XMLTOOL_DLLLOCAL UnknownElementMarshaller;\r
73     };\r
74 \r
75     /**\r
76      * Factory for UnknownElementImpl objects\r
77      */\r
78     class XMLTOOL_DLLLOCAL UnknownElementBuilder : public virtual XMLObjectBuilder\r
79     {\r
80     public:\r
81         /**\r
82          * @see XMLObjectBuilder::buildObject()\r
83          */\r
84         XMLObject* buildObject() const {\r
85             return new UnknownElementImpl();\r
86         }\r
87     };\r
88 \r
89     /**\r
90      * Marshaller for UnknownElementImpl objects\r
91      */\r
92     class XMLTOOL_DLLLOCAL UnknownElementMarshaller : public virtual Marshaller\r
93     {\r
94     public:\r
95         /**\r
96          * @see Marshaller::marshall(XMLObject*,DOMDocument*, const MarshallingContext*)\r
97          */\r
98         DOMElement* marshall(XMLObject* xmlObject, DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const;\r
99 \r
100         /**\r
101          * @see Marshaller::marshall(XMLObject*,DOMElement*, const MarshallingContext* ctx)\r
102          */\r
103         DOMElement* marshall(XMLObject* xmlObject, DOMElement* parentElement, MarshallingContext* ctx=NULL) const;\r
104         \r
105     protected:\r
106         void setDocumentElement(DOMDocument* document, DOMElement* element) const {\r
107             DOMElement* documentRoot = document->getDocumentElement();\r
108             if (documentRoot)\r
109                 document->replaceChild(documentRoot, element);\r
110             else\r
111                 document->appendChild(element);\r
112         }\r
113     };\r
114 \r
115     /**\r
116      * Unmarshaller for UnknownElementImpl objects\r
117      */\r
118     class XMLTOOL_DLLLOCAL UnknownElementUnmarshaller : public virtual Unmarshaller\r
119     {\r
120     public:\r
121         /**\r
122          * @see Unmarshaller::unmarshall()\r
123          */\r
124         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const;\r
125     };\r
126 };\r
127 \r
128 #if defined (_MSC_VER)\r
129     #pragma warning( pop )\r
130 #endif\r
131 \r
132 #endif /* __xmltooling_unkelement_h__ */\r