source: obsolete/tags/VUT/0.4/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/schema/ComplexTypeInfo.hpp @ 358

Revision 358, 17.5 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: ComplexTypeInfo.hpp,v 1.23 2004/09/23 00:37:24 cargilld Exp $
19 */
20
21#if !defined(COMPLEXTYPEINFO_HPP)
22#define COMPLEXTYPEINFO_HPP
23
24
25/**
26  * The class act as a place holder to store complex type information.
27  *
28  * The class is intended for internal use.
29  */
30
31// ---------------------------------------------------------------------------
32//  Includes
33// ---------------------------------------------------------------------------
34#include <xercesc/util/XMLString.hpp>
35#include <xercesc/util/RefHash2KeysTableOf.hpp>
36#include <xercesc/util/RefVectorOf.hpp>
37#include <xercesc/framework/XMLElementDecl.hpp>
38#include <xercesc/framework/XMLContentModel.hpp>
39#include <xercesc/validators/schema/SchemaAttDef.hpp>
40#include <xercesc/internal/XSerializable.hpp>
41
42XERCES_CPP_NAMESPACE_BEGIN
43
44
45// ---------------------------------------------------------------------------
46//  Forward Declarations
47// ---------------------------------------------------------------------------
48class DatatypeValidator;
49class ContentSpecNode;
50class SchemaAttDefList;
51class SchemaElementDecl;
52class XSDLocator;
53
54
55class VALIDATORS_EXPORT ComplexTypeInfo : public XSerializable, public XMemory
56{
57public:
58    // -----------------------------------------------------------------------
59    //  Public Constructors/Destructor
60    // -----------------------------------------------------------------------
61    ComplexTypeInfo(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
62    ~ComplexTypeInfo();
63
64    // -----------------------------------------------------------------------
65    //  Getter methods
66    // -----------------------------------------------------------------------
67    bool                     getAbstract() const;
68    bool                     getAdoptContentSpec() const;
69    bool                     containsAttWithTypeId() const;
70    bool                     getPreprocessed() const;
71    int                      getDerivedBy() const;
72    int                      getBlockSet() const;
73    int                      getFinalSet() const;
74    int                      getScopeDefined() const;
75    unsigned int             getElementId() const;
76    int                      getContentType() const;
77    unsigned int             elementCount() const;
78    XMLCh*                   getTypeName() const;
79    DatatypeValidator*       getBaseDatatypeValidator() const;
80    DatatypeValidator*       getDatatypeValidator() const;
81    ComplexTypeInfo*         getBaseComplexTypeInfo() const;
82    ContentSpecNode*         getContentSpec() const;
83    const SchemaAttDef*      getAttWildCard() const;
84    SchemaAttDef*            getAttWildCard();
85    const SchemaAttDef*      getAttDef(const XMLCh* const baseName,
86                                       const int uriId) const;
87    SchemaAttDef*            getAttDef(const XMLCh* const baseName,
88                                       const int uriId);
89    XMLAttDefList&           getAttDefList() const;
90    const SchemaElementDecl* elementAt(const unsigned int index) const;
91    SchemaElementDecl*       elementAt(const unsigned int index);
92    XMLContentModel*         getContentModel(const bool checkUPA = false);
93    const XMLCh*             getFormattedContentModel ()   const;
94    XSDLocator*              getLocator() const;
95    const XMLCh*             getTypeLocalName() const;
96    const XMLCh*             getTypeUri() const;
97
98    /**
99     * returns true if this type is anonymous
100     **/
101    bool getAnonymous() const;
102
103    // -----------------------------------------------------------------------
104    //  Setter methods
105    // -----------------------------------------------------------------------
106    void setAbstract(const bool isAbstract);
107    void setAdoptContentSpec(const bool toAdopt);
108    void setAttWithTypeId(const bool value);
109    void setPreprocessed(const bool aValue = true);
110    void setDerivedBy(const int derivedBy);
111    void setBlockSet(const int blockSet);
112    void setFinalSet(const int finalSet);
113    void setScopeDefined(const int scopeDefined);
114    void setElementId(const unsigned int elemId);
115    void setTypeName(const XMLCh* const typeName);
116    void setContentType(const int contentType);
117    void setBaseDatatypeValidator(DatatypeValidator* const baseValidator);
118    void setDatatypeValidator(DatatypeValidator* const validator);
119    void setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo);
120    void setContentSpec(ContentSpecNode* const toAdopt);
121    void setAttWildCard(SchemaAttDef* const toAdopt);
122    void addAttDef(SchemaAttDef* const toAdd);
123    void addElement(SchemaElementDecl* const toAdd);
124    /**     
125     * @deprecated; not thread-safe (will not work with shared grammars)
126     */
127    void setContentModel(XMLContentModel* const newModelToAdopt);
128    void setLocator(XSDLocator* const aLocator);
129
130    /**
131     * sets this type to be anonymous
132     **/
133    void setAnonymous();
134
135    // -----------------------------------------------------------------------
136    //  Helper methods
137    // -----------------------------------------------------------------------
138    bool hasAttDefs() const;
139    bool contains(const XMLCh* const attName);
140    XMLAttDef* findAttr
141    (
142        const   XMLCh* const    qName
143        , const unsigned int    uriId
144        , const XMLCh* const    baseName
145        , const XMLCh* const    prefix
146        , const XMLElementDecl::LookupOpts      options
147        ,       bool&           wasAdded
148    )   const;
149    bool resetDefs();
150    void checkUniqueParticleAttribution
151    (
152        SchemaGrammar*    const pGrammar
153      , GrammarResolver*  const pGrammarResolver
154      , XMLStringPool*    const pStringPool
155      , XMLValidator*     const pValidator
156    ) ;
157
158    /**
159      * Return a singleton that represents 'anyType'
160      *
161      * @param emptyNSId the uri id of the empty namespace
162      */
163    static ComplexTypeInfo* getAnyType(unsigned int emptyNSId);
164
165    /**
166      *  Notification that lazy data has been deleted
167      */
168    static void reinitAnyType();
169
170    /***
171     * Support for Serialization/De-serialization
172     ***/
173    DECL_XSERIALIZABLE(ComplexTypeInfo)
174
175private:
176    // -----------------------------------------------------------------------
177    //  Unimplemented contstructors and operators
178    // -----------------------------------------------------------------------
179    ComplexTypeInfo(const ComplexTypeInfo& elemInfo);
180    ComplexTypeInfo& operator= (const ComplexTypeInfo& other);
181
182    // -----------------------------------------------------------------------
183    //  Private helper methods
184    // -----------------------------------------------------------------------
185    void faultInAttDefList() const;
186    XMLContentModel* createChildModel(ContentSpecNode* specNode, const bool isMixed);
187    XMLContentModel* makeContentModel(const bool checkUPA = false);
188    XMLContentModel* buildContentModel(ContentSpecNode* const specNode);
189    XMLCh* formatContentModel () const ;
190    ContentSpecNode* expandContentModel(ContentSpecNode* const curNode, const int minOccurs, const int maxOccurs);
191    ContentSpecNode* convertContentSpecTree(ContentSpecNode* const curNode, const bool checkUPA = false);
192    void resizeContentSpecOrgURI();
193
194    // -----------------------------------------------------------------------
195    //  Private data members
196    // -----------------------------------------------------------------------
197    bool                               fAnonymous;
198    bool                               fAbstract;
199    bool                               fAdoptContentSpec;
200    bool                               fAttWithTypeId;
201    bool                               fPreprocessed;
202    int                                fDerivedBy;
203    int                                fBlockSet;
204    int                                fFinalSet;
205    int                                fScopeDefined;
206    unsigned int                       fElementId;
207    int                                fContentType;
208    XMLCh*                             fTypeName;
209    XMLCh*                             fTypeLocalName;
210    XMLCh*                             fTypeUri;
211    DatatypeValidator*                 fBaseDatatypeValidator;
212    DatatypeValidator*                 fDatatypeValidator;
213    ComplexTypeInfo*                   fBaseComplexTypeInfo;
214    ContentSpecNode*                   fContentSpec;
215    SchemaAttDef*                      fAttWildCard;
216    SchemaAttDefList*                  fAttList;
217    RefVectorOf<SchemaElementDecl>*    fElements;   
218    RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
219    XMLContentModel*                   fContentModel;
220    XMLCh*                             fFormattedModel;
221    unsigned int*                      fContentSpecOrgURI;
222    unsigned int                       fUniqueURI;
223    unsigned int                       fContentSpecOrgURISize;
224    XSDLocator*                        fLocator;
225    MemoryManager*                     fMemoryManager;
226
227    static ComplexTypeInfo*            fAnyType;
228};
229
230// ---------------------------------------------------------------------------
231//  ComplexTypeInfo: Getter methods
232// ---------------------------------------------------------------------------
233inline bool ComplexTypeInfo::getAbstract() const {
234
235    return fAbstract;
236}
237
238inline bool ComplexTypeInfo::getAdoptContentSpec() const {
239
240    return fAdoptContentSpec;
241}
242
243inline bool ComplexTypeInfo::containsAttWithTypeId() const {
244
245    return fAttWithTypeId;
246}
247
248inline bool ComplexTypeInfo::getPreprocessed() const {
249
250    return fPreprocessed;
251}
252
253inline int ComplexTypeInfo::getDerivedBy() const {
254
255    return fDerivedBy;
256}
257
258inline int ComplexTypeInfo::getBlockSet() const {
259
260    return fBlockSet;
261}
262
263inline int ComplexTypeInfo::getFinalSet() const {
264
265    return fFinalSet;
266}
267
268inline int ComplexTypeInfo::getScopeDefined() const {
269
270    return fScopeDefined;
271}
272
273inline unsigned int ComplexTypeInfo::getElementId() const {
274
275    return fElementId;
276}
277
278inline int ComplexTypeInfo::getContentType() const {
279
280    return fContentType;
281}
282
283inline unsigned int ComplexTypeInfo::elementCount() const {
284
285    if (fElements) {
286        return fElements->size();
287    }
288
289    return 0;
290}
291
292inline XMLCh* ComplexTypeInfo::getTypeName() const {
293    return fTypeName;
294}
295
296inline DatatypeValidator* ComplexTypeInfo::getBaseDatatypeValidator() const {
297
298    return fBaseDatatypeValidator;
299}
300
301inline DatatypeValidator* ComplexTypeInfo::getDatatypeValidator() const {
302
303    return fDatatypeValidator;
304}
305
306inline ComplexTypeInfo* ComplexTypeInfo::getBaseComplexTypeInfo() const {
307
308    return fBaseComplexTypeInfo;
309}
310
311inline ContentSpecNode* ComplexTypeInfo::getContentSpec() const {
312
313    return fContentSpec;
314}
315
316inline const SchemaAttDef* ComplexTypeInfo::getAttWildCard() const {
317
318    return fAttWildCard;
319}
320
321inline SchemaAttDef* ComplexTypeInfo::getAttWildCard() {
322
323    return fAttWildCard;
324}
325
326inline const SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
327                                                      const int uriId) const {
328
329    // If no list, then return a null
330    if (!fAttDefs)
331        return 0;
332
333    return fAttDefs->get(baseName, uriId);
334}
335
336inline SchemaAttDef* ComplexTypeInfo::getAttDef(const XMLCh* const baseName,
337                                                const int uriId)
338{
339    // If no list, then return a null
340    if (!fAttDefs)
341        return 0;
342
343    return fAttDefs->get(baseName, uriId);
344}
345
346inline SchemaElementDecl*
347ComplexTypeInfo::elementAt(const unsigned int index) {
348
349    if (!fElements) {
350        return 0; // REVISIT - need to throw an exception
351    }
352
353    return fElements->elementAt(index);
354}
355
356inline const SchemaElementDecl*
357ComplexTypeInfo::elementAt(const unsigned int index) const {
358
359    if (!fElements) {
360        return 0; // REVISIT - need to throw an exception
361    }
362
363    return fElements->elementAt(index);
364}
365
366inline XMLContentModel* ComplexTypeInfo::getContentModel(const bool checkUPA)
367{
368    if (!fContentModel && fContentSpec)
369        fContentModel = makeContentModel(checkUPA);
370
371    return fContentModel;
372}
373
374inline XSDLocator* ComplexTypeInfo::getLocator() const
375{
376    return fLocator;
377}
378
379inline bool ComplexTypeInfo::getAnonymous() const {
380    return fAnonymous;
381}
382
383inline const XMLCh* ComplexTypeInfo::getTypeLocalName() const
384{
385    return fTypeLocalName;
386}
387
388inline const XMLCh* ComplexTypeInfo::getTypeUri() const
389{
390   return fTypeUri;
391}
392
393// ---------------------------------------------------------------------------
394//  ComplexTypeInfo: Setter methods
395// ---------------------------------------------------------------------------
396inline void ComplexTypeInfo::setAbstract(const bool isAbstract) {
397
398    fAbstract = isAbstract;
399}
400
401inline void ComplexTypeInfo::setAdoptContentSpec(const bool toAdopt) {
402
403    fAdoptContentSpec = toAdopt;
404}
405
406inline void ComplexTypeInfo::setAttWithTypeId(const bool value) {
407
408    fAttWithTypeId = value;
409}
410
411inline void ComplexTypeInfo::setPreprocessed(const bool aValue) {
412
413    fPreprocessed = aValue;
414}
415
416inline void ComplexTypeInfo::setDerivedBy(const int derivedBy) {
417
418    fDerivedBy = derivedBy;
419}
420
421inline void ComplexTypeInfo::setBlockSet(const int blockSet) {
422
423    fBlockSet = blockSet;
424}
425
426inline void ComplexTypeInfo::setFinalSet(const int finalSet) {
427
428    fFinalSet = finalSet;
429}
430
431inline void ComplexTypeInfo::setScopeDefined(const int scopeDefined) {
432
433    fScopeDefined = scopeDefined;
434}
435
436inline void ComplexTypeInfo::setElementId(const unsigned int elemId) {
437
438    fElementId = elemId;
439}
440
441inline void
442ComplexTypeInfo::setContentType(const int contentType) {
443
444    fContentType = contentType;
445}
446
447inline void ComplexTypeInfo::setTypeName(const XMLCh* const typeName) {
448
449    fMemoryManager->deallocate(fTypeName);//delete [] fTypeName;
450    fMemoryManager->deallocate(fTypeLocalName);//delete [] fTypeLocalName;
451    fMemoryManager->deallocate(fTypeUri);//delete [] fTypeUri;   
452
453    if (typeName)
454    {
455        fTypeName = XMLString::replicate(typeName, fMemoryManager);
456
457        int index = XMLString::indexOf(fTypeName, chComma);
458        int length = XMLString::stringLen(fTypeName);
459        fTypeLocalName = (XMLCh*) fMemoryManager->allocate
460        (
461            (length - index + 1) * sizeof(XMLCh)
462        ); //new XMLCh[length - index + 1];
463        XMLString::subString(fTypeLocalName, fTypeName, index + 1, length, fMemoryManager);
464       
465        fTypeUri = (XMLCh*) fMemoryManager->allocate
466        (
467            (index + 1) * sizeof(XMLCh)
468        ); //new XMLCh[index + 1];
469        XMLString::subString(fTypeUri, fTypeName, 0, index, fMemoryManager);       
470    }
471    else
472    {
473        fTypeName = fTypeLocalName = fTypeUri = 0;
474    }
475}
476
477inline void
478ComplexTypeInfo::setBaseDatatypeValidator(DatatypeValidator* const validator) {
479
480    fBaseDatatypeValidator = validator;
481}
482
483inline void
484ComplexTypeInfo::setDatatypeValidator(DatatypeValidator* const validator) {
485
486    fDatatypeValidator = validator;
487}
488
489inline void
490ComplexTypeInfo::setBaseComplexTypeInfo(ComplexTypeInfo* const typeInfo) {
491
492    fBaseComplexTypeInfo = typeInfo;
493}
494
495inline void ComplexTypeInfo::addElement(SchemaElementDecl* const elem) {
496
497    if (!fElements) {
498        fElements = new (fMemoryManager) RefVectorOf<SchemaElementDecl>(8, false, fMemoryManager);
499    }
500    else if (fElements->containsElement(elem)) {
501        return;
502    }
503
504    fElements->addElement(elem);
505}
506
507inline void ComplexTypeInfo::setAttWildCard(SchemaAttDef* const toAdopt) {
508
509    if (fAttWildCard) {
510       delete fAttWildCard;
511    }
512
513    fAttWildCard = toAdopt;
514}
515
516inline void
517ComplexTypeInfo::setContentModel(XMLContentModel* const newModelToAdopt)
518{
519    delete fContentModel;
520    fContentModel = newModelToAdopt;
521
522    // reset formattedModel
523    if (fFormattedModel)
524    {
525        fMemoryManager->deallocate(fFormattedModel);
526        fFormattedModel = 0;
527    }
528}
529
530
531
532inline void ComplexTypeInfo::setAnonymous() {
533    fAnonymous = true;
534}
535
536// ---------------------------------------------------------------------------
537//  ComplexTypeInfo: Helper methods
538// ---------------------------------------------------------------------------
539inline bool ComplexTypeInfo::hasAttDefs() const
540{
541    // If the collection hasn't been faulted in, then no att defs
542    if (!fAttDefs)
543        return false;
544
545    return !fAttDefs->isEmpty();
546}
547
548inline bool ComplexTypeInfo::contains(const XMLCh* const attName) {
549
550    if (!fAttDefs) {
551        return false;
552    }
553
554    RefHash2KeysTableOfEnumerator<SchemaAttDef> enumDefs(fAttDefs, false, fMemoryManager);
555
556    while (enumDefs.hasMoreElements()) {
557
558        if (XMLString::equals(attName, enumDefs.nextElement().getAttName()->getLocalPart())) {
559            return true;
560        }
561    }
562
563    return false;
564}
565
566XERCES_CPP_NAMESPACE_END
567
568#endif
569
570/**
571  * End of file ComplexTypeInfo.hpp
572  */
573
Note: See TracBrowser for help on using the repository browser.