1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: DatatypeValidatorFactory.hpp 568078 2007-08-21 11:43:25Z amassari $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(DATATYPEVALIDATORFACTORY_HPP) |
---|
23 | #define DATATYPEVALIDATORFACTORY_HPP |
---|
24 | |
---|
25 | /** |
---|
26 | * This class implements a factory of Datatype Validators. Internally the |
---|
27 | * DatatypeValidators are kept in a registry. |
---|
28 | * There is one instance of DatatypeValidatorFactory per Parser. |
---|
29 | * There is one datatype Registry per instance of DatatypeValidatorFactory, |
---|
30 | * such registry is first allocated with the number DatatypeValidators needed. |
---|
31 | * e.g. |
---|
32 | * If Parser finds an XML document with a DTD, a registry of DTD validators (only |
---|
33 | * 9 validators) get initialized in the registry. |
---|
34 | * The initialization process consist of instantiating the Datatype and |
---|
35 | * facets and registering the Datatype into registry table. |
---|
36 | * This implementation uses a Hahtable as a registry. The datatype validators created |
---|
37 | * by the factory will be deleted by the registry. |
---|
38 | * |
---|
39 | * As the Parser parses an instance document it knows if validation needs |
---|
40 | * to be checked. If no validation is necesary we should not instantiate a |
---|
41 | * DatatypeValidatorFactory. |
---|
42 | * If validation is needed, we need to instantiate a DatatypeValidatorFactory. |
---|
43 | */ |
---|
44 | |
---|
45 | // --------------------------------------------------------------------------- |
---|
46 | // Includes |
---|
47 | // --------------------------------------------------------------------------- |
---|
48 | #include <xercesc/validators/datatype/DatatypeValidator.hpp> |
---|
49 | #include <xercesc/validators/datatype/XMLCanRepGroup.hpp> |
---|
50 | #include <xercesc/util/RefVectorOf.hpp> |
---|
51 | |
---|
52 | #include <xercesc/internal/XSerializable.hpp> |
---|
53 | |
---|
54 | XERCES_CPP_NAMESPACE_BEGIN |
---|
55 | |
---|
56 | // --------------------------------------------------------------------------- |
---|
57 | // DatatypeValidatorFactory: Local declaration |
---|
58 | // --------------------------------------------------------------------------- |
---|
59 | typedef RefHashTableOf<KVStringPair> KVStringPairHashTable; |
---|
60 | typedef RefHashTableOf<DatatypeValidator> DVHashTable; |
---|
61 | typedef RefArrayVectorOf<XMLCh> XMLChRefVector; |
---|
62 | |
---|
63 | |
---|
64 | class VALIDATORS_EXPORT DatatypeValidatorFactory : public XSerializable, public XMemory |
---|
65 | { |
---|
66 | public: |
---|
67 | |
---|
68 | // ----------------------------------------------------------------------- |
---|
69 | // Public Constructors and Destructor |
---|
70 | // ----------------------------------------------------------------------- |
---|
71 | /** @name Constructors */ |
---|
72 | //@{ |
---|
73 | |
---|
74 | DatatypeValidatorFactory |
---|
75 | ( |
---|
76 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
77 | ); |
---|
78 | |
---|
79 | //@} |
---|
80 | |
---|
81 | /** @name Destructor. */ |
---|
82 | //@{ |
---|
83 | |
---|
84 | ~DatatypeValidatorFactory(); |
---|
85 | |
---|
86 | //@} |
---|
87 | |
---|
88 | // ----------------------------------------------------------------------- |
---|
89 | // Getter methods |
---|
90 | // ----------------------------------------------------------------------- |
---|
91 | /** @name Getter Functions */ |
---|
92 | //@{ |
---|
93 | |
---|
94 | /** |
---|
95 | * Returns the datatype validator |
---|
96 | * |
---|
97 | * @param dvType Datatype validator name/type |
---|
98 | */ |
---|
99 | DatatypeValidator* getDatatypeValidator(const XMLCh* const dvType) const; |
---|
100 | |
---|
101 | /** |
---|
102 | * Returns the user defined registry of types |
---|
103 | **/ |
---|
104 | DVHashTable* getUserDefinedRegistry() const; |
---|
105 | |
---|
106 | |
---|
107 | /** |
---|
108 | * Returns the built in registry of types |
---|
109 | **/ |
---|
110 | static DVHashTable* getBuiltInRegistry(); |
---|
111 | |
---|
112 | //@} |
---|
113 | |
---|
114 | // ----------------------------------------------------------------------- |
---|
115 | // Registry Initialization methods |
---|
116 | // ----------------------------------------------------------------------- |
---|
117 | /** @name Registry Initialization Functions */ |
---|
118 | //@{ |
---|
119 | |
---|
120 | /** |
---|
121 | * Initializes registry with primitive and derived Simple types. |
---|
122 | * |
---|
123 | * This method does not clear the registry to clear the registry you |
---|
124 | * have to call resetRegistry. |
---|
125 | * |
---|
126 | * The net effect of this method is to start with the smallest set of |
---|
127 | * datatypes needed by the validator. |
---|
128 | * |
---|
129 | * If we start with Schema's then we initialize to full set of |
---|
130 | * validators. |
---|
131 | */ |
---|
132 | void expandRegistryToFullSchemaSet(); |
---|
133 | |
---|
134 | //@} |
---|
135 | |
---|
136 | // ----------------------------------------------------------------------- |
---|
137 | // Canonical Representation Group |
---|
138 | // ----------------------------------------------------------------------- |
---|
139 | void initCanRepRegistory(); |
---|
140 | |
---|
141 | static XMLCanRepGroup::CanRepGroup getCanRepGroup(const DatatypeValidator* const); |
---|
142 | |
---|
143 | static DatatypeValidator* getBuiltInBaseValidator(const DatatypeValidator* const); |
---|
144 | |
---|
145 | // ----------------------------------------------------------------------- |
---|
146 | // Validator Factory methods |
---|
147 | // ----------------------------------------------------------------------- |
---|
148 | /** @name Validator Factory Functions */ |
---|
149 | //@{ |
---|
150 | |
---|
151 | /** |
---|
152 | * Creates a new datatype validator of type baseValidator's class and |
---|
153 | * adds it to the registry |
---|
154 | * |
---|
155 | * @param typeName Datatype validator name |
---|
156 | * |
---|
157 | * @param baseValidator Base datatype validator |
---|
158 | * |
---|
159 | * @param facets datatype facets if any |
---|
160 | * |
---|
161 | * @param enums vector of values for enum facet |
---|
162 | * |
---|
163 | * @param isDerivedByList Indicates whether the datatype is derived by |
---|
164 | * list or not |
---|
165 | * |
---|
166 | * @param finalSet 'final' values of the simpleType |
---|
167 | * |
---|
168 | * @param isUserDefined Indicates whether the datatype is built-in or |
---|
169 | * user defined |
---|
170 | */ |
---|
171 | DatatypeValidator* createDatatypeValidator |
---|
172 | ( |
---|
173 | const XMLCh* const typeName |
---|
174 | , DatatypeValidator* const baseValidator |
---|
175 | , RefHashTableOf<KVStringPair>* const facets |
---|
176 | , RefArrayVectorOf<XMLCh>* const enums |
---|
177 | , const bool isDerivedByList |
---|
178 | , const int finalSet = 0 |
---|
179 | , const bool isUserDefined = true |
---|
180 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
181 | ); |
---|
182 | |
---|
183 | /** |
---|
184 | * Creates a new datatype validator of type UnionDatatypeValidator and |
---|
185 | * adds it to the registry |
---|
186 | * |
---|
187 | * @param typeName Datatype validator name |
---|
188 | * |
---|
189 | * @param validators Vector of datatype validators |
---|
190 | * |
---|
191 | * @param finalSet 'final' values of the simpleType |
---|
192 | * |
---|
193 | * @param isUserDefined Indicates whether the datatype is built-in or |
---|
194 | * user defined |
---|
195 | */ |
---|
196 | DatatypeValidator* createDatatypeValidator |
---|
197 | ( |
---|
198 | const XMLCh* const typeName |
---|
199 | , RefVectorOf<DatatypeValidator>* const validators |
---|
200 | , const int finalSet |
---|
201 | , const bool isUserDefined = true |
---|
202 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
---|
203 | ); |
---|
204 | |
---|
205 | //@} |
---|
206 | |
---|
207 | /** |
---|
208 | * Reset datatype validator registry |
---|
209 | */ |
---|
210 | void resetRegistry(); |
---|
211 | |
---|
212 | // ----------------------------------------------------------------------- |
---|
213 | // Notification that lazy data has been deleted |
---|
214 | // ----------------------------------------------------------------------- |
---|
215 | static void reinitRegistry(); |
---|
216 | |
---|
217 | /*** |
---|
218 | * Support for Serialization/De-serialization |
---|
219 | ***/ |
---|
220 | DECL_XSERIALIZABLE(DatatypeValidatorFactory) |
---|
221 | |
---|
222 | private: |
---|
223 | |
---|
224 | // ----------------------------------------------------------------------- |
---|
225 | // CleanUp methods |
---|
226 | // ----------------------------------------------------------------------- |
---|
227 | void cleanUp(); |
---|
228 | |
---|
229 | // ----------------------------------------------------------------------- |
---|
230 | // Unimplemented constructors and operators |
---|
231 | // ----------------------------------------------------------------------- |
---|
232 | DatatypeValidatorFactory(const DatatypeValidatorFactory&); |
---|
233 | DatatypeValidatorFactory& operator=(const DatatypeValidatorFactory&); |
---|
234 | |
---|
235 | // ----------------------------------------------------------------------- |
---|
236 | // Private data members |
---|
237 | // |
---|
238 | // fUserDefinedRegistry |
---|
239 | // This is a hashtable of user defined dataype validators. |
---|
240 | // |
---|
241 | // fBuiltInRegistry |
---|
242 | // This is a hashtable of built-in primitive datatype validators. |
---|
243 | // ----------------------------------------------------------------------- |
---|
244 | XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XERCES_CPP_NAMESPACE_QUALIFIER DatatypeValidator>* fUserDefinedRegistry; |
---|
245 | static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<DatatypeValidator>* fBuiltInRegistry; |
---|
246 | static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XMLCanRepGroup>* fCanRepRegistry; |
---|
247 | XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const fMemoryManager; |
---|
248 | |
---|
249 | friend class XPath2ContextImpl; |
---|
250 | }; |
---|
251 | |
---|
252 | inline DatatypeValidator* |
---|
253 | DatatypeValidatorFactory::getDatatypeValidator(const XMLCh* const dvType) const |
---|
254 | { |
---|
255 | if (dvType) { |
---|
256 | if (fBuiltInRegistry && fBuiltInRegistry->containsKey(dvType)) { |
---|
257 | return fBuiltInRegistry->get(dvType); |
---|
258 | } |
---|
259 | |
---|
260 | if (fUserDefinedRegistry && fUserDefinedRegistry->containsKey(dvType)) { |
---|
261 | return fUserDefinedRegistry->get(dvType); |
---|
262 | |
---|
263 | } |
---|
264 | } |
---|
265 | return 0; |
---|
266 | } |
---|
267 | |
---|
268 | inline DVHashTable* |
---|
269 | DatatypeValidatorFactory::getUserDefinedRegistry() const { |
---|
270 | return fUserDefinedRegistry; |
---|
271 | } |
---|
272 | |
---|
273 | inline DVHashTable* |
---|
274 | DatatypeValidatorFactory::getBuiltInRegistry() { |
---|
275 | return fBuiltInRegistry; |
---|
276 | } |
---|
277 | // --------------------------------------------------------------------------- |
---|
278 | // DatatypeValidator: CleanUp methods |
---|
279 | // --------------------------------------------------------------------------- |
---|
280 | inline void DatatypeValidatorFactory::cleanUp() { |
---|
281 | |
---|
282 | if (fUserDefinedRegistry) |
---|
283 | { |
---|
284 | delete fUserDefinedRegistry; |
---|
285 | fUserDefinedRegistry = 0; |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | XERCES_CPP_NAMESPACE_END |
---|
290 | |
---|
291 | #endif |
---|
292 | |
---|
293 | /** |
---|
294 | * End of file DatatypeValidatorFactory.hpp |
---|
295 | */ |
---|
296 | |
---|