source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/validators/DTD/DTDElementDecl.hpp @ 2674

Revision 2674, 9.5 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: DTDElementDecl.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#if !defined(DTDELEMENTDECL_HPP)
24#define DTDELEMENTDECL_HPP
25
26#include <xercesc/util/RefHashTableOf.hpp>
27#include <xercesc/util/QName.hpp>
28#include <xercesc/framework/XMLElementDecl.hpp>
29#include <xercesc/framework/XMLContentModel.hpp>
30#include <xercesc/validators/DTD/DTDAttDef.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34class ContentSpecNode;
35class DTDAttDefList;
36
37
38//
39//  This class is a derivative of the basic element decl. This one implements
40//  the virtuals so that they work for a DTD. THe big difference is that
41//  they don't live in any URL in the DTD. The names are just stored as full
42//  QNames, so they are not split out and element decls don't live within
43//  URL namespaces or anything like that.
44//
45
46class VALIDATORS_EXPORT DTDElementDecl : public XMLElementDecl
47{
48public :
49    // -----------------------------------------------------------------------
50    //  Class specific types
51    //
52    //  ModelTypes
53    //      Indicates the type of content model that an element has. This
54    //      indicates how the content model is represented and validated.
55    // -----------------------------------------------------------------------
56    enum ModelTypes
57    {
58        Empty
59        , Any
60        , Mixed_Simple
61        , Children
62
63        , ModelTypes_Count
64    };
65
66
67    // -----------------------------------------------------------------------
68    //  Constructors and Destructor
69    // -----------------------------------------------------------------------
70    DTDElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
71    DTDElementDecl
72    (
73          const XMLCh* const   elemRawName
74        , const unsigned int   uriId
75        , const ModelTypes     modelType
76        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
77    );
78    DTDElementDecl
79    (
80          QName* const         elementName
81        , const ModelTypes     modelType = Any
82        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
83    );
84
85    ~DTDElementDecl();
86
87
88    // -----------------------------------------------------------------------
89    //  The virtual element decl interface
90    // -----------------------------------------------------------------------
91    virtual XMLAttDef* findAttr
92    (
93        const   XMLCh* const    qName
94        , const unsigned int    uriId
95        , const XMLCh* const    baseName
96        , const XMLCh* const    prefix
97        , const LookupOpts      options
98        ,       bool&           wasAdded
99    )   const;
100    virtual XMLAttDefList& getAttDefList() const;
101    virtual CharDataOpts getCharDataOpts() const;
102    virtual bool hasAttDefs() const;
103    virtual bool resetDefs();
104    virtual const ContentSpecNode* getContentSpec() const;
105    virtual ContentSpecNode* getContentSpec();
106    virtual void setContentSpec(ContentSpecNode* toAdopt);
107    virtual XMLContentModel* getContentModel();
108    virtual void setContentModel(XMLContentModel* const newModelToAdopt);
109    virtual const XMLCh* getFormattedContentModel ()   const;
110
111    // -----------------------------------------------------------------------
112    // Support keyed collections
113    //
114    // This method allows objects of this type be placed into one of the
115    // standard keyed collections. This method will return the full name of
116    // the element, which will vary depending upon the type of the grammar.
117    // -----------------------------------------------------------------------
118    const XMLCh* getKey() const;
119
120    // -----------------------------------------------------------------------
121    //  Getter methods
122    // -----------------------------------------------------------------------
123    const DTDAttDef* getAttDef(const XMLCh* const attName) const;
124    DTDAttDef* getAttDef(const XMLCh* const attName);
125    ModelTypes getModelType() const;
126
127    /**
128     * @deprecated
129    **/
130    const XMLCh* getDOMTypeInfoName() const;
131
132    /**
133     * @deprecated
134    **/
135    const XMLCh* getDOMTypeInfoUri() const;
136
137    // -----------------------------------------------------------------------
138    //  Setter methods
139    // -----------------------------------------------------------------------
140    void addAttDef(DTDAttDef* const toAdd);
141    void setModelType(const DTDElementDecl::ModelTypes toSet);
142
143    /***
144     * Support for Serialization/De-serialization
145     ***/
146    DECL_XSERIALIZABLE(DTDElementDecl)
147
148    virtual XMLElementDecl::objectType  getObjectType() const;
149
150private :
151    // -----------------------------------------------------------------------
152    //  Private helper methods
153    // -----------------------------------------------------------------------
154    void faultInAttDefList() const;
155    XMLContentModel* createChildModel() ;
156    XMLContentModel* makeContentModel() ;
157    XMLCh* formatContentModel () const ;
158
159    // -----------------------------------------------------------------------
160    // Unimplemented constructors and operators
161    // -----------------------------------------------------------------------
162    DTDElementDecl(const DTDElementDecl &);
163    DTDElementDecl& operator = (const  DTDElementDecl&);
164
165    // -----------------------------------------------------------------------
166    //  Private data members
167    //
168    //  fAttDefs
169    //      The list of attributes that are defined for this element. Each
170    //      element is its own little 'namespace' for attributes, so each
171    //      element maintains its own list of owned attribute defs. It is
172    //      faulted in when an attribute is actually added.
173    //
174    //  fAttList
175    //      We have to return a view of our att defs via the abstract view
176    //      that the scanner understands. It may or may not ever be asked
177    //      for so we fault it in as needed.
178    //
179    //  fContentSpec
180    //      This is the content spec for the node. It contains the original
181    //      content spec that was read from the DTD, as a tree of nodes. This
182    //      one is always set up, and is used to build the fContentModel
183    //      version if we are validating.
184    //
185    //  fModelType
186    //      The content model type of this element. This tells us what kind
187    //      of content model to create.
188    //
189    //  fContentModel
190    //      The content model object for this element. It is stored here via
191    //      its abstract interface.
192    //
193    //  fFormattedModel
194    //      This is a faulted in member. When the outside world asks for
195    //      our content model as a string, we format it and fault it into
196    //      this field (to avoid doing the formatted over and over.)
197    // -----------------------------------------------------------------------
198    ModelTypes                  fModelType;
199
200    RefHashTableOf<DTDAttDef>*  fAttDefs;
201    DTDAttDefList*              fAttList;
202    ContentSpecNode*            fContentSpec;
203    XMLContentModel*            fContentModel;
204    XMLCh*                      fFormattedModel;
205};
206
207// ---------------------------------------------------------------------------
208//  DTDElementDecl: XMLElementDecl virtual interface implementation
209// ---------------------------------------------------------------------------
210inline ContentSpecNode* DTDElementDecl::getContentSpec()
211{
212    return fContentSpec;
213}
214
215inline const ContentSpecNode* DTDElementDecl::getContentSpec() const
216{
217    return fContentSpec;
218}
219
220inline XMLContentModel* DTDElementDecl::getContentModel()
221{
222    if (!fContentModel)
223        fContentModel = makeContentModel();
224    return fContentModel;
225}
226
227inline void
228DTDElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
229{
230    delete fContentModel;
231    fContentModel = newModelToAdopt;
232
233    // reset formattedModel
234    if (fFormattedModel)
235    {
236        getMemoryManager()->deallocate(fFormattedModel);
237        fFormattedModel = 0;
238    }
239}
240
241// ---------------------------------------------------------------------------
242//  DTDElementDecl: Miscellaneous methods
243// ---------------------------------------------------------------------------
244inline const XMLCh* DTDElementDecl::getKey() const
245{
246    return getFullName();
247}
248
249// ---------------------------------------------------------------------------
250//  DTDElementDecl: Getter methods
251// ---------------------------------------------------------------------------
252inline DTDElementDecl::ModelTypes DTDElementDecl::getModelType() const
253{
254    return fModelType;
255}
256
257inline const XMLCh* DTDElementDecl::getDOMTypeInfoName() const {
258    return 0;
259}
260
261inline const XMLCh* DTDElementDecl::getDOMTypeInfoUri() const {
262    return 0;
263}
264
265// ---------------------------------------------------------------------------
266//  DTDElementDecl: Setter methods
267// ---------------------------------------------------------------------------
268inline void
269DTDElementDecl::setModelType(const DTDElementDecl::ModelTypes toSet)
270{
271    fModelType = toSet;
272}
273
274XERCES_CPP_NAMESPACE_END
275
276#endif
Note: See TracBrowser for help on using the repository browser.