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/AbstractDOMCachingXMLObject.h>
\r
28 #if defined (_MSC_VER)
\r
29 #pragma warning( push )
\r
30 #pragma warning( disable : 4250 4251 )
\r
33 namespace xmltooling {
\r
36 * A thread-safe abstract marshaller.
\r
38 class XMLTOOL_API AbstractXMLObjectMarshaller : public virtual AbstractDOMCachingXMLObject
\r
41 virtual ~AbstractXMLObjectMarshaller() {}
\r
44 * @see XMLObject::marshall(DOMDocument*,const MarshallingContext*)
\r
46 DOMElement* marshall(DOMDocument* document=NULL, MarshallingContext* ctx=NULL) const;
\r
49 * @see XMLObject::marshall(DOMElement*,const MarshallingContext*)
\r
51 DOMElement* marshall(DOMElement* parentElement, MarshallingContext* ctx=NULL) const;
\r
54 AbstractXMLObjectMarshaller() {}
\r
57 * Sets the given element as the Document Element of the given Document.
\r
58 * If the document already has a Document Element it is replaced by the given element.
\r
60 * @param document the document
\r
61 * @param element the Element that will serve as the Document Element
\r
63 void setDocumentElement(DOMDocument* document, DOMElement* element) const {
\r
64 DOMElement* documentRoot = document->getDocumentElement();
\r
66 document->replaceChild(documentRoot, element);
\r
68 document->appendChild(element);
\r
72 * Marshalls the XMLObject into the given DOM Element.
\r
73 * The DOM Element must be within a DOM tree rooted in the owning Document.
\r
75 * @param targetElement the Element into which the XMLObject is marshalled into
\r
76 * @param ctx optional marshalling context
\r
78 * @throws MarshallingException thrown if there is a problem marshalling the object
\r
79 * @throws SignatureException thrown if a problem occurs during signature creation
\r
81 void marshallInto(DOMElement* targetElement, MarshallingContext* ctx) const;
\r
84 * Creates an xsi:type attribute, corresponding to the given type of the XMLObject, on the DOM element.
\r
86 * @param domElement the DOM element
\r
88 * @throws MarshallingException thrown if the type on the XMLObject is doesn't contain
\r
89 * a local name, prefix, and namespace URI
\r
91 void marshallElementType(DOMElement* domElement) const;
\r
94 * Creates the xmlns attributes for any namespaces set on the XMLObject.
\r
96 * @param domElement the DOM element the namespaces will be added to
\r
98 void marshallNamespaces(DOMElement* domElement) const;
\r
101 * Marshalls the child elements of the XMLObject.
\r
103 * @param domElement the DOM element that will recieved the marshalled children
\r
105 * @throws MarshallingException thrown if there is a problem marshalling a child element
\r
107 void marshallChildElements(DOMElement* domElement) const;
\r
110 * Marshalls the attributes from the XMLObject into the given DOM element.
\r
112 * @param domElement the DOM Element into which attributes will be marshalled
\r
114 * @throws MarshallingException thrown if there is a problem marshalling an attribute
\r
116 virtual void marshallAttributes(DOMElement* domElement) const=0;
\r
119 * Marshalls data from the XMLObject into content of the DOM Element.
\r
121 * @param domElement the DOM element recieving the content
\r
123 virtual void marshallElementContent(DOMElement* domElement) const=0;
\r
128 #if defined (_MSC_VER)
\r
129 #pragma warning( pop )
\r
132 #endif /* __xmltooling_xmlmarshaller_h__ */
\r