90d9a67b4e0ebcf160ddcac82a0c4c800d1b5da0
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.h
1 /*
2 *  Copyright 2001-2010 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=nullptr, const XMLCh* elementLocalName=nullptr, const XMLCh* namespacePrefix=nullptr);
46     
47         virtual ~UnknownElementImpl();
48
49         void releaseDOM() const;
50         XMLObject* clone() const;
51         const XMLCh* getTextContent(unsigned int position=0) const;
52         void setTextContent(const XMLCh*, unsigned int position=0);
53
54         xercesc::DOMElement* marshall(
55             xercesc::DOMDocument* document=nullptr
56 #ifndef XMLTOOLING_NO_XMLSEC
57             ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
58             ,const Credential* credential=nullptr
59 #endif
60             ) const;
61
62         xercesc::DOMElement* marshall(
63             xercesc::DOMElement* parentElement
64 #ifndef XMLTOOLING_NO_XMLSEC
65             ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
66             ,const Credential* credential=nullptr
67 #endif
68             ) const;
69         XMLObject* unmarshall(xercesc::DOMElement* element, bool bindDocument=false);
70         
71     protected:
72         void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const;
73
74         mutable std::string m_xml;
75
76         void serialize(std::string& s) const;
77     };
78     /// @endcond
79     
80     /**
81      * Builder for UnknownElementImpl objects.
82      * Use as the default builder when you want unknown DOM content treated as raw/ignored XML.
83      */
84     class XMLTOOL_API UnknownElementBuilder : public XMLObjectBuilder
85     {
86     public:
87         XMLObject* buildObject(
88             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
89             ) const;
90     };
91
92 };
93
94 #if defined (_MSC_VER)
95     #pragma warning( pop )
96 #endif
97
98 #endif /* __xmltooling_unkelement_h__ */