source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/validators/schema/SchemaAttDef.hpp @ 2674

Revision 2674, 15.6 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: SchemaAttDef.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21#if !defined(SCHEMAATTDEF_HPP)
22#define SCHEMAATTDEF_HPP
23
24#include <xercesc/util/XMLString.hpp>
25#include <xercesc/framework/XMLAttDef.hpp>
26#include <xercesc/util/ValueVectorOf.hpp>
27#include <xercesc/validators/datatype/DatatypeValidator.hpp>
28#include <xercesc/validators/datatype/UnionDatatypeValidator.hpp>
29#include <xercesc/validators/schema/PSVIDefs.hpp>
30
31XERCES_CPP_NAMESPACE_BEGIN
32
33class DatatypeValidator;
34class QName;
35class ComplexTypeInfo;
36//
37//  This class is a derivative of the core XMLAttDef class. This class adds
38//  any Schema specific data members and provides Schema specific implementations
39//  of any underlying attribute def virtual methods.
40//
41class VALIDATORS_EXPORT SchemaAttDef : public XMLAttDef
42{
43public :
44    // -----------------------------------------------------------------------
45    //  Constructors and Destructors
46    // -----------------------------------------------------------------------
47    SchemaAttDef(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
48    SchemaAttDef
49    (
50          const XMLCh* const           prefix
51        , const XMLCh* const           localPart
52        , const int                    uriId
53        , const XMLAttDef::AttTypes    type = CData
54        , const XMLAttDef::DefAttTypes defType = Implied
55        , MemoryManager* const         manager = XMLPlatformUtils::fgMemoryManager
56    );
57    SchemaAttDef
58    (
59          const XMLCh* const           prefix
60        , const XMLCh* const           localPart
61        , const int                    uriId
62        , const XMLCh* const           attValue
63        , const XMLAttDef::AttTypes    type
64        , const XMLAttDef::DefAttTypes defType
65        , const XMLCh* const           enumValues = 0
66        , MemoryManager* const         manager = XMLPlatformUtils::fgMemoryManager
67    );
68    SchemaAttDef
69    (
70          const SchemaAttDef*                   other
71    );
72    virtual ~SchemaAttDef();
73
74    // -----------------------------------------------------------------------
75    //  Implementation of the XMLAttDef interface
76    // -----------------------------------------------------------------------
77    virtual const XMLCh* getFullName() const;
78    virtual void reset();
79
80
81    // ----------------------------------------------------------------------
82    // Partial implementation of PSVI
83    // The values these methods return are only accurate until the DOMAttr
84    // is created that uses the values. After this a clean up method is called
85    // and the SchemaAttDef may be used again.
86    // note that some of this information has dependancies. For example,
87    // if something is not valid then the information returned by the other
88    // calls may be meaningless
89    // See http://www.w3.org/TR/xmlschema-1/ for detailed information
90    // ----------------------------------------------------------------------
91
92    /**
93     * The appropriate case among the following:
94     * 1 If it was strictly assessed, then the appropriate case among the following:
95     * 1.1 If it was valid as defined by Attribute Locally Valid (3.2.4), then valid;
96     * 1.2 otherwise invalid.
97     * 2 otherwise notKnown.
98     * @deprecated
99     */
100    PSVIDefs::Validity getValidity() const;
101
102    /**
103     * The appropriate case among the following:
104     * 1 If it was strictly assessed, then full;
105     * 2 otherwise none.
106     * @deprecated
107     */
108    PSVIDefs::Validation getValidationAttempted() const;
109
110    /**
111     * @return the complexity. Always simple for attrs
112     * @deprecated
113     */
114    PSVIDefs::Complexity getTypeType() const;
115
116    /**
117     * The target namespace of the type definition.
118     * @deprecated
119     */
120    const XMLCh* getTypeUri() const;
121
122    /**
123     * The {name} of the type definition, if it is not absent.
124     * @deprecated
125     */
126    const XMLCh* getTypeName() const;
127
128    /**
129     * true if the {name} of the type definition is absent, otherwise false.
130     * @deprecated
131     */
132    bool getTypeAnonymous() const;
133
134    /**
135     * If this method returns true and validity is VALID then the next three
136     * produce accurate results
137     * @return true if the element is validated using a union type
138     * @deprecated
139     */
140    bool isTypeDefinitionUnion() const;
141
142    /**
143     * The {target namespace} of the actual member type definition.
144     * @deprecated
145     */
146    const XMLCh* getMemberTypeUri() const;
147
148    /**
149     * @return true if the {name} of the actual member type definition is absent, otherwise false.
150     * @deprecated
151     */
152    bool getMemberTypeAnonymous() const;
153
154    /**
155     * @return the {name} of the actual member type definition, if it is not absent.
156     * @deprecated
157     */
158    const XMLCh* getMemberTypeName() const;
159
160    /*
161     * @deprecated
162     */
163    virtual const XMLCh* getDOMTypeInfoUri() const;
164    /*
165     * @deprecated
166     */
167    virtual const XMLCh* getDOMTypeInfoName() const;
168   
169   
170
171    // -----------------------------------------------------------------------
172    //  Getter methods
173    // -----------------------------------------------------------------------
174    unsigned int getElemId() const;
175    QName* getAttName() const;
176    DatatypeValidator* getDatatypeValidator() const;
177    ValueVectorOf<unsigned int>* getNamespaceList() const;
178    const SchemaAttDef* getBaseAttDecl() const;
179    SchemaAttDef* getBaseAttDecl();
180    PSVIDefs::PSVIScope getPSVIScope() const;
181
182    /*
183     * @deprecated
184     */
185    ComplexTypeInfo* getEnclosingCT() const;
186
187    // -----------------------------------------------------------------------
188    //  Setter methods
189    // -----------------------------------------------------------------------
190    void setElemId(const unsigned int newId);
191    void setAttName
192    (
193        const XMLCh* const        prefix
194       ,const XMLCh* const        localPart
195       ,const int                 uriId = -1
196    );
197    void setDatatypeValidator(DatatypeValidator* newDatatypeValidator);
198    /*
199     * @deprecated
200     */
201    void setAnyDatatypeValidator(DatatypeValidator* newDatatypeValidator);
202    void setBaseAttDecl(SchemaAttDef* const attDef);
203    void setPSVIScope(const PSVIDefs::PSVIScope toSet);
204
205    /*
206     * @deprecated
207     */
208    void setMembertypeValidator(const DatatypeValidator* newDatatypeValidator);
209    void setNamespaceList(const ValueVectorOf<unsigned int>* const toSet);
210    void resetNamespaceList();
211    /*
212     * @deprecated
213     */
214    void setValidity(PSVIDefs::Validity valid);
215    /*
216     * @deprecated
217     */
218    void setValidationAttempted(PSVIDefs::Validation validation);
219    void setEnclosingCT(ComplexTypeInfo* complexTypeInfo);
220    /***
221     * Support for Serialization/De-serialization
222     ***/
223    DECL_XSERIALIZABLE(SchemaAttDef)
224
225private :
226    // -----------------------------------------------------------------------
227    //  Unimplemented constructors and operators
228    // -----------------------------------------------------------------------
229    SchemaAttDef(const SchemaAttDef&);
230    SchemaAttDef& operator=(const SchemaAttDef&);
231
232    // -----------------------------------------------------------------------
233    //  Private data members
234    //
235    //  fElemId
236    //      This is the id of the element (the id is into the element decl
237    //      pool) of the element this attribute def said it belonged to.
238    //      This is used later to link back to the element, mostly for
239    //      validation purposes.
240    //
241    //  fAttName
242    //      This is the name of the attribute.
243    //
244    //  fDatatypeValidator
245    //      The DatatypeValidator used to validate this attribute type.
246    //
247    //  fAnyDatatypeValidator
248    //      Tempory storage for the DatatypeValidator used to validate an any
249    //
250    //  fMemberTypeValidator
251    //      Tempory storage used when the validator being used is of union type.
252    //      This stores the actual member validator used to validate.
253    //
254    //  fNamespaceList
255    //      The list of namespace values for a wildcard attribute
256    //
257    //  fValidity
258    //      After this attr has been validated this is its validity
259    //
260    //  fValidation
261    //      The type of validation that happened to this attr
262    //
263    //  fBaseAttDecl
264    //      The base attribute declaration that this attribute is based on
265    //      NOTE: we do not have a notion of attribute use, so in the case
266    //      of ref'd attributes and inherited attributes, we make a copy
267    //      of the actual attribute declaration. The fBaseAttDecl stores that
268    //      declaration, and will be helpful when we build the XSModel (i.e
269    //      easy access the XSAnnotation object).
270    // -----------------------------------------------------------------------
271    unsigned int                 fElemId;
272
273    PSVIDefs::Validity           fValidity;
274    PSVIDefs::Validation         fValidation;
275    PSVIDefs::PSVIScope          fPSVIScope;
276
277    QName*                       fAttName;
278    DatatypeValidator*           fDatatypeValidator;
279    DatatypeValidator*           fAnyDatatypeValidator;
280    const DatatypeValidator*     fMemberTypeValidator;
281    ValueVectorOf<unsigned int>* fNamespaceList;
282    SchemaAttDef*                fBaseAttDecl;
283};
284
285
286// ---------------------------------------------------------------------------
287//  SchemaAttDef: Getter methods
288// ---------------------------------------------------------------------------
289inline unsigned int SchemaAttDef::getElemId() const
290{
291    return fElemId;
292}
293
294
295inline QName* SchemaAttDef::getAttName() const
296{
297    return fAttName;
298}
299
300inline DatatypeValidator* SchemaAttDef::getDatatypeValidator() const
301{
302    return fDatatypeValidator;
303}
304
305inline void SchemaAttDef::setValidity(PSVIDefs::Validity valid) {
306    fValidity = valid;
307}
308
309inline void SchemaAttDef::setValidationAttempted(PSVIDefs::Validation validation) {
310    fValidation = validation;
311}
312
313
314inline const XMLCh* SchemaAttDef::getTypeName() const {
315    if(fAnyDatatypeValidator)
316        return fAnyDatatypeValidator->getTypeLocalName();
317    else if(fDatatypeValidator)
318        return fDatatypeValidator->getTypeLocalName();
319
320    //its anySimpleType if we have not done validation on it
321    if(getValidationAttempted() == PSVIDefs::NONE)
322        return SchemaSymbols::fgDT_ANYSIMPLETYPE;
323
324
325    return 0;
326}
327
328inline PSVIDefs::Complexity SchemaAttDef::getTypeType() const {
329    return PSVIDefs::SIMPLE;
330}
331
332inline const XMLCh* SchemaAttDef::getTypeUri() const {
333    if(fAnyDatatypeValidator)
334        return fAnyDatatypeValidator->getTypeUri();
335    else if(fDatatypeValidator)
336        return fDatatypeValidator->getTypeUri();
337
338    //its anySimpleType if we have not done validation on it
339    if(getValidationAttempted() == PSVIDefs::NONE)
340        return SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
341
342    return 0;
343}
344
345
346inline const XMLCh* SchemaAttDef::getMemberTypeName() const {
347    if(fMemberTypeValidator)
348        return fMemberTypeValidator->getTypeLocalName();
349    return 0;
350}
351
352inline const XMLCh* SchemaAttDef::getMemberTypeUri() const {
353    if(fMemberTypeValidator)
354        return fMemberTypeValidator->getTypeUri();
355    return 0;
356}
357
358inline PSVIDefs::Validity SchemaAttDef::getValidity() const {
359    return fValidity;
360}
361
362inline PSVIDefs::Validation SchemaAttDef::getValidationAttempted() const {
363    return fValidation;
364}
365
366inline const XMLCh* SchemaAttDef::getDOMTypeInfoName() const {
367    if(fValidity != PSVIDefs::VALID)
368        return SchemaSymbols::fgDT_ANYSIMPLETYPE;
369    if(getTypeAnonymous() || getMemberTypeAnonymous())
370        return 0;
371    if(fMemberTypeValidator)
372        return getMemberTypeName();
373
374    return getTypeName();
375}
376
377inline const XMLCh* SchemaAttDef::getDOMTypeInfoUri() const {
378    if(fValidity != PSVIDefs::VALID)
379        return SchemaSymbols::fgURI_SCHEMAFORSCHEMA;
380    if(getTypeAnonymous() || getMemberTypeAnonymous())
381        return 0;
382    if(fMemberTypeValidator)
383        return getMemberTypeUri();
384    return getTypeUri();
385}
386
387inline bool SchemaAttDef::getTypeAnonymous() const {
388    if(fAnyDatatypeValidator)
389        return fAnyDatatypeValidator->getAnonymous();
390    else if(fDatatypeValidator)
391        return fDatatypeValidator->getAnonymous();
392
393    return false;
394}
395
396inline bool SchemaAttDef::getMemberTypeAnonymous() const {
397    if(fMemberTypeValidator)
398        return fMemberTypeValidator->getAnonymous();
399
400    return false;
401}
402
403inline bool SchemaAttDef::isTypeDefinitionUnion() const {
404   if(fAnyDatatypeValidator && fAnyDatatypeValidator->getType() == DatatypeValidator::Union ||
405      fDatatypeValidator && fDatatypeValidator->getType() == DatatypeValidator::Union)
406       return true;
407    return false;
408}
409
410inline ValueVectorOf<unsigned int>*
411SchemaAttDef::getNamespaceList() const {
412    return fNamespaceList;
413}
414
415inline ComplexTypeInfo* SchemaAttDef::getEnclosingCT() const
416{
417    return 0;
418}
419
420inline SchemaAttDef* SchemaAttDef::getBaseAttDecl()
421{
422    return fBaseAttDecl;
423}
424
425inline const SchemaAttDef* SchemaAttDef::getBaseAttDecl() const
426{
427    return fBaseAttDecl;
428}
429
430inline PSVIDefs::PSVIScope SchemaAttDef::getPSVIScope() const
431{
432    return fPSVIScope;
433}
434
435// ---------------------------------------------------------------------------
436//  SchemaAttDef: Setter methods
437// ---------------------------------------------------------------------------
438inline void SchemaAttDef::setElemId(const unsigned int newId)
439{
440    fElemId = newId;
441}
442
443inline void SchemaAttDef::setDatatypeValidator(DatatypeValidator* newDatatypeValidator)
444{
445    fDatatypeValidator = newDatatypeValidator;
446}
447
448inline void SchemaAttDef::setAnyDatatypeValidator(DatatypeValidator* newDatatypeValidator)
449{
450    fAnyDatatypeValidator = newDatatypeValidator;
451}
452
453inline void SchemaAttDef::setMembertypeValidator(const DatatypeValidator* newDatatypeValidator)
454{
455    fMemberTypeValidator = newDatatypeValidator;
456}
457
458inline void SchemaAttDef::resetNamespaceList() {
459
460    if (fNamespaceList && fNamespaceList->size()) {
461        fNamespaceList->removeAllElements();
462    }
463}
464
465inline void SchemaAttDef::setNamespaceList(const ValueVectorOf<unsigned int>* const toSet) {
466
467    if (toSet && toSet->size()) {
468
469        if (fNamespaceList) {
470            *fNamespaceList = *toSet;
471        }
472        else {
473            fNamespaceList = new (getMemoryManager()) ValueVectorOf<unsigned int>(*toSet);
474        }
475    }
476    else  {
477        resetNamespaceList();
478    }
479}
480
481inline void SchemaAttDef::reset() {
482    if(fAnyDatatypeValidator && fAnyDatatypeValidator->getType() == DatatypeValidator::Union)
483        ((UnionDatatypeValidator *)fAnyDatatypeValidator)->reset();
484    else if(fDatatypeValidator && fDatatypeValidator->getType() == DatatypeValidator::Union)
485        ((UnionDatatypeValidator *)fDatatypeValidator)->reset();
486    fAnyDatatypeValidator = 0;
487    fMemberTypeValidator = 0;
488    fValidity = PSVIDefs::UNKNOWN;
489    fValidation = PSVIDefs::NONE;   
490}
491
492inline void SchemaAttDef::setEnclosingCT(ComplexTypeInfo*)
493{
494}
495
496inline void SchemaAttDef::setBaseAttDecl(SchemaAttDef* const attDef)
497{
498    fBaseAttDecl = attDef;
499}
500
501inline void SchemaAttDef::setPSVIScope(const PSVIDefs::PSVIScope toSet)
502{
503    fPSVIScope = toSet;
504}
505
506XERCES_CPP_NAMESPACE_END
507
508#endif
Note: See TracBrowser for help on using the repository browser.