Multi-line svn commit, see body.
[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 xmltooling/impl/UnknownElement.h\r
19  * \r
20  * Basic implementation suitable for use as default for unrecognized content\r
21  */\r
22 \r
23 #ifndef __xmltooling_unkelement_h__\r
24 #define __xmltooling_unkelement_h__\r
25 \r
26 #include <xmltooling/AbstractSimpleElement.h>\r
27 #include <xmltooling/exceptions.h>\r
28 #include <xmltooling/XMLObjectBuilder.h>\r
29 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>\r
30 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.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     /// @cond off\r
42     class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractSimpleElement, public AbstractDOMCachingXMLObject\r
43     {\r
44     public:\r
45         UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)\r
46             : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix) {}\r
47     \r
48         void releaseDOM() const;\r
49 \r
50         XMLObject* clone() const;\r
51 \r
52         const XMLCh* getTextContent(unsigned int position=0) const {\r
53             throw XMLObjectException("Direct access to content is not permitted.");\r
54         }\r
55 \r
56         void setTextContent(const XMLCh*, unsigned int position=0) {\r
57             throw XMLObjectException("Direct access to content is not permitted.");\r
58         }\r
59 \r
60         DOMElement* marshall(\r
61             DOMDocument* document=NULL\r
62 #ifndef XMLTOOLING_NO_XMLSEC\r
63             ,const std::vector<xmlsignature::Signature*>* sigs=NULL\r
64 #endif\r
65             ) const;\r
66 \r
67         DOMElement* marshall(\r
68             DOMElement* parentElement\r
69 #ifndef XMLTOOLING_NO_XMLSEC\r
70             ,const std::vector<xmlsignature::Signature*>* sigs=NULL\r
71 #endif\r
72             ) const;\r
73         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false);\r
74         \r
75     protected:\r
76         void setDocumentElement(DOMDocument* document, DOMElement* element) const {\r
77             DOMElement* documentRoot = document->getDocumentElement();\r
78             if (documentRoot)\r
79                 document->replaceChild(element, documentRoot);\r
80             else\r
81                 document->appendChild(element);\r
82         }\r
83 \r
84         mutable std::string m_xml;\r
85 \r
86         void serialize(std::string& s) const;\r
87     };\r
88     /// @endcond\r
89     \r
90     /**\r
91      * Builder for UnknownElementImpl objects.\r
92      * Use as the default builder when you want unknown DOM content treated as raw/ignored XML.\r
93      */\r
94     class XMLTOOL_API UnknownElementBuilder : public XMLObjectBuilder\r
95     {\r
96     public:\r
97         XMLObject* buildObject(\r
98             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
99             ) const;\r
100     };\r
101 \r
102 };\r
103 \r
104 #if defined (_MSC_VER)\r
105     #pragma warning( pop )\r
106 #endif\r
107 \r
108 #endif /* __xmltooling_unkelement_h__ */\r