source: NonGTP/Xerces/xercesc/validators/DTD/DTDElementDecl.hpp @ 188

Revision 188, 13.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: DTDElementDecl.hpp,v $
59 * Revision 1.9  2004/01/29 11:52:30  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.8  2003/12/12 18:35:44  peiyongz
63 * getObjectType()
64 *
65 * Revision 1.7  2003/10/10 16:24:51  peiyongz
66 * Implementation of Serialization/Deserialization
67 *
68 * Revision 1.6  2003/10/08 21:33:18  peiyongz
69 * Synchronize ContentSpec/ContentModel/FormattedModel
70 *
71 * Revision 1.5  2003/05/16 21:43:19  knoaman
72 * Memory manager implementation: Modify constructors to pass in the memory manager.
73 *
74 * Revision 1.4  2003/05/15 18:54:50  knoaman
75 * Partial implementation of the configurable memory manager.
76 *
77 * Revision 1.3  2003/01/29 19:46:40  gareth
78 * added DOMTypeInfo API
79 *
80 * Revision 1.2  2002/11/04 14:50:40  tng
81 * C++ Namespace Support.
82 *
83 * Revision 1.1.1.1  2002/02/01 22:22:43  peiyongz
84 * sane_include
85 *
86 * Revision 1.12  2001/09/05 20:49:10  knoaman
87 * Fix for complexTypes with mixed content model.
88 *
89 * Revision 1.11  2001/08/21 16:06:11  tng
90 * Schema: Unique Particle Attribution Constraint Checking.
91 *
92 * Revision 1.10  2001/05/11 13:27:08  tng
93 * Copyright update.
94 *
95 * Revision 1.9  2001/04/19 18:17:20  tng
96 * Schema: SchemaValidator update, and use QName in Content Model
97 *
98 * Revision 1.8  2001/03/21 21:56:19  tng
99 * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
100 *
101 * Revision 1.7  2001/03/21 19:29:43  tng
102 * Schema: Content Model Updates, by Pei Yong Zhang.
103 *
104 * Revision 1.6  2001/02/26 19:29:21  tng
105 * Schema: add virtual method getURI(), getContentSpec and setContenSpec in XMLElementDecl, and DTDElementDecl.
106 *
107 * Revision 1.5  2001/02/26 19:22:02  tng
108 * Schema: add parameter prefix in findElem and findAttr.
109 *
110 * Revision 1.4  2000/02/24 20:16:49  abagchi
111 * Swat for removing Log from API docs
112 *
113 * Revision 1.3  2000/02/09 21:42:37  abagchi
114 * Copyright swat
115 *
116 * Revision 1.2  1999/11/23 01:51:04  rahulj
117 * Cannot use class qualifier in class defn. CC under HPUX is happy.
118 *
119 * Revision 1.1.1.1  1999/11/09 01:03:32  twl
120 * Initial checkin
121 *
122 * Revision 1.3  1999/11/08 20:45:40  rahul
123 * Swat for adding in Product name and CVS comment log variable.
124 *
125 */
126
127
128#if !defined(DTDELEMENTDECL_HPP)
129#define DTDELEMENTDECL_HPP
130
131#include <xercesc/util/RefHashTableOf.hpp>
132#include <xercesc/util/QName.hpp>
133#include <xercesc/framework/XMLElementDecl.hpp>
134#include <xercesc/framework/XMLContentModel.hpp>
135#include <xercesc/validators/DTD/DTDAttDef.hpp>
136
137XERCES_CPP_NAMESPACE_BEGIN
138
139class ContentSpecNode;
140class DTDAttDefList;
141
142
143//
144//  This class is a derivative of the basic element decl. This one implements
145//  the virtuals so that they work for a DTD. THe big difference is that
146//  they don't live in any URL in the DTD. The names are just stored as full
147//  QNames, so they are not split out and element decls don't live within
148//  URL namespaces or anything like that.
149//
150
151class VALIDATORS_EXPORT DTDElementDecl : public XMLElementDecl
152{
153public :
154    // -----------------------------------------------------------------------
155    //  Class specific types
156    //
157    //  ModelTypes
158    //      Indicates the type of content model that an element has. This
159    //      indicates how the content model is represented and validated.
160    // -----------------------------------------------------------------------
161    enum ModelTypes
162    {
163        Empty
164        , Any
165        , Mixed_Simple
166        , Children
167
168        , ModelTypes_Count
169    };
170
171
172    // -----------------------------------------------------------------------
173    //  Constructors and Destructor
174    // -----------------------------------------------------------------------
175    DTDElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
176    DTDElementDecl
177    (
178          const XMLCh* const   elemRawName
179        , const unsigned int   uriId
180        , const ModelTypes     modelType
181        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
182    );
183    DTDElementDecl
184    (
185          QName* const         elementName
186        , const ModelTypes     modelType = Any
187        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
188    );
189
190    ~DTDElementDecl();
191
192
193    // -----------------------------------------------------------------------
194    //  The virtual element decl interface
195    // -----------------------------------------------------------------------
196    virtual XMLAttDef* findAttr
197    (
198        const   XMLCh* const    qName
199        , const unsigned int    uriId
200        , const XMLCh* const    baseName
201        , const XMLCh* const    prefix
202        , const LookupOpts      options
203        ,       bool&           wasAdded
204    )   const;
205    virtual XMLAttDefList& getAttDefList() const;
206    virtual CharDataOpts getCharDataOpts() const;
207    virtual bool hasAttDefs() const;
208    virtual bool resetDefs();
209    virtual const ContentSpecNode* getContentSpec() const;
210    virtual ContentSpecNode* getContentSpec();
211    virtual void setContentSpec(ContentSpecNode* toAdopt);
212    virtual XMLContentModel* getContentModel();
213    virtual void setContentModel(XMLContentModel* const newModelToAdopt);
214    virtual const XMLCh* getFormattedContentModel ()   const;
215
216    // -----------------------------------------------------------------------
217    // Support keyed collections
218    //
219    // This method allows objects of this type be placed into one of the
220    // standard keyed collections. This method will return the full name of
221    // the element, which will vary depending upon the type of the grammar.
222    // -----------------------------------------------------------------------
223    const XMLCh* getKey() const;
224
225    // -----------------------------------------------------------------------
226    //  Getter methods
227    // -----------------------------------------------------------------------
228    const DTDAttDef* getAttDef(const XMLCh* const attName) const;
229    DTDAttDef* getAttDef(const XMLCh* const attName);
230    ModelTypes getModelType() const;
231
232    const XMLCh* getDOMTypeInfoName() const;
233
234    const XMLCh* getDOMTypeInfoUri() const;
235
236    // -----------------------------------------------------------------------
237    //  Setter methods
238    // -----------------------------------------------------------------------
239    void addAttDef(DTDAttDef* const toAdd);
240    void setModelType(const DTDElementDecl::ModelTypes toSet);
241
242    /***
243     * Support for Serialization/De-serialization
244     ***/
245    DECL_XSERIALIZABLE(DTDElementDecl)
246
247    virtual XMLElementDecl::objectType  getObjectType() const;
248
249private :
250    // -----------------------------------------------------------------------
251    //  Private helper methods
252    // -----------------------------------------------------------------------
253    void faultInAttDefList() const;
254    XMLContentModel* createChildModel() ;
255    XMLContentModel* makeContentModel() ;
256    XMLCh* formatContentModel () const ;
257
258    // -----------------------------------------------------------------------
259    // Unimplemented constructors and operators
260    // -----------------------------------------------------------------------
261    DTDElementDecl(const DTDElementDecl &);
262    DTDElementDecl& operator = (const  DTDElementDecl&);
263
264    // -----------------------------------------------------------------------
265    //  Private data members
266    //
267    //  fAttDefs
268    //      The list of attributes that are defined for this element. Each
269    //      element is its own little 'namespace' for attributes, so each
270    //      element maintains its own list of owned attribute defs. It is
271    //      faulted in when an attribute is actually added.
272    //
273    //  fAttList
274    //      We have to return a view of our att defs via the abstract view
275    //      that the scanner understands. It may or may not ever be asked
276    //      for so we fault it in as needed.
277    //
278    //  fContentSpec
279    //      This is the content spec for the node. It contains the original
280    //      content spec that was read from the DTD, as a tree of nodes. This
281    //      one is always set up, and is used to build the fContentModel
282    //      version if we are validating.
283    //
284    //  fModelType
285    //      The content model type of this element. This tells us what kind
286    //      of content model to create.
287    //
288    //  fContentModel
289    //      The content model object for this element. It is stored here via
290    //      its abstract interface.
291    //
292    //  fFormattedModel
293    //      This is a faulted in member. When the outside world asks for
294    //      our content model as a string, we format it and fault it into
295    //      this field (to avoid doing the formatted over and over.)
296    // -----------------------------------------------------------------------
297    RefHashTableOf<DTDAttDef>*  fAttDefs;
298    DTDAttDefList*              fAttList;
299    ContentSpecNode*            fContentSpec;
300    ModelTypes                  fModelType;
301    XMLContentModel*            fContentModel;
302    XMLCh*                      fFormattedModel;
303};
304
305// ---------------------------------------------------------------------------
306//  DTDElementDecl: XMLElementDecl virtual interface implementation
307// ---------------------------------------------------------------------------
308inline ContentSpecNode* DTDElementDecl::getContentSpec()
309{
310    return fContentSpec;
311}
312
313inline const ContentSpecNode* DTDElementDecl::getContentSpec() const
314{
315    return fContentSpec;
316}
317
318inline XMLContentModel* DTDElementDecl::getContentModel()
319{
320    if (!fContentModel)
321        fContentModel = makeContentModel();
322    return fContentModel;
323}
324
325inline void
326DTDElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
327{
328    delete fContentModel;
329    fContentModel = newModelToAdopt;
330
331    // reset formattedModel
332    if (fFormattedModel)
333    {
334        getMemoryManager()->deallocate(fFormattedModel);
335        fFormattedModel = 0;
336    }
337}
338
339// ---------------------------------------------------------------------------
340//  DTDElementDecl: Miscellaneous methods
341// ---------------------------------------------------------------------------
342inline const XMLCh* DTDElementDecl::getKey() const
343{
344    return getFullName();
345}
346
347// ---------------------------------------------------------------------------
348//  DTDElementDecl: Getter methods
349// ---------------------------------------------------------------------------
350inline DTDElementDecl::ModelTypes DTDElementDecl::getModelType() const
351{
352    return fModelType;
353}
354
355inline const XMLCh* DTDElementDecl::getDOMTypeInfoName() const {
356    return 0;
357}
358
359inline const XMLCh* DTDElementDecl::getDOMTypeInfoUri() const {
360    return 0;
361}
362
363// ---------------------------------------------------------------------------
364//  DTDElementDecl: Setter methods
365// ---------------------------------------------------------------------------
366inline void
367DTDElementDecl::setModelType(const DTDElementDecl::ModelTypes toSet)
368{
369    fModelType = toSet;
370}
371
372XERCES_CPP_NAMESPACE_END
373
374#endif
Note: See TracBrowser for help on using the repository browser.