source: tags/VUT/0.4/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/datatype/DatatypeValidator.hpp @ 358

Revision 358, 20.0 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: DatatypeValidator.hpp,v 1.26 2004/09/08 13:56:52 peiyongz Exp $
19 */
20
21#if !defined(DATATYPEVALIDATOR_HPP)
22#define DATATYPEVALIDATOR_HPP
23
24#include <xercesc/util/PlatformUtils.hpp>
25#include <xercesc/util/RefHashTableOf.hpp>
26#include <xercesc/util/KVStringPair.hpp>
27#include <xercesc/util/XMLUniDefs.hpp>
28#include <xercesc/util/regx/RegularExpression.hpp>
29#include <xercesc/validators/schema/SchemaSymbols.hpp>
30#include <xercesc/internal/XSerializable.hpp>
31#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
32#include <xercesc/framework/ValidationContext.hpp>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36class MemoryManager;
37
38/**
39  * DataTypeValidator defines the interface that data type validators must
40  * obey. These validators can be supplied by the application writer and may
41  * be useful as standalone code as well as plugins to the validator
42  * architecture.
43  *
44  * Notice:
45  * The datatype validator will own the facets hashtable passed to it during
46  * construction, which means that the datatype validator will be responsible
47  * for the deletion. The facets hashtable will be created during parsing and
48  * passed to the appropriate datatype validator which in turn will delete it
49  * upon its destruction.
50  *
51  */
52
53
54class VALIDATORS_EXPORT DatatypeValidator : public XSerializable, public XMemory
55{
56public:
57    // -----------------------------------------------------------------------
58    // Constant data
59    // -----------------------------------------------------------------------
60        //facets
61        enum {
62        FACET_LENGTH         = 1,
63        FACET_MINLENGTH      = 1<<1,
64        FACET_MAXLENGTH      = 1<<2,
65        FACET_PATTERN        = 1<<3,
66        FACET_ENUMERATION    = 1<<4,
67        FACET_MAXINCLUSIVE   = 1<<5,
68        FACET_MAXEXCLUSIVE   = 1<<6,
69        FACET_MININCLUSIVE   = 1<<7,
70        FACET_MINEXCLUSIVE   = 1<<8,
71        FACET_TOTALDIGITS    = 1<<9,
72        FACET_FRACTIONDIGITS = 1<<10,
73        FACET_ENCODING       = 1<<11,
74        FACET_DURATION       = 1<<12,
75        FACET_PERIOD         = 1<<13,
76        FACET_WHITESPACE     = 1<<14
77    };
78
79    //2.4.2.6 whiteSpace - Datatypes
80        enum {
81        PRESERVE = 0,
82        REPLACE  = 1,
83        COLLAPSE = 2
84    };
85
86    enum ValidatorType {
87        String,
88        AnyURI,
89        QName,
90        Name,
91        NCName,
92        Boolean,
93        Float,
94        Double,
95        Decimal,
96        HexBinary,
97        Base64Binary,
98        Duration,
99        DateTime,
100        Date,
101        Time,
102        MonthDay,
103        YearMonth,
104        Year,
105        Month,
106        Day,
107        ID,
108        IDREF,
109        ENTITY,
110        NOTATION,
111        List,
112        Union,
113        AnySimpleType,
114        UnKnown
115    };
116
117    // -----------------------------------------------------------------------
118    //  Public Destructor
119    // -----------------------------------------------------------------------
120        /** @name Destructor. */
121    //@{
122
123    virtual ~DatatypeValidator();
124
125        //@}
126
127    // -----------------------------------------------------------------------
128    // Getter methods
129    // -----------------------------------------------------------------------
130    /** @name Getter Functions */
131    //@{
132
133    /**
134      * Returns the final values of the simpleType
135      */
136    int getFinalSet() const;
137
138    /**
139      * Returns the datatype facet if any is set.
140      */
141        RefHashTableOf<KVStringPair>* getFacets() const;
142
143    /**
144      * Returns default value (collapse) for whiteSpace facet.
145      * This function is overwritten in StringDatatypeValidator.
146      */
147    short getWSFacet () const;
148
149    /**
150      * Returns the base datatype validator if set.
151      */
152    DatatypeValidator* getBaseValidator() const;
153
154    /**
155      * Returns the 'class' type of datatype validator
156      */
157    ValidatorType getType() const;
158
159    /**
160      * Returns whether the type is atomic or not
161      *
162      * To be redefined in List/Union validators
163      */
164    virtual bool isAtomic() const;
165
166    /**
167      * Returns the datatype enumeration if any is set.
168          * Derived class shall provide their own copy.
169      */
170        virtual const RefArrayVectorOf<XMLCh>* getEnumString() const = 0;
171
172    /**
173     * returns true if this type is anonymous
174     **/
175    bool getAnonymous() const;
176
177    /**
178     * sets this type to be anonymous
179     **/
180    void setAnonymous();
181
182    /**
183     *  Fundamental Facet: ordered
184     */
185    XSSimpleTypeDefinition::ORDERING getOrdered() const;
186
187    /**
188     * Fundamental Facet: cardinality.
189     */
190    bool getFinite() const;
191
192    /**
193     * Fundamental Facet: bounded.
194     */
195    bool getBounded() const;
196
197    /**
198     * Fundamental Facet: numeric.
199     */
200    bool getNumeric() const;
201
202    /**
203     *    Canonical Representation
204     *
205     *    Derivative datatype may overwrite this method once
206     *    it has its own canonical representation other than
207     *    the default one.
208     *
209     * @param rawData:    data in raw string
210     * @param memMgr:     memory manager
211     * @param toValiate:  to validate the raw string or not
212     *
213     * @return: canonical representation of the data
214     *
215     * Note: 
216     *
217     *    1. the return value is kept in memory allocated
218     *       by the memory manager passed in or by dv's
219     *       if no memory manager is provided.
220     *
221     *    2. client application is responsible for the
222     *       proper deallcation of the memory allocated
223     *       for the returned value.
224     *
225     *    3. In the case where the rawData is not valid
226     *       with regards to the fundamental datatype,
227     *       a null string is returned.
228     *
229     */
230    virtual const XMLCh* getCanonicalRepresentation
231                        (
232                          const XMLCh*         const rawData
233                        ,       MemoryManager* const memMgr = 0
234                        ,       bool                 toValidate = false
235                        ) const;
236
237    //@}
238
239    // -----------------------------------------------------------------------
240    // Validation methods
241    // -----------------------------------------------------------------------
242    /** @name Validation Function */
243    //@{
244
245     /**
246           * Checks that the "content" string is valid datatype.
247       * If invalid, a Datatype validation exception is thrown.
248           *
249           * @param  content   A string containing the content to be validated
250           *
251           */
252        virtual void validate
253                 (
254                  const XMLCh*             const content
255                ,       ValidationContext* const context = 0
256                ,       MemoryManager*     const manager = XMLPlatformUtils::fgMemoryManager
257                  ) = 0;
258
259    /**
260      * Checks whether a given type can be used as a substitute
261      *
262      * @param  toCheck    A datatype validator of the type to be used as a
263      *                    substitute
264      *
265      * To be redefined in UnionDatatypeValidator
266      */
267
268    virtual bool isSubstitutableBy(const DatatypeValidator* const toCheck);
269
270         //@}
271
272    // -----------------------------------------------------------------------
273    // Compare methods
274    // -----------------------------------------------------------------------
275    /** @name Compare Function */
276    //@{
277
278    /**
279      * Compares content in the Domain value vs. lexical value.
280      *
281      * e.g. If type is a float then 1.0 may be equivalent to 1 even though
282      * both are lexically different.
283      *
284      * @param  value1    string to compare
285      *
286      * @param  value2    string to compare
287      *
288      * We will provide a default behavior that should be redefined at the
289      * children level, if necessary (i.e. boolean case).
290      */
291    virtual int compare(const XMLCh* const value1, const XMLCh* const value2
292        ,       MemoryManager*     const manager = XMLPlatformUtils::fgMemoryManager
293        );
294
295    //@}
296
297    /**
298      * Returns an instance of the base datatype validator class
299          * Used by the DatatypeValidatorFactory.
300      */
301        virtual DatatypeValidator* newInstance
302    (
303        RefHashTableOf<KVStringPair>* const facets
304        , RefArrayVectorOf<XMLCh>* const enums
305        , const int finalSet
306        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
307    ) = 0;
308
309    /**
310     * Returns the uri,name of the type this validator is for
311     */
312    const XMLCh* getTypeName() const;
313
314    /**
315     * sets the uri,name that this  validator is for - typeName is uri,name string.
316     * due to the internals of xerces this will set the uri to be the schema uri if
317     * there is no comma in typeName
318     */
319    void setTypeName(const XMLCh* const typeName);
320
321    /**
322     * sets the uri,name that this  validator is for
323     */
324    void setTypeName(const XMLCh* const name, const XMLCh* const uri);
325
326    /**
327     * Returns the uri of the type this validator is for
328     */
329    const XMLCh* getTypeUri() const;
330
331    /**
332     * Returns the name of the type this validator is for
333     */
334    const XMLCh* getTypeLocalName() const;
335
336    /**
337     * Returns the plugged-in memory manager
338     */
339    MemoryManager* getMemoryManager() const;
340
341    /***
342     * Support for Serialization/De-serialization
343     ***/
344    DECL_XSERIALIZABLE(DatatypeValidator)
345
346    /***
347      *
348      *  Serialzie DatatypeValidator derivative
349      *
350      *  Param
351      *     serEng: serialize engine
352      *     dv:     DatatypeValidator derivative
353      *
354      *  Return:
355      *
356      ***/
357        static void storeDV(XSerializeEngine&        serEng
358                      , DatatypeValidator* const dv);
359
360    /***
361      *
362      *  Create a DatatypeValidator derivative from the binary
363      *  stream.
364      *
365      *  Param
366      *     serEng: serialize engine
367      *
368      *  Return:
369      *     DatatypeValidator derivative
370      *
371      ***/
372        static DatatypeValidator* loadDV(XSerializeEngine& serEng);
373
374protected:
375    // -----------------------------------------------------------------------
376    //  Protected Constructors
377    // -----------------------------------------------------------------------
378    /** @name Constructors */
379    //@{
380
381    /**
382      *
383      * @param  baseValidator  The base datatype validator for derived
384      *                        validators. Null if native validator.
385      *
386      * @param  facets         A hashtable of datatype facets (except enum).
387      *
388      * @param  finalSet       'final' value of the simpleType
389      */
390
391        DatatypeValidator(DatatypeValidator* const baseValidator,
392                      RefHashTableOf<KVStringPair>* const facets,
393                      const int finalSet,
394                      const ValidatorType type,
395                      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
396
397    //@}
398
399
400        friend class DatatypeValidatorFactory;
401    friend class XSObjectFactory;
402
403    /**
404      * facetDefined
405          */
406        int   getFacetsDefined() const;
407    void  setFacetsDefined(int);
408
409    /**
410      * fixed
411          */
412        int   getFixed() const;
413    void  setFixed(int);
414
415
416    /**
417      * fPattern
418          */
419    const XMLCh* getPattern() const;
420        void         setPattern(const XMLCh* );
421
422    /**
423      * fRegex
424          */
425        RegularExpression* getRegex() const;
426        void               setRegex(RegularExpression* const);
427
428    /**
429      * set fType
430      */
431    void setType(ValidatorType);
432
433    /**
434      * set fWhiteSpace
435      */
436    void setWhiteSpace(short);
437
438    /**
439      * get WSString
440      */
441    const XMLCh*   getWSstring(const short WSType) const;
442
443    /**
444     *  Fundamental Facet: ordered
445     */
446    void setOrdered(XSSimpleTypeDefinition::ORDERING ordered);
447
448    /**
449     * Fundamental Facet: cardinality.
450     */
451    void setFinite(bool finite);
452
453    /**
454     * Fundamental Facet: bounded.
455     */
456    void setBounded(bool bounded);
457
458    /**
459     * Fundamental Facet: numeric.
460     */
461    void setNumeric(bool numeric);
462
463    // -----------------------------------------------------------------------
464    //  Protected data members
465    //
466    //  fMemoryManager
467    //      Pluggable memory manager for dynamic allocation/deallocation.
468    // -----------------------------------------------------------------------
469    MemoryManager*                fMemoryManager;
470
471private:
472    // -----------------------------------------------------------------------
473    //  CleanUp methods
474    // -----------------------------------------------------------------------
475    void cleanUp();
476
477    // -----------------------------------------------------------------------
478    //  Unimplemented constructors and operators
479    // -----------------------------------------------------------------------
480    DatatypeValidator(const DatatypeValidator&);
481    DatatypeValidator& operator=(const DatatypeValidator&);
482
483    // -----------------------------------------------------------------------
484    //  Private data members
485    //
486    //  fFinalSet
487    //      stores "final" values of simpleTypes
488    //
489    //  fBaseValidator
490    //      This is a pointer to a base datatype validator. If value is null,
491        //      it means we have a native datatype validator not a derived one.
492        //             
493    //  fFacets
494    //      This is a hashtable of dataype facets.
495    //
496    //  fType
497    //      Stores the class type of datatype validator
498    //
499    //  fFacetsDefined
500    //      Stores the constaiting facets flag
501    //
502    //  fPattern
503    //      the pointer to the String of the pattern. The actual data is
504    //      in the Facets.
505    //
506    //  fRegex
507    //      pointer to the RegularExpress object
508    //
509    //
510    //  fFixed
511    //      if {fixed} is true, then types for which this type is the
512    //      {base type definition} cannot specify a value for a specific
513    //      facet.
514    //
515    //  fTypeName
516    //      the uri,name of the type this validator will validate
517    //
518    //  fTypeLocalName
519    //      the name of the type this validator will validate
520    //
521    //  fTypeUri
522    //      the uri of the type this validator will validate
523    //  fAnonymous
524    //      true if this type is anonynous
525    //
526    // -----------------------------------------------------------------------
527    bool                                fAnonymous;
528    short                               fWhiteSpace;
529    int                                 fFinalSet;
530    int                                 fFacetsDefined;
531    int                                 fFixed;
532    ValidatorType                       fType;
533        DatatypeValidator*                  fBaseValidator;
534        RefHashTableOf<KVStringPair>*       fFacets;
535    XMLCh*                              fPattern;
536    RegularExpression*                  fRegex;
537    XMLCh*                              fTypeName;
538    const XMLCh*                        fTypeLocalName;
539    const XMLCh*                        fTypeUri;
540    XSSimpleTypeDefinition::ORDERING    fOrdered;
541    bool                                fFinite;
542    bool                                fBounded;
543    bool                                fNumeric;
544};
545
546
547// ---------------------------------------------------------------------------
548//  DatatypeValidator: Getters
549// ---------------------------------------------------------------------------
550inline int DatatypeValidator::getFinalSet() const {
551
552    return fFinalSet;
553}
554
555inline RefHashTableOf<KVStringPair>* DatatypeValidator::getFacets() const {
556
557    return fFacets;
558}
559
560inline DatatypeValidator* DatatypeValidator::getBaseValidator() const {
561
562        return fBaseValidator;
563}
564
565inline short DatatypeValidator::getWSFacet() const {
566
567    return fWhiteSpace;
568}
569
570inline DatatypeValidator::ValidatorType DatatypeValidator::getType() const
571{
572    return fType;
573}
574
575inline int DatatypeValidator::getFacetsDefined() const
576{
577    return fFacetsDefined;
578}
579
580inline int DatatypeValidator::getFixed() const
581{
582    return fFixed;
583}
584
585inline const XMLCh* DatatypeValidator::getPattern() const
586{
587    return fPattern;
588}
589
590inline RegularExpression* DatatypeValidator::getRegex() const
591{
592    return fRegex;
593}
594
595inline const XMLCh* DatatypeValidator::getTypeName() const
596{
597    return fTypeName;
598}
599
600inline bool DatatypeValidator::getAnonymous() const
601{
602    return fAnonymous;
603}
604
605inline const XMLCh* DatatypeValidator::getTypeLocalName() const
606{
607    return fTypeLocalName;
608}
609
610inline const XMLCh* DatatypeValidator::getTypeUri() const
611{
612    return fTypeUri;
613}
614
615inline MemoryManager* DatatypeValidator::getMemoryManager() const
616{
617    return fMemoryManager;
618}
619
620inline XSSimpleTypeDefinition::ORDERING DatatypeValidator::getOrdered() const
621{
622    return fOrdered;
623}
624
625inline bool DatatypeValidator::getFinite() const
626{
627    return fFinite;
628}
629 
630inline bool DatatypeValidator::getBounded() const
631{
632    return fBounded;
633}
634
635inline bool DatatypeValidator::getNumeric() const
636{
637    return fNumeric;
638}
639
640// ---------------------------------------------------------------------------
641//  DatatypeValidator: Setters
642// ---------------------------------------------------------------------------
643inline void DatatypeValidator::setType(ValidatorType theType)
644{
645    fType = theType;
646}
647
648inline void DatatypeValidator::setWhiteSpace(short newValue)
649{
650    fWhiteSpace = newValue;
651}
652
653inline void DatatypeValidator::setFacetsDefined(int facets)
654{
655    fFacetsDefined |= facets;
656}
657
658inline void DatatypeValidator::setFixed(int fixed)
659{
660    fFixed |= fixed;
661}
662
663inline void DatatypeValidator::setPattern(const XMLCh* pattern)
664{
665    if (fPattern)
666        fMemoryManager->deallocate(fPattern);//delete [] fPattern;
667    fPattern = XMLString::replicate(pattern, fMemoryManager);
668}
669
670inline void DatatypeValidator::setRegex(RegularExpression* const regex)
671{
672    fRegex = regex;
673}
674
675inline bool DatatypeValidator::isAtomic() const {
676
677    return true;
678}
679
680inline void DatatypeValidator::setAnonymous() {
681    fAnonymous = true;
682}
683
684inline void DatatypeValidator::setOrdered(XSSimpleTypeDefinition::ORDERING ordered)
685{
686    fOrdered = ordered;
687}
688
689inline void DatatypeValidator::setFinite(bool finite)
690{
691    fFinite = finite;
692}
693
694inline void DatatypeValidator::setBounded(bool bounded)
695{
696    fBounded = bounded;
697}
698
699inline void DatatypeValidator::setNumeric(bool numeric)
700{
701    fNumeric = numeric;
702}
703
704// ---------------------------------------------------------------------------
705//  DatatypeValidators: Compare methods
706// ---------------------------------------------------------------------------
707inline int DatatypeValidator::compare(const XMLCh* const lValue,
708                                      const XMLCh* const rValue
709                                      , MemoryManager*     const)
710{
711    return XMLString::compareString(lValue, rValue);
712}
713
714// ---------------------------------------------------------------------------
715//  DatatypeValidators: Validation methods
716// ---------------------------------------------------------------------------
717inline bool
718DatatypeValidator::isSubstitutableBy(const DatatypeValidator* const toCheck)
719{
720    const DatatypeValidator* dv = toCheck;
721
722        while (dv != 0) {
723
724        if (dv == this) {
725            return true;
726        }
727
728        dv = dv->getBaseValidator();
729    }
730
731    return false;
732}
733
734XERCES_CPP_NAMESPACE_END
735
736#endif
737
738/**
739  * End of file DatatypeValidator.hpp
740  */
741
Note: See TracBrowser for help on using the repository browser.