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 Marshaller.h
\r
20 * Transforms XMLObjects into DOM trees
\r
23 #if !defined(__xmltooling_marshaller_h__)
\r
24 #define __xmltooling_marshaller_h__
\r
27 #include <xercesc/dom/DOM.hpp>
\r
28 #include <xmltooling/XMLObject.h>
\r
30 using namespace xercesc;
\r
32 #if defined (_MSC_VER)
\r
33 #pragma warning( push )
\r
34 #pragma warning( disable : 4250 4251 )
\r
37 namespace xmltooling {
\r
40 * Marshallers are used to marshall an XMLObject into a W3C DOM element.
\r
42 class XMLTOOL_API Marshaller
\r
44 MAKE_NONCOPYABLE(Marshaller);
\r
47 virtual ~Marshaller() {}
\r
50 * Marshall this element, and its children, into a W3C DOM element rooted in a given document.
\r
51 * If no document is provided, then the marshaller will create one, and bind it to the
\r
52 * object being marshalled.
\r
54 * @param xmlObject the object to marshall
\r
55 * @param document the DOM document the marshalled element will be rooted in
\r
57 * @return the W3C DOM element representing this XML element
\r
59 * @throws MarshallingException thrown if there is a problem marshalling the given object
\r
61 virtual DOMElement* marshall(XMLObject* xmlObject, DOMDocument* document=NULL) const=0;
\r
64 * Retrieves a Marshaller using the key it was registered with.
\r
66 * @param key the key used to register the marshaller
\r
67 * @return the marshaller or NULL
\r
69 static const Marshaller* getMarshaller(const QName& key) {
\r
70 std::map<QName,Marshaller*>::const_iterator i=m_map.find(key);
\r
71 return (i==m_map.end()) ? NULL : i->second;
\r
75 * Retrieves a Marshaller for an XML object
\r
76 * If no match is found, the default marshaller is returned, if any.
\r
78 * @param xmlObject the object for which to return a marshaller
\r
79 * @return the marshaller or NULL
\r
81 static const Marshaller* getMarshaller(const XMLObject* xmlObject);
\r
84 * Retrieves default Marshaller for DOM elements
\r
86 * @return the default marshaller or NULL
\r
88 static const Marshaller* getDefaultMarshaller() {
\r
93 * Gets an immutable list of all the marshallers currently registered.
\r
95 * @return list of all the marshallers currently registered
\r
97 static const std::map<QName,Marshaller*>& getMarshallers() {
\r
102 * Registers a new marshaller for the given key.
\r
104 * @param key the key used to retrieve this marshaller later
\r
105 * @param marshaller the marshaller
\r
107 static void registerMarshaller(const QName& key, Marshaller* marshaller) {
\r
108 deregisterMarshaller(key);
\r
109 m_map[key]=marshaller;
\r
113 * Registers default marshaller
\r
115 * @param marshaller the default marshaller
\r
117 static void registerDefaultMarshaller(Marshaller* marshaller) {
\r
118 deregisterDefaultMarshaller();
\r
119 m_default=marshaller;
\r
123 * Deregisters a marshaller.
\r
125 * @param key the key for the marshaller to be deregistered
\r
127 static void deregisterMarshaller(const QName& key) {
\r
128 delete getMarshaller(key);
\r
133 * Deregisters default marshaller.
\r
135 static void deregisterDefaultMarshaller() {
\r
141 * Unregisters and destroys all registered marshallers.
\r
143 static void destroyMarshallers();
\r
146 static std::map<QName,Marshaller*> m_map;
\r
147 static Marshaller* m_default;
\r
152 #if defined (_MSC_VER)
\r
153 #pragma warning( pop )
\r
156 #endif /* __xmltooling_marshaller_h__ */
\r