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 #if !defined(__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 #if defined (_MSC_VER)
\r
36 #pragma warning( push )
\r
37 #pragma warning( disable : 4250 4251 )
\r
40 namespace xmltooling {
\r
42 #ifndef XMLTOOLING_NO_XMLSEC
\r
43 class XMLTOOL_API Signature;
\r
44 class XMLTOOL_API SigningContext;
\r
48 * Supplies additional information to the marshalling process.
\r
49 * Currently this only consists of signature related information.
\r
51 class XMLTOOL_API MarshallingContext
\r
53 MAKE_NONCOPYABLE(MarshallingContext);
\r
55 MarshallingContext() {}
\r
56 ~MarshallingContext() {}
\r
58 #ifndef XMLTOOLING_NO_XMLSEC
\r
59 MarshallingContext(Signature* sig, const SigningContext* ctx) {
\r
60 m_signingContexts.push_back(std::make_pair(sig,ctx));
\r
63 /** Array of signing contexts, keyed off of the associated Signature */
\r
64 std::vector< std::pair<Signature*,const SigningContext*> > m_signingContexts;
\r
69 * Object that represents an XML Element that has been unmarshalled into this C++ object.
\r
71 class XMLTOOL_API XMLObject
\r
73 MAKE_NONCOPYABLE(XMLObject);
\r
75 virtual ~XMLObject() {}
\r
78 * Creates a copy of the object, along with all of its children.
\r
80 * The new object tree will be completely distinct and independent of
\r
81 * the original in all respects.
\r
83 virtual XMLObject* clone() const=0;
\r
86 * Gets the QName for this element. This QName <strong>MUST</strong>
\r
87 * contain the namespace URI, namespace prefix, and local element name.
\r
89 * @return constant reference to the QName for this object
\r
91 virtual const QName& getElementQName() const=0;
\r
94 * Sets the namespace prefix for this element.
\r
96 * @param prefix the prefix for this element
\r
98 virtual void setElementNamespacePrefix(const XMLCh* prefix)=0;
\r
101 * Gets the namespaces that are scoped to this element.
\r
103 * The caller MUST NOT modify the set returned, but may use any
\r
104 * non-modifying operations or algorithms on it. Iterators will
\r
105 * remain valid unless the set member referenced is removed using
\r
106 * the removeNamespace method.
\r
108 * @return the namespaces that are scoped to this element
\r
110 virtual const std::set<Namespace>& getNamespaces() const=0;
\r
113 * Adds a namespace to the ones already scoped to this element
\r
115 * @param ns the namespace to add
\r
117 virtual void addNamespace(const Namespace& ns) const=0;
\r
120 * Removes a namespace from this element
\r
122 * @param ns the namespace to remove
\r
124 virtual void removeNamespace(const Namespace& ns)=0;
\r
127 * Gets the XML schema type of this element. This translates to contents the xsi:type
\r
128 * attribute for the element.
\r
130 * @return XML schema type of this element
\r
132 virtual const QName* getSchemaType() const=0;
\r
135 * Sets the XML schema type of this element. This translates to contents the xsi:type
\r
136 * attribute for the element.
\r
138 * @param type XML schema type of this element
\r
140 virtual void setSchemaType(const QName* type)=0;
\r
143 * Checks to see if this object has a parent.
\r
145 * @return true if the object has a parent, false if not
\r
147 virtual bool hasParent() const=0;
\r
150 * Gets the parent of this element or null if there is no parent.
\r
152 * @return the parent of this element or null
\r
154 virtual XMLObject* getParent() const=0;
\r
157 * Sets the parent of this element.
\r
159 * @param parent the parent of this element
\r
161 virtual void setParent(XMLObject* parent)=0;
\r
164 * Checks if this XMLObject has children.
\r
166 * @return true if this XMLObject has children, false if not
\r
168 virtual bool hasChildren() const=0;
\r
171 * Returns an unmodifiable list of child objects in the order that they
\r
172 * should appear in the serialized representation.
\r
174 * The validity of the returned list is not maintained if any non-const
\r
175 * operations are performed on the parent object.
\r
177 * @return the list of children
\r
179 virtual const std::list<XMLObject*>& getOrderedChildren() const=0;
\r
182 * Marshalls the XMLObject, and its children, into a DOM element.
\r
183 * If a document is supplied, then it will be used to create the resulting elements.
\r
184 * If the document does not have a Document Element set, then the resulting
\r
185 * element will be set as the Document Element. If no document is supplied, then
\r
186 * a new document will be created and bound to the lifetime of the root object being
\r
187 * marshalled, unless an existing DOM can be reused without creating a new document.
\r
189 * @param document the DOM document the marshalled element will be placed in, or NULL
\r
190 * @param ctx optional marshalling context
\r
191 * @return the DOM element representing this XMLObject
\r
193 * @throws MarshallingException thrown if there is a problem marshalling the given object
\r
194 * @throws SignatureException thrown if a problem occurs during signature creation
\r
196 virtual DOMElement* marshall(DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const=0;
\r
199 * Marshalls the XMLObject and appends it as a child of the given parent element.
\r
201 * <strong>NOTE:</strong> The given Element must be within a DOM tree rooted in
\r
202 * the Document owning the given Element.
\r
204 * @param parentElement the parent element to append the resulting DOM tree
\r
205 * @param ctx optional marshalling context
\r
206 * @return the marshalled element tree
\r
208 * @throws MarshallingException thrown if the given XMLObject can not be marshalled.
\r
209 * @throws SignatureException thrown if a problem occurs during signature creation
\r
211 virtual DOMElement* marshall(DOMElement* parentElement, MarshallingContext* ctx=NULL) const=0;
\r
214 * Unmarshalls the given W3C DOM element into the XMLObject.
\r
215 * The root of a given XML construct should be unmarshalled with the bindDocument parameter
\r
218 * @param element the DOM element to unmarshall
\r
219 * @param bindDocument true iff the resulting XMLObject should take ownership of the DOM's Document
\r
221 * @return the unmarshalled XMLObject
\r
223 * @throws UnmarshallingException thrown if an error occurs unmarshalling the DOM element into the XMLObject
\r
225 virtual XMLObject* unmarshall(DOMElement* element, bool bindDocument=false)=0;
\r
231 #if defined (_MSC_VER)
\r
232 #pragma warning( pop )
\r
237 #endif /* __xmltooling_xmlobj_h__ */
\r