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
18 * @file AbstractXMLObjectMarshaller.h
\r
20 * A thread-safe abstract marshaller.
\r
23 #if !defined(__xmltooling_xmlmarshaller_h__)
\r
24 #define __xmltooling_xmlmarshaller_h__
\r
26 #include <xmltooling/io/Marshaller.h>
\r
28 namespace xmltooling {
\r
31 * A thread-safe abstract marshaller.
\r
33 class XMLTOOL_API AbstractXMLObjectMarshaller : public virtual Marshaller
\r
36 virtual ~AbstractXMLObjectMarshaller() {}
\r
39 * @see Marshaller::marshall(XMLObject*,DOMDocument*,const MarshallingContext*)
\r
41 DOMElement* marshall(XMLObject* xmlObject, DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const;
\r
44 * @see Marshaller::marshall(XMLObject*,DOMElement*,const MarshallingContext*)
\r
46 DOMElement* marshall(XMLObject* xmlObject, DOMElement* parentElement, MarshallingContext* ctx=NULL) const;
\r
49 AbstractXMLObjectMarshaller();
\r
52 * Sets the given element as the Document Element of the given Document.
\r
53 * If the document already has a Document Element it is replaced by the given element.
\r
55 * @param document the document
\r
56 * @param element the Element that will serve as the Document Element
\r
58 void setDocumentElement(DOMDocument* document, DOMElement* element) const {
\r
59 DOMElement* documentRoot = document->getDocumentElement();
\r
61 document->replaceChild(documentRoot, element);
\r
63 document->appendChild(element);
\r
67 * Marshalls the given XMLObject into the given DOM Element.
\r
68 * The DOM Element must be within a DOM tree rooted in the owning Document.
\r
70 * @param xmlObject the XMLObject to marshall
\r
71 * @param targetElement the Element into which the XMLObject is marshalled into
\r
72 * @param ctx optional marshalling context
\r
74 * @throws MarshallingException thrown if there is a problem marshalling the object
\r
75 * @throws SignatureException thrown if a problem occurs during signature creation
\r
77 void marshallInto(XMLObject& xmlObject, DOMElement* targetElement, MarshallingContext* ctx) const;
\r
80 * Creates an xsi:type attribute, corresponding to the given type of the XMLObject, on the DOM element.
\r
82 * @param xmlObject the XMLObject
\r
83 * @param domElement the DOM element
\r
85 * @throws MarshallingException thrown if the type on the XMLObject is doesn't contain
\r
86 * a local name, prefix, and namespace URI
\r
88 void marshallElementType(XMLObject& xmlObject, DOMElement* domElement) const;
\r
91 * Creates the xmlns attributes for any namespaces set on the given XMLObject.
\r
93 * @param xmlObject the XMLObject
\r
94 * @param domElement the DOM element the namespaces will be added to
\r
96 void marshallNamespaces(const XMLObject& xmlObject, DOMElement* domElement) const;
\r
99 * Marshalls the child elements of the given XMLObject.
\r
101 * @param xmlObject the XMLObject whose children will be marshalled
\r
102 * @param domElement the DOM element that will recieved the marshalled children
\r
104 * @throws MarshallingException thrown if there is a problem marshalling a child element
\r
106 void marshallChildElements(const XMLObject& xmlObject, DOMElement* domElement) const;
\r
109 * Marshalls the attributes from the given XMLObject into the given DOM element.
\r
110 * The XMLObject passed to this method is guaranteed to be of the target name
\r
111 * specified during this marshaller's construction.
\r
113 * @param xmlObject the XMLObject being marshalled
\r
114 * @param domElement the DOM Element into which attributes will be marshalled
\r
116 * @throws UnmarshallingException thrown if there is a problem unmarshalling an attribute
\r
118 virtual void marshallAttributes(const XMLObject& xmlObject, DOMElement* domElement) const=0;
\r
121 * Marshalls data from the XMLObject into content of the DOM Element.
\r
123 * @param xmlObject the XMLObject
\r
124 * @param domElement the DOM element recieving the content
\r
126 virtual void marshallElementContent(const XMLObject& xmlObject, DOMElement* domElement) const=0;
\r
133 #endif /* __xmltooling_xmlmarshaller_h__ */
\r