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

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