source: NonGTP/Xerces/xerces/include/xercesc/framework/XMLEntityDecl.hpp @ 358

Revision 358, 16.9 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-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: XMLEntityDecl.hpp,v $
19 * Revision 1.10  2004/09/08 13:55:59  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.9  2003/12/01 23:23:25  neilg
23 * fix for bug 25118; thanks to Jeroen Witmond
24 *
25 * Revision 1.8  2003/10/10 16:23:29  peiyongz
26 * Implementation of Serialization/Deserialization
27 *
28 * Revision 1.7  2003/05/16 21:36:55  knoaman
29 * Memory manager implementation: Modify constructors to pass in the memory manager.
30 *
31 * Revision 1.6  2003/05/15 18:26:07  knoaman
32 * Partial implementation of the configurable memory manager.
33 *
34 * Revision 1.5  2003/04/21 20:46:01  knoaman
35 * Use XMLString::release to prepare for configurable memory manager.
36 *
37 * Revision 1.4  2003/03/07 18:08:10  tng
38 * Return a reference instead of void for operator=
39 *
40 * Revision 1.3  2002/11/04 15:00:21  tng
41 * C++ Namespace Support.
42 *
43 * Revision 1.2  2002/08/22 19:27:41  tng
44 * [Bug 11448] DomCount has problems with XHTML1.1 DTD.
45 *
46 * Revision 1.1.1.1  2002/02/01 22:21:51  peiyongz
47 * sane_include
48 *
49 * Revision 1.6  2000/02/24 20:00:23  abagchi
50 * Swat for removing Log from API docs
51 *
52 * Revision 1.5  2000/02/16 23:03:48  roddey
53 * More documentation updates
54 *
55 * Revision 1.4  2000/02/16 21:42:58  aruna1
56 * API Doc++ summary changes in
57 *
58 * Revision 1.3  2000/02/15 01:21:30  roddey
59 * Some initial documentation improvements. More to come...
60 *
61 * Revision 1.2  2000/02/06 07:47:48  rahulj
62 * Year 2K copyright swat.
63 *
64 * Revision 1.1.1.1  1999/11/09 01:08:32  twl
65 * Initial checkin
66 *
67 * Revision 1.2  1999/11/08 20:44:38  rahul
68 * Swat for adding in Product name and CVS comment log variable.
69 *
70 */
71
72#if !defined(XMLENTITYDECL_HPP)
73#define XMLENTITYDECL_HPP
74
75#include <xercesc/util/XMemory.hpp>
76#include <xercesc/util/PlatformUtils.hpp>
77#include <xercesc/util/XMLString.hpp>
78#include <xercesc/internal/XSerializable.hpp>
79
80XERCES_CPP_NAMESPACE_BEGIN
81
82/**
83 *  This class defines that core information that defines an XML entity, no
84 *  matter what validator is used. Each validator will create a derivative
85 *  of this class which adds any extra information it requires.
86 *
87 *  This class supports keyed collection semantics via the getKey() method
88 *  which extracts the key field, the entity name in this case. The name will
89 *  have whatever form is deemed appropriate for the type of validator in
90 *  use.
91 *
92 *  When setting the fields of this class, you must make sure that you do
93 *  not set conflicting values. For instance, an internal entity cannot have
94 *  a notation name. And an external entity cannot have a value string.
95 *  These rules are defined by the XML specification. In most cases, these
96 *  objects are created by validator objects as they parse a DTD or Schema
97 *  or whatever, at which time they confirm the correctness of the data before
98 *  creating the entity decl object.
99 */
100class XMLPARSER_EXPORT XMLEntityDecl : public XSerializable, public XMemory
101{
102public:
103    // -----------------------------------------------------------------------
104    //  Constructors and Destructor
105    // -----------------------------------------------------------------------
106
107    /** @name Constructors */
108    //@{
109
110    /**
111      *  Deafult Constructor
112      */
113    XMLEntityDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
114
115    /** Constructor with a const entity name
116      *
117      * @param  entName The new name to give to this entity.
118      * @param  manager Pointer to the memory manager to be used to
119      *                 allocate objects.
120      */
121    XMLEntityDecl
122    (
123        const   XMLCh* const    entName
124        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
125    );
126
127    /**
128      * Constructor with a const entity name and value
129      *
130      * @param  entName The new name to give to this entity.
131      * @param  value   The new value to give to this entity name.
132      * @param  manager Pointer to the memory manager to be used to
133      *                 allocate objects.
134      */
135    XMLEntityDecl
136    (
137        const   XMLCh* const    entName
138        , const XMLCh* const    value
139        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
140    );
141
142    /**
143      * Constructor with a const entity name and single XMLCh value
144      *
145      * @param  entName The new name to give to this entity.
146      * @param  value   The new value to give to this entity name.
147      * @param manager  Pointer to the memory manager to be used to
148      *                 allocate objects.
149      */
150    XMLEntityDecl
151    (
152        const   XMLCh* const    entName
153        , const XMLCh           value
154        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
155    );
156    //@}
157
158    /** @name Destructor */
159    //@{
160
161    /**
162      *  Default destructor
163      */
164    virtual ~XMLEntityDecl();
165
166    //@}
167
168
169    // -----------------------------------------------------------------------
170    //  Virtual entity decl interface
171    // -----------------------------------------------------------------------
172
173    /** @name The pure virtual methods in this interface. */
174    //@{
175
176    /** Get the 'declared in internal subset' flag
177      *
178      * Gets the state of the flag which indicates whether the entity was
179      * declared in the internal or external subset. Some structural
180      * description languages might not have an internal subset concept, in
181      * which case this will always return false.
182      */
183    virtual bool getDeclaredInIntSubset() const = 0;
184
185    /** Get the 'is parameter entity' flag
186      *
187      * Gets the state of the flag which indicates whether this entity is
188      * a parameter entity. If not, then its a general entity.
189      */
190    virtual bool getIsParameter() const = 0;
191
192    /** Get the 'is special char entity' flag
193      *
194      * Gets the state of the flag that indicates whether this entity is
195      * one of the special, intrinsically supported character entities.
196      */
197    virtual bool getIsSpecialChar() const = 0;
198
199    //@}
200
201
202    // -----------------------------------------------------------------------
203    //  Getter methods
204    // -----------------------------------------------------------------------
205
206    /** @name Getter methods */
207    //@{
208
209    /**
210      * Gets the pool id of this entity. Validators maintain all decls in
211      * pools, from which they can be quickly extracted via id.
212      */
213    unsigned int getId() const;
214
215    /**
216      * Returns a const pointer to the name of this entity decl. This name
217      * will be in whatever format is appropriate for the type of validator
218      * in use.
219      */
220    const XMLCh* getName() const;
221
222    /**
223      * Gets the notation name, if any, declared for this entity. If this
224      * entity is not a notation type entity, it will be a null pointer.
225      */
226    const XMLCh* getNotationName() const;
227
228    /**
229      * Gets the public id declared for this entity. Public ids are optional
230      * so it can be a null pointer.
231      */
232    const XMLCh* getPublicId() const;
233
234    /**
235      * Gets the system id declared for this entity. The system id is required
236      * so this method should never return a null pointers.
237      */
238    const XMLCh* getSystemId() const;
239
240    /**
241      * Gets the base URI for this entity.
242      */
243    const XMLCh* getBaseURI() const;
244
245    /**
246      * This method returns the value of an internal entity. If this is not
247      * an internal entity (i.e. its external), then this will be a null
248      * pointer.
249      */
250    const XMLCh* getValue() const;
251
252    /**
253     *  This method returns the number of characters in the value returned
254     *  by getValue(). If this entity is external, this will be zero since
255     *  an external entity has no internal value.
256     */
257    unsigned int getValueLen() const;
258
259    /**
260      * Indicates that this entity is an external entity. If not, then it is
261      * assumed to be an internal entity, suprise.
262      */
263    bool isExternal() const;
264
265    /**
266      * Indicates whether this entity is unparsed. This is meaningless for
267      * internal entities. Some external entities are unparsed in that they
268      * refer to something other than XML source.
269      */
270    bool isUnparsed() const;
271
272    /** Get the plugged-in memory manager
273      *
274      * This method returns the plugged-in memory manager user for dynamic
275      * memory allocation/deallocation.
276      *
277      * @return the plugged-in memory manager
278      */
279    MemoryManager* getMemoryManager() const;
280
281    //@}
282
283
284    // -----------------------------------------------------------------------
285    //  Setter methods
286    // -----------------------------------------------------------------------
287
288    /** @name Setter methods */
289    //@{
290
291    /**
292     *  This method will set the entity name. The format of this name is
293     *  defined by the particular validator in use, since it will be the
294     *  one who creates entity definitions as it parses the DTD, Schema,
295     *  ect...
296     *
297     *  @param  entName   The new name to give to this entity.
298     */
299    void setName
300    (
301        const   XMLCh* const    entName
302    );
303
304    /**
305     *  This method will set the notation name for this entity. By setting
306     *  this, you are indicating that this is an unparsed external entity.
307     *
308     *  @param  newName   The new notation name to give to this entity.
309     */
310    void setNotationName(const XMLCh* const newName);
311
312    /**
313     *  This method will set a new public id on this entity. The public id
314     *  has no particular form and is purely for client consumption.
315     *
316     *  @param  newId     The new public id to give to this entity.
317     */
318    void setPublicId(const XMLCh* const newId);
319
320    /**
321     *  This method will set a new sysetm id on this entity. This will
322     *  then control where the source for this entity lives. If it is
323     *  an internal entity, then the system id is only for bookkeeping
324     *  purposes, and to allow any external entities referenced from
325     *  within the entity to be correctly resolved.
326     *
327     *  @param  newId     The new system id to give to the entity.
328     */
329    void setSystemId(const XMLCh* const newId);
330
331    /**
332     *  This method will set a new baseURI on this entity. This will
333     *  then control the URI used to resolve the relative system Id.
334     *
335     *  @param  newId     The new base URI to give to the entity.
336     */
337    void setBaseURI(const XMLCh* const newId);
338
339    /**
340     *  This method will set a new value for this entity. This is only
341     *  valid if the entity is to be an internal entity. By setting this
342     *  field, you are indicating that the entity is internal.
343     *
344     *  @param  newValue  The new value to give to this entity.
345     */
346    void setValue(const XMLCh* const newValue);
347
348    //@}
349
350    /* For internal use only */
351    void setId(const unsigned int newId);
352
353
354    // -----------------------------------------------------------------------
355    //  Support named pool syntax
356    // -----------------------------------------------------------------------
357
358    /** @name Setter methods */
359    //@{
360
361    /**
362      * This method allows objects of this class to be used within a standard
363      * keyed collection used commonly within the parser system. The collection
364      * calls this method to get the key (usually to hash it) by which the
365      * object is to be stored.
366      */
367    const XMLCh* getKey() const;
368
369    //@}
370
371    /***
372     * Support for Serialization/De-serialization
373     ***/
374    DECL_XSERIALIZABLE(XMLEntityDecl)
375
376private :
377    // -----------------------------------------------------------------------
378    //  Unimplemented constructors and operators
379    // -----------------------------------------------------------------------
380    XMLEntityDecl(const XMLEntityDecl&);
381    XMLEntityDecl& operator=(XMLEntityDecl&);
382
383
384    // -----------------------------------------------------------------------
385    //  XMLEntityDecl: Private helper methods
386    // -----------------------------------------------------------------------
387    void cleanUp();
388
389
390    // -----------------------------------------------------------------------
391    //  Private data members
392    //
393    //  fId
394    //      This is the unique id given to this entity decl.
395    //
396    //  fName
397    //      The name of the enitity. Entity names are never namespace based.
398    //
399    //  fNotationName
400    //      The optional notation of the entity. If there was none, then its
401    //      empty.
402    //
403    //  fPublicId
404    //      The public id of the entity, which can be empty.
405    //
406    //  fSystemId
407    //      The system id of the entity.
408    //
409    //  fValue
410    //  fValueLen
411    //      The entity's value and length, which is only valid if its an
412    //      internal style entity.
413    //
414    //  fBaseURI
415    //      The base URI of the entity.   According to XML InfoSet, such value
416    //      is the URI where it is declared (NOT referenced).
417    // -----------------------------------------------------------------------
418    unsigned int    fId;
419    unsigned int    fValueLen;
420    XMLCh*          fValue;
421    XMLCh*          fName;
422    XMLCh*          fNotationName;
423    XMLCh*          fPublicId;
424    XMLCh*          fSystemId;
425    XMLCh*          fBaseURI;
426    MemoryManager*  fMemoryManager;
427};
428
429
430// ---------------------------------------------------------------------------
431//  XMLEntityDecl: Getter methods
432// ---------------------------------------------------------------------------
433inline unsigned int XMLEntityDecl::getId() const
434{
435    return fId;
436}
437
438inline const XMLCh* XMLEntityDecl::getName() const
439{
440    return fName;
441}
442
443inline const XMLCh* XMLEntityDecl::getNotationName() const
444{
445    return fNotationName;
446}
447
448inline const XMLCh* XMLEntityDecl::getPublicId() const
449{
450    return fPublicId;
451}
452
453inline const XMLCh* XMLEntityDecl::getSystemId() const
454{
455    return fSystemId;
456}
457
458inline const XMLCh* XMLEntityDecl::getBaseURI() const
459{
460    return fBaseURI;
461}
462
463inline const XMLCh* XMLEntityDecl::getValue() const
464{
465    return fValue;
466}
467
468inline unsigned int XMLEntityDecl::getValueLen() const
469{
470    return fValueLen;
471}
472
473inline bool XMLEntityDecl::isExternal() const
474{
475    // If it has a system or public id, its external
476    return ((fPublicId != 0) || (fSystemId != 0));
477}
478
479inline bool XMLEntityDecl::isUnparsed() const
480{
481    // If it has a notation, its unparsed
482    return (fNotationName != 0);
483}
484
485inline MemoryManager* XMLEntityDecl::getMemoryManager() const
486{
487    return fMemoryManager;
488}
489
490// ---------------------------------------------------------------------------
491//  XMLEntityDecl: Setter methods
492// ---------------------------------------------------------------------------
493inline void XMLEntityDecl::setId(const unsigned int newId)
494{
495    fId = newId;
496}
497
498inline void XMLEntityDecl::setNotationName(const XMLCh* const newName)
499{
500    if (fNotationName)
501        fMemoryManager->deallocate(fNotationName);
502
503    fNotationName = XMLString::replicate(newName, fMemoryManager);
504}
505
506inline void XMLEntityDecl::setPublicId(const XMLCh* const newId)
507{
508    if (fPublicId)
509        fMemoryManager->deallocate(fPublicId);
510
511    fPublicId = XMLString::replicate(newId, fMemoryManager);
512}
513
514inline void XMLEntityDecl::setSystemId(const XMLCh* const newId)
515{
516    if (fSystemId)
517        fMemoryManager->deallocate(fSystemId);
518
519    fSystemId = XMLString::replicate(newId, fMemoryManager);
520}
521
522inline void XMLEntityDecl::setBaseURI(const XMLCh* const newId)
523{
524    if (fBaseURI)
525        fMemoryManager->deallocate(fBaseURI);
526
527    fBaseURI = XMLString::replicate(newId, fMemoryManager);
528}
529
530inline void XMLEntityDecl::setValue(const XMLCh* const newValue)
531{
532    if (fValue)
533        fMemoryManager->deallocate(fValue);
534
535    fValue = XMLString::replicate(newValue, fMemoryManager);
536    fValueLen = XMLString::stringLen(newValue);
537}
538
539
540// ---------------------------------------------------------------------------
541//  XMLEntityDecl: Support named pool syntax
542// ---------------------------------------------------------------------------
543inline const XMLCh* XMLEntityDecl::getKey() const
544{
545    return fName;
546}
547
548XERCES_CPP_NAMESPACE_END
549
550#endif
Note: See TracBrowser for help on using the repository browser.