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/10/09 22:56:21 UTC

cvs commit: xml-xerces/c/src/validators/datatype ListDatatypeValidator.cpp ListDatatypeValidator.hpp

peiyongz    01/10/09 13:56:21

  Modified:    c/src/validators/datatype ListDatatypeValidator.cpp
                        ListDatatypeValidator.hpp
  Log:
  inherit from AbstractStringValidator instead of DatatypeValidator to reuse
  the code.
  
  Revision  Changes    Path
  1.7       +156 -469  xml-xerces/c/src/validators/datatype/ListDatatypeValidator.cpp
  
  Index: ListDatatypeValidator.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/ListDatatypeValidator.cpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ListDatatypeValidator.cpp	2001/10/02 18:59:29	1.6
  +++ ListDatatypeValidator.cpp	2001/10/09 20:56:21	1.7
  @@ -55,8 +55,12 @@
    */
   
   /*
  - * $Id: ListDatatypeValidator.cpp,v 1.6 2001/10/02 18:59:29 peiyongz Exp $
  + * $Id: ListDatatypeValidator.cpp,v 1.7 2001/10/09 20:56:21 peiyongz Exp $
    * $Log: ListDatatypeValidator.cpp,v $
  + * Revision 1.7  2001/10/09 20:56:21  peiyongz
  + * inherit from AbstractStringValidator instead of DatatypeValidator to reuse
  + * the code.
  + *
    * Revision 1.6  2001/10/02 18:59:29  peiyongz
    * Invalid_Facet_Tag to display the tag name
    *
  @@ -95,31 +99,17 @@
   //  Constructors and Destructor
   // ---------------------------------------------------------------------------
   ListDatatypeValidator::ListDatatypeValidator()
  -:DatatypeValidator(0, 0, 0, DatatypeValidator::List)
  -,fLength(0)
  -,fMaxLength(SchemaSymbols::fgINT_MAX_VALUE)
  -,fMinLength(0)
  -,fEnumerationInherited(false)
  -,fEnumeration(0)
  +:AbstractStringValidator(0, 0, 0, DatatypeValidator::List)
   ,fContent(0)
   {}
   
  -ListDatatypeValidator::~ListDatatypeValidator()
  -{
  -    cleanUp();
  -}
  -
   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)
  +:AbstractStringValidator(baseValidator, facets, finalSet, DatatypeValidator::List)
  +,fContent(0)
   {
       //
       // baseValidator shall either 
  @@ -131,428 +121,68 @@
       if (!baseValidator)
           ThrowXML(InvalidDatatypeFacetException, XMLExcepts::FACET_List_Null_baseValidator);
   
  -    try
  -    {
  -        init(baseValidator, facets, enums);
  -    }
  -    catch (...)
  -    {
  -        cleanUp();
  -        throw;
  -    }
  +    init(enums);
   }
  -
  -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
  -            {
  -                 ThrowXML1(InvalidDatatypeFacetException
  -                         , XMLExcepts::FACET_Invalid_Tag
  -                         , key);
  -            }
  -        }//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 (...)
  -                        {
  -                            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;
  +ListDatatypeValidator::~ListDatatypeValidator()
  +{}
   
  -        // inherit length
  -        if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
  -            ((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) == 0))
  -        {
  -            setLength(pBaseValidator->getLength());
  -            setFacetsDefined(DatatypeValidator::FACET_LENGTH);
  -        }
  +DatatypeValidator* ListDatatypeValidator::newInstance(
  +                                      RefHashTableOf<KVStringPair>* const facets
  +                                    , RefVectorOf<XMLCh>*           const enums
  +                                    , const int                           finalSet)
  +{
  +    return (DatatypeValidator*) new ListDatatypeValidator(this, facets, enums, finalSet);
  +}
   
  -        // 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);
  -        }
  +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();         
   
  -        // inherit enumeration
  -        if (((pBaseValidator->getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) !=0) &&
  -            ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) == 0))
  +    if (lNumberOfTokens < rNumberOfTokens)
  +        return -1; 
  +    else if (lNumberOfTokens > rNumberOfTokens)
  +        return 1;
  +    else 
  +    { //compare each token   
  +        for ( int i = 0; i < lNumberOfTokens; i++)
           {
  -            setEnumeration(pBaseValidator->getEnumeration(), true);
  +            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;
  +    }
  +       
  +}
   
  -        // we don't inherit pattern
  +bool ListDatatypeValidator::isAtomic() const {
  +    return false;
  +}
   
  -        // inherit "fixed" option
  -        setFixed(getFixed() | pBaseValidator->getFixed());
  +void ListDatatypeValidator::validate( const XMLCh* const content)
  +{
  +    setContent(content);
  +    RefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content);
  +    Janitor<RefVectorOf<XMLCh> > janName(tokenVector);
  +    checkContent(tokenVector, false);
  +}
   
  -    } // end of inheritance
  +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);
   }
   
   //
  @@ -561,6 +191,7 @@
   void ListDatatypeValidator::checkContent( RefVectorOf<XMLCh>* tokenVector, bool asBase)
   {
       DatatypeValidator* bv = getBaseValidator();
  +
       if (bv->getType() == DatatypeValidator::List)
           ((ListDatatypeValidator*)bv)->checkContent(tokenVector, true);
       else
  @@ -569,8 +200,10 @@
               bv->validate(tokenVector->elementAt(i));
       }
   
  +    int thisFacetsDefined = getFacetsDefined();
  +
       // we check pattern first
  -    if ( (getFacetsDefined() & DatatypeValidator::FACET_PATTERN ) != 0 )
  +    if ( (thisFacetsDefined & DatatypeValidator::FACET_PATTERN ) != 0 )
       {
           // lazy construction
           if (getRegex() == 0) 
  @@ -605,7 +238,7 @@
   
       unsigned int tokenNumber = tokenVector->size();
   
  -    if (((getFacetsDefined() & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
  +    if (((thisFacetsDefined & DatatypeValidator::FACET_MAXLENGTH) != 0) &&
           (tokenNumber > getMaxLength()))
       {
           XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
  @@ -618,7 +251,7 @@
                   , value2);
       }
   
  -    if (((getFacetsDefined() & DatatypeValidator::FACET_MINLENGTH) != 0) &&
  +    if (((thisFacetsDefined & DatatypeValidator::FACET_MINLENGTH) != 0) &&
           (tokenNumber < getMinLength()))
       {
           XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
  @@ -631,11 +264,11 @@
                   , value2);
       }
   
  -    if (((getFacetsDefined() & DatatypeValidator::FACET_LENGTH) != 0) &&
  -        (tokenNumber != getLength()))
  +    if (((thisFacetsDefined & DatatypeValidator::FACET_LENGTH) != 0) &&
  +        (tokenNumber != AbstractStringValidator::getLength()))
       {
           XMLString::binToText(tokenNumber, value1, BUF_LEN, 10);
  -        XMLString::binToText(getLength(), value2, BUF_LEN, 10);
  +        XMLString::binToText(AbstractStringValidator::getLength(), value2, BUF_LEN, 10);
   
           ThrowXML3(InvalidDatatypeValueException
                   , XMLExcepts::VALUE_NE_Len
  @@ -644,7 +277,7 @@
                   , value2);
       }
   
  -    if ((getFacetsDefined() & DatatypeValidator::FACET_ENUMERATION) != 0 &&
  +    if ((thisFacetsDefined & DatatypeValidator::FACET_ENUMERATION) != 0 &&
           (getEnumeration() != 0))
       {
           int i;
  @@ -693,50 +326,105 @@
       return true;
   }
   
  -int ListDatatypeValidator::compare(const XMLCh* const lValue
  -                                 , const XMLCh* const rValue)
  +DatatypeValidator* ListDatatypeValidator::getItemTypeDTV() const
   {
  -    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();         
  +    DatatypeValidator* bdv = this->getBaseValidator();
   
  -    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;
  -    }
  -       
  +    while (bdv->getType() == DatatypeValidator::List)
  +        bdv = bdv->getBaseValidator();
  +
  +    return bdv;
   }
   
  -void ListDatatypeValidator::validate( const XMLCh* const content)
  +// ---------------------------------------------------------------------------
  +//  Utilities
  +// ---------------------------------------------------------------------------
  +void ListDatatypeValidator::assignAdditionalFacet( const XMLCh* const key
  +                                                 , const XMLCh* const)
   {
  -    setContent(content);
  -    RefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content);
  -    Janitor<RefVectorOf<XMLCh> > janName(tokenVector);
  -    checkContent(tokenVector, false);
  +    ThrowXML1(InvalidDatatypeFacetException
  +            , XMLExcepts::FACET_Invalid_Tag
  +            , key);
   }
   
  -void ListDatatypeValidator::checkContent( const XMLCh* const content, bool asBase)
  +void ListDatatypeValidator::inheritAdditionalFacet()
  +{}
  +
  +void ListDatatypeValidator::checkAdditionalFacetConstraints() const
  +{}
  +
  +void ListDatatypeValidator::checkAdditionalFacet(const XMLCh* const) const
  +{}
  +
  +void ListDatatypeValidator::checkValueSpace(const XMLCh* const content)
  +{}
  +
  +int ListDatatypeValidator::getLength(const XMLCh* const content) const
   {
  -    setContent(content);
       RefVectorOf<XMLCh>* tokenVector = XMLString::tokenizeString(content);
       Janitor<RefVectorOf<XMLCh> > janName(tokenVector);
  -    checkContent(tokenVector, asBase);
  +
  +    return tokenVector->size();
   }
  +
  +void ListDatatypeValidator::inspectFacetBase()
  +{
  +
  +    //
  +    // we are pretty sure baseValidator is not null
  +    //
  +
  +    if (getBaseValidator()->getType() == DatatypeValidator::List)
  +    {
  +        AbstractStringValidator::inspectFacetBase();
  +    }
  +    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++)
  +                            getBaseValidator()->validate(tempList->elementAt(j));
  +                    }
  +                    catch (...)
  +                    {
  +                        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 inspectFacetBase()
   
   /**
     * End of file ListDatatypeValidator.cpp
  
  
  
  1.8       +37 -123   xml-xerces/c/src/validators/datatype/ListDatatypeValidator.hpp
  
  Index: ListDatatypeValidator.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/validators/datatype/ListDatatypeValidator.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ListDatatypeValidator.hpp	2001/08/29 19:03:40	1.7
  +++ ListDatatypeValidator.hpp	2001/10/09 20:56:21	1.8
  @@ -55,8 +55,12 @@
    */
   
   /*
  - * $Id: ListDatatypeValidator.hpp,v 1.7 2001/08/29 19:03:40 peiyongz Exp $
  + * $Id: ListDatatypeValidator.hpp,v 1.8 2001/10/09 20:56:21 peiyongz Exp $
    * $Log: ListDatatypeValidator.hpp,v $
  + * Revision 1.8  2001/10/09 20:56:21  peiyongz
  + * inherit from AbstractStringValidator instead of DatatypeValidator to reuse
  + * the code.
  + *
    * Revision 1.7  2001/08/29 19:03:40  peiyongz
    * Bugzilla# 2816:on AIX 4.2, xlC 3 r ev.1, Compilation error on inline method
    *
  @@ -81,10 +85,10 @@
   #if !defined(LIST_DATATYPEVALIDATOR_HPP)
   #define LIST_DATATYPEVALIDATOR_HPP
   
  -#include <validators/datatype/DatatypeValidator.hpp>
  +#include <validators/datatype/AbstractStringValidator.hpp>
   #include <validators/schema/SchemaSymbols.hpp>
   
  -class VALIDATORS_EXPORT ListDatatypeValidator : public DatatypeValidator
  +class VALIDATORS_EXPORT ListDatatypeValidator : public AbstractStringValidator
   {
   public:
   
  @@ -101,14 +105,10 @@
                           , RefVectorOf<XMLCh>*           const enums
                           , const int                           finalSet);
   
  -
       virtual ~ListDatatypeValidator();
   
   	//@}
   
  -    // -----------------------------------------------------------------------
  -    // Getter methods
  -    // -----------------------------------------------------------------------
       /** @name Getter Functions */
       //@{
       /**
  @@ -156,55 +156,56 @@
         * Returns an instance of the base datatype validator class
   	  * Used by the DatatypeValidatorFactory.
         */
  -    DatatypeValidator* newInstance(RefHashTableOf<KVStringPair>* const facets
  -                                 , RefVectorOf<XMLCh>*           const enums
  -                                 , const int                           finalSet);
  +    virtual DatatypeValidator* newInstance(RefHashTableOf<KVStringPair>* const facets
  +                                         , RefVectorOf<XMLCh>*           const enums
  +                                         , const int                           finalSet);
   
       DatatypeValidator* getItemTypeDTV() const;
   
  -private:
  +protected:
   
  -    void checkContent(const XMLCh* const content, bool asBase);
  +    //
  +    // ctor provided to be used by derived classes: No
  +    //
   
  -    void checkContent(RefVectorOf<XMLCh>* tokenVector, bool asBase);
  +    virtual void assignAdditionalFacet(const XMLCh* const key
  +                                     , const XMLCh* const value);
   
  -    void init(DatatypeValidator*            const baseValidator
  -            , RefHashTableOf<KVStringPair>* const facets
  -            , RefVectorOf<XMLCh>*           const enums);
  +    virtual void inheritAdditionalFacet();
   
  -    void cleanUp();
  +    virtual void checkAdditionalFacetConstraints() const;
   
  +    virtual void checkAdditionalFacet(const XMLCh* const content) const;
   
  -    bool valueSpaceCheck(RefVectorOf<XMLCh>* tokenVector
  -                       , const XMLCh* const  enumStr) const;
  +    virtual void checkValueSpace(const XMLCh* const content);
   
  -// -----------------------------------------------------------------------
  -// Getter methods
  -// -----------------------------------------------------------------------
  +    virtual int  getLength(const XMLCh* const content) const;
   
  -    unsigned int         getLength() const;
  +    // 
  +    // Overwrite AbstractStringValidator's 
  +    //
  +    virtual void inspectFacetBase();
   
  -    unsigned int         getMaxLength() const;
  +private:
   
  -    unsigned int         getMinLength() const;
  +    void checkContent(const XMLCh* const content, bool asBase);
   
  -    RefVectorOf<XMLCh>*  getEnumeration() const;
  +    void checkContent(RefVectorOf<XMLCh>* tokenVector, bool asBase);
   
  -    const XMLCh* const   getContent() const;
  +    bool valueSpaceCheck(RefVectorOf<XMLCh>* tokenVector
  +                       , const XMLCh* const  enumStr) const;
   
   // -----------------------------------------------------------------------
  -// Setter methods
  +// Getter methods
   // -----------------------------------------------------------------------
  -
  -    void                 setLength(unsigned int);
   
  -    void                 setMaxLength(unsigned int);
  +    inline const XMLCh* const   getContent() const;
   
  -    void                 setMinLength(unsigned int);
  -
  -    void                 setEnumeration(RefVectorOf<XMLCh>*, bool);
  +// -----------------------------------------------------------------------
  +// Setter methods
  +// -----------------------------------------------------------------------
   
  -    void                 setContent(const XMLCh* const content);
  +    inline void                 setContent(const XMLCh* const content);
   
       // -----------------------------------------------------------------------
       //  Private data members
  @@ -214,107 +215,21 @@
       //      for error reporting purpose.
       //
       // -----------------------------------------------------------------------
  -     unsigned int         fLength;
  -     unsigned int         fMaxLength;
  -     unsigned int         fMinLength;
  -     bool                 fEnumerationInherited;
  -     RefVectorOf<XMLCh>*  fEnumeration;
        const XMLCh*         fContent;
   };
   
  -inline DatatypeValidator* ListDatatypeValidator::newInstance(
  -                                      RefHashTableOf<KVStringPair>* const facets
  -                                    , RefVectorOf<XMLCh>*           const enums
  -                                    , const int                           finalSet)
  -{
  -    return (DatatypeValidator*) new ListDatatypeValidator(this, facets, enums, finalSet);
  -}
  -
  -
  -
  -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
  +const XMLCh* const ListDatatypeValidator::getContent() 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;
  -}
  -
  -inline bool ListDatatypeValidator::isAtomic() const {
  -    return false;
  -}
  -
   // -----------------------------------------------------------------------
   // 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)
  +void ListDatatypeValidator::setContent(const XMLCh* const content)
   {
       fContent = content;
   }
  
  
  

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