You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2001/07/11 23:37:25 UTC

cvs commit: xml-xerces/c/src/validators/datatype ListDatatypeValidator.hpp ListDatatypeValidator.cpp Makefile.in DatatypeValidatorFactory.cpp DatatypeValidator.hpp

peiyongz    01/07/11 14:37:25

  Modified:    c/src/validators/datatype Makefile.in
                        DatatypeValidatorFactory.cpp DatatypeValidator.hpp
  Added:       c/src/validators/datatype ListDatatypeValidator.hpp
                        ListDatatypeValidator.cpp
  Log:
  ListDatatypeDTV
  
  Revision  Changes    Path
  1.13      +5 -0      xml-xerces/c/src/validators/datatype/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/Makefile.in,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Makefile.in	2001/07/06 20:21:46	1.12
  +++ Makefile.in	2001/07/11 21:37:15	1.13
  @@ -55,6 +55,9 @@
   #
   #
   # $Log: Makefile.in,v $
  +# Revision 1.13  2001/07/11 21:37:15  peiyongz
  +# ListDatatypeDTV
  +#
   # Revision 1.12  2001/07/06 20:21:46  peiyongz
   # QNameDTV & ENTITYDTV enabled
   #
  @@ -129,6 +132,7 @@
   	NOTATIONDatatypeValidator.hpp \
   	ENTITYDatatypeValidator.hpp \
   	QNameDatatypeValidator.hpp \
  +	ListDatatypeValidator.hpp \
   	IDREFDatatypeValidator.hpp
   
   VALIDATORS_DATATYPE_CPP_PRIVHEADERS =
  @@ -147,6 +151,7 @@
   	NOTATIONDatatypeValidator.$(TO) \
   	ENTITYDatatypeValidator.$(TO) \
   	QNameDatatypeValidator.$(TO) \
  +	ListDatatypeValidator.$(TO) \
   	IDREFDatatypeValidator.$(TO)
   
   all::	includes $(VALIDATORS_DATATYPE_CPP_OBJECTS)
  
  
  
  1.15      +5 -2      xml-xerces/c/src/validators/datatype/DatatypeValidatorFactory.cpp
  
  Index: DatatypeValidatorFactory.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DatatypeValidatorFactory.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DatatypeValidatorFactory.cpp	2001/07/06 20:21:58	1.14
  +++ DatatypeValidatorFactory.cpp	2001/07/11 21:37:18	1.15
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: DatatypeValidatorFactory.cpp,v $
  + * Revision 1.15  2001/07/11 21:37:18  peiyongz
  + * ListDatatypeDTV
  + *
    * Revision 1.14  2001/07/06 20:21:58  peiyongz
    * QNameDTV & ENTITYDTV enabled
    *
  @@ -121,6 +124,7 @@
   #include <validators/datatype/NOTATIONDatatypeValidator.hpp>
   #include <validators/datatype/ENTITYDatatypeValidator.hpp>
   #include <validators/datatype/QNameDatatypeValidator.hpp>
  +#include <validators/datatype/ListDatatypeValidator.hpp>
   #include <util/PlatformUtils.hpp>
   #include <util/XMLDeleterFor.hpp>
   
  @@ -643,8 +647,7 @@
   	DatatypeValidator* datatypeValidator = 0;
   
       if (derivedByList) {
  -
  -        //TO DO
  +        datatypeValidator = new ListDatatypeValidator(baseValidator, facets, enums, finalSet);
       }
       else {
   
  
  
  
  1.10      +2 -2      xml-xerces/c/src/validators/datatype/DatatypeValidator.hpp
  
  Index: DatatypeValidator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/DatatypeValidator.hpp,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DatatypeValidator.hpp	2001/06/20 17:58:33	1.9
  +++ DatatypeValidator.hpp	2001/07/11 21:37:20	1.10
  @@ -55,7 +55,7 @@
    */
   
   /*
  - * $Id: DatatypeValidator.hpp,v 1.9 2001/06/20 17:58:33 peiyongz Exp $
  + * $Id: DatatypeValidator.hpp,v 1.10 2001/07/11 21:37:20 peiyongz Exp $
    */
   
   #if !defined(DATATYPEVALIDATOR_HPP)
  @@ -232,7 +232,7 @@
         * We will provide a default behavior that should be redefined at the
         * children level, if necessary (i.e. boolean case).
         */
  -    int compare(const XMLCh* const value1, const XMLCh* const value2);
  +    virtual int compare(const XMLCh* const value1, const XMLCh* const value2);
   
       //@}
   
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/ListDatatypeValidator.hpp
  
  Index: ListDatatypeValidator.hpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 2001, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: ListDatatypeValidator.hpp,v 1.1 2001/07/11 21:37:17 peiyongz Exp $
   * $Log: ListDatatypeValidator.hpp,v $
   * Revision 1.1  2001/07/11 21:37:17  peiyongz
   * ListDatatypeDTV
   *
   */
  
  #if !defined(LIST_DATATYPEVALIDATOR_HPP)
  #define LIST_DATATYPEVALIDATOR_HPP
  
  #include <validators/datatype/DatatypeValidator.hpp>
  #include <validators/schema/SchemaSymbols.hpp>
  
  class VALIDATORS_EXPORT ListDatatypeValidator : public DatatypeValidator
  {
  public:
  
      // -----------------------------------------------------------------------
      //  Public ctor/dtor
      // -----------------------------------------------------------------------
  	/** @name Constructor. */
      //@{
  
      ListDatatypeValidator();
  
      ListDatatypeValidator(DatatypeValidator*            const baseValidator
                          , RefHashTableOf<KVStringPair>* const facets
                          , RefVectorOf<XMLCh>*           const enums
                          , const int                           finalSet);
  
  
      virtual ~ListDatatypeValidator();
  
  	//@}
  
      // -----------------------------------------------------------------------
      // Getter methods
      // -----------------------------------------------------------------------
      /** @name Getter Functions */
      //@{
  
      //@}
  
      // -----------------------------------------------------------------------
      // Validation methods
      // -----------------------------------------------------------------------
      /** @name Validation Function */
      //@{
  
      /**
       * validate that a string matches the boolean datatype
       * @param content A string containing the content to be validated
       *
       * @exception throws InvalidDatatypeException if the content is
       * is not valid.
       */
  
  	void validate(const XMLCh* const content);
  
      //@}
  
      // -----------------------------------------------------------------------
      // Compare methods
      // -----------------------------------------------------------------------
      /** @name Compare Function */
      //@{
  
      /**
       * Compare two boolean data types
       *
       * @param content1
       * @param content2
       * @return
       */
      int compare(const XMLCh* const, const XMLCh* const);
  
      //@}
  
      /**
        * Returns an instance of the base datatype validator class
  	  * Used by the DatatypeValidatorFactory.
        */
      DatatypeValidator* newInstance(DatatypeValidator* const            baseValidator
                                   , RefHashTableOf<KVStringPair>* const facets
                                   , RefVectorOf<XMLCh>*           const enums
                                   , const int                           finalSet);
  
  private:
  
      void checkContent(const XMLCh* const content, bool asBase);
      
      void checkContent(RefVectorOf<XMLCh>* tokenVector, bool asBase);
  
      void init(DatatypeValidator*            const baseValidator
              , RefHashTableOf<KVStringPair>* const facets
              , RefVectorOf<XMLCh>*           const enums);
  
      void cleanUp();
  
      DatatypeValidator* getItemTypeDTV() const;
  
      bool valueSpaceCheck(RefVectorOf<XMLCh>* tokenVector
                         , const XMLCh* const  enumStr) const;
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
      unsigned int         getLength() const;
  
      unsigned int         getMaxLength() const;
  
      unsigned int         getMinLength() const;
  
      RefVectorOf<XMLCh>*  getEnumeration() const;
  
      const XMLCh* const   getContent() const;
  
  // -----------------------------------------------------------------------
  // Setter methods
  // -----------------------------------------------------------------------
  
      void                 setLength(unsigned int);
  
      void                 setMaxLength(unsigned int);
  
      void                 setMinLength(unsigned int);
  
      void                 setEnumeration(RefVectorOf<XMLCh>*, bool);
  
      void                 setContent(const XMLCh* const content);
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fContent
      //      temporary var referenceing the content to be validated,
      //      for error reporting purpose.
      //
      // -----------------------------------------------------------------------
       unsigned int         fLength;
       unsigned int         fMaxLength;
       unsigned int         fMinLength;
       bool                 fEnumerationInherited;
       RefVectorOf<XMLCh>*  fEnumeration;
       const XMLCh*         fContent;
  };
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  inline ListDatatypeValidator::ListDatatypeValidator()
  :DatatypeValidator(0, 0, 0, DatatypeValidator::List)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumerationInherited(false)
  ,fEnumeration(0)
  ,fContent(0)
  {}
  
  inline ListDatatypeValidator::~ListDatatypeValidator()
  {
      cleanUp();
  }
  
  inline DatatypeValidator* ListDatatypeValidator::newInstance(
                                        DatatypeValidator*            const baseValidator
                                      , RefHashTableOf<KVStringPair>* const facets
                                      , RefVectorOf<XMLCh>*           const enums
                                      , const int                           finalSet)
  {
      return (DatatypeValidator*) new ListDatatypeValidator(baseValidator, facets, enums, finalSet);
  }
  
  inline void ListDatatypeValidator::validate( const XMLCh* const content)
  {
      setContent(content);
      RefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content);
      Janitor<RefVectorOf<XMLCh> > janName(tokenVector);
      checkContent(tokenVector, false);
  }
  
  inline void ListDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
  {
      setContent(content);
      RefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content);
      Janitor<RefVectorOf<XMLCh> > janName(tokenVector);
      checkContent(tokenVector, asBase);
  }
  
  inline void ListDatatypeValidator::cleanUp()
  {
      //~RefVectorOf will delete all adopted elements
      if (fEnumeration && !fEnumerationInherited)
          delete fEnumeration;
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  inline unsigned int ListDatatypeValidator::getLength() const
  {
      return fLength;
  }
  
  inline unsigned int ListDatatypeValidator::getMaxLength() const
  {
      return fMaxLength;
  }
  
  inline unsigned int ListDatatypeValidator::getMinLength() const
  {
      return fMinLength;
  }
  
  inline RefVectorOf<XMLCh>* ListDatatypeValidator:: getEnumeration() const
  {
      return fEnumeration;
  }
  
  inline const XMLCh* const ListDatatypeValidator::getContent() const
  {
      return fContent;
  }
  
  inline 
  DatatypeValidator* ListDatatypeValidator::getItemTypeDTV() const
  {
      DatatypeValidator* bdv = this->getBaseValidator();
  
      while (bdv->getType() == DatatypeValidator::List) 
          bdv = bdv->getBaseValidator();
  
      return bdv;
  }
  
  // -----------------------------------------------------------------------
  // Setter methods
  // -----------------------------------------------------------------------
  inline void ListDatatypeValidator::setLength(unsigned int newLength)
  {
      fLength = newLength;
  }
  
  inline void ListDatatypeValidator::setMaxLength(unsigned int newMaxLength)
  {
      fMaxLength = newMaxLength;
  }
  
  inline void ListDatatypeValidator::setMinLength(unsigned int newMinLength)
  {
      fMinLength = newMinLength;
  }
  
  inline void ListDatatypeValidator::setEnumeration(RefVectorOf<XMLCh>* enums
                                                  , bool                inherited)
  {
      if (enums)
      {
          if (fEnumeration && !fEnumerationInherited)
              delete fEnumeration;
  
          fEnumeration = enums;
          fEnumerationInherited = inherited;
          setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
      }
  }
  
  inline void ListDatatypeValidator::setContent(const XMLCh* const content)
  {
      fContent = content;
  }
  
  /**
    * End of file ListDatatypeValidator.hpp
    */
  #endif
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/ListDatatypeValidator.cpp
  
  Index: ListDatatypeValidator.cpp
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache\@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation, and was
   * originally based on software copyright (c) 2001, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: ListDatatypeValidator.cpp,v 1.1 2001/07/11 21:37:17 peiyongz Exp $
   * $Log: ListDatatypeValidator.cpp,v $
   * Revision 1.1  2001/07/11 21:37:17  peiyongz
   * ListDatatypeDTV
   *
   *
   */
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <validators/datatype/ListDatatypeValidator.hpp>
  #include <validators/datatype/InvalidDatatypeFacetException.hpp>
  #include <validators/datatype/InvalidDatatypeValueException.hpp>
  #include <util/NumberFormatException.hpp>
  
  static const int BUF_LEN = 64;
  static XMLCh value1[BUF_LEN+1];
  static XMLCh value2[BUF_LEN+1];
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  ListDatatypeValidator::ListDatatypeValidator(
                            DatatypeValidator*            const baseValidator
                          , RefHashTableOf<KVStringPair>* const facets
                          , RefVectorOf<XMLCh>*           const enums
                          , const int                           finalSet)
  :DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::List)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumerationInherited(false)
  ,fEnumeration(0)
  {
      //
      // baseValidator shall either 
      // an atomic DTV which servers as itemType, or
      // another ListDTV from which, this ListDTV is derived by restriction.
      // 
      // In either case, it shall be not null
      //
      if (!baseValidator)
          ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value1);
          //ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_List_Null_baseValidator);
          //"Not Null baseValidator required for ListDatatypeValidator
  
      try
      {
          init(baseValidator, facets, enums);
      }
      catch (XMLException&)
      {
          cleanUp();
          throw;
      }
  }
  
  void ListDatatypeValidator::init(DatatypeValidator*            const baseValidator
                                 , RefHashTableOf<KVStringPair>* const facets
                                 , RefVectorOf<XMLCh>*           const enums)
  {
      // Set Facets if any defined
      if (facets)
      {
          if (enums)
              setEnumeration(enums, false);
  
          XMLCh* key;
          XMLCh* value;
          RefHashTableOfEnumerator<KVStringPair> e(facets);
  
          while (e.hasMoreElements())
          {
              KVStringPair pair = e.nextElement();
              key = pair.getKey();
              value = pair.getValue();
  
              if (XMLString::compareString(key, SchemaSymbols::fgELT_LENGTH)==0)
              {
                  int val;
                  try
                  {
                      val = XMLString::parseInt(value);
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value);
                  }
  
                  if ( val < 0 )
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value);
  
                  setLength(val);
                  setFacetsDefined(DatatypeValidator::FACET_LENGTH);
              }
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_MINLENGTH)==0)
              {
                  int val;
                  try
                  {
                      val = XMLString::parseInt(value);
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value);
                  }
  
                  if ( val < 0 )
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value);
  
                  setMinLength(val);
                  setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
              }
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_MAXLENGTH)==0)
              {
                  int val;
                  try
                  {
                      val = XMLString::parseInt(value);
                  }
                  catch (NumberFormatException nfe)
                  {
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value);
                  }
  
                  if ( val < 0 )
                      ThrowXML1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value);
  
                  setMaxLength(val);
                  setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
              }
              else if (XMLString::compareString(key, SchemaSymbols::fgELT_PATTERN)==0)
              {
                  setPattern(value);
                  if (getPattern())
                      setFacetsDefined(DatatypeValidator::FACET_PATTERN);
                  // do not construct regex until needed
              }
              else if (XMLString::compareString(key, SchemaSymbols::fgATT_FIXED)==0)
              {
                  unsigned int val;
                  bool         retStatus;
                  try
                  {
                       retStatus = XMLString::textToBin(value, val);
                  }
                  catch (RuntimeException)
                  {
                      ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
                  }
  
                  if (!retStatus)
                  {
                      ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed);
                  }
  
                  setFixed(val);
                  //no setFacetsDefined here
              }
              else
              {
                   ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Tag);
              }
          }//while
  
          /***
             Schema constraint: Part I -- self checking
          ***/
  
          // check 4.3.1.c1 error: length & (maxLength | minLength)
          if ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0)
          {
              if ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0)
                   ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
              else if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0))
                   ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
          }
  
          // check 4.3.2.c1 must: minLength <= maxLength
          if ((getFacetsDefined() & (DatatypeValidator::FACET_MINLENGTH
                                    |DatatypeValidator::FACET_MAXLENGTH)) != 0)
          {
              if ( getMinLength() > getMaxLength() )
              {
                  XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
                  XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
  
                  ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_maxLen_minLen
                          , value1
                          , value2);
              }
          }
  
          /***
             Schema constraint: Part II base vs derived checking
          ***/
          if (baseValidator->getType() == DatatypeValidator::List)
          {
              /***
                  check facets against base.facets
              ***/
              ListDatatypeValidator *pBaseValidator = (ListDatatypeValidator*) baseValidator;
  
              /***
                  Non coexistence of derived' length and base'    (minLength | maxLength)
                                     base'    length and derived' (minLength | maxLength)
              ***/
  
              // check 4.3.1.c1 error: length & (base.maxLength | base.minLength)
              if ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0)
              {
                  if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0)
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
                  else if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0)
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
              }
  
              // check 4.3.1.c1 error: base.length & (maxLength | minLength)
              if ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0)
              {
                  if ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0)
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_maxLen);
                  else if ((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0)
                       ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_Len_minLen);
              }
  
              // check 4.3.1.c2 error: length != base.length
              if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0) &&
                  ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) !=0))
              {
                  if ( getLength() != pBaseValidator->getLength() )
                  {
                      XMLString::binToText(getLength(), value1, BUF_LEN, 10);
                      XMLString::binToText(pBaseValidator->getLength(), value2, BUF_LEN, 10);
  
                      ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_Len_baseLen
                          , value1
                          , value2);
                  }                    
              }
  
              /***
                                     |---  derived   ---|
                  base.minLength <= minLength <= maxLength <= base.maxLength
                  |-------------------        base      -------------------|
              ***/
  
              // check 4.3.2.c1 must: minLength <= base.maxLength
              if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH ) != 0) &&
                  ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH ) != 0))
              {
                  if ( getMinLength() > pBaseValidator->getMaxLength() )
                  {
                      XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
                      XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
  
                      ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_minLen_baseminLen
                          , value1
                          , value2);
                  }
              }
  
              // check 4.3.2.c2 error: minLength < base.minLength
              if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
                  ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0))
              {
                  if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MINLENGTH) !=0)
                  {
                      if ( getMinLength() != pBaseValidator->getMinLength() )
                      {
                          XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
                          XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
  
                          ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_minLen_base_fixed
                          , value1
                          , value2);
                      }
                  }
                  else
                  {
                      if ( getMinLength() < pBaseValidator->getMinLength() )
                      {
                          XMLString::binToText(getMinLength(), value1, BUF_LEN, 10);
                          XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
  
                          ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_minLen_basemaxLen
                          , value1
                          , value2);
                      }
                  }
              }
  
              // check 4.3.2.c1 must: base.minLength <= maxLength
              if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
                  ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0))
              {
                  if ( pBaseValidator->getMinLength() > getMaxLength() )
                  {
                      XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
                      XMLString::binToText(pBaseValidator->getMinLength(), value2, BUF_LEN, 10);
  
                      ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_maxLen_baseminLen
                          , value1
                          , value2);
                  }
              }
  
              // check 4.3.3.c1 error: maxLength > base.maxLength
              if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
                  ((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0))
              {
                  if ((pBaseValidator->getFixed() & DatatypeValidator::FACET_MAXLENGTH) !=0)
                  {
                      if ( getMaxLength() != pBaseValidator->getMaxLength() )
                      {
                          XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
                          XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
  
                          ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_maxLen_base_fixed
                          , value1
                          , value2);
                      }
                  }
                  else
                  {
                      if ( getMaxLength() > pBaseValidator->getMaxLength() )
                      {
                          XMLString::binToText(getMaxLength(), value1, BUF_LEN, 10);
                          XMLString::binToText(pBaseValidator->getMaxLength(), value2, BUF_LEN, 10);
  
                          ThrowXML2(InvalidDatatypeFacetException
                          , XMLExcepts::FACET_maxLen_basemaxLen
                          , value1
                          , value2);
                      }
                  }
              }
  
              // check 4.3.5.c0 must: enumeration values from the value space of base
              if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) &&
                   (getEnumeration() !=0))
              {
                  int i = 0;
                  int enumLength = getEnumeration()->size();
                  try
                  {
                      for ( ; i < enumLength; i++)
                      {
                          // ask parent do a complete check
                          pBaseValidator->checkContent(getEnumeration()->elementAt(i), false);
                          // enum shall pass this->checkContent() as well.
                          checkContent(getEnumeration()->elementAt(i), false);
                      }
                  }
  
                  catch ( XMLException& )
                  {
                      ThrowXML1(InvalidDatatypeFacetException
                              , XMLExcepts::FACET_enum_base
                              , getEnumeration()->elementAt(i));
                  }
              }
  
          } //ListDTV
          else
          {
              // the first level ListDTV
              // check 4.3.5.c0 must: enumeration values from the value space of base
              if ( ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0) &&
                   (getEnumeration() !=0))
              {
                  int i;
                  int enumLength = getEnumeration()->size();
                  try
                  {
                      for ( i = 0; i < enumLength; i++)
                      {
                          // ask the itemType for a complete check
                          RefVectorOf<XMLCh>* tempList = XMLString::tokenizeString(getEnumeration()->elementAt(i));
                          int tokenNumber = tempList->size();
  
                          try 
                          {
                              for ( int j = 0; j < tokenNumber; j++)
                                  baseValidator->validate(tempList->elementAt(j));
                          }
                          catch ( XMLException& )
                          {
                              delete tempList;
                              throw;
                          }
  
                          delete tempList;
  
                          // enum shall pass this->checkContent() as well.
                          checkContent(getEnumeration()->elementAt(i), false);
                      }
                  }
  
                  catch ( XMLException& )
                  {
                      ThrowXML1(InvalidDatatypeFacetException
                              , XMLExcepts::FACET_enum_base
                              , getEnumeration()->elementAt(i));
                  }
              }
          }
  
      }// End of Facet setting
  
      /***
          Inherit facets from base.facets
  
          The reason of this inheriting (or copying values) is to ease
          schema constraint checking, so that we need NOT trace back to our
          very first base validator in the hierachy. Instead, we are pretty
          sure checking against immediate base validator is enough.  
      ***/
      if (baseValidator->getType() == DatatypeValidator::List)
      {
          ListDatatypeValidator *pBaseValidator = (ListDatatypeValidator*) baseValidator;
  
          // inherit length
          if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
              ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) == 0))
          {
              setLength(pBaseValidator->getLength());
              setFacetsDefined(DatatypeValidator::FACET_LENGTH);
          }
  
          // inherit minLength
          if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) !=0) &&
              ((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) == 0))
          {
              setMinLength(pBaseValidator->getMinLength());
              setFacetsDefined(DatatypeValidator::FACET_MINLENGTH);
          }
  
          // inherit maxLength
          if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) !=0) &&
              ((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) == 0))
          {
              setMaxLength(pBaseValidator->getMaxLength());
              setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH);
          }
  
          // inherit enumeration
          if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) !=0) &&
              ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) == 0))
          {
              setEnumeration(pBaseValidator->getEnumeration(), true);
          }
  
          // we don't inherit pattern
  
          // inherit "fixed" option
          setFixed(getFixed() | pBaseValidator->getFixed());
  
      } // end of inheritance
  }
  
  //
  // here content is a list of items
  //
  void ListDatatypeValidator::checkContent( RefVectorOf<XMLCh>* tokenVector, bool asBase)
  {
      DatatypeValidator* bv = getBaseValidator();
      if (bv->getType() == DatatypeValidator::List)
          ((ListDatatypeValidator*)bv)->checkContent(tokenVector, true);
      else
      {   // the ultimate itemType DTV
          for (unsigned int i = 0; i < tokenVector->size(); i++)
              bv->validate(tokenVector->elementAt(i));
      }
  
      // we check pattern first
      if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 )
      {
          // lazy construction
          if (getRegex() == 0) 
          {
              try {
                  setRegex(new RegularExpression(getPattern(), SchemaSymbols::fgRegEx_XOption));
              }
              catch (XMLException &e)
              {
                  ThrowXML1(InvalidDatatypeValueException, XMLExcepts::RethrowError, e.getMessage());
              }
          }
  
          //check each and every item in the list   
          for (unsigned int i = 0; i < tokenVector->size(); i++)
          {
              if (getRegex()->matches(tokenVector->elementAt(i)) ==false)
              {
                  ThrowXML2(InvalidDatatypeValueException
                      , XMLExcepts::VALUE_NotMatch_Pattern
                      , tokenVector->elementAt(i)
                      , getPattern());
              }
  
          }
      }
  
      // if this is a base validator, we only need to check pattern facet
      // all other facet were inherited by the derived type
      if (asBase)
          return;
  
      unsigned int tokenNumber = tokenVector->size();
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
          (tokenNumber > getMaxLength()))
      {
          XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
          XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_GT_maxLen
                  , getContent()
                  , value1
                  , value2);
      }
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0) &&
          (tokenNumber < getMinLength()))
      {
          XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
          XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_LT_minLen
                  , getContent()
                  , value1
                  , value2);
      }
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
          (tokenNumber != getLength()))
      {
          XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
          XMLString::binToText(getLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_NE_Len
                  , getContent()
                  , value1
                  , value2);
      }
  
      if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 &&
          (getEnumeration() != 0))
      {
          int i;
          int enumLength = getEnumeration()->size();
  
          for ( i = 0; i < enumLength; i++)
          {
              //optimization: we do a lexical comparision first
              // this may be faster for string and its derived
              if (XMLString::compareString(getEnumeration()->elementAt(i), getContent()) == 0)
                  break; // a match found
  
              // do a value space check
              // this is needed for decimal (and probably other types 
              // such as datetime related)
              // eg.
              // tokenVector = "1 2 3.0 4" vs enumeration = "1 2 3 4.0"
              //
              if (valueSpaceCheck(tokenVector, getEnumeration()->elementAt(i)))
                  break;
          }
  
          if (i == enumLength)
              ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, getContent());
  
      } // enumeration
  
  }
  
  bool ListDatatypeValidator::valueSpaceCheck(RefVectorOf<XMLCh>* tokenVector
                                            , const XMLCh* const  enumStr) const
  {
      DatatypeValidator* theItemTypeDTV = getItemTypeDTV();
      RefVectorOf<XMLCh>* enumVector = XMLString::tokenizeString(enumStr);
      Janitor<RefVectorOf<XMLCh> > janName(enumVector);
  
      if (tokenVector->size() != enumVector->size())
          return false;
  
      for ( unsigned int j = 0; j < tokenVector->size(); j++ )
      {
          if (theItemTypeDTV->compare(tokenVector->elementAt(j), enumVector->elementAt(j)) != 0)
              return false;
      }
  
      return true;
  }
  
  int ListDatatypeValidator::compare(const XMLCh* const lValue
                                   , const XMLCh* const rValue)
  {
      DatatypeValidator* theItemTypeDTV = getItemTypeDTV();
      RefVectorOf<XMLCh>* lVector = XMLString::tokenizeString(lValue);
      Janitor<RefVectorOf<XMLCh> > janl(lVector);
      RefVectorOf<XMLCh>* rVector = XMLString::tokenizeString(rValue);
      Janitor<RefVectorOf<XMLCh> > janr(rVector);
     
      int lNumberOfTokens = lVector->size();         
      int rNumberOfTokens = rVector->size();         
  
      if (lNumberOfTokens < rNumberOfTokens)
          return -1; 
      else if (lNumberOfTokens > rNumberOfTokens)
          return 1;
      else 
      { //compare each token   
          for ( int i = 0; i < lNumberOfTokens; i++)
          {
              int returnValue = theItemTypeDTV->compare(lVector->elementAt(i), rVector->elementAt(i));
              if (returnValue != 0) 
                  return returnValue; //REVISIT: does it make sense to return -1 or +1..?               
          }
          return 0;
      }
         
  }
  
  /**
    * End of file ListDatatypeValidator.cpp
    */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org