source: icXML/icXML-devel/src/icxercesc/validators/DTD/DTDElementDecl.hpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

File size: 9.7 KB
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 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_DTDELEMENTDECL_HPP)
23#define XERCESC_INCLUDE_GUARD_DTDELEMENTDECL_HPP
24
25#include <xercesc/util/RefHashTableOf.hpp>
26#include <xercesc/util/QName.hpp>
27#include <xercesc/framework/XMLElementDecl.hpp>
28#include <xercesc/framework/XMLContentModel.hpp>
29#include <xercesc/validators/DTD/DTDAttDef.hpp>
30#include <icxmlc/XMLConfig.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
72        DTDElementDecl
73        (
74                  const XMLCh* const   elemRawName
75                , const unsigned int   uriId
76                , const ModelTypes     modelType
77                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
78        );
79
80        DTDElementDecl
81        (
82                  const QName* const   elementName
83                , const ModelTypes     modelType = Any
84                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
85        );
86
87        ~DTDElementDecl();
88
89
90        // -----------------------------------------------------------------------
91        //  The virtual element decl interface
92        // -----------------------------------------------------------------------
93        virtual XMLAttDefList& getAttDefList() const;
94        virtual CharDataOpts getCharDataOpts() const;
95        virtual bool hasAttDefs() const;
96        virtual const ContentSpecNode* getContentSpec() const;
97        virtual ContentSpecNode* getContentSpec();
98        virtual void setContentSpec(ContentSpecNode* toAdopt);
99        virtual XMLContentModel* getContentModel();
100        virtual void setContentModel(XMLContentModel* const newModelToAdopt);
101        virtual const XMLCh* getFormattedContentModel ()   const;
102
103        // -----------------------------------------------------------------------
104        // Support keyed collections
105        //
106        // This method allows objects of this type be placed into one of the
107        // standard keyed collections. This method will return the full name of
108        // the element, which will vary depending upon the type of the grammar.
109        // -----------------------------------------------------------------------
110        const XMLCh* getKey() const;
111
112        // -----------------------------------------------------------------------
113        //  Getter methods
114        // -----------------------------------------------------------------------
115        const DTDAttDef* getAttDef(const XMLCh* const attName) const;
116        DTDAttDef* getAttDef(const XMLCh* const attName);
117        ModelTypes getModelType() const;
118
119        // -----------------------------------------------------------------------
120        //  Setter methods
121        // -----------------------------------------------------------------------
122        void addAttDef(DTDAttDef* const toAdd);
123        void setModelType(const DTDElementDecl::ModelTypes toSet);
124
125        /***
126         * Support for Serialization/De-serialization
127         ***/
128        DECL_XSERIALIZABLE(DTDElementDecl)
129
130        virtual XMLElementDecl::objectType  getObjectType() const;
131
132private :
133        // -----------------------------------------------------------------------
134        //  Private helper methods
135        // -----------------------------------------------------------------------
136        void faultInAttDefList() const;
137        XMLContentModel* createChildModel() ;
138        XMLContentModel* makeContentModel() ;
139        XMLCh* formatContentModel () const ;
140
141        // -----------------------------------------------------------------------
142        // Unimplemented constructors and operators
143        // -----------------------------------------------------------------------
144        DTDElementDecl(const DTDElementDecl &);
145        DTDElementDecl& operator = (const  DTDElementDecl&);
146
147        // -----------------------------------------------------------------------
148        //  Private data members
149        //
150        //  fAttDefs
151        //      The list of attributes that are defined for this element. Each
152        //      element is its own little 'namespace' for attributes, so each
153        //      element maintains its own list of owned attribute defs. It is
154        //      faulted in when an attribute is actually added.
155        //
156        //  fAttList
157        //      We have to return a view of our att defs via the abstract view
158        //      that the scanner understands. It may or may not ever be asked
159        //      for so we fault it in as needed.
160        //
161        //  fContentSpec
162        //      This is the content spec for the node. It contains the original
163        //      content spec that was read from the DTD, as a tree of nodes. This
164        //      one is always set up, and is used to build the fContentModel
165        //      version if we are validating.
166        //
167        //  fModelType
168        //      The content model type of this element. This tells us what kind
169        //      of content model to create.
170        //
171        //  fContentModel
172        //      The content model object for this element. It is stored here via
173        //      its abstract interface.
174        //
175        //  fFormattedModel
176        //      This is a faulted in member. When the outside world asks for
177        //      our content model as a string, we format it and fault it into
178        //      this field (to avoid doing the formatted over and over.)
179        // -----------------------------------------------------------------------
180        ModelTypes                  fModelType;
181
182        RefHashTableOf<DTDAttDef>*  fAttDefs;
183        DTDAttDefList*              fAttList;
184        ContentSpecNode*            fContentSpec;
185        XMLContentModel*            fContentModel;
186        XMLCh*                      fFormattedModel;
187};
188
189// ---------------------------------------------------------------------------
190//  DTDElementDecl: XMLElementDecl virtual interface implementation
191// ---------------------------------------------------------------------------
192inline ContentSpecNode* DTDElementDecl::getContentSpec()
193{
194        return fContentSpec;
195}
196
197inline const ContentSpecNode* DTDElementDecl::getContentSpec() const
198{
199        return fContentSpec;
200}
201
202inline XMLContentModel* DTDElementDecl::getContentModel()
203{
204        if (!fContentModel)
205                fContentModel = makeContentModel();
206        return fContentModel;
207}
208
209inline void
210DTDElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
211{
212        delete fContentModel;
213        fContentModel = newModelToAdopt;
214
215        // reset formattedModel
216        if (fFormattedModel)
217        {
218                getMemoryManager()->deallocate(fFormattedModel);
219                fFormattedModel = 0;
220        }
221}
222
223// ---------------------------------------------------------------------------
224//  DTDElementDecl: Miscellaneous methods
225// ---------------------------------------------------------------------------
226inline const XMLCh* DTDElementDecl::getKey() const
227{
228        return getFullName();
229}
230
231// ---------------------------------------------------------------------------
232//  DTDElementDecl: Getter methods
233// ---------------------------------------------------------------------------
234inline DTDElementDecl::ModelTypes DTDElementDecl::getModelType() const
235{
236        return fModelType;
237}
238
239// ---------------------------------------------------------------------------
240//  DTDElementDecl: Setter methods
241// ---------------------------------------------------------------------------
242inline void
243DTDElementDecl::setModelType(const DTDElementDecl::ModelTypes toSet)
244{
245        fModelType = toSet;
246}
247
248#ifdef PRINT_DEBUG_MESSAGE
249static std::ostream & operator << (std::ostream & out, const DTDElementDecl & elemDecl)
250{
251    out << '('
252        << elemDecl.getFullName()
253        << ',';
254
255    switch (elemDecl.getModelType())
256    {
257        case DTDElementDecl::Empty: out << "Empty"; break;
258        case DTDElementDecl::Any: out << "Any"; break;
259        case DTDElementDecl::Mixed_Simple: out << "Mixed_Simple"; break;
260        case DTDElementDecl::Children: out << "Children"; break;
261    }
262
263    out << ',';
264
265    switch (elemDecl.getCreateReason())
266    {
267        case XMLElementDecl::NoReason: out << "NoReason"; break;
268        case XMLElementDecl::Declared: out << "Declared"; break;
269        case XMLElementDecl::AttList: out << "AttList"; break;
270        case XMLElementDecl::InContentModel: out << "InContentModel"; break;
271        case XMLElementDecl::AsRootElem: out << "AsRootElem"; break;
272        case XMLElementDecl::JustFaultIn: out << "JustFaultIn"; break;
273    }
274
275    out << ',' << elemDecl.getURI()
276        << ',' << elemDecl.getObjectType()
277        << ')';
278    return out;
279}
280
281static std::ostream & operator << (std::ostream & out, const DTDElementDecl * elemDecl)
282{
283    if (likely(elemDecl != 0))
284        {
285        out << *elemDecl;
286        }
287        return out;
288}
289#endif
290
291XERCES_CPP_NAMESPACE_END
292
293#endif
Note: See TracBrowser for help on using the repository browser.