peiyongz    2003/12/11 13:40:24

  Modified:    c/src/xercesc/validators/datatype
                        AbstractNumericValidator.cpp
                        DatatypeValidatorFactory.cpp
                        DatatypeValidatorFactory.hpp
                        DateTimeDatatypeValidator.cpp DateTimeValidator.hpp
                        DecimalDatatypeValidator.cpp
                        TimeDatatypeValidator.cpp
  Log:
  support for Canonical Representation for Datatype
  
  Revision  Changes    Path
  1.9       +9 -23     
xml-xerces/c/src/xercesc/validators/datatype/AbstractNumericValidator.cpp
  
  Index: AbstractNumericValidator.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/AbstractNumericValidator.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractNumericValidator.cpp      28 Nov 2003 18:53:07 -0000      1.8
  +++ AbstractNumericValidator.cpp      11 Dec 2003 21:40:24 -0000      1.9
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.9  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.8  2003/11/28 18:53:07  peiyongz
    * Support for getCanonicalRepresentation
    *
  @@ -94,6 +97,7 @@
   // ---------------------------------------------------------------------------
   #include <xercesc/validators/datatype/AbstractNumericValidator.hpp>
   #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
  +#include <xercesc/util/XMLAbstractDoubleFloat.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -189,35 +193,17 @@
   
   }
   
  -/***
  - * 3.2.4 float
  - * 3.2.5 double
  - *
  - * . the exponent must be indicated by "E". 
  - *
  - * . For the mantissa, 
  - *      the preceding optional "+" sign is prohibited and 
  - *      the decimal point is required. 
  - *
  - * . For the exponent, 
  - *      the preceding optional "+" sign is prohibited. 
  - *      Leading zeroes are prohibited.
  - *      
  - * . Leading and trailing zeroes are prohibited subject to the following: 
  - *      number representations must be normalized such that 
  - *          . there is a single digit to the left of the decimal point and
  - *          . at least a single digit to the right of the decimal point.
  - *
  - ***/     
   const XMLCh* AbstractNumericValidator::getCanonicalRepresentation(const XMLCh*      
   const rawData
                                                                    ,      
MemoryManager* const memMgr) const
   {
  +    //Validate the content
       AbstractNumericValidator* temp = (AbstractNumericValidator*) this;
       temp->checkContent(rawData, 0, false);
   
       MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
  -    //todo: change behaviour later
  -    return XMLString::replicate(rawData, toUse);
  +
  +    return XMLAbstractDoubleFloat::getCanonicalRepresentation(rawData, toUse);
  +
   }
   
   /***
  
  
  
  1.23      +89 -1     
xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp
  
  Index: DatatypeValidatorFactory.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- DatatypeValidatorFactory.cpp      13 Nov 2003 23:02:09 -0000      1.22
  +++ DatatypeValidatorFactory.cpp      11 Dec 2003 21:40:24 -0000      1.23
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.23  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.22  2003/11/13 23:02:09  peiyongz
    * using default memory manager and specify derivated from list, not user defined
    *
  @@ -246,6 +249,7 @@
   #include <xercesc/util/XMLRegisterCleanup.hpp>
   
   #include <xercesc/internal/XTemplateSerializer.hpp>
  +#include <xercesc/util/HashPtr.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -416,6 +420,7 @@
   //  DatatypeValidatorFactory: Static member data
   // ---------------------------------------------------------------------------
   RefHashTableOf<DatatypeValidator>* DatatypeValidatorFactory::fBuiltInRegistry = 0;
  +RefHashTableOf<XMLCanRepGroup>*    DatatypeValidatorFactory::fCanRepRegistry = 0;
   
   // ---------------------------------------------------------------------------
   //  DatatypeValidatorFactory: Constructors and Destructor
  @@ -452,6 +457,9 @@
       delete fBuiltInRegistry;
       fBuiltInRegistry = 0;
   
  +    delete fCanRepRegistry;
  +    fCanRepRegistry = 0;
  +
       // delete local static data
       delete sBuiltInRegistryMutex;
       sBuiltInRegistryMutex = 0;
  @@ -798,16 +806,96 @@
                , false
              );
   
  +            initCanRepRegistory();
  +
               // register cleanup method
               builtInRegistryCleanup.registerCleanup(reinitRegistry);
               sBuiltInRegistryMutexRegistered = true;
  +
           }
       }
   
  -    //todo: to move these to fBuiltInRegistry
  +}
  +
  +/***
  + *
  + *   For Decimal-derivated, an instance of DecimalDatatypeValidator
  + *   can be used by the primitive datatype, decimal, or any one of 
  + *   the derivated datatypes, such as int, long, unsighed short, just
  + *   name a few, or any user-defined datatypes, which may derivate from
  + *   either the primitive datatype, decimal, or from any one of those 
  + *   decimal derivated datatypes, or other user-defined datatypes, which
  + *   in turn, indirectly derivate from decimal or decimal-derived.
  + *
  + *   fCanRepRegisty captures deciaml dv and its derivatives.
  + *
  + ***/
  +void DatatypeValidatorFactory::initCanRepRegistory()
  +{
  +
  +     /***
  +      * key:  dv
  +      * data: XMLCanRepGroup
  +      ***/
  +     fCanRepRegistry  = new RefHashTableOf<XMLCanRepGroup>(29, true, new HashPtr() 
);
  +
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_DECIMAL),
  +                        new  XMLCanRepGroup(XMLCanRepGroup::Decimal));
  +
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_INTEGER),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_LONG),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_INT),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_SHORT),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_BYTE),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) 
getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +     fCanRepRegistry->put((void*) 
getDatatypeValidator(SchemaSymbols::fgDT_POSITIVEINTEGER),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_signed));
  +
  +     fCanRepRegistry->put((void*) 
getDatatypeValidator(SchemaSymbols::fgDT_NEGATIVEINTEGER),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_unsigned));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_ULONG),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_unsigned));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_UINT),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_unsigned));
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_USHORT),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_unsigned));        
  +     fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_UBYTE),
  +                        new  
XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_unsigned));
  +
  +     fCanRepRegistry->put((void*) 
getDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER),
  +                        new  XMLCanRepGroup(XMLCanRepGroup::Decimal_Derivated_npi));
   
  +}
  +
  +/***
  + *
  + *   For any dv other than Decimaldv, return String only.
  + *   Later on if support to dv other than Decimaldv arise, we may
  + *   add them fCanRepRegistry during DatatypeValidatorFactory::initCanRepRegistory()
  + *
  + ***/
  +XMLCanRepGroup::CanRepGroup DatatypeValidatorFactory::getCanRepGroup(const 
DatatypeValidator* const dv)
  +{
  +    if (!dv)
  +        return XMLCanRepGroup::String;
  +
  +    DatatypeValidator *curdv = (DatatypeValidator*) dv;
   
  +    while (curdv)
  +    {
  +        if (fCanRepRegistry->containsKey(curdv))
  +            return fCanRepRegistry->get(curdv)->getGroup();
  +        else
  +            curdv = curdv->getBaseValidator();
  +    }
   
  +    return XMLCanRepGroup::String;
   }
   
   // ---------------------------------------------------------------------------
  
  
  
  1.13      +11 -1     
xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.hpp
  
  Index: DatatypeValidatorFactory.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.hpp,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DatatypeValidatorFactory.hpp      5 Nov 2003 16:35:31 -0000       1.12
  +++ DatatypeValidatorFactory.hpp      11 Dec 2003 21:40:24 -0000      1.13
  @@ -85,6 +85,7 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include <xercesc/validators/datatype/DatatypeValidator.hpp>
  +#include <xercesc/validators/datatype/XMLCanRepGroup.hpp>
   #include <xercesc/util/RefVectorOf.hpp>
   
   #include <xercesc/internal/XSerializable.hpp>
  @@ -170,6 +171,14 @@
       void expandRegistryToFullSchemaSet();
   
       //@}
  +
  +    // -----------------------------------------------------------------------
  +    // Canonical Representation Group
  +    // -----------------------------------------------------------------------
  +           void                        initCanRepRegistory();
  +
  +    static XMLCanRepGroup::CanRepGroup getCanRepGroup(const DatatypeValidator* 
const);
  +
       // -----------------------------------------------------------------------
       // Validator Factory methods
       // -----------------------------------------------------------------------
  @@ -263,6 +272,7 @@
       // -----------------------------------------------------------------------
       XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XERCES_CPP_NAMESPACE_QUALIFIER 
DatatypeValidator>*        fUserDefinedRegistry;
       static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<DatatypeValidator>* 
