source: icXML/icXML-devel/src/xercesc/framework/XMLEntityDecl.hpp @ 2722

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

Original Xerces files with import mods for icxercesc

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