source: NonGTP/Xerces/xerces/include/xercesc/validators/common/ContentSpecNode.hpp @ 358

Revision 358, 17.0 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-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 * $Log: ContentSpecNode.hpp,v $
19 * Revision 1.12  2004/09/08 13:56:51  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.11  2004/01/29 11:51:21  cargilld
23 * Code cleanup changes to get rid of various compiler diagnostic messages.
24 *
25 * Revision 1.10  2003/11/20 17:52:14  knoaman
26 * PSVI: store element declaration (leaf nodes)
27 *
28 * Revision 1.9  2003/11/07 17:08:11  knoaman
29 * For PSVI support, distinguish wildcard elements with namespace lists.
30 *
31 * Revision 1.8  2003/09/26 18:29:27  peiyongz
32 * Implement serialization/deserialization
33 *
34 * Revision 1.7  2003/05/18 14:02:06  knoaman
35 * Memory manager implementation: pass per instance manager.
36 *
37 * Revision 1.6  2003/05/15 18:48:27  knoaman
38 * Partial implementation of the configurable memory manager.
39 *
40 * Revision 1.5  2002/11/04 14:54:58  tng
41 * C++ Namespace Support.
42 *
43 * Revision 1.4  2002/10/30 21:52:00  tng
44 * [Bug 13641] compiler-generated copy-constructor for QName doesn't do the right thing.
45 *
46 * Revision 1.3  2002/04/04 14:42:41  knoaman
47 * Change min/maxOccurs from unsigned int to int.
48 *
49 * Revision 1.2  2002/03/21 15:41:48  knoaman
50 * Move behavior from TraverseSchema.
51 *
52 * Revision 1.1.1.1  2002/02/01 22:22:38  peiyongz
53 * sane_include
54 *
55 * Revision 1.19  2001/12/06 17:50:42  tng
56 * Performance Enhancement. The ContentSpecNode constructor always copied the QName
57 * that was passed to it.  Added a second constructor that allows the QName to be just assigned, not copied.
58 * That was because there are some cases in which a temporary QName was constructed, passed to ContentSpecNode, and then deleted.
59 * There were examples of that in TraverseSchema and DTDScanner.
60 * By Henry Zongaro.
61 *
62 * Revision 1.18  2001/11/07 21:50:28  tng
63 * Fix comment log that lead to error.
64 *
65 * Revision 1.17  2001/11/07 21:12:15  tng
66 * Performance: Create QName in ContentSpecNode only if it is a leaf/Any/PCDataNode.
67 *
68 * Revision 1.16  2001/08/28 20:21:08  peiyongz
69 * * AIX 4.2, xlC 3 rev.1 compilation error: get*() declared with external linkage
70 * and called or defined before being declared as inline
71 *
72 * Revision 1.15  2001/08/24 12:48:48  tng
73 * Schema: AllContentModel
74 *
75 * Revision 1.14  2001/08/23 11:54:26  tng
76 * Add newline at the end and various typo fixes.
77 *
78 * Revision 1.13  2001/08/22 16:04:07  tng
79 * ContentSpecNode copy constructor should copy Min and Max as well.
80 *
81 * Revision 1.12  2001/08/21 18:47:42  peiyongz
82 * AIX 4.2, xlC 3 rev.1 compilation error: dtor() declared with external linkage
83 *                                 and called or defined before being declared as inline
84 *
85 * Revision 1.11  2001/08/21 16:06:11  tng
86 * Schema: Unique Particle Attribution Constraint Checking.
87 *
88 * Revision 1.10  2001/08/20 13:18:58  tng
89 * bug in ContentSpecNode copy constructor.
90 *
91 * Revision 1.9  2001/07/24 18:33:13  knoaman
92 * Added support for <group> + extra constraint checking for complexType
93 *
94 * Revision 1.8  2001/07/09 15:22:36  knoaman
95 * complete <any> declaration.
96 *
97 * Revision 1.7  2001/05/11 13:27:18  tng
98 * Copyright update.
99 *
100 * Revision 1.6  2001/05/10 16:33:08  knoaman
101 * Traverse Schema Part III + error messages.
102 *
103 * Revision 1.5  2001/05/03 20:34:39  tng
104 * Schema: SchemaValidator update
105 *
106 * Revision 1.4  2001/04/19 18:17:29  tng
107 * Schema: SchemaValidator update, and use QName in Content Model
108 *
109 * Revision 1.3  2001/03/21 21:56:26  tng
110 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
111 *
112 * Revision 1.2  2001/02/27 14:48:49  tng
113 * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
114 *
115 * Revision 1.1  2001/02/16 14:17:29  tng
116 * Schema: Move the common Content Model files that are shared by DTD
117 * and schema from 'DTD' folder to 'common' folder.  By Pei Yong Zhang.
118 *
119 * Revision 1.4  2000/03/02 19:55:38  roddey
120 * This checkin includes many changes done while waiting for the
121 * 1.1.0 code to be finished. I can't list them all here, but a list is
122 * available elsewhere.
123 *
124 * Revision 1.3  2000/02/24 20:16:48  abagchi
125 * Swat for removing Log from API docs
126 *
127 * Revision 1.2  2000/02/09 21:42:37  abagchi
128 * Copyright swat
129 *
130 * Revision 1.1.1.1  1999/11/09 01:03:14  twl
131 * Initial checkin
132 *
133 * Revision 1.2  1999/11/08 20:45:38  rahul
134 * Swat for adding in Product name and CVS comment log variable.
135 *
136 */
137
138
139#if !defined(CONTENTSPECNODE_HPP)
140#define CONTENTSPECNODE_HPP
141
142#include <xercesc/framework/XMLElementDecl.hpp>
143#include <xercesc/framework/MemoryManager.hpp>
144
145#include <xercesc/internal/XSerializable.hpp>
146
147XERCES_CPP_NAMESPACE_BEGIN
148
149class XMLBuffer;
150class Grammar;
151
152
153class XMLUTIL_EXPORT ContentSpecNode : public XSerializable, public XMemory
154{
155public :
156    // -----------------------------------------------------------------------
157    //  Class specific types
158    // -----------------------------------------------------------------------
159    enum NodeTypes
160    {
161        Leaf = 0
162        , ZeroOrOne
163        , ZeroOrMore
164        , OneOrMore
165        , Choice
166        , Sequence
167        , Any
168        , Any_Other
169        , Any_NS = 8
170        , All = 9
171        , Any_NS_Choice = 20
172        , ModelGroupSequence = 21
173        , Any_Lax = 22
174        , Any_Other_Lax = 23
175        , Any_NS_Lax = 24
176        , ModelGroupChoice = 36
177        , Any_Skip = 38
178        , Any_Other_Skip = 39
179        , Any_NS_Skip = 40
180
181        , UnknownType = -1
182    };
183
184
185    // -----------------------------------------------------------------------
186    //  Constructors and Destructor
187    // -----------------------------------------------------------------------
188    ContentSpecNode(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
189    ContentSpecNode
190    (
191        QName* const toAdopt
192        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
193    );
194    ContentSpecNode
195    (
196        XMLElementDecl* const elemDecl
197        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
198    );
199    ContentSpecNode
200    (
201        QName* const toAdopt
202        , const bool copyQName
203        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
204    );
205    ContentSpecNode
206    (
207        const   NodeTypes               type
208        ,       ContentSpecNode* const  firstToAdopt
209        ,       ContentSpecNode* const  secondToAdopt
210        , const bool                    adoptFirst = true
211        , const bool                    adoptSecond = true
212        ,       MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
213    );
214    ContentSpecNode(const ContentSpecNode&);
215        ~ContentSpecNode();
216
217    // -----------------------------------------------------------------------
218    //  Getter methods
219    // -----------------------------------------------------------------------
220    QName* getElement();
221    const QName* getElement() const;
222    XMLElementDecl* getElementDecl();
223    const XMLElementDecl* getElementDecl() const;
224    ContentSpecNode* getFirst();
225    const ContentSpecNode* getFirst() const;
226    ContentSpecNode* getSecond();
227    const ContentSpecNode* getSecond() const;
228    NodeTypes getType() const;
229    ContentSpecNode* orphanFirst();
230    ContentSpecNode* orphanSecond();
231    int getMinOccurs() const;
232    int getMaxOccurs() const;
233    bool isFirstAdopted() const;
234    bool isSecondAdopted() const;
235
236
237    // -----------------------------------------------------------------------
238    //  Setter methods
239    // -----------------------------------------------------------------------
240    void setElement(QName* const toAdopt);
241    void setFirst(ContentSpecNode* const toAdopt);
242    void setSecond(ContentSpecNode* const toAdopt);
243    void setType(const NodeTypes type);
244    void setMinOccurs(int min);
245    void setMaxOccurs(int max);
246    void setAdoptFirst(bool adoptFirst);
247    void setAdoptSecond(bool adoptSecond);
248
249
250    // -----------------------------------------------------------------------
251    //  Miscellaneous
252    // -----------------------------------------------------------------------
253    void formatSpec (XMLBuffer&      bufToFill)   const;
254    bool hasAllContent();
255    int  getMinTotalRange() const;
256    int  getMaxTotalRange() const;
257
258    /***
259     * Support for Serialization/De-serialization
260     ***/
261    DECL_XSERIALIZABLE(ContentSpecNode)
262
263private :
264    // -----------------------------------------------------------------------
265    //  Unimplemented constructors and operators
266    // -----------------------------------------------------------------------
267    ContentSpecNode& operator=(const ContentSpecNode&);
268
269
270    // -----------------------------------------------------------------------
271    //  Private Data Members
272    //
273    //  fElement
274    //      If the type is Leaf/Any*, then this is the qName of the element. If the URI
275    //      is fgPCDataElemId, then its a PCData node.  Else, it is zero.
276    //
277    //  fFirst
278    //  fSecond
279    //      The optional first and second nodes. The fType field indicates
280    //      which of these are valid. The validaty constraints are:
281    //
282    //          Leaf = Neither valid
283    //          ZeroOrOne, ZeroOrMore = First
284    //          Choice, Sequence, All = First and Second
285    //          Any* = Neither valid
286    //
287    //  fType
288    //      The type of node. This controls how many of the child node fields
289    //      are used.
290    //
291    //  fAdoptFirst
292    //      Indicate if this ContentSpecNode adopts the fFirst, and is responsible
293    //      for deleting it.
294    //
295    //  fAdoptSecond
296    //      Indicate if this ContentSpecNode adopts the fSecond, and is responsible
297    //      for deleting it.
298    //
299    //  fMinOccurs
300    //      Indicate the minimum times that this node can occur
301    //
302    //  fMaxOccurs
303    //      Indicate the maximum times that this node can occur
304    //      -1 (Unbounded), default (1)
305    // -----------------------------------------------------------------------
306    MemoryManager*      fMemoryManager;
307    QName*              fElement;
308    XMLElementDecl*     fElementDecl;
309    ContentSpecNode*    fFirst;
310    ContentSpecNode*    fSecond;
311    NodeTypes           fType;
312    bool                fAdoptFirst;
313    bool                fAdoptSecond;
314    int                 fMinOccurs;
315    int                 fMaxOccurs;
316};
317
318// ---------------------------------------------------------------------------
319//  ContentSpecNode: Constructors and Destructor
320// ---------------------------------------------------------------------------
321inline ContentSpecNode::ContentSpecNode(MemoryManager* const manager) :
322
323    fMemoryManager(manager)
324    , fElement(0)
325    , fElementDecl(0)
326    , fFirst(0)
327    , fSecond(0)
328    , fType(ContentSpecNode::Leaf)
329    , fAdoptFirst(true)
330    , fAdoptSecond(true)
331    , fMinOccurs(1)
332    , fMaxOccurs(1)
333{
334}
335
336inline
337ContentSpecNode::ContentSpecNode(QName* const element,
338                                 MemoryManager* const manager) :
339
340    fMemoryManager(manager)
341    , fElement(0)
342    , fElementDecl(0)
343    , fFirst(0)
344    , fSecond(0)
345    , fType(ContentSpecNode::Leaf)
346    , fAdoptFirst(true)
347    , fAdoptSecond(true)
348    , fMinOccurs(1)
349    , fMaxOccurs(1)
350{
351    if (element)
352        fElement = new (fMemoryManager) QName(*element);
353}
354
355inline
356ContentSpecNode::ContentSpecNode(XMLElementDecl* const elemDecl,
357                                 MemoryManager* const manager) :
358
359    fMemoryManager(manager)
360    , fElement(0)
361    , fElementDecl(elemDecl)
362    , fFirst(0)
363    , fSecond(0)
364    , fType(ContentSpecNode::Leaf)
365    , fAdoptFirst(true)
366    , fAdoptSecond(true)
367    , fMinOccurs(1)
368    , fMaxOccurs(1)
369{
370    if (elemDecl)
371        fElement = new (manager) QName(*(elemDecl->getElementName()));
372}
373
374inline
375ContentSpecNode::ContentSpecNode( QName* const element
376                                , const bool copyQName
377                                , MemoryManager* const manager) :
378
379    fMemoryManager(manager)
380    , fElement(0)
381    , fElementDecl(0)
382    , fFirst(0)
383    , fSecond(0)
384    , fType(ContentSpecNode::Leaf)
385    , fAdoptFirst(true)
386    , fAdoptSecond(true)
387    , fMinOccurs(1)
388    , fMaxOccurs(1)
389{
390    if (copyQName)
391    {
392        if (element)
393            fElement = new (fMemoryManager) QName(*element);
394    }
395    else
396    {
397        fElement = element;
398    }
399}
400
401inline
402ContentSpecNode::ContentSpecNode(const  NodeTypes              type
403                                ,       ContentSpecNode* const firstAdopt
404                                ,       ContentSpecNode* const secondAdopt
405                                , const bool                   adoptFirst
406                                , const bool                   adoptSecond
407                                ,       MemoryManager* const   manager) :
408
409    fMemoryManager(manager)
410    , fElement(0)
411    , fElementDecl(0)
412    , fFirst(firstAdopt)
413    , fSecond(secondAdopt)
414    , fType(type)
415    , fAdoptFirst(adoptFirst)
416    , fAdoptSecond(adoptSecond)
417    , fMinOccurs(1)
418    , fMaxOccurs(1)
419{
420}
421
422inline ContentSpecNode::~ContentSpecNode()
423{
424    // Delete our children, which cause recursive cleanup
425    if (fAdoptFirst) {
426                delete fFirst;
427    }
428
429    if (fAdoptSecond) {
430                delete fSecond;
431    }
432
433    delete fElement;
434}
435
436// ---------------------------------------------------------------------------
437//  ContentSpecNode: Getter methods
438// ---------------------------------------------------------------------------
439inline QName* ContentSpecNode::getElement()
440{
441    return fElement;
442}
443
444inline const QName* ContentSpecNode::getElement() const
445{
446    return fElement;
447}
448
449inline XMLElementDecl* ContentSpecNode::getElementDecl()
450{
451    return fElementDecl;
452}
453
454inline const XMLElementDecl* ContentSpecNode::getElementDecl() const
455{
456    return fElementDecl;
457}
458
459inline ContentSpecNode* ContentSpecNode::getFirst()
460{
461    return fFirst;
462}
463
464inline const ContentSpecNode* ContentSpecNode::getFirst() const
465{
466    return fFirst;
467}
468
469inline ContentSpecNode* ContentSpecNode::getSecond()
470{
471    return fSecond;
472}
473
474inline const ContentSpecNode* ContentSpecNode::getSecond() const
475{
476    return fSecond;
477}
478
479inline ContentSpecNode::NodeTypes ContentSpecNode::getType() const
480{
481    return fType;
482}
483
484inline ContentSpecNode* ContentSpecNode::orphanFirst()
485{
486    ContentSpecNode* retNode = fFirst;
487    fFirst = 0;
488    return retNode;
489}
490
491inline ContentSpecNode* ContentSpecNode::orphanSecond()
492{
493    ContentSpecNode* retNode = fSecond;
494    fSecond = 0;
495    return retNode;
496}
497
498inline int ContentSpecNode::getMinOccurs() const
499{
500    return fMinOccurs;
501}
502
503inline int ContentSpecNode::getMaxOccurs() const
504{
505    return fMaxOccurs;
506}
507
508inline bool ContentSpecNode::isFirstAdopted() const
509{
510    return fAdoptFirst;
511}
512
513inline bool ContentSpecNode::isSecondAdopted() const
514{
515    return fAdoptSecond;
516}
517
518
519// ---------------------------------------------------------------------------
520//  ContentSpecType: Setter methods
521// ---------------------------------------------------------------------------
522inline void ContentSpecNode::setElement(QName* const element)
523{
524    delete fElement;
525    fElement = 0;
526    if (element)
527        fElement = new (fMemoryManager) QName(*element);
528}
529
530inline void ContentSpecNode::setFirst(ContentSpecNode* const toAdopt)
531{
532    if (fAdoptFirst)
533        delete fFirst;
534    fFirst = toAdopt;
535}
536
537inline void ContentSpecNode::setSecond(ContentSpecNode* const toAdopt)
538{
539    if (fAdoptSecond)
540        delete fSecond;
541    fSecond = toAdopt;
542}
543
544inline void ContentSpecNode::setType(const NodeTypes type)
545{
546    fType = type;
547}
548
549inline void ContentSpecNode::setMinOccurs(int min)
550{
551    fMinOccurs = min;
552}
553
554inline void ContentSpecNode::setMaxOccurs(int max)
555{
556    fMaxOccurs = max;
557}
558
559inline void ContentSpecNode::setAdoptFirst(bool newState)
560{
561    fAdoptFirst = newState;
562}
563
564inline void ContentSpecNode::setAdoptSecond(bool newState)
565{
566    fAdoptSecond = newState;
567}
568
569// ---------------------------------------------------------------------------
570//  ContentSpecNode: Miscellaneous
571// ---------------------------------------------------------------------------
572inline bool ContentSpecNode::hasAllContent() {
573
574    if (fType == ContentSpecNode::ZeroOrOne) {
575        return (fFirst->getType() == ContentSpecNode::All);
576    }
577
578    return (fType == ContentSpecNode::All);
579}
580
581XERCES_CPP_NAMESPACE_END
582
583#endif
Note: See TracBrowser for help on using the repository browser.