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