source: NonGTP/Xerces/xerces/include/xercesc/validators/schema/SchemaInfo.hpp @ 358

Revision 358, 14.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: SchemaInfo.hpp,v 1.18 2004/09/29 20:58:10 knoaman Exp $
19 */
20
21#if !defined(SCHEMAINFO_HPP)
22#define SCHEMAINFO_HPP
23
24
25/** When in a <redefine>, type definitions being used (and indeed
26  * refs to <group>'s and <attributeGroup>'s) may refer to info
27  * items either in the schema being redefined, in the <redefine>,
28  * or else in the schema doing the redefining.  Because of this
29  * latter we have to be prepared sometimes to look for our type
30  * definitions outside the schema stored in fSchemaRootElement.
31  * This simple class does this; it's just a linked list that
32  * lets us look at the <schema>'s on the queue; note also that this
33  * should provide us with a mechanism to handle nested <redefine>'s.
34  * It's also a handy way of saving schema info when importing/including.
35  */
36
37// ---------------------------------------------------------------------------
38//  Includes
39// ---------------------------------------------------------------------------
40#include <xercesc/dom/DOMElement.hpp>
41#include <xercesc/util/RefVectorOf.hpp>
42#include <xercesc/util/ValueVectorOf.hpp>
43
44XERCES_CPP_NAMESPACE_BEGIN
45
46// ---------------------------------------------------------------------------
47//  Forward Declarations
48// ---------------------------------------------------------------------------
49class ValidationContext;
50
51
52class VALIDATORS_EXPORT SchemaInfo : public XMemory
53{
54public:
55
56    enum ListType {
57        // Redefine is treated as an include
58        IMPORT = 1,
59        INCLUDE = 2
60    };
61
62    enum {
63        C_ComplexType,
64        C_SimpleType,
65        C_Group,
66        C_Attribute,
67        C_AttributeGroup,
68        C_Element,
69        C_Notation,
70
71        C_Count
72    };
73
74    // -----------------------------------------------------------------------
75    //  Constructor/Destructor
76    // -----------------------------------------------------------------------
77    SchemaInfo(const unsigned short fElemAttrDefaultQualified,
78               const int blockDefault,
79               const int finalDefault,
80               const int targetNSURI,
81               const int scopeCount,
82               const unsigned int namespaceScopeLevel,
83               XMLCh* const schemaURL,
84               const XMLCh* const targetNSURIString,
85               const DOMElement* const root,
86               MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
87    ~SchemaInfo();
88
89
90    // -----------------------------------------------------------------------
91    //  Getter methods
92    // -----------------------------------------------------------------------
93    XMLCh*                            getCurrentSchemaURL() const;
94    const XMLCh* const                getTargetNSURIString() const;
95    const DOMElement*                 getRoot() const;
96    bool                              getProcessed() const;
97    int                               getBlockDefault() const;
98    int                               getFinalDefault() const;
99    int                               getTargetNSURI() const;
100    int                               getScopeCount() const;
101    unsigned int                      getNamespaceScopeLevel() const;
102    unsigned short                    getElemAttrDefaultQualified() const;
103    BaseRefVectorEnumerator<SchemaInfo>   getImportingListEnumerator() const;
104    ValueVectorOf<const DOMElement*>* getRecursingAnonTypes() const;
105    ValueVectorOf<const XMLCh*>*      getRecursingTypeNames() const;
106    ValueVectorOf<DOMNode*>*          getNonXSAttList() const;
107    ValidationContext*                getValidationContext() const;
108
109    // -----------------------------------------------------------------------
110    //  Setter methods
111    // -----------------------------------------------------------------------
112    void setProcessed(const bool aValue = true);
113    void setScopeCount(const int aValue);
114    void setBlockDefault(const int aValue);
115    void setFinalDefault(const int aValue);
116    void setElemAttrDefaultQualified(const unsigned short aValue);
117
118    // -----------------------------------------------------------------------
119    //  Access methods
120    // -----------------------------------------------------------------------
121    void addSchemaInfo(SchemaInfo* const toAdd, const ListType aListType);
122    bool containsInfo(const SchemaInfo* const toCheck, const ListType aListType) const;
123    SchemaInfo* getImportInfo(const unsigned int namespaceURI) const;
124    DOMElement* getTopLevelComponent(const unsigned short compCategory,
125                                     const XMLCh* const compName,
126                                     const XMLCh* const name);
127    DOMElement* getTopLevelComponent(const unsigned short compCategory,
128                                     const XMLCh* const compName,
129                                     const XMLCh* const name,
130                                     SchemaInfo** enclosingSchema);
131    void updateImportingInfo(SchemaInfo* const importingInfo);
132    bool circularImportExist(const unsigned int nameSpaceURI);
133    bool isFailedRedefine(const DOMElement* const anElem);
134    void addFailedRedefine(const DOMElement* const anElem);
135    bool isImportingNS(const int namespaceURI);
136    void addImportedNS(const int namespaceURI);
137    void addRecursingType(const DOMElement* const elem, const XMLCh* const name);
138
139private:
140    // -----------------------------------------------------------------------
141    //  Unimplemented constructors and operators
142    // -----------------------------------------------------------------------
143    SchemaInfo(const SchemaInfo&);
144    SchemaInfo& operator=(const SchemaInfo&);
145
146    // -----------------------------------------------------------------------
147    //  Private helper methods
148    // -----------------------------------------------------------------------
149    void clearTopLevelComponents();
150
151    // -----------------------------------------------------------------------
152    //  Private data members
153    // -----------------------------------------------------------------------
154    bool                              fAdoptInclude;
155    bool                              fProcessed;
156    unsigned short                    fElemAttrDefaultQualified;
157    int                               fBlockDefault;
158    int                               fFinalDefault;
159    int                               fTargetNSURI;
160    int                               fScopeCount;
161    unsigned int                      fNamespaceScopeLevel;
162    XMLCh*                            fCurrentSchemaURL;
163    const XMLCh*                      fTargetNSURIString;
164    const DOMElement*                 fSchemaRootElement;
165    RefVectorOf<SchemaInfo>*          fIncludeInfoList;
166    RefVectorOf<SchemaInfo>*          fImportedInfoList;
167    RefVectorOf<SchemaInfo>*          fImportingInfoList;
168    ValueVectorOf<const DOMElement*>* fFailedRedefineList;
169    ValueVectorOf<int>*               fImportedNSList;
170    ValueVectorOf<const DOMElement*>* fRecursingAnonTypes;
171    ValueVectorOf<const XMLCh*>*      fRecursingTypeNames;
172    ValueVectorOf<DOMElement*>*       fTopLevelComponents[C_Count];
173    ValueVectorOf<DOMNode*>*          fNonXSAttList;
174    ValidationContext*                fValidationContext;
175    MemoryManager*                    fMemoryManager;
176};
177
178// ---------------------------------------------------------------------------
179//  SchemaInfo: Getter methods
180// ---------------------------------------------------------------------------
181inline unsigned short SchemaInfo::getElemAttrDefaultQualified() const {
182
183    return fElemAttrDefaultQualified;
184}
185
186inline bool SchemaInfo::getProcessed() const {
187
188    return fProcessed;
189}
190
191inline int SchemaInfo::getBlockDefault() const {
192
193    return fBlockDefault;
194}
195
196inline int SchemaInfo::getFinalDefault() const {
197
198    return fFinalDefault;
199}
200
201inline unsigned int SchemaInfo::getNamespaceScopeLevel() const {
202    return fNamespaceScopeLevel;
203}
204
205inline XMLCh* SchemaInfo::getCurrentSchemaURL() const {
206
207    return fCurrentSchemaURL;
208}
209
210inline const XMLCh* const SchemaInfo::getTargetNSURIString() const {
211
212    return fTargetNSURIString;
213}
214
215inline const DOMElement* SchemaInfo::getRoot() const {
216
217    return fSchemaRootElement;
218}
219
220inline int SchemaInfo::getTargetNSURI() const {
221
222    return fTargetNSURI;
223}
224
225inline int SchemaInfo::getScopeCount() const {
226
227    return fScopeCount;
228}
229
230inline BaseRefVectorEnumerator<SchemaInfo>
231SchemaInfo::getImportingListEnumerator() const {
232
233    return BaseRefVectorEnumerator<SchemaInfo>(fImportingInfoList);
234}
235
236inline ValueVectorOf<const DOMElement*>*
237SchemaInfo::getRecursingAnonTypes() const {
238
239    return fRecursingAnonTypes;
240}
241
242
243inline ValueVectorOf<const XMLCh*>*
244SchemaInfo::getRecursingTypeNames() const {
245
246    return fRecursingTypeNames;
247}
248
249inline ValueVectorOf<DOMNode*>* SchemaInfo::getNonXSAttList() const
250{
251    return fNonXSAttList;
252}
253
254// ---------------------------------------------------------------------------
255//  Setter methods
256// ---------------------------------------------------------------------------
257inline void SchemaInfo::setScopeCount(const int aValue) {
258
259    fScopeCount = aValue;
260}
261
262inline void SchemaInfo::setBlockDefault(const int aValue) {
263
264    fBlockDefault = aValue;
265}
266
267inline void SchemaInfo::setFinalDefault(const int aValue) {
268
269    fFinalDefault = aValue;
270}
271
272inline void SchemaInfo::setElemAttrDefaultQualified(const unsigned short aValue) {
273
274    fElemAttrDefaultQualified = aValue;
275}
276
277inline void SchemaInfo::setProcessed(const bool aValue) {
278
279    fProcessed = aValue;
280
281/*    if (fProcessed && fIncludeInfoList) {
282
283        unsigned int includeListLen = fIncludeInfoList->size());
284        for (unsigned int i = 0; i < includeListLen; i++) {
285            fIncludeInfoList->elementAt(i)->clearTopLevelComponents();
286        }
287    }*/
288}
289
290// ---------------------------------------------------------------------------
291//  SchemaInfo: Access methods
292// ---------------------------------------------------------------------------
293inline void SchemaInfo::addImportedNS(const int namespaceURI) {
294
295    if (!fImportedNSList) {
296        fImportedNSList = new (fMemoryManager) ValueVectorOf<int>(4, fMemoryManager);
297    }
298
299    if (!fImportedNSList->containsElement(namespaceURI))
300        fImportedNSList->addElement(namespaceURI);
301}
302
303inline void SchemaInfo::addSchemaInfo(SchemaInfo* const toAdd,
304                                      const ListType aListType) {
305
306    if (aListType == IMPORT) {
307
308        if (!fImportedInfoList)
309            fImportedInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager);
310
311        if (!fImportedInfoList->containsElement(toAdd)) {
312
313            fImportedInfoList->addElement(toAdd);
314            addImportedNS(toAdd->getTargetNSURI());
315            toAdd->updateImportingInfo(this);
316        }
317    }
318    else {
319
320        if (!fIncludeInfoList) {
321
322            fIncludeInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(8, false, fMemoryManager);
323            fAdoptInclude = true;
324        }
325
326        if (!fIncludeInfoList->containsElement(toAdd)) {
327
328                    fIncludeInfoList->addElement(toAdd);
329            toAdd->fIncludeInfoList = fIncludeInfoList;
330        }
331    }
332}
333
334inline SchemaInfo* SchemaInfo::getImportInfo(const unsigned int namespaceURI) const {
335
336    unsigned int importSize = (fImportedInfoList) ? fImportedInfoList->size() : 0;
337    SchemaInfo* currInfo = 0;
338
339    for (unsigned int i=0; i < importSize; i++) {
340
341        currInfo = fImportedInfoList->elementAt(i);
342
343        if (currInfo->getTargetNSURI() == (int) namespaceURI)
344            break;
345    }
346
347    return currInfo;
348}
349
350inline ValidationContext* SchemaInfo::getValidationContext() const {
351
352    return fValidationContext;
353}
354
355inline bool SchemaInfo::containsInfo(const SchemaInfo* const toCheck,
356                                     const ListType aListType) const {
357
358    if ((aListType == INCLUDE) && fIncludeInfoList) {
359        return fIncludeInfoList->containsElement(toCheck);
360    }
361    else if ((aListType == IMPORT) && fImportedInfoList) {
362        return fImportedInfoList->containsElement(toCheck);
363    }
364
365    return false;
366}
367
368inline bool SchemaInfo::circularImportExist(const unsigned int namespaceURI) {
369
370    unsigned int importSize = fImportingInfoList->size();
371
372    for (unsigned int i=0; i < importSize; i++) {
373        if (fImportingInfoList->elementAt(i)->getTargetNSURI() == (int) namespaceURI) {
374            return true;
375        }
376    }
377
378    return false;
379}
380
381inline bool SchemaInfo::isFailedRedefine(const DOMElement* const anElem) {
382
383    if (fFailedRedefineList)
384        return (fFailedRedefineList->containsElement(anElem));
385
386    return false;
387}
388
389inline void SchemaInfo::addFailedRedefine(const DOMElement* const anElem) {
390
391    if (!fFailedRedefineList) {
392        fFailedRedefineList = new (fMemoryManager) ValueVectorOf<const DOMElement*>(4, fMemoryManager);
393    }
394
395    fFailedRedefineList->addElement(anElem);
396}
397
398inline bool SchemaInfo::isImportingNS(const int namespaceURI) {
399
400    if (!fImportedNSList)
401        return false;
402
403    return (fImportedNSList->containsElement(namespaceURI));
404}
405
406inline void SchemaInfo::addRecursingType(const DOMElement* const elem,
407                                         const XMLCh* const name) {
408
409    if (!fRecursingAnonTypes) {
410        fRecursingAnonTypes = new (fMemoryManager) ValueVectorOf<const DOMElement*>(8, fMemoryManager);
411        fRecursingTypeNames = new (fMemoryManager) ValueVectorOf<const XMLCh*>(8, fMemoryManager);
412    }
413
414    fRecursingAnonTypes->addElement(elem);
415    fRecursingTypeNames->addElement(name);
416}
417
418inline void SchemaInfo::clearTopLevelComponents() {
419
420    for (unsigned int i = 0; i < C_Count; i++) {
421
422        delete fTopLevelComponents[i];
423        fTopLevelComponents[i] = 0;
424    }
425}
426
427XERCES_CPP_NAMESPACE_END
428
429#endif
430
431/**
432  * End of file SchemaInfo.hpp
433  */
434
Note: See TracBrowser for help on using the repository browser.