2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/io/AbstractXMLObjectMarshaller.h
24 * A mix-in to implement object marshalling with DOM reuse.
27 #ifndef __xmltooling_xmlmarshaller_h__
28 #define __xmltooling_xmlmarshaller_h__
30 #include <xmltooling/AbstractDOMCachingXMLObject.h>
32 #if defined (_MSC_VER)
33 #pragma warning( push )
34 #pragma warning( disable : 4250 4251 )
37 namespace xmltooling {
40 * A mix-in to implement object marshalling with DOM reuse.
42 class XMLTOOL_API AbstractXMLObjectMarshaller : public virtual AbstractXMLObject
45 virtual ~AbstractXMLObjectMarshaller();
47 xercesc::DOMElement* marshall(
48 xercesc::DOMDocument* document=nullptr
49 #ifndef XMLTOOLING_NO_XMLSEC
50 ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
51 ,const Credential* credential=nullptr
55 xercesc::DOMElement* marshall(
56 xercesc::DOMElement* parentElement
57 #ifndef XMLTOOLING_NO_XMLSEC
58 ,const std::vector<xmlsignature::Signature*>* sigs=nullptr
59 ,const Credential* credential=nullptr
64 AbstractXMLObjectMarshaller();
67 * Sets the given element as the Document Element of the given Document.
68 * If the document already has a Document Element it is replaced by the given element.
70 * @param document the document
71 * @param element the Element that will serve as the Document Element
73 void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const;
75 #ifndef XMLTOOLING_NO_XMLSEC
77 * Marshalls the XMLObject into the given DOM Element.
78 * The DOM Element must be within a DOM tree rooted in the owning Document.
80 * @param targetElement the Element into which the XMLObject is marshalled into
81 * @param sigs optional array of signatures to create after marshalling
82 * @param credential optional credential to supply signing key and related info
84 * @throws MarshallingException thrown if there is a problem marshalling the object
85 * @throws SignatureException thrown if a problem occurs during signature creation
88 xercesc::DOMElement* targetElement, const std::vector<xmlsignature::Signature*>* sigs, const Credential* credential=nullptr
92 * Marshalls the XMLObject into the given DOM Element.
93 * The DOM Element must be within a DOM tree rooted in the owning Document.
95 * @param targetElement the Element into which the XMLObject is marshalled into
97 * @throws MarshallingException thrown if there is a problem marshalling the object
99 void marshallInto(xercesc::DOMElement* targetElement) const;
103 * Creates an xsi:type attribute, corresponding to the given type of the XMLObject, on the DOM element.
105 * @param domElement the DOM element
107 * @throws MarshallingException thrown if the type on the XMLObject is doesn't contain
108 * a local name, prefix, and namespace URI
110 void marshallElementType(xercesc::DOMElement* domElement) const;
113 * Creates the xmlns attributes for any namespaces set on the XMLObject.
115 * @param domElement the DOM element the namespaces will be added to
117 void marshallNamespaces(xercesc::DOMElement* domElement) const;
119 #ifndef XMLTOOLING_NO_XMLSEC
121 * Marshalls the text content and/or child elements of the XMLObject.
123 * @param domElement the DOM element that will recieved the marshalled children
124 * @param credential optional credential to supply signing key and related info
126 * @throws MarshallingException thrown if there is a problem marshalling a child element
128 void marshallContent(xercesc::DOMElement* domElement, const Credential* credential) const;
131 * Marshalls the text content and/or child elements of the XMLObject.
133 * @param domElement the DOM element that will recieved the marshalled children
135 * @throws MarshallingException thrown if there is a problem marshalling a child element
137 void marshallContent(xercesc::DOMElement* domElement) const;
141 * Marshalls the attributes from the XMLObject into the given DOM element.
143 * @param domElement the DOM Element into which attributes will be marshalled
145 * @throws MarshallingException thrown if there is a problem marshalling an attribute
147 virtual void marshallAttributes(xercesc::DOMElement* domElement) const;
150 * Called before marshalling in the event that a new DOM is being generated.
151 * <p>Allows objects to adjust internal state prior to the marshalling step.
153 virtual void prepareForMarshalling() const;
158 #if defined (_MSC_VER)
159 #pragma warning( pop )
162 #endif /* __xmltooling_xmlmarshaller_h__ */