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