DatatypeValidatorFactory.hpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:10k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  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.  * $Id: DatatypeValidatorFactory.hpp,v 1.7 2001/10/23 23:14:22 peiyongz Exp $
  58.  */
  59. #if !defined(DATATYPEVALIDATORFACTORY_HPP)
  60. #define DATATYPEVALIDATORFACTORY_HPP
  61. /**
  62.  * This class implements a factory of Datatype Validators. Internally the
  63.  * DatatypeValidators are kept in a registry.
  64.  * There is one instance of DatatypeValidatorFactory per Parser.
  65.  * There is one datatype Registry per instance of DatatypeValidatorFactory,
  66.  * such registry is first allocated with the number DatatypeValidators needed.
  67.  * e.g.
  68.  * If Parser finds an XML document with a DTD, a registry of DTD validators (only
  69.  * 9 validators) get initialized in the registry.
  70.  * The initialization process consist of instantiating the Datatype and
  71.  * facets and registering the Datatype into registry table.
  72.  * This implementation uses a Hahtable as a registry. The datatype validators created
  73.  * by the factory will be deleted by the registry.
  74.  * 
  75.  * As the Parser parses an instance document it knows if validation needs
  76.  * to be checked. If no validation is necesary we should not instantiate a
  77.  * DatatypeValidatorFactory.
  78.  * If validation is needed, we need to instantiate a DatatypeValidatorFactory.
  79.  */
  80. // ---------------------------------------------------------------------------
  81. //  Includes
  82. // ---------------------------------------------------------------------------
  83. #include <validators/datatype/DatatypeValidator.hpp>
  84. #include <util/RefVectorOf.hpp>
  85. // ---------------------------------------------------------------------------
  86. //  DatatypeValidatorFactory: Local declaration
  87. // ---------------------------------------------------------------------------
  88. typedef RefHashTableOf<KVStringPair> KVStringPairHashTable;
  89. typedef RefHashTableOf<DatatypeValidator> DVHashTable;
  90. typedef RefVectorOf<XMLCh> XMLChRefVector;
  91. class VALIDATORS_EXPORT DatatypeValidatorFactory
  92. {
  93. public:
  94. // -----------------------------------------------------------------------
  95.     //  Public Constructors and Destructor
  96.     // -----------------------------------------------------------------------
  97.     /** @name Constructors */
  98.     //@{
  99.     DatatypeValidatorFactory();
  100. //@}
  101. /** @name Destructor. */
  102.     //@{
  103.     ~DatatypeValidatorFactory();
  104. //@}
  105.     // -----------------------------------------------------------------------
  106.     // Getter methods
  107.     // -----------------------------------------------------------------------
  108.     /** @name Getter Functions */
  109.     //@{
  110.     /**
  111.       * Returns the datatype validator
  112.   *
  113.   * @param  dvType   Datatype validator name/type
  114.   */
  115. DatatypeValidator* getDatatypeValidator(const XMLCh* const dvType) const;
  116.     //@}
  117.     // -----------------------------------------------------------------------
  118.     // Registry Initialization methods
  119.     // -----------------------------------------------------------------------
  120.     /** @name Registry Initialization Functions */
  121.     //@{
  122.     /**
  123.   * Initializes registry with primitive and derived Simple types.
  124.       * 
  125.       * This method does not clear the registry to clear the registry you 
  126.   * have to call resetRegistry.
  127.       * 
  128.       * The net effect of this method is to start with a the smallest set of 
  129.   * datatypes needed by the validator.
  130.   *
  131.   * If we start with DTD's, then we initialize the table to only 
  132.   * the 9 validators needed by DTD Validation.
  133.   */
  134. void initializeDTDRegistry();
  135. /**
  136.   * Initializes registry with primitive and derived Simple types.
  137.       * 
  138.       * This method does not clear the registry to clear the registry you 
  139.   * have to call resetRegistry.
  140.       * 
  141.       * The net effect of this method is to start with a the smallest set of 
  142.   * datatypes needed by the validator.
  143.   *
  144.       * If we start with Schema's then we initialize to to full set of 
  145.   * validators.   
  146.   */
  147. void expandRegistryToFullSchemaSet();
  148. //@}
  149.     // -----------------------------------------------------------------------
  150.     // Validator Factory methods
  151.     // -----------------------------------------------------------------------
  152.     /** @name Validator Factory Functions */
  153.     //@{
  154.     /** 
  155.       * Creates a new datatype validator of type baseValidator's class and
  156.       * adds it to the registry
  157.       *
  158.       * @param  typeName       Datatype validator name
  159.       *
  160.       * @param  baseValidator  Base datatype validator
  161.       *
  162.       * @param  facets         datatype facets if any
  163.       *
  164.       * @param  enums          vector of values for enum facet
  165.       *
  166.       * @param  derivedByList  Indicates whether the datatype is derived by
  167.   *                        list or not
  168.       *
  169.       * @param  finalSet       'final' values of the simpleType
  170.   */
  171. DatatypeValidator* createDatatypeValidator(const XMLCh* const,
  172.                                        DatatypeValidator* const,
  173.                                                RefHashTableOf<KVStringPair>* const,
  174.                                                RefVectorOf<XMLCh>* const enums,
  175.                                                const bool,
  176.                                                const int = 0,
  177.                                                const bool = true);
  178.     /** 
  179.       * Creates a new datatype validator of type UnionDatatypeValidator and
  180.       * adds it to the registry
  181.       *
  182.       * @param  typeName       Datatype validator name
  183.       *
  184.       * @param  validators     Vector of datatype validators
  185.       *
  186.       */
  187.     DatatypeValidator* createDatatypeValidator(const XMLCh* const,
  188.                                                RefVectorOf<DatatypeValidator>* const,
  189.                                                const int finalSet,
  190.                                                const bool = true);
  191. //@}
  192.     /**
  193.       * Reset datatype validator registry
  194.       */
  195. void resetRegistry();
  196. // -----------------------------------------------------------------------
  197.     //  Notification that lazy data has been deleted
  198.     // -----------------------------------------------------------------------
  199. static void reinitRegistry();
  200. private:
  201.     // -----------------------------------------------------------------------
  202.     //  CleanUp methods
  203.     // -----------------------------------------------------------------------
  204. void cleanUp();
  205.     // -----------------------------------------------------------------------
  206.     //  Private data members
  207.     //
  208.     //  fRegistryExpanded
  209.     //      Indicated whether we have expanded the registry or not.
  210. //
  211.     //  fUserDefinedRegistry
  212.     //      This is a hashtable of user defined dataype validators.
  213.     //
  214.     //  fBuiltInRegistry
  215.     //      This is a hashtable of built-in primitive datatype validators.
  216.     // -----------------------------------------------------------------------
  217.     RefHashTableOf<DatatypeValidator>*        fUserDefinedRegistry;
  218. static int                                fRegistryExpanded;
  219. static RefHashTableOf<DatatypeValidator>* fBuiltInRegistry;
  220. };
  221. // ---------------------------------------------------------------------------
  222. //  DatatypeValidatorFactory: Getters
  223. // ---------------------------------------------------------------------------
  224. inline DatatypeValidator* 
  225. DatatypeValidatorFactory::getDatatypeValidator(const XMLCh* const dvType) const
  226. {
  227. if (dvType) {
  228.         if (fBuiltInRegistry && fBuiltInRegistry->containsKey(dvType)) {
  229.     return fBuiltInRegistry->get(dvType);
  230.         }
  231.         if (fUserDefinedRegistry && fUserDefinedRegistry->containsKey(dvType)) {
  232.     return fUserDefinedRegistry->get(dvType);
  233.         }
  234.     }
  235. return 0;
  236. }
  237. // ---------------------------------------------------------------------------
  238. //  DatatypeValidator: CleanUp methods
  239. // ---------------------------------------------------------------------------
  240. inline void DatatypeValidatorFactory::cleanUp() {
  241. delete fUserDefinedRegistry;
  242. }
  243. #endif
  244. /**
  245.   * End of file DatatypeValidatorFactory.hpp
  246.   */