Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.h
1 /*
2 *  Copyright 2001-2007 Internet2
3  * 
4 * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file xmltooling/impl/UnknownElement.h
19  * 
20  * Basic implementation suitable for use as default for unrecognized content
21  */
22
23 #ifndef __xmltooling_unkelement_h__
24 #define __xmltooling_unkelement_h__
25
26 #include <xmltooling/AbstractSimpleElement.h>
27 #include <xmltooling/exceptions.h>
28 #include <xmltooling/XMLObjectBuilder.h>
29 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>
30 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
31
32 #include <string>
33
34 #if defined (_MSC_VER)
35     #pragma warning( push )
36     #pragma warning( disable : 4250 4251 )
37 #endif
38
39 namespace xmltooling {
40
41     /// @cond off
42     class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractSimpleElement, public AbstractDOMCachingXMLObject
43     {
44     public:
45         UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL)
46             : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix) {}
47     
48         void releaseDOM() const;
49
50         XMLObject* clone() const;
51
52         const XMLCh* getTextContent(unsigned int position=0) const {
53             throw XMLObjectException("Direct access to content is not permitted.");
54         }
55
56         void setTextContent(const XMLCh*, unsigned int position=0) {
57             throw XMLObjectException("Direct access to content is not permitted.");
58         }
59
60         DOMElement* marshall(
61             DOMDocument* document=NULL
62 #ifndef XMLTOOLING_NO_XMLSEC
63             ,const std::vector<xmlsignature::Signature*>* sigs=NULL
64 #endif
65             ) const;
66
67         DOMElement* marshall(
68             DOMElement* parentElement
69 #ifndef XMLTOOLING_NO_XMLSEC
70             ,const std::vector<xmlsignature::Signature*>* sigs=NULL
71 #endif
72             ) const;
73         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false);
74         
75     protected:
76         void setDocumentElement(DOMDocument* document, DOMElement* element) const {
77             DOMElement* documentRoot = document->getDocumentElement();
78             if (documentRoot)
79                 document->replaceChild(element, documentRoot);
80             else
81                 document->appendChild(element);
82         }
83
84         mutable std::string m_xml;
85
86         void serialize(std::string& s) const;
87     };
88     /// @endcond
89     
90     /**
91      * Builder for UnknownElementImpl objects.
92      * Use as the default builder when you want unknown DOM content treated as raw/ignored XML.
93      */
94     class XMLTOOL_API UnknownElementBuilder : public XMLObjectBuilder
95     {
96     public:
97         XMLObject* buildObject(
98             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
99             ) const;
100     };
101
102 };
103
104 #if defined (_MSC_VER)
105     #pragma warning( pop )
106 #endif
107
108 #endif /* __xmltooling_unkelement_h__ */