Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLObjectBuilder.h
1 /*\r
2  *  Copyright 2001-2009 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 /**\r
18  * @file xmltooling/XMLObjectBuilder.h\r
19  * \r
20  * Factory interface for XMLObjects.\r
21  */\r
22 \r
23 #ifndef __xmltooling_xmlobjbuilder_h__\r
24 #define __xmltooling_xmlobjbuilder_h__\r
25 \r
26 #include <xmltooling/QName.h>\r
27 #include <xmltooling/XMLObject.h>\r
28 #include <xmltooling/util/XMLHelper.h>\r
29 \r
30 #include <map>\r
31 #include <memory>\r
32 \r
33 #if defined (_MSC_VER)\r
34     #pragma warning( push )\r
35     #pragma warning( disable : 4250 4251 )\r
36 #endif\r
37 \r
38 namespace xmltooling {\r
39 \r
40     /**\r
41      * A factory interface for obtaining XMLObjects.\r
42      * Subclasses MAY supply additional factory methods.\r
43      */\r
44     class XMLTOOL_API XMLObjectBuilder\r
45     {\r
46     MAKE_NONCOPYABLE(XMLObjectBuilder);\r
47     public:\r
48         virtual ~XMLObjectBuilder();\r
49         \r
50         /**\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
53          * \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
59          */\r
60         virtual XMLObject* buildObject(\r
61             const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\r
62             ) const=0;\r
63 \r
64         /**\r
65          * Creates an empty XMLObject with a particular element name.\r
66          * \r
67          * @param q     QName of element for object\r
68          * @return the empty XMLObject\r
69          */\r
70         XMLObject* buildFromQName(const QName& q) const;\r
71 \r
72         /**\r
73          * Creates an unmarshalled XMLObject from a DOM Element.\r
74          * \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
78          */\r
79         XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const;\r
80 \r
81         /**\r
82          * Creates an unmarshalled XMLObject from the root of a DOM Document.\r
83          * \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
87          */\r
88         XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const;\r
89 \r
90         /**\r
91          * Creates an unmarshalled XMLObject using the default build method, if a builder can be found.\r
92          * \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
96          */\r
97         static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false);\r
98 \r
99         /**\r
100          * Retrieves an XMLObjectBuilder using the key it was registered with.\r
101          * \r
102          * @param key the key used to register the builder\r
103          * @return the builder or NULL\r
104          */\r
105         static const XMLObjectBuilder* getBuilder(const QName& key);\r
106 \r
107         /**\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
110          * \r
111          * @param element the element for which to locate a builder\r
112          * @return the builder or NULL\r
113          */\r
114         static const XMLObjectBuilder* getBuilder(const xercesc::DOMElement* element);\r
115 \r
116         /**\r
117          * Retrieves the default XMLObjectBuilder for DOM elements\r
118          * \r
119          * @return the default builder or NULL\r
120          */\r
121         static const XMLObjectBuilder* getDefaultBuilder();\r
122 \r
123         /**\r
124          * Gets an immutable list of all the builders currently registered.\r
125          * \r
126          * @return list of all the builders currently registered\r
127          */\r
128         static const std::map<QName,XMLObjectBuilder*>& getBuilders();\r
129     \r
130         /**\r
131          * Registers a new builder for the given key.\r
132          * \r
133          * @param builderKey the key used to retrieve this builder later\r
134          * @param builder the builder\r
135          */\r
136         static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder);\r
137 \r
138         /**\r
139          * Registers a default builder\r
140          * \r
141          * @param builder the default builder\r
142          */\r
143         static void registerDefaultBuilder(XMLObjectBuilder* builder);\r
144 \r
145         /**\r
146          * Deregisters a builder.\r
147          * \r
148          * @param builderKey the key for the builder to be deregistered\r
149          */\r
150         static void deregisterBuilder(const QName& builderKey);\r
151 \r
152         /**\r
153          * Deregisters default builder.\r
154          */\r
155         static void deregisterDefaultBuilder();\r
156 \r
157         /**\r
158          * Unregisters and destroys all registered builders. \r
159          */\r
160         static void destroyBuilders();\r
161 \r
162     protected:\r
163         XMLObjectBuilder();\r
164     \r
165     private:\r
166         static std::map<QName,XMLObjectBuilder*> m_map;\r
167         static XMLObjectBuilder* m_default;\r
168     };\r
169 \r
170 };\r
171 \r
172 #if defined (_MSC_VER)\r
173     #pragma warning( pop )\r
174 #endif\r
175 \r
176 #endif /* __xmltooling_xmlobjbuilder_h__ */\r