source: NonGTP/Xerces/xercesc/validators/schema/SchemaInfo.hpp @ 188

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