source: obsolete/tags/VUT/0.4/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/datatype/DatatypeValidatorFactory.hpp @ 358

Revision 358, 10.2 KB checked in by bittner, 19 years ago (diff)

xerces added

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