Multi-line svn commit, see body.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLObject.h
index 1624b35..1fb26d6 100644 (file)
@@ -20,7 +20,7 @@
  * Abstract interface to objects that can be manipulated in and out of XML form. \r
  */\r
 \r
-#if !defined(__xmltooling_xmlobj_h__)\r
+#ifndef __xmltooling_xmlobj_h__\r
 #define __xmltooling_xmlobj_h__\r
 \r
 #include <set>\r
 \r
 using namespace xercesc;\r
 \r
+#ifndef XMLTOOLING_NO_XMLSEC\r
+namespace xmlsignature {\r
+    class XMLTOOL_API Signature;\r
+};\r
+#endif\r
+\r
 #if defined (_MSC_VER)\r
     #pragma warning( push )\r
     #pragma warning( disable : 4250 4251 )\r
@@ -39,38 +45,11 @@ using namespace xercesc;
 \r
 namespace xmltooling {\r
 \r
-#ifndef XMLTOOLING_NO_XMLSEC\r
-    class XMLTOOL_API Signature;\r
-    class XMLTOOL_API SigningContext;\r
-#endif\r
-\r
-    /**\r
-     * Supplies additional information to the marshalling process.\r
-     * Currently this only consists of signature related information.\r
-     */\r
-    class XMLTOOL_API MarshallingContext\r
-    {\r
-        MAKE_NONCOPYABLE(MarshallingContext);\r
-    public:\r
-        MarshallingContext() {}\r
-        ~MarshallingContext() {}\r
-\r
-#ifndef XMLTOOLING_NO_XMLSEC\r
-        MarshallingContext(Signature* sig, const SigningContext* ctx) {\r
-            m_signingContexts.push_back(std::make_pair(sig,ctx));\r
-        }\r
-        \r
-        /** Array of signing contexts, keyed off of the associated Signature */\r
-        std::vector< std::pair<Signature*,const SigningContext*> > m_signingContexts;\r
-#endif\r
-    };\r
-\r
     /**\r
      * Object that represents an XML Element that has been unmarshalled into this C++ object.\r
      */\r
     class XMLTOOL_API XMLObject\r
     {\r
-        MAKE_NONCOPYABLE(XMLObject);\r
     public:\r
         virtual ~XMLObject() {}\r
         \r
@@ -83,6 +62,18 @@ namespace xmltooling {
         virtual XMLObject* clone() const=0;\r
         \r
         /**\r
+         * Specialized function for detaching a child object from its parent\r
+         * <strong>while disposing of the parent</strong>.\r
+         *\r
+         * This is not a generic way of detaching any child object, but only of\r
+         * pruning a single child from the root of an XMLObject tree. If the\r
+         * detached XMLObject's parent is itself a child, an exception will be\r
+         * thrown. It's mainly useful for turning a child into the new root of\r
+         * the tree without having to clone the child.\r
+         */\r
+        virtual void detach()=0;\r
+\r
+        /**\r
          * Gets the QName for this element.  This QName <strong>MUST</strong> \r
          * contain the namespace URI, namespace prefix, and local element name.\r
          * \r
@@ -125,12 +116,11 @@ namespace xmltooling {
         virtual const QName* getSchemaType() const=0;\r
         \r
         /**\r
-         * Sets the XML schema type of this element.  This translates to contents the xsi:type\r
-         * attribute for the element.\r
+         * Gets the value of the ID attribute set on this object, if any.\r
          * \r
-         * @param type XML schema type of this element\r
+         * @return an ID value or NULL \r
          */\r
-        virtual void setSchemaType(const QName* type)=0;\r
+        virtual const XMLCh* getXMLID() const=0;\r
         \r
         /**\r
          * Checks to see if this object has a parent.\r
@@ -172,6 +162,95 @@ namespace xmltooling {
         virtual const std::list<XMLObject*>& getOrderedChildren() const=0;\r
 \r
         /**\r
+         * Used by a child's detach method to isolate the child from\r
+         * this parent object in preparation for destroying the parent\r
+         * (this object).\r
+         * \r
+         * @param child the child object to remove\r
+         */\r
+        virtual void removeChild(XMLObject* child)=0;\r
+\r
+        /**\r
+         * Returns the text content at the specified position relative to\r
+         * any child elements. A zero represents leading text, 1 comes after\r
+         * the first child, and so forth.\r
+         *\r
+         * @param position  the relative child element position of the text  \r
+         * @return the designated text value\r
+         */\r
+        virtual const XMLCh* getTextContent(unsigned int position=0) const=0;\r
+\r
+        /**\r
+         * Sets (or clears) text content relative to a child element's position. \r
+         * \r
+         * @param value         value to set, or NULL to clear\r
+         * @param position      position relative to child element \r
+         */\r
+        virtual void setTextContent(const XMLCh* value, unsigned int position=0)=0;\r
+\r
+        /**\r
+         * Gets the DOM representation of this XMLObject, if one exists.\r
+         * \r
+         * @return the DOM representation of this XMLObject\r
+         */\r
+        virtual DOMElement* getDOM() const=0;\r
+        \r
+        /**\r
+         * Sets the DOM representation of this XMLObject.\r
+         * \r
+         * @param dom       DOM representation of this XMLObject\r
+         * @param bindDocument  true if the object should take ownership of the associated Document\r
+         */\r
+        virtual void setDOM(DOMElement* dom, bool bindDocument=false) const=0;\r
+    \r
+        /**\r
+         * Assigns ownership of a DOM document to the XMLObject.\r
+         * This binds the lifetime of the document to the lifetime of the object.\r
+         * \r
+         * @param doc DOM document bound to this object \r
+         */\r
+        virtual void setDocument(DOMDocument* doc) const=0;\r
+\r
+        /**\r
+         * Releases the DOM representation of this XMLObject, if there is one.\r
+         */\r
+        virtual void releaseDOM() const=0;\r
+        \r
+        /**\r
+         * Releases the DOM representation of this XMLObject's parent.\r
+         * \r
+         * @param propagateRelease true if all ancestors of this element should release their DOM\r
+         */\r
+        virtual void releaseParentDOM(bool propagateRelease=true) const=0;\r
+        \r
+        /**\r
+         * Releases the DOM representation of this XMLObject's children.\r
+         * \r
+         * @param propagateRelease true if all descendants of this element should release their DOM\r
+         */\r
+        virtual void releaseChildrenDOM(bool propagateRelease=true) const=0;\r
+\r
+        /**\r
+         * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).\r
+         */\r
+        void releaseThisandParentDOM() const {\r
+            if (getDOM()) {\r
+                releaseDOM();\r
+                releaseParentDOM(true);\r
+            }\r
+        }\r
+    \r
+        /**\r
+         * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM().\r
+         */\r
+        void releaseThisAndChildrenDOM() const {\r
+            if (getDOM()) {\r
+                releaseChildrenDOM(true);\r
+                releaseDOM();\r
+            }\r
+        }\r
+\r
+        /**\r
          * Marshalls the XMLObject, and its children, into a DOM element.\r
          * If a document is supplied, then it will be used to create the resulting elements.\r
          * If the document does not have a Document Element set, then the resulting\r
@@ -180,13 +259,18 @@ namespace xmltooling {
          * marshalled, unless an existing DOM can be reused without creating a new document. \r
          * \r
          * @param document  the DOM document the marshalled element will be placed in, or NULL\r
-         * @param ctx       optional marshalling context\r
+         * @param sigs      ordered array of signatures to create after marshalling is complete\r
          * @return the DOM element representing this XMLObject\r
          * \r
          * @throws MarshallingException thrown if there is a problem marshalling the given object\r
          * @throws SignatureException thrown if a problem occurs during signature creation \r
          */\r
-        virtual DOMElement* marshall(DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const=0;\r
+        virtual DOMElement* marshall(\r
+            DOMDocument* document=NULL\r
+#ifndef XMLTOOLING_NO_XMLSEC\r
+            ,const std::vector<xmlsignature::Signature*>* sigs=NULL\r
+#endif\r
+            ) const=0;\r
         \r
         /**\r
          * Marshalls the XMLObject and appends it as a child of the given parent element.\r
@@ -195,13 +279,18 @@ namespace xmltooling {
          * the Document owning the given Element.\r
          * \r
          * @param parentElement the parent element to append the resulting DOM tree\r
-         * @param ctx       optional marshalling context\r
+         * @param sigs          ordered array of signatures to create after marshalling is complete\r
          * @return the marshalled element tree\r
 \r
          * @throws MarshallingException thrown if the given XMLObject can not be marshalled.\r
          * @throws SignatureException thrown if a problem occurs during signature creation \r
          */\r
-        virtual DOMElement* marshall(DOMElement* parentElement, MarshallingContext* ctx=NULL) const=0;\r
+        virtual DOMElement* marshall(\r
+            DOMElement* parentElement\r
+#ifndef XMLTOOLING_NO_XMLSEC\r
+            ,const std::vector<xmlsignature::Signature*>* sigs=NULL\r
+#endif\r
+            ) const=0;\r
 \r
         /**\r
          * Unmarshalls the given W3C DOM element into the XMLObject.\r
@@ -219,6 +308,8 @@ namespace xmltooling {
 \r
     protected:\r
         XMLObject() {}\r
+    private:\r
+        XMLObject& operator=(const XMLObject& src);\r
     };\r
 \r
 #if defined (_MSC_VER)\r