source: icXML/icXML-devel/src/icxercesc/framework/XMLEntityDecl.hpp @ 3157

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

Additional files for icXML 0.9

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