source: trunk/VUT/GtpVisibilityPreprocessor/support/xercesc/validators/datatype/UnionDatatypeValidator.hpp @ 188

Revision 188, 16.7 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: UnionDatatypeValidator.hpp,v 1.17 2004/01/29 11:51:22 cargilld Exp $
59 * $Log: UnionDatatypeValidator.hpp,v $
60 * Revision 1.17  2004/01/29 11:51:22  cargilld
61 * Code cleanup changes to get rid of various compiler diagnostic messages.
62 *
63 * Revision 1.16  2003/12/23 21:50:36  peiyongz
64 * Absorb exception thrown in getCanonicalRepresentation and return 0,
65 * only validate when required
66 *
67 * Revision 1.15  2003/12/17 00:18:39  cargilld
68 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
69 *
70 * Revision 1.14  2003/11/28 18:53:07  peiyongz
71 * Support for getCanonicalRepresentation
72 *
73 * Revision 1.13  2003/11/24 05:10:26  neilg
74 * implement method for determining member type of union that validated some value
75 *
76 * Revision 1.12  2003/11/12 20:32:03  peiyongz
77 * Statless Grammar: ValidationContext
78 *
79 * Revision 1.11  2003/10/07 19:39:03  peiyongz
80 * Implementation of Serialization/Deserialization
81 *
82 * Revision 1.10  2003/08/16 18:42:49  neilg
83 * fix for bug 22457.  Union types that are restrictions of other union types were previously considered not to inherit their parents member types.  This is at variance with the behaviour of the Java parser and apparently with the spec, so I have changed this.
84 *
85 * Revision 1.9  2003/05/15 18:53:27  knoaman
86 * Partial implementation of the configurable memory manager.
87 *
88 * Revision 1.8  2003/02/06 13:51:55  gareth
89 * fixed bug with multiple attributes being validated by the same union type.
90 *
91 * Revision 1.7  2003/01/29 19:55:19  gareth
92 * updated to deal with null pointer issue with fValidatedDatatype.
93 *
94 * Revision 1.6  2003/01/29 19:53:35  gareth
95 * we now store information about which validator was used to validate.
96 *
97 * Revision 1.5  2003/01/10 16:48:47  tng
98 * [Bug 14912] crashes inside UnionDatatypeValidator::isSubstitutableBy.   Patch from Alberto Massari.
99 *
100 * Revision 1.4  2002/12/18 14:17:55  gareth
101 * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
102 *
103 * Revision 1.3  2002/11/04 14:53:28  tng
104 * C++ Namespace Support.
105 *
106 * Revision 1.2  2002/02/14 15:17:31  peiyongz
107 * getEnumString()
108 *
109 * Revision 1.1.1.1  2002/02/01 22:22:43  peiyongz
110 * sane_include
111 *
112 * Revision 1.9  2001/12/13 16:48:29  peiyongz
113 * Avoid dangling pointer
114 *
115 * Revision 1.8  2001/09/05 20:49:10  knoaman
116 * Fix for complexTypes with mixed content model.
117 *
118 * Revision 1.7  2001/08/31 16:53:41  knoaman
119 * Misc. fixes.
120 *
121 * Revision 1.6  2001/08/24 17:12:01  knoaman
122 * Add support for anySimpleType.
123 * Remove parameter 'baseValidator' from the virtual method 'newInstance'.
124 *
125 * Revision 1.5  2001/08/21 20:05:41  peiyongz
126 * put back changes introduced in 1.3
127 *
128 * Revision 1.3  2001/08/16 14:41:38  knoaman
129 * implementation of virtual methods.
130 *
131 * Revision 1.2  2001/07/24 21:23:40  tng
132 * Schema: Use DatatypeValidator for ID/IDREF/ENTITY/ENTITIES/NOTATION.
133 *
134 * Revision 1.1  2001/07/13 14:10:40  peiyongz
135 * UnionDTV
136 *
137 */
138
139#if !defined(UNION_DATATYPEVALIDATOR_HPP)
140#define UNION_DATATYPEVALIDATOR_HPP
141
142#include <xercesc/validators/datatype/DatatypeValidator.hpp>
143
144XERCES_CPP_NAMESPACE_BEGIN
145
146class VALIDATORS_EXPORT UnionDatatypeValidator : public DatatypeValidator
147{
148public:
149
150    // -----------------------------------------------------------------------
151    //  Public ctor/dtor
152    // -----------------------------------------------------------------------
153        /** @name Constructors and Destructor. */
154    //@{
155
156    UnionDatatypeValidator
157    (
158        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
159    );
160
161    //
162    // constructor for native Union datatype validator
163    // <simpleType name="nativeUnion">
164    //      <union   memberTypes="member1 member2 ...">
165    // </simpleType>
166    //
167    UnionDatatypeValidator
168    (
169        RefVectorOf<DatatypeValidator>* const memberTypeValidators
170        , const int finalSet
171        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
172    );
173
174    //
175    // constructor for derived Union datatype validator
176    // <simpleType name="derivedUnion">
177    //      <restriction base="nativeUnion">
178    //          <pattern     value="patter_value"/>
179    //          <enumeration value="enum_value"/>
180    //      </restriction>
181    // </simpleType>
182    //
183    UnionDatatypeValidator
184    (
185        DatatypeValidator* const baseValidator
186        , RefHashTableOf<KVStringPair>* const facets
187        , RefArrayVectorOf<XMLCh>* const enums
188        , const int finalSet
189        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
190        , RefVectorOf<DatatypeValidator>* const memberTypeValidators = 0
191        , const bool memberTypesInherited = true
192    );
193
194    virtual ~UnionDatatypeValidator();
195
196        //@}
197
198        virtual const RefArrayVectorOf<XMLCh>* getEnumString() const;
199
200    // -----------------------------------------------------------------------
201    // Getter methods
202    // -----------------------------------------------------------------------
203    /** @name Getter Functions */
204    //@{
205    /**
206      * Returns whether the type is atomic or not
207      */
208    virtual bool isAtomic() const;
209
210    virtual const XMLCh* getCanonicalRepresentation
211                        (
212                          const XMLCh*         const rawData
213                        ,       MemoryManager* const memMgr = 0
214                        ,       bool                 toValidate = false
215                        ) const;
216
217    //@}
218
219    // -----------------------------------------------------------------------
220    // Validation methods
221    // -----------------------------------------------------------------------
222    /** @name Validation Function */
223    //@{
224
225    /**
226     * validate that a string matches the boolean datatype
227     * @param content A string containing the content to be validated
228     *
229     * @exception throws InvalidDatatypeException if the content is
230     * is not valid.
231     */
232
233        virtual void validate
234                 (
235                  const XMLCh*             const content
236                ,       ValidationContext* const context = 0
237                ,       MemoryManager*     const manager = XMLPlatformUtils::fgMemoryManager
238                  );
239
240    /**
241      * Checks whether a given type can be used as a substitute
242      *
243      * @param  toCheck    A datatype validator of the type to be used as a
244      *                    substitute
245      *
246      * To be redefined in UnionDatatypeValidator
247      */
248
249    virtual bool isSubstitutableBy(const DatatypeValidator* const toCheck);
250
251    //@}
252
253    // -----------------------------------------------------------------------
254    // Compare methods
255    // -----------------------------------------------------------------------
256    /** @name Compare Function */
257    //@{
258
259    /**
260     * Compare two boolean data types
261     *
262     * @param content1
263     * @param content2
264     * @return
265     */
266    int compare(const XMLCh* const, const XMLCh* const
267        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
268        );
269
270    //@}
271
272    /**
273      * Returns an instance of the base datatype validator class
274          * Used by the DatatypeValidatorFactory.
275      */
276    virtual DatatypeValidator* newInstance
277    (
278        RefHashTableOf<KVStringPair>* const facets
279        , RefArrayVectorOf<XMLCh>* const enums
280        , const int finalSet
281        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
282    );
283
284    /***
285     * Support for Serialization/De-serialization
286     ***/
287    DECL_XSERIALIZABLE(UnionDatatypeValidator)
288
289
290    RefVectorOf<DatatypeValidator>* getMemberTypeValidators() const;
291
292
293    /**
294     * Returns the type name that was actually used to validate the last time validate was called
295     * note - this does not mean that it fully validated sucessfully
296     **/
297    const XMLCh* getMemberTypeName() const;
298
299    /**
300     * Returns the type uri that was actually used to validate the last time validate was called
301     * note - this does not mean that it fully validated sucessfully
302     **/
303    const XMLCh* getMemberTypeUri() const;
304
305    /**
306     * Returns true if the type that was actually used to validate the last time validate was called
307     * is anonymous
308     */
309    bool getMemberTypeAnonymous() const;
310
311
312    /**
313     * Returns the member DatatypeValidator used to validate the content the last time validate
314     * was called
315     */
316    const DatatypeValidator* getMemberTypeValidator() const;
317
318    /**
319     * Called inbetween uses of this validator to reset PSVI information
320     */
321    void reset();
322
323private:
324    // -----------------------------------------------------------------------
325    //  Unimplemented constructors and operators
326    // -----------------------------------------------------------------------   
327    UnionDatatypeValidator(const UnionDatatypeValidator&);
328    UnionDatatypeValidator& operator=(const UnionDatatypeValidator&);
329
330    virtual void checkContent(const XMLCh*             const content
331                            ,       ValidationContext* const context
332                            , bool                           asBase
333                            ,       MemoryManager*     const manager);
334
335    void init(DatatypeValidator*            const baseValidator
336            , RefHashTableOf<KVStringPair>* const facets
337            , RefArrayVectorOf<XMLCh>*      const enums
338            , MemoryManager*                const manager);
339
340    void cleanUp();
341   
342    RefArrayVectorOf<XMLCh>*  getEnumeration() const;
343
344    void                 setEnumeration(RefArrayVectorOf<XMLCh>*, bool);
345
346
347    // -----------------------------------------------------------------------
348    //  Private data members
349    //
350    //  fEnumeration
351    //      we own it (or not, depending on state of fEnumerationInherited).
352    //
353    //  fMemberTypeValidators
354    //      we own it (or not, depending on the state of fMemberTypesInherited).
355    //
356    //  fValidatedDatatype
357    //      the dataTypeValidator  that was actually used to validate the last time validate was called
358    //
359    // -----------------------------------------------------------------------
360
361     bool                             fEnumerationInherited;
362     bool                             fMemberTypesInherited;
363     RefArrayVectorOf<XMLCh>*         fEnumeration;
364     RefVectorOf<DatatypeValidator>*  fMemberTypeValidators;
365     DatatypeValidator*               fValidatedDatatype;
366};
367
368inline DatatypeValidator* UnionDatatypeValidator::newInstance
369(
370      RefHashTableOf<KVStringPair>* const facets
371    , RefArrayVectorOf<XMLCh>* const      enums
372    , const int                           finalSet
373    , MemoryManager* const                manager
374)
375{
376    return (DatatypeValidator*) new (manager) UnionDatatypeValidator(this, facets, enums, finalSet, manager, fMemberTypeValidators, true);
377}
378
379inline void UnionDatatypeValidator::validate( const XMLCh*             const content
380                                           ,        ValidationContext* const context
381                                           ,        MemoryManager*     const manager)
382{
383    checkContent(content, context, false, manager);
384}
385
386inline void UnionDatatypeValidator::cleanUp()
387{
388    //~RefVectorOf will delete all adopted elements
389    if ( !fEnumerationInherited && fEnumeration)
390        delete fEnumeration;
391
392    if (!fMemberTypesInherited && fMemberTypeValidators)
393        delete fMemberTypeValidators;
394   
395}
396
397inline RefArrayVectorOf<XMLCh>* UnionDatatypeValidator:: getEnumeration() const
398{
399    return fEnumeration;
400}
401
402inline void UnionDatatypeValidator::setEnumeration(RefArrayVectorOf<XMLCh>* enums
403                                                 , bool                inherited)
404{
405    if (enums)
406    {
407        if (  !fEnumerationInherited && fEnumeration)
408            delete fEnumeration;
409
410        fEnumeration = enums;
411        fEnumerationInherited = inherited;
412        setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
413    }
414}
415
416//
417// get the native UnionDTV's fMemberTypeValidators
418//
419inline
420RefVectorOf<DatatypeValidator>* UnionDatatypeValidator::getMemberTypeValidators() const
421{
422    return this->fMemberTypeValidators;
423}
424
425inline bool UnionDatatypeValidator::isAtomic() const {
426
427
428
429    if (!fMemberTypeValidators) {
430        return false;
431    }
432
433    unsigned int memberSize = fMemberTypeValidators->size();
434
435    for (unsigned int i=0; i < memberSize; i++) {
436        if (!fMemberTypeValidators->elementAt(i)->isAtomic()) {
437            return false;
438        }
439    }
440
441    return true;
442}
443
444inline bool UnionDatatypeValidator::isSubstitutableBy(const DatatypeValidator* const toCheck) {
445
446    if (toCheck == this) {
447        return true;
448    }
449
450    if (fMemberTypeValidators) {
451        unsigned int memberSize = fMemberTypeValidators->size();
452
453        for (unsigned int i=0; i < memberSize; i++) {
454            if (fMemberTypeValidators->elementAt(i)->isSubstitutableBy(toCheck)) {
455                return true;
456            }
457        }
458    }
459    return false;
460}
461
462inline const XMLCh* UnionDatatypeValidator::getMemberTypeName() const {
463    if(fValidatedDatatype) {
464        return fValidatedDatatype->getTypeLocalName();
465    }
466    return 0;
467}
468
469inline const XMLCh* UnionDatatypeValidator::getMemberTypeUri() const
470{
471    if(fValidatedDatatype) {
472        return fValidatedDatatype->getTypeUri();
473    }
474    return 0;
475}
476
477inline bool UnionDatatypeValidator::getMemberTypeAnonymous() const {
478    if(fValidatedDatatype) {
479        return fValidatedDatatype->getAnonymous();
480    }
481    return 0;
482}
483
484inline const DatatypeValidator* UnionDatatypeValidator::getMemberTypeValidator() const {
485    return fValidatedDatatype;
486}
487
488inline void UnionDatatypeValidator::reset() {
489    fValidatedDatatype = 0;
490}
491
492XERCES_CPP_NAMESPACE_END
493
494#endif
495
496/**
497  * End of file UnionDatatypeValidator.hpp
498  */
499
Note: See TracBrowser for help on using the repository browser.