source: NonGTP/Xerces/xercesc/validators/common/MixedContentModel.hpp @ 188

Revision 188, 10.8 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) 1999-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) 1999, 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 * $Log: MixedContentModel.hpp,v $
59 * Revision 1.7  2004/01/29 11:51:21  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.6  2003/05/16 21:43:20  knoaman
63 * Memory manager implementation: Modify constructors to pass in the memory manager.
64 *
65 * Revision 1.5  2003/05/15 18:48:27  knoaman
66 * Partial implementation of the configurable memory manager.
67 *
68 * Revision 1.4  2003/03/07 18:16:57  tng
69 * Return a reference instead of void for operator=
70 *
71 * Revision 1.3  2002/11/04 14:54:58  tng
72 * C++ Namespace Support.
73 *
74 * Revision 1.2  2002/02/25 21:18:53  tng
75 * Schema Fix: Ensure no invalid uri index for UPA checking.
76 *
77 * Revision 1.1.1.1  2002/02/01 22:22:39  peiyongz
78 * sane_include
79 *
80 * Revision 1.12  2001/11/28 16:46:20  tng
81 * Schema fix: Check for invalid URI index first.
82 *
83 * Revision 1.11  2001/11/21 14:30:13  knoaman
84 * Fix for UPA checking.
85 *
86 * Revision 1.10  2001/08/21 16:06:11  tng
87 * Schema: Unique Particle Attribution Constraint Checking.
88 *
89 * Revision 1.9  2001/08/13 15:06:39  knoaman
90 * update <any> validation.
91 *
92 * Revision 1.8  2001/05/11 13:27:19  tng
93 * Copyright update.
94 *
95 * Revision 1.7  2001/05/03 21:02:31  tng
96 * Schema: Add SubstitutionGroupComparator and update exception messages.  By Pei Yong Zhang.
97 *
98 * Revision 1.6  2001/04/19 18:17:33  tng
99 * Schema: SchemaValidator update, and use QName in Content Model
100 *
101 * Revision 1.5  2001/03/21 21:56:28  tng
102 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
103 *
104 * Revision 1.4  2001/03/21 19:29:58  tng
105 * Schema: Content Model Updates, by Pei Yong Zhang.
106 *
107 * Revision 1.3  2001/02/27 18:32:33  tng
108 * Schema: Use XMLElementDecl instead of DTDElementDecl in Content Model.
109 *
110 * Revision 1.2  2001/02/27 14:48:55  tng
111 * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
112 *
113 * Revision 1.1  2001/02/16 14:17:29  tng
114 * Schema: Move the common Content Model files that are shared by DTD
115 * and schema from 'DTD' folder to 'common' folder.  By Pei Yong Zhang.
116 *
117 * Revision 1.3  2000/02/24 20:16:49  abagchi
118 * Swat for removing Log from API docs
119 *
120 * Revision 1.2  2000/02/09 21:42:39  abagchi
121 * Copyright swat
122 *
123 * Revision 1.1.1.1  1999/11/09 01:03:45  twl
124 * Initial checkin
125 *
126 * Revision 1.3  1999/11/08 20:45:43  rahul
127 * Swat for adding in Product name and CVS comment log variable.
128 *
129 */
130
131
132#if !defined(MIXEDCONTENTMODEL_HPP)
133#define MIXEDCONTENTMODEL_HPP
134
135#include <xercesc/util/ValueVectorOf.hpp>
136#include <xercesc/framework/XMLContentModel.hpp>
137#include <xercesc/validators/common/ContentLeafNameTypeVector.hpp>
138
139XERCES_CPP_NAMESPACE_BEGIN
140
141class ContentSpecNode;
142
143//
144//  MixedContentModel is a derivative of the abstract content model base
145//  class that handles the special case of mixed model elements. If an element
146//  is mixed model, it has PCDATA as its first possible content, followed
147//  by an alternation of the possible children. The children cannot have any
148//  numeration or order, so it must look like this:
149//
150//  <!ELEMENT Foo ((#PCDATA|a|b|c|)*)>
151//
152//  So, all we have to do is to keep an array of the possible children and
153//  validate by just looking up each child being validated by looking it up
154//  in the list.
155//
156class MixedContentModel : public XMLContentModel
157{
158public :
159    // -----------------------------------------------------------------------
160    //  Constructors and Destructor
161    // -----------------------------------------------------------------------
162    MixedContentModel
163    (
164        const bool                dtd
165        , ContentSpecNode* const  parentContentSpec
166                , const bool              ordered = false
167        , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
168    );
169
170    ~MixedContentModel();
171
172
173    // -----------------------------------------------------------------------
174    //  Getter methods
175    // -----------------------------------------------------------------------
176    bool hasDups() const;
177
178    // -----------------------------------------------------------------------
179    //  Implementation of the ContentModel virtual interface
180    // -----------------------------------------------------------------------
181    virtual int validateContent
182    (
183        QName** const         children
184      , const unsigned int    childCount
185      , const unsigned int    emptyNamespaceId
186    )   const;
187
188        virtual int validateContentSpecial
189    (
190        QName** const         children
191      , const unsigned int    childCount
192      , const unsigned int    emptyNamespaceId
193      , GrammarResolver*  const pGrammarResolver
194      , XMLStringPool*    const pStringPool
195    ) const;
196
197    virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ;
198
199    virtual unsigned int getNextState(const unsigned int currentState,
200                                      const unsigned int elementIndex) const;
201
202    virtual void checkUniqueParticleAttribution
203    (
204        SchemaGrammar*    const pGrammar
205      , GrammarResolver*  const pGrammarResolver
206      , XMLStringPool*    const pStringPool
207      , XMLValidator*     const pValidator
208      , unsigned int*     const pContentSpecOrgURI
209    ) ;
210
211private :
212    // -----------------------------------------------------------------------
213    //  Private helper methods
214    // -----------------------------------------------------------------------
215    void buildChildList
216    (
217        ContentSpecNode* const                     curNode
218      , ValueVectorOf<QName*>&                     toFill
219      , ValueVectorOf<ContentSpecNode::NodeTypes>& toType
220    );
221
222    // -----------------------------------------------------------------------
223    //  Unimplemented constructors and operators
224    // -----------------------------------------------------------------------
225    MixedContentModel();
226    MixedContentModel(const MixedContentModel&);
227    MixedContentModel& operator=(const MixedContentModel&);
228
229
230    // -----------------------------------------------------------------------
231    //  Private data members
232    //
233    //  fCount
234    //      The count of possible children in the fChildren member.
235    //
236    //  fChildren
237    //      The list of possible children that we have to accept. This array
238    //      is allocated as large as needed in the constructor.
239    //
240    //  fChildTypes
241    //      The type of the children to support ANY.
242    //
243    //  fOrdered
244    //      True if mixed content model is ordered. DTD mixed content models
245    //      are <em>always</em> unordered.
246    //
247    //  fDTD
248    //      Boolean to allow DTDs to validate even with namespace support.
249    //
250    // -----------------------------------------------------------------------
251    unsigned int                fCount;
252    QName**                     fChildren;
253    ContentSpecNode::NodeTypes* fChildTypes;
254    bool                        fOrdered;
255    bool                        fDTD;
256    MemoryManager*              fMemoryManager;
257};
258
259inline ContentLeafNameTypeVector* MixedContentModel::getContentLeafNameTypeVector() const
260{
261        return 0;
262}
263
264inline unsigned int
265MixedContentModel::getNextState(const unsigned int,
266                                const unsigned int) const {
267
268    return XMLContentModel::gInvalidTrans;
269}
270
271inline void MixedContentModel::checkUniqueParticleAttribution
272    (
273        SchemaGrammar*    const
274      , GrammarResolver*  const
275      , XMLStringPool*    const
276      , XMLValidator*     const
277      , unsigned int*     const pContentSpecOrgURI
278    )
279{
280    // rename back
281    unsigned int i = 0;
282    for (i = 0; i < fCount; i++) {
283        unsigned int orgURIIndex = fChildren[i]->getURI();
284        if ((orgURIIndex != XMLContentModel::gEOCFakeId) &&
285            (orgURIIndex != XMLElementDecl::fgInvalidElemId) &&
286            (orgURIIndex != XMLElementDecl::fgPCDataElemId))
287            fChildren[i]->setURI(pContentSpecOrgURI[orgURIIndex]);
288    }
289
290    // for mixed content model, it's only a sequence
291    // UPA checking is not necessary
292}
293
294XERCES_CPP_NAMESPACE_END
295
296#endif
Note: See TracBrowser for help on using the repository browser.