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 XMLObjectBuilder.h
\r
20 * Factory interface for XMLObjects
\r
23 #if !defined(__xmltooling_xmlobjbuilder_h__)
\r
24 #define __xmltooling_xmlobjbuilder_h__
\r
27 #include <xmltooling/QName.h>
\r
28 #include <xmltooling/XMLObject.h>
\r
30 #if defined (_MSC_VER)
\r
31 #pragma warning( push )
\r
32 #pragma warning( disable : 4250 4251 )
\r
35 namespace xmltooling {
\r
38 * A factory interface for obtaining XMLObjects.
\r
39 * Subclasses MAY supply additional factory methods.
\r
41 class XMLTOOL_API XMLObjectBuilder
\r
43 MAKE_NONCOPYABLE(XMLObjectBuilder);
\r
45 virtual ~XMLObjectBuilder() {}
\r
48 * Creates an empty XMLObject.
\r
50 * @return the empty XMLObject
\r
52 virtual XMLObject* buildObject()=0;
\r
55 * Resets the state of the builder.
\r
57 * This normally means null'ing out any properties that were
\r
58 * needed to build an object.
\r
60 virtual void resetState()=0;
\r
63 * Retrieves an XMLObjectBuilder using the key it was registered with.
\r
65 * @param key the key used to register the builder
\r
66 * @return the builder
\r
68 static XMLObjectBuilder* getBuilder(const QName& key) {
\r
69 std::map<QName,XMLObjectBuilder*>::const_iterator i=m_map.find(key);
\r
70 return (i==m_map.end()) ? NULL : i->second;
\r
74 * Gets an immutable list of all the builders currently registered.
\r
76 * @return list of all the builders currently registered
\r
78 static const std::map<QName,XMLObjectBuilder*>& getBuilders() {
\r
83 * Registers a new builder for the given key.
\r
85 * @param builderKey the key used to retrieve this builder later
\r
86 * @param builder the builder
\r
88 static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder) {
\r
89 m_map[builderKey]=builder;
\r
93 * Deregisters a builder.
\r
95 * @param builderKey the key for the builder to be deregistered
\r
97 static void deregisterBuilder(const QName& builderKey) {
\r
98 delete getBuilder(builderKey);
\r
99 m_map.erase(builderKey);
\r
103 * Unregisters and destroys all registered builders.
\r
105 static void destroyBuilders();
\r
108 static std::map<QName,XMLObjectBuilder*> m_map;
\r
113 #if defined (_MSC_VER)
\r
114 #pragma warning( pop )
\r
117 #endif /* __xmltooling_xmlobjbuilder_h__ */
\r