2 * Copyright 2001-2006 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file AbstractXMLObjectMarshaller.h
20 * A thread-safe abstract marshaller.
23 #if !defined(__xmltooling_xmlmarshaller_h__)
24 #define __xmltooling_xmlmarshaller_h__
26 #include <xmltooling/AbstractDOMCachingXMLObject.h>
28 #if defined (_MSC_VER)
29 #pragma warning( push )
30 #pragma warning( disable : 4250 4251 )
33 namespace xmltooling {
36 * A thread-safe abstract marshaller.
38 class XMLTOOL_API AbstractXMLObjectMarshaller : public virtual AbstractXMLObject
41 virtual ~AbstractXMLObjectMarshaller() {}
44 DOMDocument* document=NULL
45 #ifndef XMLTOOLING_NO_XMLSEC
46 ,const std::vector<xmlsignature::Signature*>* sigs=NULL
51 DOMElement* parentElement
52 #ifndef XMLTOOLING_NO_XMLSEC
53 ,const std::vector<xmlsignature::Signature*>* sigs=NULL
58 AbstractXMLObjectMarshaller() {}
61 * Sets the given element as the Document Element of the given Document.
62 * If the document already has a Document Element it is replaced by the given element.
64 * @param document the document
65 * @param element the Element that will serve as the Document Element
67 void setDocumentElement(DOMDocument* document, DOMElement* element) const {
68 DOMElement* documentRoot = document->getDocumentElement();
70 document->replaceChild(element, documentRoot);
72 document->appendChild(element);
76 * Marshalls the XMLObject into the given DOM Element.
77 * The DOM Element must be within a DOM tree rooted in the owning Document.
79 * @param targetElement the Element into which the XMLObject is marshalled into
80 * @param ctx optional marshalling context
82 * @throws MarshallingException thrown if there is a problem marshalling the object
83 * @throws SignatureException thrown if a problem occurs during signature creation
86 DOMElement* targetElement
87 #ifndef XMLTOOLING_NO_XMLSEC
88 ,const std::vector<xmlsignature::Signature*>* sigs
93 * Creates an xsi:type attribute, corresponding to the given type of the XMLObject, on the DOM element.
95 * @param domElement the DOM element
97 * @throws MarshallingException thrown if the type on the XMLObject is doesn't contain
98 * a local name, prefix, and namespace URI
100 void marshallElementType(DOMElement* domElement) const;
103 * Creates the xmlns attributes for any namespaces set on the XMLObject.
105 * @param domElement the DOM element the namespaces will be added to
107 void marshallNamespaces(DOMElement* domElement) const;
110 * Marshalls the text content and/or child elements of the XMLObject.
112 * @param domElement the DOM element that will recieved the marshalled children
114 * @throws MarshallingException thrown if there is a problem marshalling a child element
116 void marshallContent(DOMElement* domElement) const;
119 * Marshalls the attributes from the XMLObject into the given DOM element.
121 * @param domElement the DOM Element into which attributes will be marshalled
123 * @throws MarshallingException thrown if there is a problem marshalling an attribute
125 virtual void marshallAttributes(DOMElement* domElement) const {}
130 #if defined (_MSC_VER)
131 #pragma warning( pop )
134 #endif /* __xmltooling_xmlmarshaller_h__ */