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 Unmarshaller.h
\r
20 * Transforms DOM trees into XMLObjects
\r
23 #if !defined(__xmltooling_unmarshaller_h__)
\r
24 #define __xmltooling_unmarshaller_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 * Unmarshallers are used to unmarshall a W3C DOM element into an XMLObject.
\r
42 class XMLTOOL_API Unmarshaller
\r
44 MAKE_NONCOPYABLE(Unmarshaller);
\r
47 virtual ~Unmarshaller() {}
\r
50 * Unmarshalls the given W3C DOM element into an XMLObject.
\r
51 * The root of a given XML construct should be unmarshalled with the bindDocument parameter
\r
54 * @param element the DOM element to unmarshall
\r
55 * @param bindDocument true iff the resulting XMLObject should take ownership of the DOM's Document
\r
57 * @return the unmarshalled XMLObject
\r
59 * @throws UnmarshallingException thrown if an error occurs unmarshalling the DOM element into the XMLObject
\r
61 virtual XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const=0;
\r
64 * Retrieves an unmarshaller using the key it was registered with.
\r
66 * @param key the key used to register the unmarshaller
\r
67 * @return the unmarshaller
\r
69 static const Unmarshaller* getUnmarshaller(const QName& key) {
\r
70 std::map<QName,Unmarshaller*>::const_iterator i=m_map.find(key);
\r
71 return (i==m_map.end()) ? NULL : i->second;
\r
75 * Retrieves an Unmarshaller for a DOM element.
\r
76 * If no match is found, the default unmarshaller is returned, if any.
\r
78 * @param element the element for which to return an unmarshaller
\r
79 * @return the unmarshaller or NULL
\r
81 static const Unmarshaller* getUnmarshaller(const DOMElement* key);
\r
84 * Retrieves the default Unmarshaller for an unknown DOM element
\r
86 * @return the default unmarshaller or NULL
\r
88 static const Unmarshaller* getDefaultUnmarshaller() {
\r
93 * Gets an immutable list of all the unmarshallers currently registered.
\r
95 * @return list of all the unmarshallers currently registered
\r
97 static const std::map<QName,Unmarshaller*>& getUnmarshallers() {
\r
102 * Registers a new unmarshaller for the given key.
\r
104 * @param key the key used to retrieve this unmarshaller later
\r
105 * @param unmarshaller the unmarshaller
\r
107 static void registerUnmarshaller(const QName& key, Unmarshaller* unmarshaller) {
\r
108 deregisterUnmarshaller(key);
\r
109 m_map[key]=unmarshaller;
\r
113 * Registers a new default unmarshaller
\r
115 * @param unmarshaller the default unmarshaller
\r
117 static void registerDefaultUnmarshaller(Unmarshaller* unmarshaller) {
\r
118 deregisterDefaultUnmarshaller();
\r
119 m_default=unmarshaller;
\r
123 * Deregisters a unmarshaller.
\r
125 * @param key the key for the unmarshaller to be deregistered
\r
127 static void deregisterUnmarshaller(const QName& key) {
\r
128 delete getUnmarshaller(key);
\r
133 * Deregisters the default unmarshaller.
\r
135 static void deregisterDefaultUnmarshaller() {
\r
141 * Unregisters and destroys all registered unmarshallers.
\r
143 static void destroyUnmarshallers();
\r
146 static std::map<QName,Unmarshaller*> m_map;
\r
147 static Unmarshaller* m_default;
\r
152 #if defined (_MSC_VER)
\r
153 #pragma warning( pop )
\r
156 #endif /* __xmltooling_unmarshaller_h__ */
\r