fBuiltInRegistry;
  +    static XERCES_CPP_NAMESPACE_QUALIFIER RefHashTableOf<XMLCanRepGroup>*    
fCanRepRegistry;
       XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const fMemoryManager;
   
       friend class XPath2ContextImpl;
  
  
  
  1.11      +8 -9      
xml-xerces/c/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp
  
  Index: DateTimeDatatypeValidator.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DateTimeDatatypeValidator.cpp     28 Nov 2003 18:53:07 -0000      1.10
  +++ DateTimeDatatypeValidator.cpp     11 Dec 2003 21:40:24 -0000      1.11
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.11  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.10  2003/11/28 18:53:07  peiyongz
    * Support for getCanonicalRepresentation
    *
  @@ -169,21 +172,17 @@
       pDate->parseDateTime();
   }
   
  -/***
  - *3.2.7 dateTime
  - *
  - *  . either the time zone must be omitted or, 
  - *    if present, the time zone must be Coordinated Universal Time (UTC) indicated 
by a "Z".
  - ***/   
   const XMLCh* DateTimeDatatypeValidator::getCanonicalRepresentation(const XMLCh*     
    const rawData
                                                                     ,      
MemoryManager* const memMgr) const
   {
  +    // we need the checkContent to build the fDateTime
  +    // to get the canonical representation
       DateTimeDatatypeValidator* temp = (DateTimeDatatypeValidator*) this;
       temp->checkContent(rawData, 0, false);
   
       MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
  -    //todo: change behaviour later
  -    return XMLString::replicate(rawData, toUse);
  +    //Have the fDateTime to do the job
  +    return fDateTime->getDateTimeCanonicalRepresentation(toUse);
   }
   
   /***
  
  
  
  1.7       +5 -3      
xml-xerces/c/src/xercesc/validators/datatype/DateTimeValidator.hpp
  
  Index: DateTimeValidator.hpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DateTimeValidator.hpp,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DateTimeValidator.hpp     12 Nov 2003 20:32:03 -0000      1.6
  +++ DateTimeValidator.hpp     11 Dec 2003 21:40:24 -0000      1.7
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.7  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.6  2003/11/12 20:32:03  peiyongz
    * Statless Grammar: ValidationContext
    *
  @@ -176,8 +179,7 @@
                                         , const XMLDateTime* const rValue
                                         , bool                     strict);
   
  -private:
  -    XMLDateTime* fDateTime;
  +    XMLDateTime* fDateTime;    //made available to derivatives
   };
   
   XERCES_CPP_NAMESPACE_END
  
  
  
  1.18      +38 -24    
xml-xerces/c/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp
  
  Index: DecimalDatatypeValidator.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DecimalDatatypeValidator.cpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DecimalDatatypeValidator.cpp      28 Nov 2003 18:53:07 -0000      1.17
  +++ DecimalDatatypeValidator.cpp      11 Dec 2003 21:40:24 -0000      1.18
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.18  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.17  2003/11/28 18:53:07  peiyongz
    * Support for getCanonicalRepresentation
    *
  @@ -168,11 +171,15 @@
   //  Includes
   // ---------------------------------------------------------------------------
   #include <xercesc/validators/datatype/DecimalDatatypeValidator.hpp>
  +#include <xercesc/validators/datatype/XMLCanRepGroup.hpp>
   #include <xercesc/validators/schema/SchemaSymbols.hpp>
   #include <xercesc/validators/datatype/InvalidDatatypeFacetException.hpp>
   #include <xercesc/validators/datatype/InvalidDatatypeValueException.hpp>
  +
  +#include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp>
   #include <xercesc/util/NumberFormatException.hpp>
   #include <xercesc/util/XMLBigDecimal.hpp>
  +#include <xercesc/util/XMLBigInteger.hpp>
   
   XERCES_CPP_NAMESPACE_BEGIN
   
  @@ -645,10 +652,12 @@
    *   . the preceding optional "+" sign is prohibited and
    *   . leading zeroes are prohibited.
    *   
  + *
  + *  E2-27
    *  3.3.14 nonPositiveInteger
    *
  - *  . the negative sign ("-") is required with the token "0" and 
  - *  . leading zeroes are prohibited.
  + *   . In the canonical form for zero, the sign must be omitted. 
  + *   . leading zeroes are prohibited.
    *  
    *  3.3.15 negativeInteger
    *  3.3.21 unsignedLong
  @@ -658,37 +667,42 @@
    *
    *  . leading zeroes are prohibited.
    *  
  - *  todo:
  - *    In order to implement this method, this class shall have a way to tell if 
itself
  - *    is an 'int', or 'unsignedLong', or something list above, not merely 'Decimal'.
  - *
  - *    Thus we need to extend DatatypeValidator::ValidatorType to include these
  - *    'new' dv types. And assign them the value the way that once AND with mask
  - *    it would be 'Decimal', and all the existing dv type would remain what they
  - *    are.
  - *
  - *    eg. 'String' & mask = 'String'
  - *        'AnyURI' & mask = 'AnyURI',
  - *
  - *        'int'    & mask = 'Decimal'
  - *        'long'   & mask = 'long'
  - *    
  - *    thus, when deserialize, we can create 'Decimal'dv even they are 'int',
  - *    'long'.
  - *
  - *    All dv' ctor need to carry an extra field DatatypeValidator::ValidatorType
  - *    to specify who it is rather than merely relying on the c++ object itself.
  + *  Summary:
  + *  . leading zeros are prohibited for all three groups
  + *  . '-' is required for nonPositiveInteger if it is zero
    *
    ***/
  +
   const XMLCh* DecimalDatatypeValidator::getCanonicalRepresentation(const XMLCh*      
   const rawData
                                                                    ,      
MemoryManager* const memMgr) const
   {
  +    //Validate it first
       DecimalDatatypeValidator* temp = (DecimalDatatypeValidator*) this;
       temp->checkContent(rawData, 0, false);
   
       MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
  -    //todo: change behaviour later
  -    return XMLString::replicate(rawData, toUse);
  +
  +    XMLCanRepGroup::CanRepGroup dvType = 
DatatypeValidatorFactory::getCanRepGroup(temp);
  +
  +    if ((dvType == XMLCanRepGroup::Decimal_Derivated_signed)   ||
  +        (dvType == XMLCanRepGroup::Decimal_Derivated_unsigned) ||
  +        (dvType == XMLCanRepGroup::Decimal_Derivated_npi)        )
  +    {          
  +        return XMLBigInteger::getCanonicalRepresentation
  +               (
  +                rawData
  +              , toUse
  +               );
  +    }
  +    else if (dvType == XMLCanRepGroup::Decimal) 
  +    {
  +        return XMLBigDecimal::getCanonicalRepresentation(rawData, toUse);
  +    }
  +    else //in case?
  +    {
  +        return XMLString::replicate(rawData, toUse);
  +    }
  +
   }
   
   /***
  
  
  
  1.11      +8 -12     
xml-xerces/c/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp
  
  Index: TimeDatatypeValidator.cpp
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/c/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TimeDatatypeValidator.cpp 28 Nov 2003 18:53:07 -0000      1.10
  +++ TimeDatatypeValidator.cpp 11 Dec 2003 21:40:24 -0000      1.11
  @@ -57,6 +57,9 @@
   /*
    * $Id$
    * $Log$
  + * Revision 1.11  2003/12/11 21:40:24  peiyongz
  + * support for Canonical Representation for Datatype
  + *
    * Revision 1.10  2003/11/28 18:53:07  peiyongz
    * Support for getCanonicalRepresentation
    *
  @@ -169,24 +172,17 @@
       pDate->parseTime();
   }
   
  -/***
  - * 3.2.8 time
  - *
  - *  . either the time zone must be omitted or, 
  - *    if present, the time zone must be Coordinated Universal Time (UTC) indicated 
by a "Z".   
  - *
  - *  . Additionally, the canonical representation for midnight is 00:00:00.
  - *
  -***/
   const XMLCh* TimeDatatypeValidator::getCanonicalRepresentation(const XMLCh*         
const rawData
                                                                 ,      MemoryManager* 
const memMgr) const
   {
  +    // we need the checkContent to build the fDateTime
  +    // to get the canonical representation
       TimeDatatypeValidator* temp = (TimeDatatypeValidator*) this;
       temp->checkContent(rawData, 0, false);
   
       MemoryManager* toUse = memMgr? memMgr : fMemoryManager;
  -    //todo: change behaviour later
  -    return XMLString::replicate(rawData, toUse);
  +    //Have the fDateTime to do the job
  +    return fDateTime->getTimeCanonicalRepresentation(toUse);
   }
   
   /***
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to