Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.h
index 787cea1..411ef40 100644 (file)
-/*\r
-*  Copyright 2001-2006 Internet2\r
- * \r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * @file UnknownElement.h\r
- * \r
- * Basic implementations suitable for use as defaults for unrecognized content\r
- */\r
-\r
-#if !defined(__xmltooling_unkelement_h__)\r
-#define __xmltooling_unkelement_h__\r
-\r
-#include "internal.h"\r
-#include "AbstractDOMCachingXMLObject.h"\r
-#include "XMLObjectBuilder.h"\r
-#include "io/Marshaller.h"\r
-#include "io/Unmarshaller.h"\r
-\r
-#include <string>\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( push )\r
-    #pragma warning( disable : 4250 4251 )\r
-#endif\r
-\r
-namespace xmltooling {\r
-\r
-    /**\r
-     * Implementation class for unrecognized DOM elements.\r
-     * Purpose is to wrap the DOM and do any necessary caching/reconstruction\r
-     * when a DOM has to cross into a new document.\r
-     */\r
-    class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractDOMCachingXMLObject\r
-    {\r
-    public:\r
-        UnknownElementImpl() {}\r
-        virtual ~UnknownElementImpl() {}\r
-\r
-        /**\r
-         * Overridden to ensure XML content of DOM isn't lost.\r
-         * \r
-         * @see DOMCachingXMLObject::releaseDOM()\r
-         */\r
-        void releaseDOM();\r
-\r
-        /**\r
-          * @see XMLObject::clone()\r
-          */\r
-        XMLObject* clone() const;\r
-\r
-        /**\r
-         * @see XMLObject::hasChildren()\r
-         */\r
-        bool hasChildren() const {\r
-            return false;\r
-        }\r
-\r
-        /**\r
-         * @see XMLObject::getOrderedChildren()\r
-         */\r
-        size_t getOrderedChildren(std::vector<XMLObject*>& v) const {\r
-            return 0;\r
-        }\r
-\r
-    protected:\r
-        /**\r
-         * When needed, we can serialize the DOM into XML form and preserve it here.\r
-         */\r
-        std::string m_xml;\r
-\r
-    private:\r
-        void serialize(std::string& s) const;\r
-        friend class XMLTOOL_API UnknownElementMarshaller;\r
-    };\r
-\r
-    /**\r
-     * Factory for UnknownElementImpl objects\r
-     */\r
-    class XMLTOOL_DLLLOCAL UnknownElementBuilder : public virtual XMLObjectBuilder\r
-    {\r
-    public:\r
-        UnknownElementBuilder() {}\r
-        virtual ~UnknownElementBuilder() {}\r
-    \r
-        /**\r
-         * @see XMLObjectBuilder::buildObject()\r
-         */\r
-        XMLObject* buildObject() const {\r
-            return new UnknownElementImpl();\r
-        }\r
-    };\r
-\r
-    /**\r
-     * Marshaller for UnknownElementImpl objects\r
-     */\r
-    class XMLTOOL_DLLLOCAL UnknownElementMarshaller : public virtual Marshaller\r
-    {\r
-    public:\r
-        UnknownElementMarshaller() {}\r
-        virtual ~UnknownElementMarshaller() {}\r
-    \r
-        /**\r
-         * @see Marshaller::marshall(XMLObject*,DOMDocument*)\r
-         */\r
-        DOMElement* marshall(XMLObject* xmlObject, DOMDocument* document=NULL) const;\r
-\r
-        /**\r
-         * @see Marshaller::marshall(XMLObject*,DOMElement*)\r
-         */\r
-        DOMElement* marshall(XMLObject* xmlObject, DOMElement* parentElement) const;\r
-        \r
-    protected:\r
-        void setDocumentElement(DOMDocument* document, DOMElement* element) const {\r
-            DOMElement* documentRoot = document->getDocumentElement();\r
-            if (documentRoot)\r
-                document->replaceChild(documentRoot, element);\r
-            else\r
-                document->appendChild(element);\r
-        }\r
-    };\r
-\r
-    /**\r
-     * Marshaller for UnknownElementImpl objects\r
-     */\r
-    class XMLTOOL_DLLLOCAL UnknownElementUnmarshaller : public virtual Unmarshaller\r
-    {\r
-    public:\r
-        UnknownElementUnmarshaller() {}\r
-        virtual ~UnknownElementUnmarshaller() {}\r
-    \r
-        /**\r
-         * @see Unmarshaller::unmarshall()\r
-         */\r
-        XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const;\r
-    };\r
-};\r
-\r
-#if defined (_MSC_VER)\r
-    #pragma warning( pop )\r
-#endif\r
-\r
-#endif /* __xmltooling_unkelement_h__ */\r
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+
+/**
+ * @file xmltooling/impl/UnknownElement.h
+ * 
+ * Basic implementation suitable for use as default for unrecognized content.
+ */
+
+#ifndef __xmltooling_unkelement_h__
+#define __xmltooling_unkelement_h__
+
+#include <xmltooling/AbstractSimpleElement.h>
+#include <xmltooling/exceptions.h>
+#include <xmltooling/XMLObjectBuilder.h>
+#include <xmltooling/io/AbstractXMLObjectMarshaller.h>
+#include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
+
+#include <string>
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4250 4251 )
+#endif
+
+namespace xmltooling {
+
+    /// @cond off
+    class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractSimpleElement, public AbstractDOMCachingXMLObject
+    {
+    public:
+        UnknownElementImpl(const XMLCh* namespaceURI=nullptr, const XMLCh* elementLocalName=nullptr, const XMLCh* namespacePrefix=nullptr);
+    
+        virtual ~UnknownElementImpl();
+
+        void releaseDOM() const;
+        XMLObject* clone() const;
+        const XMLCh* getTextContent(unsigned int position=0) const;
+        void setTextContent(const XMLCh*, unsigned int position=0);
+
+        xercesc::DOMElement* marshall(
+            xercesc::DOMDocument* document=nullptr
+#ifndef XMLTOOLING_NO_XMLSEC
+            ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
+            ,const Credential* credential=nullptr
+#endif
+            ) const;
+
+        xercesc::DOMElement* marshall(
+            xercesc::DOMElement* parentElement
+#ifndef XMLTOOLING_NO_XMLSEC
+            ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
+            ,const Credential* credential=nullptr
+#endif
+            ) const;
+        XMLObject* unmarshall(xercesc::DOMElement* element, bool bindDocument=false);
+        
+    protected:
+        void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const;
+
+        mutable std::string m_xml;
+
+        void serialize(std::string& s) const;
+    };
+    /// @endcond
+    
+    /**
+     * Builder for UnknownElementImpl objects.
+     * Use as the default builder when you want unknown DOM content treated as raw/ignored XML.
+     */
+    class XMLTOOL_API UnknownElementBuilder : public XMLObjectBuilder
+    {
+    public:
+        XMLObject* buildObject(
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=nullptr, const QName* schemaType=nullptr
+            ) const;
+    };
+
+};
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+#endif /* __xmltooling_unkelement_h__ */