source: icXML/icXML-devel/src/icxercesc/validators/datatype/DatatypeValidatorFactory.hpp @ 3157

Last change on this file since 3157 was 3157, checked in by cameron, 6 years ago

Fixes for icXML 0.9

File size: 8.9 KB
Line 
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 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DATATYPEVALIDATORFACTORY_HPP)
23#define XERCESC_INCLUDE_GUARD_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 Hashtable 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 necessary 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
54XERCES_CPP_NAMESPACE_BEGIN
55
56// ---------------------------------------------------------------------------
57//  DatatypeValidatorFactory: Local declaration
58// ---------------------------------------------------------------------------
59typedef RefHashTableOf<KVStringPair> KVStringPairHashTable;
60typedef RefHashTableOf<DatatypeValidator> DVHashTable;
61typedef RefArrayVectorOf<XMLCh> XMLChRefVector;
62
63
64class VALIDATORS_EXPORT DatatypeValidatorFactory : public XSerializable, public XMemory
65{
66public:
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  private:
115        /**
116         * Initializes registry with primitive and derived Simple types.
117         *
118         * This method does not clear the registry to clear the registry you
119         * have to call resetRegistry.
120         *
121         * The net effect of this method is to start with the smallest set of
122         * datatypes needed by the validator.
123         *
124         * If we start with Schema's then we initialize to full set of
125         * validators.
126         */
127        void expandRegistryToFullSchemaSet();
128
129  public:
130        // -----------------------------------------------------------------------
131        // Canonical Representation Group
132        // -----------------------------------------------------------------------
133                   void                        initCanRepRegistory();
134
135        static XMLCanRepGroup::CanRepGroup getCanRepGroup(const DatatypeValidator* const);
136
137        static DatatypeValidator* getBuiltInBaseValidator(const DatatypeValidator* const);
138
139        // -----------------------------------------------------------------------
140        // Validator Factory methods
141        // -----------------------------------------------------------------------
142        /** @name Validator Factory Functions */
143        //@{
144
145        /**
146         * Creates a new datatype validator of type baseValidator's class and
147         * adds it to the registry
148         *
149         * @param  typeName        Datatype validator name
150         *
151         * @param  baseValidator   Base datatype validator
152         *
153         * @param  facets          datatype facets if any
154         *
155         * @param  enums           vector of values for enum facet
156         *
157         * @param  isDerivedByList Indicates whether the datatype is derived by
158         *                         list or not
159         *
160         * @param  finalSet       'final' values of the simpleType
161         *
162         * @param  isUserDefined  Indicates whether the datatype is built-in or
163         *                        user defined
164         */
165        DatatypeValidator* createDatatypeValidator
166        (
167                const XMLCh* const                    typeName
168                , DatatypeValidator* const            baseValidator
169                , RefHashTableOf<KVStringPair>* const facets
170                , RefArrayVectorOf<XMLCh>* const      enums
171                , const bool                          isDerivedByList
172                , const int                           finalSet = 0
173                , const bool                          isUserDefined = true
174                , MemoryManager* const                manager = XMLPlatformUtils::fgMemoryManager
175        );
176
177        /**
178         * Creates a new datatype validator of type UnionDatatypeValidator and
179         * adds it to the registry
180         *
181         * @param  typeName       Datatype validator name
182         *
183         * @param  validators     Vector of datatype validators
184         *
185         * @param  finalSet       'final' values of the simpleType
186         *
187         * @param  isUserDefined  Indicates whether the datatype is built-in or
188         *                        user defined
189         */
190        DatatypeValidator* createDatatypeValidator
191        (
192                  const XMLCh* const                    typeName
193                , RefVectorOf<DatatypeValidator>* const validators
194                , const int                             finalSet
195                , const bool                            isUserDefined = true
196                , MemoryManager* const                  manager = XMLPlatformUtils::fgMemoryManager
197        );
198
199        //@}
200
201        /**
202          * Reset datatype validator registry
203          */
204        void resetRegistry();
205
206        /***
207         * Support for Serialization/De-serialization
208         ***/
209        DECL_XSERIALIZABLE(DatatypeValidatorFactory)
210
211private:
212
213        // -----------------------------------------------------------------------
214        //  CleanUp methods
215        // -----------------------------------------------------------------------
216        void cleanUp();
217
218        // -----------------------------------------------------------------------
219        //  Unimplemented constructors and operators
220        // -----------------------------------------------------------------------
221        DatatypeValidatorFactory(const DatatypeValidatorFactory&);
222        DatatypeValidatorFactory& operator=(const DatatypeValidatorFactory&);
223
224        // -----------------------------------------------------------------------
225        //  Private data members
226        //
227        //  fUserDefinedRegistry
228        //      This is a hashtable of user defined dataype validators.
229        //
230        //  fBuiltInRegistry
231        //      This is a hashtable of built-in primitive datatype validators.
232        // -----------------------------------------------------------------------
233        XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XERCES_CPP_NAMESPACE_QUALIFIER DatatypeValidator>*        fUserDefinedRegistry;
234        static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<DatatypeValidator>* fBuiltInRegistry;
235        static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XMLCanRepGroup, PtrHasher>*    fCanRepRegistry;
236        XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const fMemoryManager;
237
238        friend class XPath2ContextImpl;
239        friend class XMLInitializer;
240};
241
242inline DVHashTable*
243DatatypeValidatorFactory::getUserDefinedRegistry() const
244{
245        return fUserDefinedRegistry;
246}
247
248inline DVHashTable*
249DatatypeValidatorFactory::getBuiltInRegistry()
250{
251        return fBuiltInRegistry;
252}
253// ---------------------------------------------------------------------------
254//  DatatypeValidator: CleanUp methods
255// ---------------------------------------------------------------------------
256inline void DatatypeValidatorFactory::cleanUp()
257{
258        if (fUserDefinedRegistry)
259        {
260                delete fUserDefinedRegistry;
261                fUserDefinedRegistry = 0;
262        }
263}
264
265XERCES_CPP_NAMESPACE_END
266
267#endif
268
269/**
270  * End of file DatatypeValidatorFactory.hpp
271  */
Note: See TracBrowser for help on using the repository browser.