source: NonGTP/Xerces/xercesc/framework/XMLEntityDecl.hpp @ 188

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