[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 2001 The Apache Software Foundation. All rights
|
---|
| 5 | * reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | *
|
---|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in
|
---|
| 16 | * the documentation and/or other materials provided with the
|
---|
| 17 | * distribution.
|
---|
| 18 | *
|
---|
| 19 | * 3. The end-user documentation included with the redistribution,
|
---|
| 20 | * if any, must include the following acknowledgment:
|
---|
| 21 | * "This product includes software developed by the
|
---|
| 22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
| 23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
| 24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
| 25 | *
|
---|
| 26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
| 27 | * not be used to endorse or promote products derived from this
|
---|
| 28 | * software without prior written permission. For written
|
---|
| 29 | * permission, please contact apache\@apache.org.
|
---|
| 30 | *
|
---|
| 31 | * 5. Products derived from this software may not be called "Apache",
|
---|
| 32 | * nor may "Apache" appear in their name, without prior written
|
---|
| 33 | * permission of the Apache Software Foundation.
|
---|
| 34 | *
|
---|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 46 | * SUCH DAMAGE.
|
---|
| 47 | * ====================================================================
|
---|
| 48 | *
|
---|
| 49 | * This software consists of voluntary contributions made by many
|
---|
| 50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
| 51 | * originally based on software copyright (c) 2001, International
|
---|
| 52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
| 53 | * on the Apache Software Foundation, please see
|
---|
| 54 | * <http://www.apache.org/>.
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * $Id: DatatypeValidatorFactory.hpp,v 1.15 2004/01/29 11:51:22 cargilld Exp $
|
---|
| 59 | */
|
---|
| 60 |
|
---|
| 61 | #if !defined(DATATYPEVALIDATORFACTORY_HPP)
|
---|
| 62 | #define DATATYPEVALIDATORFACTORY_HPP
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * This class implements a factory of Datatype Validators. Internally the
|
---|
| 66 | * DatatypeValidators are kept in a registry.
|
---|
| 67 | * There is one instance of DatatypeValidatorFactory per Parser.
|
---|
| 68 | * There is one datatype Registry per instance of DatatypeValidatorFactory,
|
---|
| 69 | * such registry is first allocated with the number DatatypeValidators needed.
|
---|
| 70 | * e.g.
|
---|
| 71 | * If Parser finds an XML document with a DTD, a registry of DTD validators (only
|
---|
| 72 | * 9 validators) get initialized in the registry.
|
---|
| 73 | * The initialization process consist of instantiating the Datatype and
|
---|
| 74 | * facets and registering the Datatype into registry table.
|
---|
| 75 | * This implementation uses a Hahtable as a registry. The datatype validators created
|
---|
| 76 | * by the factory will be deleted by the registry.
|
---|
| 77 | *
|
---|
| 78 | * As the Parser parses an instance document it knows if validation needs
|
---|
| 79 | * to be checked. If no validation is necesary we should not instantiate a
|
---|
| 80 | * DatatypeValidatorFactory.
|
---|
| 81 | * If validation is needed, we need to instantiate a DatatypeValidatorFactory.
|
---|
| 82 | */
|
---|
| 83 |
|
---|
| 84 | // ---------------------------------------------------------------------------
|
---|
| 85 | // Includes
|
---|
| 86 | // ---------------------------------------------------------------------------
|
---|
| 87 | #include <xercesc/validators/datatype/DatatypeValidator.hpp>
|
---|
| 88 | #include <xercesc/validators/datatype/XMLCanRepGroup.hpp>
|
---|
| 89 | #include <xercesc/util/RefVectorOf.hpp>
|
---|
| 90 |
|
---|
| 91 | #include <xercesc/internal/XSerializable.hpp>
|
---|
| 92 |
|
---|
| 93 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 94 |
|
---|
| 95 | // ---------------------------------------------------------------------------
|
---|
| 96 | // DatatypeValidatorFactory: Local declaration
|
---|
| 97 | // ---------------------------------------------------------------------------
|
---|
| 98 | typedef RefHashTableOf<KVStringPair> KVStringPairHashTable;
|
---|
| 99 | typedef RefHashTableOf<DatatypeValidator> DVHashTable;
|
---|
| 100 | typedef RefArrayVectorOf<XMLCh> XMLChRefVector;
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | class VALIDATORS_EXPORT DatatypeValidatorFactory : public XSerializable, public XMemory
|
---|
| 104 | {
|
---|
| 105 | public:
|
---|
| 106 |
|
---|
| 107 | // -----------------------------------------------------------------------
|
---|
| 108 | // Public Constructors and Destructor
|
---|
| 109 | // -----------------------------------------------------------------------
|
---|
| 110 | /** @name Constructors */
|
---|
| 111 | //@{
|
---|
| 112 |
|
---|
| 113 | DatatypeValidatorFactory
|
---|
| 114 | (
|
---|
| 115 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 116 | );
|
---|
| 117 |
|
---|
| 118 | //@}
|
---|
| 119 |
|
---|
| 120 | /** @name Destructor. */
|
---|
| 121 | //@{
|
---|
| 122 |
|
---|
| 123 | ~DatatypeValidatorFactory();
|
---|
| 124 |
|
---|
| 125 | //@}
|
---|
| 126 |
|
---|
| 127 | // -----------------------------------------------------------------------
|
---|
| 128 | // Getter methods
|
---|
| 129 | // -----------------------------------------------------------------------
|
---|
| 130 | /** @name Getter Functions */
|
---|
| 131 | //@{
|
---|
| 132 |
|
---|
| 133 | /**
|
---|
| 134 | * Returns the datatype validator
|
---|
| 135 | *
|
---|
| 136 | * @param dvType Datatype validator name/type
|
---|
| 137 | */
|
---|
| 138 | DatatypeValidator* getDatatypeValidator(const XMLCh* const dvType) const;
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * Returns the user defined registry of types
|
---|
| 142 | **/
|
---|
| 143 | DVHashTable* getUserDefinedRegistry() const;
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | /**
|
---|
| 147 | * Returns the built in registry of types
|
---|
| 148 | **/
|
---|
| 149 | static DVHashTable* getBuiltInRegistry();
|
---|
| 150 |
|
---|
| 151 | //@}
|
---|
| 152 |
|
---|
| 153 | // -----------------------------------------------------------------------
|
---|
| 154 | // Registry Initialization methods
|
---|
| 155 | // -----------------------------------------------------------------------
|
---|
| 156 | /** @name Registry Initialization Functions */
|
---|
| 157 | //@{
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Initializes registry with primitive and derived Simple types.
|
---|
| 161 | *
|
---|
| 162 | * This method does not clear the registry to clear the registry you
|
---|
| 163 | * have to call resetRegistry.
|
---|
| 164 | *
|
---|
| 165 | * The net effect of this method is to start with the smallest set of
|
---|
| 166 | * datatypes needed by the validator.
|
---|
| 167 | *
|
---|
| 168 | * If we start with Schema's then we initialize to full set of
|
---|
| 169 | * validators.
|
---|
| 170 | */
|
---|
| 171 | void expandRegistryToFullSchemaSet();
|
---|
| 172 |
|
---|
| 173 | //@}
|
---|
| 174 |
|
---|
| 175 | // -----------------------------------------------------------------------
|
---|
| 176 | // Canonical Representation Group
|
---|
| 177 | // -----------------------------------------------------------------------
|
---|
| 178 | void initCanRepRegistory();
|
---|
| 179 |
|
---|
| 180 | static XMLCanRepGroup::CanRepGroup getCanRepGroup(const DatatypeValidator* const);
|
---|
| 181 |
|
---|
| 182 | // -----------------------------------------------------------------------
|
---|
| 183 | // Validator Factory methods
|
---|
| 184 | // -----------------------------------------------------------------------
|
---|
| 185 | /** @name Validator Factory Functions */
|
---|
| 186 | //@{
|
---|
| 187 |
|
---|
| 188 | /**
|
---|
| 189 | * Creates a new datatype validator of type baseValidator's class and
|
---|
| 190 | * adds it to the registry
|
---|
| 191 | *
|
---|
| 192 | * @param typeName Datatype validator name
|
---|
| 193 | *
|
---|
| 194 | * @param baseValidator Base datatype validator
|
---|
| 195 | *
|
---|
| 196 | * @param facets datatype facets if any
|
---|
| 197 | *
|
---|
| 198 | * @param enums vector of values for enum facet
|
---|
| 199 | *
|
---|
| 200 | * @param isDerivedByList Indicates whether the datatype is derived by
|
---|
| 201 | * list or not
|
---|
| 202 | *
|
---|
| 203 | * @param finalSet 'final' values of the simpleType
|
---|
| 204 | *
|
---|
| 205 | * @param isUserDefined Indicates whether the datatype is built-in or
|
---|
| 206 | * user defined
|
---|
| 207 | */
|
---|
| 208 | DatatypeValidator* createDatatypeValidator
|
---|
| 209 | (
|
---|
| 210 | const XMLCh* const typeName
|
---|
| 211 | , DatatypeValidator* const baseValidator
|
---|
| 212 | , RefHashTableOf<KVStringPair>* const facets
|
---|
| 213 | , RefArrayVectorOf<XMLCh>* const enums
|
---|
| 214 | , const bool isDerivedByList
|
---|
| 215 | , const int finalSet = 0
|
---|
| 216 | , const bool isUserDefined = true
|
---|
| 217 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 218 | );
|
---|
| 219 |
|
---|
| 220 | /**
|
---|
| 221 | * Creates a new datatype validator of type UnionDatatypeValidator and
|
---|
| 222 | * adds it to the registry
|
---|
| 223 | *
|
---|
| 224 | * @param typeName Datatype validator name
|
---|
| 225 | *
|
---|
| 226 | * @param validators Vector of datatype validators
|
---|
| 227 | *
|
---|
| 228 | * @param finalSet 'final' values of the simpleType
|
---|
| 229 | *
|
---|
| 230 | * @param isUserDefined Indicates whether the datatype is built-in or
|
---|
| 231 | * user defined
|
---|
| 232 | */
|
---|
| 233 | DatatypeValidator* createDatatypeValidator
|
---|
| 234 | (
|
---|
| 235 | const XMLCh* const typeName
|
---|
| 236 | , RefVectorOf<DatatypeValidator>* const validators
|
---|
| 237 | , const int finalSet
|
---|
| 238 | , const bool isUserDefined = true
|
---|
| 239 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 240 | );
|
---|
| 241 |
|
---|
| 242 | //@}
|
---|
| 243 |
|
---|
| 244 | /**
|
---|
| 245 | * Reset datatype validator registry
|
---|
| 246 | */
|
---|
| 247 | void resetRegistry();
|
---|
| 248 |
|
---|
| 249 | // -----------------------------------------------------------------------
|
---|
| 250 | // Notification that lazy data has been deleted
|
---|
| 251 | // -----------------------------------------------------------------------
|
---|
| 252 | static void reinitRegistry();
|
---|
| 253 |
|
---|
| 254 | /***
|
---|
| 255 | * Support for Serialization/De-serialization
|
---|
| 256 | ***/
|
---|
| 257 | DECL_XSERIALIZABLE(DatatypeValidatorFactory)
|
---|
| 258 |
|
---|
| 259 | private:
|
---|
| 260 |
|
---|
| 261 | // -----------------------------------------------------------------------
|
---|
| 262 | // CleanUp methods
|
---|
| 263 | // -----------------------------------------------------------------------
|
---|
| 264 | void cleanUp();
|
---|
| 265 |
|
---|
| 266 | // -----------------------------------------------------------------------
|
---|
| 267 | // Unimplemented constructors and operators
|
---|
| 268 | // -----------------------------------------------------------------------
|
---|
| 269 | DatatypeValidatorFactory(const DatatypeValidatorFactory&);
|
---|
| 270 | DatatypeValidatorFactory& operator=(const DatatypeValidatorFactory&);
|
---|
| 271 |
|
---|
| 272 | // -----------------------------------------------------------------------
|
---|
| 273 | // Private data members
|
---|
| 274 | //
|
---|
| 275 | // fUserDefinedRegistry
|
---|
| 276 | // This is a hashtable of user defined dataype validators.
|
---|
| 277 | //
|
---|
| 278 | // fBuiltInRegistry
|
---|
| 279 | // This is a hashtable of built-in primitive datatype validators.
|
---|
| 280 | // -----------------------------------------------------------------------
|
---|
| 281 | XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XERCES_CPP_NAMESPACE_QUALIFIER DatatypeValidator>* fUserDefinedRegistry;
|
---|
| 282 | static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<DatatypeValidator>* fBuiltInRegistry;
|
---|
| 283 | static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XMLCanRepGroup>* fCanRepRegistry;
|
---|
| 284 | XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const fMemoryManager;
|
---|
| 285 |
|
---|
| 286 | friend class XPath2ContextImpl;
|
---|
| 287 | };
|
---|
| 288 |
|
---|
| 289 | inline DatatypeValidator*
|
---|
| 290 | DatatypeValidatorFactory::getDatatypeValidator(const XMLCh* const dvType) const
|
---|
| 291 | {
|
---|
| 292 | if (dvType) {
|
---|
| 293 | if (fBuiltInRegistry && fBuiltInRegistry->containsKey(dvType)) {
|
---|
| 294 | return fBuiltInRegistry->get(dvType);
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | if (fUserDefinedRegistry && fUserDefinedRegistry->containsKey(dvType)) {
|
---|
| 298 | return fUserDefinedRegistry->get(dvType);
|
---|
| 299 |
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | return 0;
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | inline DVHashTable*
|
---|
| 306 | DatatypeValidatorFactory::getUserDefinedRegistry() const {
|
---|
| 307 | return fUserDefinedRegistry;
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | inline DVHashTable*
|
---|
| 311 | DatatypeValidatorFactory::getBuiltInRegistry() {
|
---|
| 312 | return fBuiltInRegistry;
|
---|
| 313 | }
|
---|
| 314 | // ---------------------------------------------------------------------------
|
---|
| 315 | // DatatypeValidator: CleanUp methods
|
---|
| 316 | // ---------------------------------------------------------------------------
|
---|
| 317 | inline void DatatypeValidatorFactory::cleanUp() {
|
---|
| 318 |
|
---|
| 319 | delete fUserDefinedRegistry;
|
---|
| 320 | fUserDefinedRegistry = 0;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | XERCES_CPP_NAMESPACE_END
|
---|
| 324 |
|
---|
| 325 | #endif
|
---|
| 326 |
|
---|
| 327 | /**
|
---|
| 328 | * End of file DatatypeValidatorFactory.hpp
|
---|
| 329 | */
|
---|
| 330 |
|
---|