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