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

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: AbstractStringValidator.hpp,v 1.8 2001/11/22 20:23:20 peiyongz Exp $
  58.  * $Log: AbstractStringValidator.hpp,v $
  59.  * Revision 1.8  2001/11/22 20:23:20  peiyongz
  60.  * _declspec(dllimport) and inline warning C4273
  61.  *
  62.  * Revision 1.7  2001/11/15 16:08:15  peiyongz
  63.  * checkContent() made virtual to allow ListDTV participate in the building of
  64.  * its own (in AbstractStringValidator's init())
  65.  *
  66.  * Revision 1.6  2001/10/11 19:32:12  peiyongz
  67.  * Allow derived to overwrite inheritFacet()
  68.  *
  69.  * Revision 1.5  2001/10/09 21:00:54  peiyongz
  70.  * . init() take 1 arg,
  71.  * . make inspectFacetBase() virtual to allow ListDTV provide its own method,
  72.  * . reorganize init() into assignFacet(), inspectFacet(), inspectFacetBase() and
  73.  * inheritFacet() to improve mantainability.
  74.  * . macro to simplify code
  75.  * . save get***() to temp vars
  76.  *
  77.  * Revision 1.4  2001/09/27 13:51:25  peiyongz
  78.  * DTV Reorganization: ctor/init created to be used by derived class
  79.  *
  80.  * Revision 1.3  2001/09/24 15:30:16  peiyongz
  81.  * DTV Reorganization: init() to be invoked from derived class' ctor to allow
  82.  *        correct resolution of virtual methods like assignAdditionalFacet(),
  83.  *        inheritAdditionalFacet(), etc.
  84.  *
  85.  * Revision 1.2  2001/09/19 18:48:27  peiyongz
  86.  * DTV reorganization:getLength() added, move inline to class declaration to avoid inline
  87.  * function interdependency.
  88.  *
  89.  * Revision 1.1  2001/09/18 14:45:04  peiyongz
  90.  * DTV reorganization
  91.  *
  92.  */
  93. #if !defined(ABSTRACT_STRING_VALIDATOR_HPP)
  94. #define ABSTRACT_STRING_VALIDATOR_HPP
  95. #include <validators/datatype/DatatypeValidator.hpp>
  96. class VALIDATORS_EXPORT AbstractStringValidator : public DatatypeValidator
  97. {
  98. public:
  99.     // -----------------------------------------------------------------------
  100.     //  Public ctor/dtor
  101.     // -----------------------------------------------------------------------
  102. /** @name Constructor. */
  103.     //@{
  104.     virtual ~AbstractStringValidator();
  105. //@}
  106.     // -----------------------------------------------------------------------
  107.     // Validation methods
  108.     // -----------------------------------------------------------------------
  109.     /** @name Validation Function */
  110.     //@{
  111.     /**
  112.      * validate that a string matches the boolean datatype
  113.      * @param content A string containing the content to be validated
  114.      *
  115.      * @exception throws InvalidDatatypeException if the content is
  116.      * is not valid.
  117.      */
  118. virtual void validate(const XMLCh* const content);
  119.     //@}
  120.     // -----------------------------------------------------------------------
  121.     // Compare methods
  122.     // -----------------------------------------------------------------------
  123.     /** @name Compare Function */
  124.     //@{
  125.     virtual int compare(const XMLCh* const, const XMLCh* const);
  126.     //@}
  127. protected:
  128.     AbstractStringValidator(DatatypeValidator*            const baseValidator
  129.                           , RefHashTableOf<KVStringPair>* const facets
  130.                           , const int                           finalSet
  131.                           , const ValidatorType                 type);
  132.     void init(RefVectorOf<XMLCh>*           const enums);
  133.     //
  134.     // Abstract interface
  135.     //
  136.     virtual void assignAdditionalFacet(const XMLCh* const key
  137.                                      , const XMLCh* const value) = 0;
  138.     virtual void inheritAdditionalFacet() = 0;
  139.     virtual void checkAdditionalFacetConstraints() const = 0;
  140.     virtual void checkAdditionalFacet(const XMLCh* const content) const = 0;
  141.     virtual void checkValueSpace(const XMLCh* const content) = 0;
  142.     virtual int  getLength(const XMLCh* const content) const = 0;
  143.     //
  144.     //   to Allow ListDTV to overwrite
  145.     //
  146.     virtual void inspectFacetBase();
  147.     virtual void inheritFacet();
  148.     virtual void checkContent(const XMLCh* const content, bool asBase);
  149. // -----------------------------------------------------------------------
  150. // Getter methods
  151. // -----------------------------------------------------------------------
  152.     inline unsigned int         getLength() const;
  153.     inline unsigned int         getMaxLength() const;
  154.     inline unsigned int         getMinLength() const;
  155.     inline RefVectorOf<XMLCh>*  getEnumeration() const;
  156. // -----------------------------------------------------------------------
  157. // Setter methods
  158. // -----------------------------------------------------------------------
  159.     inline void                 setLength(unsigned int);
  160.     inline void                 setMaxLength(unsigned int);
  161.     inline void                 setMinLength(unsigned int);
  162.     inline void                 setEnumeration(RefVectorOf<XMLCh>*, bool);
  163. private:
  164.     void assignFacet();
  165.     void inspectFacet();
  166.     // -----------------------------------------------------------------------
  167.     //  Private data members
  168.     //
  169.     // -----------------------------------------------------------------------
  170.      unsigned int         fLength;
  171.      unsigned int         fMaxLength;
  172.      unsigned int         fMinLength;
  173.      bool                 fEnumerationInherited;
  174.      RefVectorOf<XMLCh>*  fEnumeration;
  175. };
  176. // -----------------------------------------------------------------------
  177. // Getter methods
  178. // -----------------------------------------------------------------------
  179. inline unsigned int AbstractStringValidator::getLength() const
  180. {
  181.     return fLength;
  182. }
  183. inline unsigned int AbstractStringValidator::getMaxLength() const
  184. {
  185.     return fMaxLength;
  186. }
  187. inline unsigned int AbstractStringValidator::getMinLength() const
  188. {
  189.     return fMinLength;
  190. }
  191. inline RefVectorOf<XMLCh>* AbstractStringValidator:: getEnumeration() const
  192. {
  193.     return fEnumeration;
  194. }
  195. // -----------------------------------------------------------------------
  196. // Setter methods
  197. // -----------------------------------------------------------------------
  198. inline void AbstractStringValidator::setLength(unsigned int newLength)
  199. {
  200.     fLength = newLength;
  201. }
  202. inline void AbstractStringValidator::setMaxLength(unsigned int newMaxLength)
  203. {
  204.     fMaxLength = newMaxLength;
  205. }
  206. inline void AbstractStringValidator::setMinLength(unsigned int newMinLength)
  207. {
  208.     fMinLength = newMinLength;
  209. }
  210. inline void AbstractStringValidator::setEnumeration(RefVectorOf<XMLCh>* enums
  211.                                            , bool                inherited)
  212. {
  213.     if (enums)
  214.     {
  215.         if (fEnumeration && !fEnumerationInherited)
  216.             delete fEnumeration;
  217.         fEnumeration = enums;
  218.         fEnumerationInherited = inherited;
  219.         setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
  220.     }
  221. }
  222. /**
  223.   * End of file AbstractStringValidator.hpp
  224.   */
  225. #endif