2 * Copyright 2001-2006 Internet2
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * Abstract interface to objects that can be manipulated in and out of XML form.
\r
23 #ifndef __xmltooling_xmlobj_h__
\r
24 #define __xmltooling_xmlobj_h__
\r
29 #include <xercesc/dom/DOM.hpp>
\r
30 #include <xmltooling/QName.h>
\r
31 #include <xmltooling/Namespace.h>
\r
33 using namespace xercesc;
\r
35 #ifndef XMLTOOLING_NO_XMLSEC
\r
36 namespace xmlsignature {
\r
37 class XMLTOOL_API Signature;
\r
41 #if defined (_MSC_VER)
\r
42 #pragma warning( push )
\r
43 #pragma warning( disable : 4250 4251 )
\r
46 namespace xmltooling {
\r
49 * Object that represents an XML Element that has been unmarshalled into this C++ object.
\r
51 class XMLTOOL_API XMLObject
\r
54 virtual ~XMLObject() {}
\r
57 * Creates a copy of the object, along with all of its children.
\r
59 * The new object tree will be completely distinct and independent of
\r
60 * the original in all respects.
\r
62 virtual XMLObject* clone() const=0;
\r
65 * Gets the QName for this element. This QName <strong>MUST</strong>
\r
66 * contain the namespace URI, namespace prefix, and local element name.
\r
68 * @return constant reference to the QName for this object
\r
70 virtual const QName& getElementQName() const=0;
\r
73 * Gets the namespaces that are scoped to this element.
\r
75 * The caller MUST NOT modify the set returned, but may use any
\r
76 * non-modifying operations or algorithms on it. Iterators will
\r
77 * remain valid unless the set member referenced is removed using
\r
78 * the removeNamespace method.
\r
80 * @return the namespaces that are scoped to this element
\r
82 virtual const std::set<Namespace>& getNamespaces() const=0;
\r
85 * Adds a namespace to the ones already scoped to this element
\r
87 * @param ns the namespace to add
\r
89 virtual void addNamespace(const Namespace& ns) const=0;
\r
92 * Removes a namespace from this element
\r
94 * @param ns the namespace to remove
\r
96 virtual void removeNamespace(const Namespace& ns)=0;
\r
99 * Gets the XML schema type of this element. This translates to contents the xsi:type
\r
100 * attribute for the element.
\r
102 * @return XML schema type of this element
\r
104 virtual const QName* getSchemaType() const=0;
\r
107 * Checks to see if this object has a parent.
\r
109 * @return true if the object has a parent, false if not
\r
111 virtual bool hasParent() const=0;
\r
114 * Gets the parent of this element or null if there is no parent.
\r
116 * @return the parent of this element or null
\r
118 virtual XMLObject* getParent() const=0;
\r
121 * Sets the parent of this element.
\r
123 * @param parent the parent of this element
\r
125 virtual void setParent(XMLObject* parent)=0;
\r
128 * Checks if this XMLObject has children.
\r
130 * @return true if this XMLObject has children, false if not
\r
132 virtual bool hasChildren() const=0;
\r
135 * Returns an unmodifiable list of child objects in the order that they
\r
136 * should appear in the serialized representation.
\r
138 * The validity of the returned list is not maintained if any non-const
\r
139 * operations are performed on the parent object.
\r
141 * @return the list of children
\r
143 virtual const std::list<XMLObject*>& getOrderedChildren() const=0;
\r
146 * Gets the DOM representation of this XMLObject, if one exists.
\r
148 * @return the DOM representation of this XMLObject
\r
150 virtual DOMElement* getDOM() const=0;
\r
153 * Sets the DOM representation of this XMLObject.
\r
155 * @param dom DOM representation of this XMLObject
\r
156 * @param bindDocument true if the object should take ownership of the associated Document
\r
158 virtual void setDOM(DOMElement* dom, bool bindDocument=false) const=0;
\r
161 * Assigns ownership of a DOM document to the XMLObject.
\r
162 * This binds the lifetime of the document to the lifetime of the object.
\r
164 * @param doc DOM document bound to this object
\r
166 virtual void setDocument(DOMDocument* doc) const=0;
\r
169 * Releases the DOM representation of this XMLObject, if there is one.
\r
171 virtual void releaseDOM() const=0;
\r
174 * Releases the DOM representation of this XMLObject's parent.
\r
176 * @param propagateRelease true if all ancestors of this element should release their DOM
\r
178 virtual void releaseParentDOM(bool propagateRelease=true) const=0;
\r
181 * Releases the DOM representation of this XMLObject's children.
\r
183 * @param propagateRelease true if all descendants of this element should release their DOM
\r
185 virtual void releaseChildrenDOM(bool propagateRelease=true) const=0;
\r
188 * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true).
\r
190 void releaseThisandParentDOM() const {
\r
193 releaseParentDOM(true);
\r
198 * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM().
\r
200 void releaseThisAndChildrenDOM() const {
\r
202 releaseChildrenDOM(true);
\r
208 * Marshalls the XMLObject, and its children, into a DOM element.
\r
209 * If a document is supplied, then it will be used to create the resulting elements.
\r
210 * If the document does not have a Document Element set, then the resulting
\r
211 * element will be set as the Document Element. If no document is supplied, then
\r
212 * a new document will be created and bound to the lifetime of the root object being
\r
213 * marshalled, unless an existing DOM can be reused without creating a new document.
\r
215 * @param document the DOM document the marshalled element will be placed in, or NULL
\r
216 * @param sigs ordered array of signatures to create after marshalling is complete
\r
217 * @return the DOM element representing this XMLObject
\r
219 * @throws MarshallingException thrown if there is a problem marshalling the given object
\r
220 * @throws SignatureException thrown if a problem occurs during signature creation
\r
222 virtual DOMElement* marshall(
\r
223 DOMDocument* document=NULL
\r
224 #ifndef XMLTOOLING_NO_XMLSEC
\r
225 ,const std::vector<xmlsignature::Signature*>* sigs=NULL
\r
230 * Marshalls the XMLObject and appends it as a child of the given parent element.
\r
232 * <strong>NOTE:</strong> The given Element must be within a DOM tree rooted in
\r
233 * the Document owning the given Element.
\r
235 * @param parentElement the parent element to append the resulting DOM tree
\r
236 * @param sigs ordered array of signatures to create after marshalling is complete
\r
237 * @return the marshalled element tree
\r
239 * @throws MarshallingException thrown if the given XMLObject can not be marshalled.
\r
240 * @throws SignatureException thrown if a problem occurs during signature creation
\r
242 virtual DOMElement* marshall(
\r
243 DOMElement* parentElement
\r
244 #ifndef XMLTOOLING_NO_XMLSEC
\r
245 ,const std::vector<xmlsignature::Signature*>* sigs=NULL
\r
250 * Unmarshalls the given W3C DOM element into the XMLObject.
\r
251 * The root of a given XML construct should be unmarshalled with the bindDocument parameter
\r
254 * @param element the DOM element to unmarshall
\r
255 * @param bindDocument true iff the resulting XMLObject should take ownership of the DOM's Document
\r
257 * @return the unmarshalled XMLObject
\r
259 * @throws UnmarshallingException thrown if an error occurs unmarshalling the DOM element into the XMLObject
\r
261 virtual XMLObject* unmarshall(DOMElement* element, bool bindDocument=false)=0;
\r
266 XMLObject& operator=(const XMLObject& src);
\r
269 #if defined (_MSC_VER)
\r
270 #pragma warning( pop )
\r
275 #endif /* __xmltooling_xmlobj_h__ */
\r