source: trunk/VUT/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/datatype/UnionDatatypeValidator.hpp @ 358

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

xerces added

RevLine 
[358]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: UnionDatatypeValidator.hpp,v 1.19 2004/09/20 14:47:13 amassari Exp $
19 * $Log: UnionDatatypeValidator.hpp,v $
20 * Revision 1.19  2004/09/20 14:47:13  amassari
21 * Mark some methods as deprecated
22 *
23 * Revision 1.18  2004/09/08 13:56:54  peiyongz
24 * Apache License Version 2.0
25 *
26 * Revision 1.17  2004/01/29 11:51:22  cargilld
27 * Code cleanup changes to get rid of various compiler diagnostic messages.
28 *
29 * Revision 1.16  2003/12/23 21:50:36  peiyongz
30 * Absorb exception thrown in getCanonicalRepresentation and return 0,
31 * only validate when required
32 *
33 * Revision 1.15  2003/12/17 00:18:39  cargilld
34 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
35 *
36 * Revision 1.14  2003/11/28 18:53:07  peiyongz
37 * Support for getCanonicalRepresentation
38 *
39 * Revision 1.13  2003/11/24 05:10:26  neilg
40 * implement method for determining member type of union that validated some value
41 *
42 * Revision 1.12  2003/11/12 20:32:03  peiyongz
43 * Statless Grammar: ValidationContext
44 *
45 * Revision 1.11  2003/10/07 19:39:03  peiyongz
46 * Implementation of Serialization/Deserialization
47 *
48 * Revision 1.10  2003/08/16 18:42:49  neilg
49 * 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.
50 *
51 * Revision 1.9  2003/05/15 18:53:27  knoaman
52 * Partial implementation of the configurable memory manager.
53 *
54 * Revision 1.8  2003/02/06 13:51:55  gareth
55 * fixed bug with multiple attributes being validated by the same union type.
56 *
57 * Revision 1.7  2003/01/29 19:55:19  gareth
58 * updated to deal with null pointer issue with fValidatedDatatype.
59 *
60 * Revision 1.6  2003/01/29 19:53:35  gareth
61 * we now store information about which validator was used to validate.
62 *
63 * Revision 1.5  2003/01/10 16:48:47  tng
64 * [Bug 14912] crashes inside UnionDatatypeValidator::isSubstitutableBy.   Patch from Alberto Massari.
65 *
66 * Revision 1.4  2002/12/18 14:17:55  gareth
67 * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
68 *
69 * Revision 1.3  2002/11/04 14:53:28  tng
70 * C++ Namespace Support.
71 *
72 * Revision 1.2  2002/02/14 15:17:31  peiyongz
73 * getEnumString()
74 *
75 * Revision 1.1.1.1  2002/02/01 22:22:43  peiyongz
76 * sane_include
77 *
78 * Revision 1.9  2001/12/13 16:48:29  peiyongz
79 * Avoid dangling pointer
80 *
81 * Revision 1.8  2001/09/05 20:49:10  knoaman
82 * Fix for complexTypes with mixed content model.
83 *
84 * Revision 1.7  2001/08/31 16:53:41  knoaman
85 * Misc. fixes.
86 *
87 * Revision 1.6  2001/08/24 17:12:01  knoaman
88 * Add support for anySimpleType.
89 * Remove parameter 'baseValidator' from the virtual method 'newInstance'.
90 *
91 * Revision 1.5  2001/08/21 20:05:41  peiyongz
92 * put back changes introduced in 1.3
93 *
94 * Revision 1.3  2001/08/16 14:41:38  knoaman
95 * implementation of virtual methods.
96 *
97 * Revision 1.2  2001/07/24 21:23:40  tng
98 * Schema: Use DatatypeValidator for ID/IDREF/ENTITY/ENTITIES/NOTATION.
99 *
100 * Revision 1.1  2001/07/13 14:10:40  peiyongz
101 * UnionDTV
102 *
103 */
104
105#if !defined(UNION_DATATYPEVALIDATOR_HPP)
106#define UNION_DATATYPEVALIDATOR_HPP
107
108#include <xercesc/validators/datatype/DatatypeValidator.hpp>
109
110XERCES_CPP_NAMESPACE_BEGIN
111
112class VALIDATORS_EXPORT UnionDatatypeValidator : public DatatypeValidator
113{
114public:
115
116    // -----------------------------------------------------------------------
117    //  Public ctor/dtor
118    // -----------------------------------------------------------------------
119        /** @name Constructors and Destructor. */
120    //@{
121
122    UnionDatatypeValidator
123    (
124        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
125    );
126
127    //
128    // constructor for native Union datatype validator
129    // <simpleType name="nativeUnion">
130    //      <union   memberTypes="member1 member2 ...">
131    // </simpleType>
132    //
133    UnionDatatypeValidator
134    (
135        RefVectorOf<DatatypeValidator>* const memberTypeValidators
136        , const int finalSet
137        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
138    );
139
140    //
141    // constructor for derived Union datatype validator
142    // <simpleType name="derivedUnion">
143    //      <restriction base="nativeUnion">
144    //          <pattern     value="patter_value"/>
145    //          <enumeration value="enum_value"/>
146    //      </restriction>
147    // </simpleType>
148    //
149    UnionDatatypeValidator
150    (
151        DatatypeValidator* const baseValidator
152        , RefHashTableOf<KVStringPair>* const facets
153        , RefArrayVectorOf<XMLCh>* const enums
154        , const int finalSet
155        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
156        , RefVectorOf<DatatypeValidator>* const memberTypeValidators = 0
157        , const bool memberTypesInherited = true
158    );
159
160    virtual ~UnionDatatypeValidator();
161
162        //@}
163
164        virtual const RefArrayVectorOf<XMLCh>* getEnumString() const;
165
166    // -----------------------------------------------------------------------
167    // Getter methods
168    // -----------------------------------------------------------------------
169    /** @name Getter Functions */
170    //@{
171    /**
172      * Returns whether the type is atomic or not
173      */
174    virtual bool isAtomic() const;
175
176    virtual const XMLCh* getCanonicalRepresentation
177                        (
178                          const XMLCh*         const rawData
179                        ,       MemoryManager* const memMgr = 0
180                        ,       bool                 toValidate = false
181                        ) const;
182
183    //@}
184
185    // -----------------------------------------------------------------------
186    // Validation methods
187    // -----------------------------------------------------------------------
188    /** @name Validation Function */
189    //@{
190
191    /**
192     * validate that a string matches the boolean datatype
193     * @param content A string containing the content to be validated
194     *
195     * @exception throws InvalidDatatypeException if the content is
196     * is not valid.
197     */
198
199        virtual void validate
200                 (
201                  const XMLCh*             const content
202                ,       ValidationContext* const context = 0
203                ,       MemoryManager*     const manager = XMLPlatformUtils::fgMemoryManager
204                  );
205
206    /**
207      * Checks whether a given type can be used as a substitute
208      *
209      * @param  toCheck    A datatype validator of the type to be used as a
210      *                    substitute
211      *
212      * To be redefined in UnionDatatypeValidator
213      */
214
215    virtual bool isSubstitutableBy(const DatatypeValidator* const toCheck);
216
217    //@}
218
219    // -----------------------------------------------------------------------
220    // Compare methods
221    // -----------------------------------------------------------------------
222    /** @name Compare Function */
223    //@{
224
225    /**
226     * Compare two boolean data types
227     *
228     * @param content1
229     * @param content2
230     * @return
231     */
232    int compare(const XMLCh* const, const XMLCh* const
233        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
234        );
235
236    //@}
237
238    /**
239      * Returns an instance of the base datatype validator class
240          * Used by the DatatypeValidatorFactory.
241      */
242    virtual DatatypeValidator* newInstance
243    (
244        RefHashTableOf<KVStringPair>* const facets
245        , RefArrayVectorOf<XMLCh>* const enums
246        , const int finalSet
247        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
248    );
249
250    /***
251     * Support for Serialization/De-serialization
252     ***/
253    DECL_XSERIALIZABLE(UnionDatatypeValidator)
254
255
256    RefVectorOf<DatatypeValidator>* getMemberTypeValidators() const;
257
258
259    /**
260     * Returns the type name that was actually used to validate the last time validate was called
261     * note - this does not mean that it fully validated sucessfully
262     * @deprecated
263     **/
264    const XMLCh* getMemberTypeName() const;
265
266    /**
267     * Returns the type uri that was actually used to validate the last time validate was called
268     * note - this does not mean that it fully validated sucessfully
269     * @deprecated
270     **/
271    const XMLCh* getMemberTypeUri() const;
272
273    /**
274     * Returns true if the type that was actually used to validate the last time validate was called
275     * is anonymous
276     * @deprecated
277     */
278    bool getMemberTypeAnonymous() const;
279
280
281    /**
282     * Returns the member DatatypeValidator used to validate the content the last time validate
283     * was called
284     * @deprecated
285     */
286    const DatatypeValidator* getMemberTypeValidator() const;
287
288    /**
289     * Called inbetween uses of this validator to reset PSVI information
290     */
291    void reset();
292
293private:
294    // -----------------------------------------------------------------------
295    //  Unimplemented constructors and operators
296    // -----------------------------------------------------------------------   
297    UnionDatatypeValidator(const UnionDatatypeValidator&);
298    UnionDatatypeValidator& operator=(const UnionDatatypeValidator&);
299
300    virtual void checkContent(const XMLCh*             const content
301                            ,       ValidationContext* const context
302                            , bool                           asBase
303                            ,       MemoryManager*     const manager);
304
305    void init(DatatypeValidator*            const baseValidator
306            , RefHashTableOf<KVStringPair>* const facets
307            , RefArrayVectorOf<XMLCh>*      const enums
308            , MemoryManager*                const manager);
309
310    void cleanUp();
311   
312    RefArrayVectorOf<XMLCh>*  getEnumeration() const;
313
314    void                 setEnumeration(RefArrayVectorOf<XMLCh>*, bool);
315
316
317    // -----------------------------------------------------------------------
318    //  Private data members
319    //
320    //  fEnumeration
321    //      we own it (or not, depending on state of fEnumerationInherited).
322    //
323    //  fMemberTypeValidators
324    //      we own it (or not, depending on the state of fMemberTypesInherited).
325    //
326    //  fValidatedDatatype
327    //      the dataTypeValidator  that was actually used to validate the last time validate was called
328    //
329    // -----------------------------------------------------------------------
330
331     bool                             fEnumerationInherited;
332     bool                             fMemberTypesInherited;
333     RefArrayVectorOf<XMLCh>*         fEnumeration;
334     RefVectorOf<DatatypeValidator>*  fMemberTypeValidators;
335     DatatypeValidator*               fValidatedDatatype;
336};
337
338inline DatatypeValidator* UnionDatatypeValidator::newInstance
339(
340      RefHashTableOf<KVStringPair>* const facets
341    , RefArrayVectorOf<XMLCh>* const      enums
342    , const int                           finalSet
343    , MemoryManager* const                manager
344)
345{
346    return (DatatypeValidator*) new (manager) UnionDatatypeValidator(this, facets, enums, finalSet, manager, fMemberTypeValidators, true);
347}
348
349inline void UnionDatatypeValidator::validate( const XMLCh*             const content
350                                           ,        ValidationContext* const context
351                                           ,        MemoryManager*     const manager)
352{
353    checkContent(content, context, false, manager);
354}
355
356inline void UnionDatatypeValidator::cleanUp()
357{
358    //~RefVectorOf will delete all adopted elements
359    if ( !fEnumerationInherited && fEnumeration)
360        delete fEnumeration;
361
362    if (!fMemberTypesInherited && fMemberTypeValidators)
363        delete fMemberTypeValidators;
364   
365}
366
367inline RefArrayVectorOf<XMLCh>* UnionDatatypeValidator:: getEnumeration() const
368{
369    return fEnumeration;
370}
371
372inline void UnionDatatypeValidator::setEnumeration(RefArrayVectorOf<XMLCh>* enums
373                                                 , bool                inherited)
374{
375    if (enums)
376    {
377        if (  !fEnumerationInherited && fEnumeration)
378            delete fEnumeration;
379
380        fEnumeration = enums;
381        fEnumerationInherited = inherited;
382        setFacetsDefined(DatatypeValidator::FACET_ENUMERATION);
383    }
384}
385
386//
387// get the native UnionDTV's fMemberTypeValidators
388//
389inline
390RefVectorOf<DatatypeValidator>* UnionDatatypeValidator::getMemberTypeValidators() const
391{
392    return this->fMemberTypeValidators;
393}
394
395inline bool UnionDatatypeValidator::isAtomic() const {
396
397
398
399    if (!fMemberTypeValidators) {
400        return false;
401    }
402
403    unsigned int memberSize = fMemberTypeValidators->size();
404
405    for (unsigned int i=0; i < memberSize; i++) {
406        if (!fMemberTypeValidators->elementAt(i)->isAtomic()) {
407            return false;
408        }
409    }
410
411    return true;
412}
413
414inline bool UnionDatatypeValidator::isSubstitutableBy(const DatatypeValidator* const toCheck) {
415
416    if (toCheck == this) {
417        return true;
418    }
419
420    if (fMemberTypeValidators) {
421        unsigned int memberSize = fMemberTypeValidators->size();
422
423        for (unsigned int i=0; i < memberSize; i++) {
424            if (fMemberTypeValidators->elementAt(i)->isSubstitutableBy(toCheck)) {
425                return true;
426            }
427        }
428    }
429    return false;
430}
431
432inline const XMLCh* UnionDatatypeValidator::getMemberTypeName() const {
433    if(fValidatedDatatype) {
434        return fValidatedDatatype->getTypeLocalName();
435    }
436    return 0;
437}
438
439inline const XMLCh* UnionDatatypeValidator::getMemberTypeUri() const
440{
441    if(fValidatedDatatype) {
442        return fValidatedDatatype->getTypeUri();
443    }
444    return 0;
445}
446
447inline bool UnionDatatypeValidator::getMemberTypeAnonymous() const {
448    if(fValidatedDatatype) {
449        return fValidatedDatatype->getAnonymous();
450    }
451    return 0;
452}
453
454inline const DatatypeValidator* UnionDatatypeValidator::getMemberTypeValidator() const {
455    return fValidatedDatatype;
456}
457
458inline void UnionDatatypeValidator::reset() {
459    fValidatedDatatype = 0;
460}
461
462XERCES_CPP_NAMESPACE_END
463
464#endif
465
466/**
467  * End of file UnionDatatypeValidator.hpp
468  */
469
Note: See TracBrowser for help on using the repository browser.