Bug fixes and API changes from second unit test.
[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         /**\r
50          * Overridden to ensure XML content of DOM isn't lost.\r
51          * \r
52          * @see DOMCachingXMLObject::releaseDOM()\r
53          */\r
54         void releaseDOM();\r
55 \r
56         /**\r
57           * @see XMLObject::clone()\r
58           */\r
59         XMLObject* clone() const;\r
60 \r
61         /**\r
62          * @see XMLObject::hasChildren()\r
63          */\r
64         bool hasChildren() const {\r
65             return false;\r
66         }\r
67 \r
68         /**\r
69          * @see XMLObject::getOrderedChildren()\r
70          */\r
71         size_t getOrderedChildren(std::vector<XMLObject*>& v) const {\r
72             return 0;\r
73         }\r
74 \r
75     protected:\r
76         /**\r
77          * When needed, we can serialize the DOM into XML form and preserve it here.\r
78          */\r
79         std::string m_xml;\r
80 \r
81     private:\r
82         void serialize(std::string& s) const;\r
83         friend class XMLTOOL_API UnknownElementMarshaller;\r
84     };\r
85 \r
86     /**\r
87      * Factory for UnknownElementImpl objects\r
88      */\r
89     class XMLTOOL_DLLLOCAL UnknownElementBuilder : public virtual XMLObjectBuilder\r
90     {\r
91     public:\r
92         /**\r
93          * @see XMLObjectBuilder::buildObject()\r
94          */\r
95         XMLObject* buildObject() const {\r
96             return new UnknownElementImpl();\r
97         }\r
98     };\r
99 \r
100     /**\r
101      * Marshaller for UnknownElementImpl objects\r
102      */\r
103     class XMLTOOL_DLLLOCAL UnknownElementMarshaller : public virtual Marshaller\r
104     {\r
105     public:\r
106         /**\r
107          * @see Marshaller::marshall(XMLObject*,DOMDocument*)\r
108          */\r
109         DOMElement* marshall(XMLObject* xmlObject, DOMDocument* document=NULL) const;\r
110 \r
111         /**\r
112          * @see Marshaller::marshall(XMLObject*,DOMElement*)\r
113          */\r
114         DOMElement* marshall(XMLObject* xmlObject, DOMElement* parentElement) const;\r
115         \r
116     protected:\r
117         void setDocumentElement(DOMDocument* document, DOMElement* element) const {\r
118             DOMElement* documentRoot = document->getDocumentElement();\r
119             if (documentRoot)\r
120                 document->replaceChild(documentRoot, element);\r
121             else\r
122                 document->appendChild(element);\r
123         }\r
124     };\r
125 \r
126     /**\r
127      * Marshaller for UnknownElementImpl objects\r
128      */\r
129     class XMLTOOL_DLLLOCAL UnknownElementUnmarshaller : public virtual Unmarshaller\r
130     {\r
131     public:\r
132         /**\r
133          * @see Unmarshaller::unmarshall()\r
134          */\r
135         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const;\r
136     };\r
137 };\r
138 \r
139 #if defined (_MSC_VER)\r
140     #pragma warning( pop )\r
141 #endif\r
142 \r
143 #endif /* __xmltooling_unkelement_h__ */\r