2 * Copyright 2001-2009 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 xmltooling/XMLObjectBuilder.h
20 * Factory interface for XMLObjects.
23 #ifndef __xmltooling_xmlobjbuilder_h__
24 #define __xmltooling_xmlobjbuilder_h__
26 #include <xmltooling/QName.h>
27 #include <xmltooling/XMLObject.h>
28 #include <xmltooling/util/XMLHelper.h>
33 #if defined (_MSC_VER)
34 #pragma warning( push )
35 #pragma warning( disable : 4250 4251 )
38 namespace xmltooling {
41 * A factory interface for obtaining XMLObjects.
42 * Subclasses MAY supply additional factory methods.
44 class XMLTOOL_API XMLObjectBuilder
46 MAKE_NONCOPYABLE(XMLObjectBuilder);
48 virtual ~XMLObjectBuilder();
51 * Creates an empty XMLObject with a particular element name.
52 * <p>The results are undefined if localName is NULL or empty.
54 * @param nsURI namespace URI for element
55 * @param localName local name of element
56 * @param prefix prefix of element name
57 * @param schemaType xsi:type of the object
58 * @return the empty XMLObject
60 virtual XMLObject* buildObject(
61 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
65 * Creates an empty XMLObject with a particular element name.
67 * @param q QName of element for object
68 * @return the empty XMLObject
70 XMLObject* buildFromQName(const QName& q) const;
73 * Creates an unmarshalled XMLObject from a DOM Element.
75 * @param element the unmarshalling source
76 * @param bindDocument true iff the XMLObject should take ownership of the DOM Document
77 * @return the unmarshalled XMLObject
79 XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const;
82 * Creates an unmarshalled XMLObject from the root of a DOM Document.
84 * @param doc the unmarshalling source
85 * @param bindDocument true iff the XMLObject should take ownership of the DOM Document
86 * @return the unmarshalled XMLObject
88 XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const;
91 * Creates an unmarshalled XMLObject using the default build method, if a builder can be found.
93 * @param element the unmarshalling source
94 * @param bindDocument true iff the new XMLObject should take ownership of the DOM Document
95 * @return the unmarshalled object or NULL if no builder is available
97 static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false);
100 * Retrieves an XMLObjectBuilder using the key it was registered with.
102 * @param key the key used to register the builder
103 * @return the builder or NULL
105 static const XMLObjectBuilder* getBuilder(const QName& key);
108 * Retrieves an XMLObjectBuilder for a given DOM element.
109 * If no match is found, the default builder is returned, if any.
111 * @param element the element for which to locate a builder
112 * @return the builder or NULL
114 static const XMLObjectBuilder* getBuilder(const xercesc::DOMElement* element);
117 * Retrieves the default XMLObjectBuilder for DOM elements
119 * @return the default builder or NULL
121 static const XMLObjectBuilder* getDefaultBuilder();
124 * Gets an immutable list of all the builders currently registered.
126 * @return list of all the builders currently registered
128 static const std::map<QName,XMLObjectBuilder*>& getBuilders();
131 * Registers a new builder for the given key.
133 * @param builderKey the key used to retrieve this builder later
134 * @param builder the builder
136 static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder);
139 * Registers a default builder
141 * @param builder the default builder
143 static void registerDefaultBuilder(XMLObjectBuilder* builder);
146 * Deregisters a builder.
148 * @param builderKey the key for the builder to be deregistered
150 static void deregisterBuilder(const QName& builderKey);
153 * Deregisters default builder.
155 static void deregisterDefaultBuilder();
158 * Unregisters and destroys all registered builders.
160 static void destroyBuilders();
166 static std::map<QName,XMLObjectBuilder*> m_map;
167 static XMLObjectBuilder* m_default;
172 #if defined (_MSC_VER)
173 #pragma warning( pop )
176 #endif /* __xmltooling_xmlobjbuilder_h__ */