source: trunk/VUT/GtpVisibilityPreprocessor/support/xercesc/validators/schema/SchemaAttDef.hpp @ 188

Revision 188, 19.8 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 * $Log: SchemaAttDef.hpp,v $
59 * Revision 1.12  2004/01/29 11:52:31  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.11  2003/12/24 17:42:03  knoaman
63 * Misc. PSVI updates
64 *
65 * Revision 1.10  2003/12/17 20:50:35  knoaman
66 * PSVI: fix for annotation of attributes in attributeGroup/derived types
67 *
68 * Revision 1.9  2003/11/24 05:13:41  neilg
69 * update method documentation
70 *
71 * Revision 1.8  2003/11/21 22:34:46  neilg
72 * More schema component model implementation, thanks to David Cargill.
73 * In particular, this cleans up and completes the XSModel, XSNamespaceItem,
74 * XSAttributeDeclaration and XSAttributeGroup implementations.
75 *
76 * Revision 1.7  2003/10/10 16:25:40  peiyongz
77 * Implementation of Serialization/Deserialization
78 *
79 * Revision 1.6  2003/05/18 14:02:07  knoaman
80 * Memory manager implementation: pass per instance manager.
81 *
82 * Revision 1.5  2003/05/16 21:43:21  knoaman
83 * Memory manager implementation: Modify constructors to pass in the memory manager.
84 *
85 * Revision 1.4  2003/02/06 13:51:55  gareth
86 * fixed bug with multiple attributes being validated by the same union type.
87 *
88 * Revision 1.3  2003/01/29 19:47:16  gareth
89 * added DOMTypeInfo and some PSVI methods
90 *
91 * Revision 1.2  2002/11/04 14:49:41  tng
92 * C++ Namespace Support.
93 *
94 * Revision 1.1.1.1  2002/02/01 22:22:46  peiyongz
95 * sane_include
96 *
97 * Revision 1.6  2001/08/10 12:34:25  knoaman
98 * Fix compilation error.
99 *
100 * Revision 1.5  2001/08/09 15:23:16  knoaman
101 * add support for <anyAttribute> declaration.
102 *
103 * Revision 1.4  2001/07/31 15:26:54  knoaman
104 * Added support for <attributeGroup>.
105 *
106 * Revision 1.3  2001/05/11 17:17:41  tng
107 * Schema: DatatypeValidator fixes.  By Pei Yong Zhang.
108 *
109 * Revision 1.2  2001/05/11 13:27:34  tng
110 * Copyright update.
111 *
112 * Revision 1.1  2001/02/27 18:48:22  tng
113 * Schema: Add SchemaAttDef, SchemaElementDecl, SchemaAttDefList.
114 *
115 */
116#if !defined(SCHEMAATTDEF_HPP)
117#define SCHEMAATTDEF_HPP
118
119#include <xercesc/util/XMLString.hpp>
120#include <xercesc/framework/XMLAttDef.hpp>
121#include <xercesc/util/ValueVectorOf.hpp>
122#include <xercesc/validators/datatype/DatatypeValidator.hpp>
123#include <xercesc/validators/datatype/UnionDatatypeValidator.hpp>
124#include <xercesc/validators/schema/PSVIDefs.hpp>
125
126XERCES_CPP_NAMESPACE_BEGIN
127
128class DatatypeValidator;
129class QName;
130class ComplexTypeInfo;
131//
132//  This class is a derivative of the core XMLAttDef class. This class adds
133//  any Schema specific data members and provides Schema specific implementations
134//  of any underlying attribute def virtual methods.
135//
136class VALIDATORS_EXPORT SchemaAttDef : public XMLAttDef
137{
138public :
139    // -----------------------------------------------------------------------
140    //  Constructors and Destructors
141    // -----------------------------------------------------------------------
142    SchemaAttDef(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
143    SchemaAttDef
144    (
145          const XMLCh* const           prefix
146        , const XMLCh* const           localPart
147        , const int                    uriId
148        , const XMLAttDef::AttTypes    type = CData
149        , const XMLAttDef::DefAttTypes defType = Implied
150        , MemoryManager* const         manager = XMLPlatformUtils::fgMemoryManager
151    );
152    SchemaAttDef
153    (
154          const XMLCh* const           prefix
155        , const XMLCh* const           localPart
156        , const int                    uriId
157        , const XMLCh* const           attValue
158        , const XMLAttDef::AttTypes    type
159        , const XMLAttDef::DefAttTypes defType
160        , const XMLCh* const           enumValues = 0
161        , MemoryManager* const         manager = XMLPlatformUtils::fgMemoryManager
162    );
163    SchemaAttDef
164    (
165          const SchemaAttDef*                   other
166    );
167    virtual ~SchemaAttDef();
168
169    // -----------------------------------------------------------------------
170    //  Implementation of the XMLAttDef interface
171    // -----------------------------------------------------------------------
172    virtual const XMLCh* getFullName() const;
173    virtual void reset();
174
175
176    // ----------------------------------------------------------------------
177    // Partial implementation of PSVI
178    // The values these methods return are only accurate until the DOMAttr
179    // is created that uses the values. After this a clean up method is called
180    // and the SchemaAttDef may be used again.
181    // note that some of this information has dependancies. For example,
182    // if something is not valid then the information returned by the other
183    // calls may be meaningless
184    // See http://www.w3.org/TR/xmlschema-1/ for detailed information
185    // ----------------------------------------------------------------------
186
187    /**
188     * The appropriate case among the following:
189     * 1 If it was strictly assessed, then the appropriate case among the following:
190     * 1.1 If it was valid as defined by Attribute Locally Valid (3.2.4), then valid;
191     * 1.2 otherwise invalid.
192     * 2 otherwise notKnown.
193     * @deprecated
194     */
195    PSVIDefs::Validity getValidity() const;
196
197    /**
198     * The appropriate case among the following:
199     * 1 If it was strictly assessed, then full;
200     * 2 otherwise none.
201     * @deprecated
202     */
203    PSVIDefs::Validation getValidationAttempted() const;
204
205    /**
206     * @return the complexity. Always simple for attrs
207     * @deprecated
208     */
209    PSVIDefs::Complexity getTypeType() const;
210
211    /**
212     * The target namespace of the type definition.
213     * @deprecated
214     */
215    const XMLCh* getTypeUri() const;
216
217    /**
218     * The {name} of the type definition, if it is not absent.
219     * @deprecated
220     */
221    const XMLCh* getTypeName() const;
222
223    /**
224     * true if the {name} of the type definition is absent, otherwise false.
225     * @deprecated
226     */
227    bool getTypeAnonymous() const;
228
229    /**
230     * If this method returns true and validity is VALID then the next three
231     * produce accurate results
232     * @return true if the element is validated using a union type
233     * @deprecated
234     */
235    bool isTypeDefinitionUnion() const;
236
237    /**
238     * The {target namespace} of the actual member type definition.
239     * @deprecated
240     */
241    const XMLCh* getMemberTypeUri() const;
242
243    /**
244     * @return true if the {name} of the actual member type definition is absent, otherwise false.
245     * @deprecated
246     */
247    bool getMemberTypeAnonymous() const;
248
249    /**
250     * @return the {name} of the actual member type definition, if it is not absent.
251     * @deprecated
252     */
253    const XMLCh* getMemberTypeName() const;
254
255    /*
256     * @deprecated
257     */
258    virtual const XMLCh* getDOMTypeInfoUri() const;
259    /*
260     * @deprecated
261     */
262    virtual const XMLCh* getDOMTypeInfoName() const;
263   
264   
265
266    // -----------------------------------------------------------------------
267    //  Getter methods
268    // -----------------------------------------------------------------------
269    unsigned int getElemId() const;
270    QName* getAttName() const;
271    DatatypeValidator* getDatatypeValidator() const;
272    ValueVectorOf<unsigned int>* getNamespaceList() const;
273    const SchemaAttDef* getBaseAttDecl() const;
274    SchemaAttDef* getBaseAttDecl();
275    PSVIDefs::PSVIScope getPSVIScope() const;
276
277    /*
278     * @deprecated
279     */
280    ComplexTypeInfo* getEnclosingCT() const;
281
282    // -----------------------------------------------------------------------
283    //  Setter methods
284    // -----------------------------------------------------------------------
285    void setElemId(const unsigned int newId);
286    void setAttName
287    (
288        const XMLCh* const        prefix
289       ,const XMLCh* const        localPart
290       ,const int                 uriId = -1
291    );
292    void setDatatypeValidator(DatatypeValidator* newDatatypeValidator);
293    void setAnyDatatypeValidator(DatatypeValidator* newDatatypeValidator);
294    void setBaseAttDecl(SchemaAttDef* const attDef);
295    void setPSVIScope(const PSVIDefs::PSVIScope toSet);
296
297    /*
298     * @deprecated
299     */
300    void setMembertypeValidator(const DatatypeValidator* newDatatypeValidator);
301    void setNamespaceList(const ValueVectorOf<unsigned int>* const toSet);
302    void resetNamespaceList();
303    /*
304     * @deprecated
305     */
306    void setValidity(PSVIDefs::Validity valid);
307    /*
308     * @deprecated
309     */
310    void setValidationAttempted(PSVIDefs::Validation validation);
311    void setEnclosingCT(ComplexTypeInfo* complexTypeInfo);
312    /***
313     * Support for Serialization/De-serialization
314     ***/
315    DECL_XSERIALIZABLE(SchemaAttDef)
316
317private :
318    // -----------------------------------------------------------------------
319    //  Unimplemented constructors and operators
320    // -----------------------------------------------------------------------
321    SchemaAttDef(const SchemaAttDef&);
322    SchemaAttDef& operator=(const SchemaAttDef&);
323
324    // -----------------------------------------------------------------------
325    //  Private data members
326    //
327    //  fElemId
328    //      This is the id of the element (the id is into the element decl
329    //      pool) of the element this attribute def said it belonged to.
330    //      This is used later to link back to the element, mostly for
331    //      validation purposes.
332    //
333    //  fAttName
334    //      This is the name of the attribute.
335    //
336    //  fDatatypeValidator
337    //      The DatatypeValidator used to validate this attribute type.
338    //
339    //  fAnyDatatypeValidator
340    //      Tempory storage for the DatatypeValidator used to validate an any
341    //
342    //  fMemberTypeValidator
343    //      Tempory storage used when the validator being used is of union type.
344    //      This stores the actual member validator used to validate.
345    //
346    //  fNamespaceList
347    //      The list of namespace values for a wildcard attribute
348    //
349    //  fValidity
350    //      After this attr has been validated this is its validity
351    //
352    //  fValidation
353    //      The type of validation that happened to this attr
354    //
355    //  fBaseAttDecl
356    //      The base attribute declaration that this attribute is based on
357    //      NOTE: we do not have a notion of attribute use, so in the case
358    //      of ref'd attributes and inherited attributes, we make a copy
359    //      of the actual attribute declaration. The fBaseAttDecl stores that
360    //      declaration, and will be helpful when we build the XSModel (i.e
361    //      easy access the XSAnnotation object).
362    // -----------------------------------------------------------------------
363    unsigned int                 fElemId;
364    QName*                       fAttName;
365    DatatypeValidator*           fDatatypeValidator;
366    DatatypeValidator*           fAnyDatatypeValidator;
367    const DatatypeValidator*     fMemberTypeValidator;
368    ValueVectorOf<unsigned int>* fNamespaceList;
369    PSVIDefs::Validity           fValidity;
370    PSVIDefs::Validation         fValidation;
371    PSVIDefs::PSVIScope          fPSVIScope;
372    SchemaAttDef*                fBaseAttDecl;
373};
374
375
376// ---------------------------------------------------------------------------
377//  SchemaAttDef: Getter methods
378// ---------------------------------------------------------------------------
379inline unsigned int SchemaAttDef::getElemId() const
380{
381    return fElemId;
382}
383
384
385inline QName* SchemaAttDef::getAttName() const
386{
387    return fAttName;
388}
389
390inline DatatypeValidator* SchemaAttDef::getDatatypeValidator() const
391{
392    return fDatatypeValidator;
393}
394
395inline void SchemaAttDef::setValidity(PSVIDefs::Validity valid) {
396    fValidity = valid;
397}
398
399inline void SchemaAttDef::setValidationAttempted(PSVIDefs::Validation validation) {
400    fValidation = validation;
401}
402
403
404inline const XMLCh* SchemaAttDef::getTypeName() const {
405    if(fAnyDatatypeValidator)
406        return fAnyDatatypeValidator->getTypeLocalName();
407    else if(fDatatypeValidator)
408        return fDatatypeValidator->getTypeLocalName();
409
410    //its anySimpleType if we have not done validation on it
411    if(getValidationAttempted() == PSVIDefs::NONE)
412        return SchemaSymbols::fgDT_ANYSIMPLETYPE;
413
414
415    return 0;
416}
417
418inline PSVIDefs::Complexity SchemaAttDef::getTypeType() const {
419    return PSVIDefs::SIMPLE;
420}
421
422inline const XMLCh* SchemaAttDef::getTypeUri() const {
423    if(fAnyDatatypeValidator)
424        return fAnyDatatypeValidator->getTypeUri();
425    else if(fDatatypeValidator)
426        return fDatatypeValidator->getTypeUri();
427
428    //its anySimpleType if we have not done validation on it
429    if(getValidationAttempted() == PSVIDefs::NONE)
430        return SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
431
432    return 0;
433}
434
435
436inline const XMLCh* SchemaAttDef::getMemberTypeName() const {
437    if(fMemberTypeValidator)
438        return fMemberTypeValidator->getTypeLocalName();
439    return 0;
440}
441
442inline const XMLCh* SchemaAttDef::getMemberTypeUri() const {
443    if(fMemberTypeValidator)
444        return fMemberTypeValidator->getTypeUri();
445    return 0;
446}
447
448inline PSVIDefs::Validity SchemaAttDef::getValidity() const {
449    return fValidity;
450}
451
452inline PSVIDefs::Validation SchemaAttDef::getValidationAttempted() const {
453    return fValidation;
454}
455
456inline const XMLCh* SchemaAttDef::getDOMTypeInfoName() const {
457    if(fValidity != PSVIDefs::VALID)
458        return SchemaSymbols::fgDT_ANYSIMPLETYPE;
459    if(getTypeAnonymous() || getMemberTypeAnonymous())
460        return 0;
461    if(fMemberTypeValidator)
462        return getMemberTypeName();
463
464    return getTypeName();
465}
466
467inline const XMLCh* SchemaAttDef::getDOMTypeInfoUri() const {
468    if(fValidity != PSVIDefs::VALID)
469        return SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
470    if(getTypeAnonymous() || getMemberTypeAnonymous())
471        return 0;
472    if(fMemberTypeValidator)
473        return getMemberTypeUri();
474    return getTypeUri();
475}
476
477inline bool SchemaAttDef::getTypeAnonymous() const {
478    if(fAnyDatatypeValidator)
479        return fAnyDatatypeValidator->getAnonymous();
480    else if(fDatatypeValidator)
481        return fDatatypeValidator->getAnonymous();
482
483    return false;
484}
485
486inline bool SchemaAttDef::getMemberTypeAnonymous() const {
487    if(fMemberTypeValidator)
488        return fMemberTypeValidator->getAnonymous();
489
490    return false;
491}
492
493inline bool SchemaAttDef::isTypeDefinitionUnion() const {
494   if(fAnyDatatypeValidator && fAnyDatatypeValidator->getType() == DatatypeValidator::Union ||
495      fDatatypeValidator && fDatatypeValidator->getType() == DatatypeValidator::Union)
496       return true;
497    return false;
498}
499
500inline ValueVectorOf<unsigned int>*
501SchemaAttDef::getNamespaceList() const {
502    return fNamespaceList;
503}
504
505inline ComplexTypeInfo* SchemaAttDef::getEnclosingCT() const
506{
507    return 0;
508}
509
510inline SchemaAttDef* SchemaAttDef::getBaseAttDecl()
511{
512    return fBaseAttDecl;
513}
514
515inline const SchemaAttDef* SchemaAttDef::getBaseAttDecl() const
516{
517    return fBaseAttDecl;
518}
519
520inline PSVIDefs::PSVIScope SchemaAttDef::getPSVIScope() const
521{
522    return fPSVIScope;
523}
524
525// ---------------------------------------------------------------------------
526//  SchemaAttDef: Setter methods
527// ---------------------------------------------------------------------------
528inline void SchemaAttDef::setElemId(const unsigned int newId)
529{
530    fElemId = newId;
531}
532
533inline void SchemaAttDef::setDatatypeValidator(DatatypeValidator* newDatatypeValidator)
534{
535    fDatatypeValidator = newDatatypeValidator;
536}
537
538inline void SchemaAttDef::setAnyDatatypeValidator(DatatypeValidator* newDatatypeValidator)
539{
540    fAnyDatatypeValidator = newDatatypeValidator;
541}
542
543inline void SchemaAttDef::setMembertypeValidator(const DatatypeValidator* newDatatypeValidator)
544{
545    fMemberTypeValidator = newDatatypeValidator;
546}
547
548inline void SchemaAttDef::resetNamespaceList() {
549
550    if (fNamespaceList && fNamespaceList->size()) {
551        fNamespaceList->removeAllElements();
552    }
553}
554
555inline void SchemaAttDef::setNamespaceList(const ValueVectorOf<unsigned int>* const toSet) {
556
557    if (toSet && toSet->size()) {
558
559        if (fNamespaceList) {
560            *fNamespaceList = *toSet;
561        }
562        else {
563            fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*toSet);
564        }
565    }
566    else  {
567        resetNamespaceList();
568    }
569}
570
571inline void SchemaAttDef::reset() {
572    if(fAnyDatatypeValidator && fAnyDatatypeValidator->getType() == DatatypeValidator::Union)
573        ((UnionDatatypeValidator *)fAnyDatatypeValidator)->reset();
574    else if(fDatatypeValidator && fDatatypeValidator->getType() == DatatypeValidator::Union)
575        ((UnionDatatypeValidator *)fDatatypeValidator)->reset();
576    fAnyDatatypeValidator = 0;
577    fMemberTypeValidator = 0;
578    fValidity = PSVIDefs::UNKNOWN;
579    fValidation = PSVIDefs::NONE;   
580}
581
582inline void SchemaAttDef::setEnclosingCT(ComplexTypeInfo*)
583{
584}
585
586inline void SchemaAttDef::setBaseAttDecl(SchemaAttDef* const attDef)
587{
588    fBaseAttDecl = attDef;
589}
590
591inline void SchemaAttDef::setPSVIScope(const PSVIDefs::PSVIScope toSet)
592{
593    fPSVIScope = toSet;
594}
595
596XERCES_CPP_NAMESPACE_END
597
598#endif
Note: See TracBrowser for help on using the repository browser.