0ad445df8f9377b4c00a2d7ea4ad0f347eda5f2f
[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 implementation suitable for use as default 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 <xmltooling/exceptions.h>\r
27 #include <xmltooling/XMLObjectBuilder.h>\r
28 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>\r
29 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>\r
30 \r
31 #include <string>\r
32 \r
33 #if defined (_MSC_VER)\r
34     #pragma warning( push )\r
35     #pragma warning( disable : 4250 4251 )\r
36 #endif\r
37 \r
38 namespace xmltooling {\r
39 \r
40     /**\r
41      * Implements a thin wrapper around unknown DOM content.\r
42      */\r
43     class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractDOMCachingXMLObject\r
44     {\r
45     public:\r
46         UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)\r
47             : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix) {}\r
48     \r
49         void releaseDOM();\r
50 \r
51         XMLObject* clone() const;\r
52 \r
53         DOMElement* marshall(DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const;\r
54         DOMElement* marshall(DOMElement* parentElement, MarshallingContext* ctx=NULL) const;\r
55         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false);\r
56         \r
57     protected:\r
58         void setDocumentElement(DOMDocument* document, DOMElement* element) const {\r
59             DOMElement* documentRoot = document->getDocumentElement();\r
60             if (documentRoot)\r
61                 document->replaceChild(documentRoot, element);\r
62             else\r
63                 document->appendChild(element);\r
64         }\r
65 \r
66         mutable std::string m_xml;\r
67 \r
68         void serialize(std::string& s) const;\r
69     };\r
70 \r
71     /**\r
72      * Builder for UnknownElementImpl objects.\r
73      */\r
74     class XMLTOOL_API UnknownElementBuilder : public XMLObjectBuilder\r
75     {\r
76     public:\r
77         /**\r
78          * @see XMLObjectBuilder::buildObject(const XMLCh*,const XMLCh*,const XMLCh*)\r
79          */\r
80         UnknownElementImpl* buildObject(\r
81             const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL\r
82             ) const {\r
83             return new UnknownElementImpl(namespaceURI,elementLocalName,namespacePrefix);\r
84         }\r
85     };\r
86 \r
87 };\r
88 \r
89 #if defined (_MSC_VER)\r
90     #pragma warning( pop )\r
91 #endif\r
92 \r
93 #endif /* __xmltooling_unkelement_h__ */\r