xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peiyo...@apache.org
Subject cvs commit: xml-xerces/c/src/validators/datatype AnyURIDatatypeValidator.hpp AnyURIDatatypeValidator.cpp Makefile.in DatatypeValidatorFactory.cpp
Date Wed, 01 Aug 2001 18:49:16 GMT
peiyongz    01/08/01 11:49:16

  Modified:    c/src/validators/datatype Makefile.in
                        DatatypeValidatorFactory.cpp
  Added:       c/src/validators/datatype AnyURIDatatypeValidator.hpp
                        AnyURIDatatypeValidator.cpp
  Log:
  AnyRUIDatatypeValidator
  
  Revision  Changes    Path
  1.17      +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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Makefile.in	2001/07/26 20:40:56	1.16
  +++ Makefile.in	2001/08/01 18:49:16	1.17
  @@ -55,6 +55,9 @@
   #
   #
   # $Log: Makefile.in,v $
  +# Revision 1.17  2001/08/01 18:49:16  peiyongz
  +# AnyRUIDatatypeValidator
  +#
   # Revision 1.16  2001/07/26 20:40:56  peiyongz
   # FloatDatatypeValidator
   #
  @@ -145,6 +148,7 @@
   	UnionDatatypeValidator.hpp \
   	DoubleDatatypeValidator.hpp \
   	FloatDatatypeValidator.hpp \
  +	AnyURIDatatypeValidator.hpp \
   	IDREFDatatypeValidator.hpp
   
   VALIDATORS_DATATYPE_CPP_PRIVHEADERS =
  @@ -167,6 +171,7 @@
   	UnionDatatypeValidator.$(TO) \
   	DoubleDatatypeValidator.$(TO) \
   	FloatDatatypeValidator.$(TO) \
  +	AnyURIDatatypeValidator.$(TO) \
   	IDREFDatatypeValidator.$(TO)
   
   all::	includes $(VALIDATORS_DATATYPE_CPP_OBJECTS)
  
  
  
  1.21      +4 -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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DatatypeValidatorFactory.cpp	2001/07/26 20:48:02	1.20
  +++ DatatypeValidatorFactory.cpp	2001/08/01 18:49:16	1.21
  @@ -56,6 +56,9 @@
   
   /*
    * $Log: DatatypeValidatorFactory.cpp,v $
  + * Revision 1.21  2001/08/01 18:49:16  peiyongz
  + * AnyRUIDatatypeValidator
  + *
    * Revision 1.20  2001/07/26 20:48:02  peiyongz
    * FloatDatatypeValidator
    *
  @@ -143,6 +146,7 @@
   #include <validators/datatype/UnionDatatypeValidator.hpp>
   #include <validators/datatype/DoubleDatatypeValidator.hpp>
   #include <validators/datatype/FloatDatatypeValidator.hpp>
  +#include <validators/datatype/AnyURIDatatypeValidator.hpp>
   #include <util/PlatformUtils.hpp>
   #include <util/XMLDeleterFor.hpp>
   
  @@ -408,10 +412,8 @@
                          new DoubleDatatypeValidator());
           fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_FLOAT,
                          new FloatDatatypeValidator());
  -/*
           fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_ANYURI,
                          new AnyURIDatatypeValidator());
  -*/
           fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_QNAME,
                          new QNameDatatypeValidator());
   /*
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/AnyURIDatatypeValidator.hpp
  
  Index: AnyURIDatatypeValidator.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) 1999, International
   * Business Machines, Inc., http://www.ibm.com .  For more information
   * on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /*
   * $Id: AnyURIDatatypeValidator.hpp,v 1.1 2001/08/01 18:49:16 peiyongz Exp $
   * $Log: AnyURIDatatypeValidator.hpp,v $
   * Revision 1.1  2001/08/01 18:49:16  peiyongz
   * AnyRUIDatatypeValidator
   *
   *
   */
  
  #if !defined(ANYURI_DATATYPEVALIDATOR_HPP)
  #define ANYURI_DATATYPEVALIDATOR_HPP
  
  #include <validators/datatype/DatatypeValidator.hpp>
  #include <validators/schema/SchemaSymbols.hpp>
  #include <util/RefVectorOf.hpp>
  #include <util/XMLURL.hpp>
  
  class VALIDATORS_EXPORT AnyURIDatatypeValidator : public DatatypeValidator
  {
  public:
  
      // -----------------------------------------------------------------------
      //  Public ctor/dtor
      // -----------------------------------------------------------------------
  	/** @name Constructor. */
      //@{
  
      AnyURIDatatypeValidator();
  
      AnyURIDatatypeValidator(DatatypeValidator*            const baseValidator
                            , RefHashTableOf<KVStringPair>* const facets 
                            , RefVectorOf<XMLCh>*           const enums            
             
                            , const int                           finalSet);
  
      virtual ~AnyURIDatatypeValidator();
  
  	//@}
  
      // -----------------------------------------------------------------------
      // 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 init(DatatypeValidator*            const baseValidator
              , RefHashTableOf<KVStringPair>* const facets
              , RefVectorOf<XMLCh>*           const enums);
  
      void cleanUp();
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
      unsigned int         getLength() const;
  
      unsigned int         getMaxLength() const;
  
      unsigned int         getMinLength() const;
  
      RefVectorOf<XMLCh>*  getEnumeration() const;
  
  // -----------------------------------------------------------------------
  // Setter methods
  // -----------------------------------------------------------------------
  
      void                 setLength(unsigned int);
  
      void                 setMaxLength(unsigned int);
  
      void                 setMinLength(unsigned int);
  
      void                 setEnumeration(RefVectorOf<XMLCh>*, bool);
  
      // -----------------------------------------------------------------------
      //  Private data members
      //
      //  fTempURL
      //     
  	//		
      // -----------------------------------------------------------------------    
       int                  fLength;
       int                  fMaxLength;  
       int                  fMinLength;  
       bool                 fEnumerationInherited;
       RefVectorOf<XMLCh>*  fEnumeration;
  
       XMLURL              *fTempURI;   //use XMLURL instead of XMLURI for the moment
  
  };
  
  // ---------------------------------------------------------------------------
  //  Constructors and Destructor
  // ---------------------------------------------------------------------------
  inline AnyURIDatatypeValidator::AnyURIDatatypeValidator()
  :DatatypeValidator(0, 0, 0, DatatypeValidator::AnyURI)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumerationInherited(false)
  ,fEnumeration(0)
  ,fTempURI(0)
  {
  }
  
  inline AnyURIDatatypeValidator::~AnyURIDatatypeValidator()
  {
      cleanUp();
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
  
  // -----------------------------------------------------------------------
  // Compare methods
  // -----------------------------------------------------------------------
  inline int AnyURIDatatypeValidator::compare(const XMLCh* const lValue
                                            , const XMLCh* const rValue)
  {
      return XMLString::compareString(lValue, rValue);
  }
  
  inline DatatypeValidator* AnyURIDatatypeValidator::newInstance(
                                        DatatypeValidator*            const baseValidator
                                      , RefHashTableOf<KVStringPair>* const facets
                                      , RefVectorOf<XMLCh>*           const enums
                                      , const int                           finalSet)
  {
      return (DatatypeValidator*) new AnyURIDatatypeValidator(baseValidator, facets, enums,
finalSet);
  }
  
  inline void AnyURIDatatypeValidator::validate( const XMLCh* const content)
  {
      checkContent(content, false);
  }
  
  inline void AnyURIDatatypeValidator::cleanUp()
  {
      //~RefVectorOf will delete all adopted elements
      if (fEnumeration && !fEnumerationInherited)
          delete fEnumeration;
  
      if ( fTempURI )
          delete fTempURI;
  }
  
  // -----------------------------------------------------------------------
  // Getter methods
  // -----------------------------------------------------------------------
  
  inline unsigned int AnyURIDatatypeValidator::getLength() const
  {
      return fLength;
  }
  
  inline unsigned int AnyURIDatatypeValidator::getMaxLength() const
  {
      return fMaxLength;
  }
  
  inline unsigned int AnyURIDatatypeValidator::getMinLength() const
  {
      return fMinLength;
  }
  
  inline RefVectorOf<XMLCh>* AnyURIDatatypeValidator:: getEnumeration() const
  {
      return fEnumeration;
  }
  
  // -----------------------------------------------------------------------
  // Setter methods
  // -----------------------------------------------------------------------
  
  inline void AnyURIDatatypeValidator::setLength(unsigned int newLength)
  {
      fLength = newLength;
  }
  
  inline void AnyURIDatatypeValidator::setMaxLength(unsigned int newMaxLength)
  {
      fMaxLength = newMaxLength;
  }
  
  inline void AnyURIDatatypeValidator::setMinLength(unsigned int newMinLength)
  {
      fMinLength = newMinLength;
  }
  
  inline void AnyURIDatatypeValidator::setEnumeration(RefVectorOf<XMLCh>* enums
                                                    , bool                inherited)
  {
      if (enums)
      {
          if (fEnumeration && !fEnumerationInherited)
              delete fEnumeration;
  
          fEnumeration = enums;
          fEnumerationInherited = inherited;
          setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
      }
  }
  
  /**
    * End of file AnyURIDatatypeValidator.hpp
    */
  #endif
  
  
  
  1.1                  xml-xerces/c/src/validators/datatype/AnyURIDatatypeValidator.cpp
  
  Index: AnyURIDatatypeValidator.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: AnyURIDatatypeValidator.cpp,v 1.1 2001/08/01 18:49:16 peiyongz Exp $
   * $Log: AnyURIDatatypeValidator.cpp,v $
   * Revision 1.1  2001/08/01 18:49:16  peiyongz
   * AnyRUIDatatypeValidator
   *
   *
   */
  
  // ---------------------------------------------------------------------------
  //  Includes
  // ---------------------------------------------------------------------------
  #include <validators/datatype/AnyURIDatatypeValidator.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
  // ---------------------------------------------------------------------------
  AnyURIDatatypeValidator::AnyURIDatatypeValidator(
                            DatatypeValidator*            const baseValidator
                          , RefHashTableOf<KVStringPair>* const facets
                          , RefVectorOf<XMLCh>*           const enums
                          , const int                           finalSet)
  :DatatypeValidator(baseValidator, facets, finalSet, DatatypeValidator::AnyURI)
  ,fLength(0)
  ,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  ,fMinLength(0)
  ,fEnumerationInherited(false)
  ,fEnumeration(0)
  ,fTempURI(0)
  {
      try
      {
          init(baseValidator, facets, enums);
      }
      catch (...)
      {
          cleanUp();
          throw;
      }
  }
  
  void AnyURIDatatypeValidator::init(DatatypeValidator*            const baseValidator
                                   , RefHashTableOf<KVStringPair>* const facets
                                   , RefVectorOf<XMLCh>*           const enums)
  {
      //
      // Make sure that baseValidator is of the same type
      // as the one to be created.
      //
      // TO DO: moving this checking to DatatypeValidator
      //        to avoid repeat this code in all DTV.
      //        special case:: union and list
      //
      if ( baseValidator && 
           (baseValidator->getType() != DatatypeValidator::AnyURI))
      {
          //invalid baseValidator's type;
      }
  
      // 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 != 0)
          {
              /***
                  check facets against base.facets
                  Note: later we need to check the "fix" option of the base type
                        and apply that to every individual facet.
              ***/
              AnyURIDatatypeValidator *pBaseValidator = (AnyURIDatatypeValidator*) 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);
                          // REVISIT: enum shall pass this->checkContent() as well.
                          checkContent(getEnumeration()->elementAt(i), false);
  
                      }
                  }
  
                  catch ( XMLException& )
                  {
                      ThrowXML1(InvalidDatatypeFacetException
                              , XMLExcepts::FACET_enum_base
                              , getEnumeration()->elementAt(i));
                  }
              }
  
           } // if baseValidator
  
       }// 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 )
      {
          AnyURIDatatypeValidator *pBaseValidator = (AnyURIDatatypeValidator*) 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
  
  }
  
  void AnyURIDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
  {
      char* p=XMLString::transcode(content);
  
      //validate against base validator if any
      AnyURIDatatypeValidator *pBaseValidator = (AnyURIDatatypeValidator*) this->getBaseValidator();
      if (pBaseValidator !=0)
          pBaseValidator->checkContent(content, true);
  
      // 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());
              }
          }
  
          if (getRegex()->matches(content) ==false)
          {
              ThrowXML2(InvalidDatatypeValueException
                      , XMLExcepts::VALUE_NotMatch_Pattern
                      , content
                      , 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 strLen = XMLString::stringLen(content);
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
          (strLen > getMaxLength()))
      {
          XMLString::binToText(strLen, value1, BUF_LEN, 10);
          XMLString::binToText(getMaxLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_GT_maxLen
                  , content
                  , value1
                  , value2);
      }
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0) &&
          (strLen < getMinLength()))
      {
          XMLString::binToText(strLen, value1, BUF_LEN, 10);
          XMLString::binToText(getMinLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_LT_minLen
                  , content
                  , value1
                  , value2);
      }
  
      if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
          (strLen != getLength()))
      {
          XMLString::binToText(strLen, value1, BUF_LEN, 10);
          XMLString::binToText(getLength(), value2, BUF_LEN, 10);
  
          ThrowXML3(InvalidDatatypeValueException
                  , XMLExcepts::VALUE_NE_Len
                  , content
                  , value1
                  , value2);
      }
  
      if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 &&
          (getEnumeration() != 0))
      {
          int i=0;
          int enumLength = getEnumeration()->size();
          for ( ; i < enumLength; i++)
          {
              if (XMLString::compareString(content, getEnumeration()->elementAt(i))==0)
                  break;
          }
  
          if (i == enumLength)
              ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration,
content);
      }
  
      // check 3.2.17.c0 must: URI (rfc 2396/2723)
      XMLURL  *newURI;
  
  #ifdef REVISIT
      try 
      {
          if (!fTempURI) 
              fTempURI = new XMLURL("http://www.template.com");
  
          // Support for relative URLs
          // According to Java 1.1: URLs may also be specified with a 
          // String and the URL object that it is related to.
          //
          if (strLen) 
          {
              newURI = new XMLURL(*fTempURI, content );   
              delete newURI;
          }
      } 
  #endif
      try 
      {
          if (strLen) 
          {
              newURI = new XMLURL(content );   
              delete newURI;
          }
      } 
      catch (...) 
      {
          ThrowXML1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content);
          //("Value '"+content+"' is a Malformed URI ");
      }
        
  }
  
  /**
    * End of file AnyURIDatatypeValidator.cpp
    */
  
  
  

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


Mime
View raw message