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

Revision 358, 22.3 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: XMLAttDef.hpp,v $
19 * Revision 1.14  2004/09/08 13:55:58  peiyongz
20 * Apache License Version 2.0
21 *
22 * Revision 1.13  2004/09/02 19:08:09  cargilld
23 * Fix API Doc warning message
24 *
25 * Revision 1.12  2003/12/17 00:18:33  cargilld
26 * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
27 *
28 * Revision 1.11  2003/11/24 05:19:15  neilg
29 * update method documentation
30 *
31 * Revision 1.10  2003/10/10 16:23:29  peiyongz
32 * Implementation of Serialization/Deserialization
33 *
34 * Revision 1.9  2003/05/16 21:36:55  knoaman
35 * Memory manager implementation: Modify constructors to pass in the memory manager.
36 *
37 * Revision 1.8  2003/05/15 18:26:07  knoaman
38 * Partial implementation of the configurable memory manager.
39 *
40 * Revision 1.7  2003/04/21 20:46:01  knoaman
41 * Use XMLString::release to prepare for configurable memory manager.
42 *
43 * Revision 1.6  2003/03/07 18:08:10  tng
44 * Return a reference instead of void for operator=
45 *
46 * Revision 1.5  2003/01/29 19:45:35  gareth
47 * added api for DOMTypeInfo
48 *
49 * Revision 1.4  2002/12/10 02:15:55  knoaman
50 * Schema Errata: E1-21.
51 *
52 * Revision 1.3  2002/11/04 15:00:21  tng
53 * C++ Namespace Support.
54 *
55 * Revision 1.2  2002/02/20 18:17:01  tng
56 * [Bug 5977] Warnings on generating apiDocs.
57 *
58 * Revision 1.1.1.1  2002/02/01 22:21:50  peiyongz
59 * sane_include
60 *
61 * Revision 1.13  2001/11/15 16:36:36  knoaman
62 * Re-organize constant values.
63 *
64 * Revision 1.12  2001/08/09 15:23:37  knoaman
65 * add support for <anyAttribute> declaration.
66 *
67 * Revision 1.11  2001/06/21 14:25:26  knoaman
68 * Fix for bug 1946
69 *
70 * Revision 1.10  2001/05/11 13:25:31  tng
71 * Copyright update.
72 *
73 * Revision 1.9  2001/02/27 18:48:20  tng
74 * Schema: Add SchemaAttDef, SchemaElementDecl, SchemaAttDefList.
75 *
76 * Revision 1.8  2000/12/14 18:49:56  tng
77 * Fix API document generation warning: "Warning: end of member group without matching begin"
78 *
79 * Revision 1.7  2000/11/30 18:22:38  andyh
80 * reuseValidator - fix bugs (spurious errors) that occured on reuse due to
81 * pools already containing some items.  Fixed by Tinny Ng.
82 *
83 * Revision 1.6  2000/07/07 22:23:38  jpolast
84 * remove useless getKey() functions.
85 *
86 * Revision 1.5  2000/02/24 20:00:22  abagchi
87 * Swat for removing Log from API docs
88 *
89 * Revision 1.4  2000/02/16 23:03:48  roddey
90 * More documentation updates
91 *
92 * Revision 1.3  2000/02/15 01:21:30  roddey
93 * Some initial documentation improvements. More to come...
94 *
95 * Revision 1.2  2000/02/06 07:47:46  rahulj
96 * Year 2K copyright swat.
97 *
98 * Revision 1.1.1.1  1999/11/09 01:08:27  twl
99 * Initial checkin
100 *
101 * Revision 1.2  1999/11/08 20:44:34  rahul
102 * Swat for adding in Product name and CVS comment log variable.
103 *
104 */
105
106#if !defined(ATTDEF_HPP)
107#define ATTDEF_HPP
108
109#include <xercesc/util/PlatformUtils.hpp>
110#include <xercesc/util/XMLString.hpp>
111#include <xercesc/util/XMemory.hpp>
112#include <xercesc/internal/XSerializable.hpp>
113
114XERCES_CPP_NAMESPACE_BEGIN
115
116class XMLAttr;
117
118/** Represents the core information of an atribute definition
119 *
120 *  This class defines the basic characteristics of an attribute, no matter
121 *  what type of validator is used. If a particular schema associates more
122 *  information with an attribute it will create a derivative of this class.
123 *  So this class provides an abstract way to get basic information on
124 *  attributes from any type of validator.
125 *
126 *  This class supports keyed collection semantics on the fully qualified
127 *  attribute name, by providing a getKey() method to extract the key string.
128 *  getKey(), in this case, just calls the virtual method getFullName() to
129 *  get the fully qualified name, as defined by the derived class.
130 *
131 *  Note that the 'value' of an attribute type definition is the default or
132 *  of fixed value given to it in its definition. If the attribute is of the
133 *  enumerated or notation type, it will have an 'enumeration value' as well
134 *  which is a space separated list of its possible vlaues.
135 */
136class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
137{
138public:
139    // -----------------------------------------------------------------------
140    //  Class specific types
141    //
142    //  AttTypes
143    //      The list of possible types that an attribute can have, according
144    //      to the XML 1.0 spec and schema.
145    //
146    //  DefAttTypes
147    //      The modifiers that an attribute decl can have, which indicates
148    //      whether instances of that attributes are required, implied, etc..
149    //
150    //  CreateReasons
151    //      This type is used to store how an attribute declaration got into
152    //      the elementdecl's attribute pool.
153    //
154    // -----------------------------------------------------------------------
155        enum AttTypes
156    {
157        CData               = 0
158        , ID                = 1
159        , IDRef             = 2
160        , IDRefs            = 3
161        , Entity            = 4
162        , Entities          = 5
163        , NmToken           = 6
164        , NmTokens          = 7
165        , Notation          = 8
166        , Enumeration       = 9
167        , Simple            = 10
168        , Any_Any           = 11
169        , Any_Other         = 12
170        , Any_List          = 13
171
172        , AttTypes_Count
173        , AttTypes_Min      = 0
174        , AttTypes_Max      = 13
175        , AttTypes_Unknown  = -1
176        };
177
178    enum DefAttTypes
179    {
180        Default                  = 0
181        , Fixed                  = 1
182        , Required               = 2
183        , Required_And_Fixed     = 3
184        , Implied                = 4
185        , ProcessContents_Skip   = 5
186        , ProcessContents_Lax    = 6
187        , ProcessContents_Strict = 7
188        , Prohibited             = 8
189
190        , DefAttTypes_Count
191        , DefAttTypes_Min   = 0
192        , DefAttTypes_Max   = 8
193        , DefAttTypes_Unknown = -1
194        };
195
196    enum CreateReasons
197    {
198        NoReason
199        , JustFaultIn
200    };
201
202    // -----------------------------------------------------------------------
203    //  Public static data members
204    // -----------------------------------------------------------------------
205    static const unsigned int fgInvalidAttrId;
206
207
208    // -----------------------------------------------------------------------
209    //  Public, static methods
210    // -----------------------------------------------------------------------
211
212    /** @name Public, static methods */
213    //@{
214
215    /** Get a string representation of the passed attribute type enum
216      *
217      * This method allows you to get a textual representation of an attriubte
218      * type, mostly for debug or display.
219      *
220      * @param attrType The attribute type value to get the string for.
221      * @param manager The MemoryManager to use to allocate objects
222      * @return A const pointer to the static string that holds the text
223      *         description of the passed type.
224      */
225    static const XMLCh* getAttTypeString(const AttTypes attrType
226        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
227
228    /** Get a string representation of the passed def attribute type enum
229      *
230      * This method allows you to get a textual representation of an default
231      * attributetype, mostly for debug or display.
232      *
233      * @param attrType The default attribute type value to get the string for.
234      * @param manager The MemoryManager to use to allocate objects
235      * @return A const pointer to the static string that holds the text
236      *         description of the passed default type.
237      */
238    static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
239        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
240
241    //@}
242
243
244    // -----------------------------------------------------------------------
245    //  Destructor
246    // -----------------------------------------------------------------------
247
248    /** @name Destructor */
249    //@{
250
251    /**
252      *  Destructor
253      */
254    virtual ~XMLAttDef();
255    //@}
256
257
258    // -----------------------------------------------------------------------
259    //  The virtual attribute def interface
260    // -----------------------------------------------------------------------
261
262    /** @name Virtual interface */
263    //@{
264
265    /** Get the full name of this attribute type
266      *
267      * The derived class should return a const pointer to the full name of
268      * this attribute. This will vary depending on the type of validator in
269      * use.
270      *
271      * @return A const pointer to the full name of this attribute type.
272      */
273    virtual const XMLCh* getFullName() const = 0;
274
275    /**
276     * The derived class should implement any cleaning up required between
277     * each use of an instance of this class for validation
278     */
279    virtual void reset() = 0;
280
281    //@}
282
283
284    // -----------------------------------------------------------------------
285    //  Getter methods
286    // -----------------------------------------------------------------------
287
288    /** @name Getter methods */
289    //@{
290
291    /** Get the default type of this attribute type
292      *
293      * This method returns the 'default type' of the attribute. Default
294      * type in this case refers to the XML concept of a default type for
295      * an attribute, i.e. #FIXED, #IMPLIED, etc...
296      *
297      * @return The default type enum for this attribute type.
298      */
299    DefAttTypes getDefaultType() const;
300
301    /** Get the enumeration value (if any) of this attribute type
302      *
303      * If the attribute is of an enumeration or notatin type, then this
304      * method will return a const reference to a string that contains the
305      * space separated values that can the attribute can have.
306      *
307      * @return A const pointer to a string that contains the space separated
308      *         legal values for this attribute.
309      */
310    const XMLCh* getEnumeration() const;
311
312    /** Get the pool id of this attribute type
313      *
314      * This method will return the id of this attribute in the validator's
315      * attribute pool. It was set by the validator when this attribute was
316      * created.
317      *
318      * @return The pool id of this attribute type.
319      */
320    unsigned int getId() const;
321
322    /** Query whether the attribute was explicitly provided.
323      *
324      * When the scanner scans a start tag, it will ask the element decl
325      * object of the element type of that start tag to clear the 'provided'
326      * flag on all its attributes. As the scanner sees explicitly provided
327      * attributes, its turns on this flag to indicate that this attribute
328      * has been provided. In this way, the scanner can catch duplicated
329      * attributes and required attributes that aren't provided, and default
330      * in fixed/default valued attributes that are not explicitly provided.
331      *
332      * @return Returns a boolean value that indicates whether this attribute
333      *         was explicitly provided.
334      * @deprecated
335      */
336    bool getProvided() const;
337
338    /** Get the type of this attribute
339      *
340      * Gets the type of this attribute. This type is represented by an enum
341      * that convers the types of attributes allowed by XML, e.g. CDATA, NMTOKEN,
342      * NOTATION, etc...
343      *
344      * @return The attribute type enumeration value for this type of
345      *         attribute.
346      */
347    AttTypes getType() const;
348
349    /** Get the default/fixed value of this attribute (if any.)
350      *
351      * If the attribute defined a default/fixed value, then it is stored
352      * and this method will retrieve it. If it has non, then a null pointer
353      * is returned.
354      *
355      * @return A const pointer to the default/fixed value for this attribute
356      *         type.
357      */
358    const XMLCh* getValue() const;
359
360    /** Get the create reason for this attribute
361      *
362      * This method returns an enumeration which indicates why this attribute
363      * declaration exists.
364      *
365      * @return An enumerated value that indicates the reason why this attribute
366      * was added to the attribute table.
367      */
368    CreateReasons getCreateReason() const;
369
370    /** Indicate whether this attribute has been declared externally
371      *
372      * This method returns a boolean that indicates whether this attribute
373      * has been declared externally.
374      *
375      * @return true if this attribute has been declared externally, else false.
376      */
377    bool isExternal() const;
378
379    /** Get the plugged-in memory manager
380      *
381      * This method returns the plugged-in memory manager user for dynamic
382      * memory allocation/deallocation.
383      *
384      * @return the plugged-in memory manager
385      */
386    MemoryManager* getMemoryManager() const;
387
388
389    /**
390     * @return the uri part of DOM Level 3 TypeInfo
391     * @deprecated
392     */
393    virtual const XMLCh* getDOMTypeInfoUri() const = 0;
394
395    /**
396     * @return the name part of DOM Level 3 TypeInfo
397     * @deprecated
398     */
399    virtual const XMLCh* getDOMTypeInfoName() const = 0;
400
401    //@}
402
403
404    // -----------------------------------------------------------------------
405    //  Setter methods
406    // -----------------------------------------------------------------------
407
408    /** @name Setter methods */
409    //@{
410
411    /** Set the default attribute type
412      *
413      * This method sets the default attribute type for this attribute.
414      * This setting controls whether the attribute is required, fixed,
415      * implied, etc...
416      *
417      * @param  newValue The new default attribute to set
418      */
419    void setDefaultType(const XMLAttDef::DefAttTypes newValue);
420
421    /** Set the pool id for this attribute type.
422      *
423      * This method sets the pool id of this attribute type. This is usually
424      * called by the validator that creates the actual instance (which is of
425      * a derived type known only by the validator.)
426      *
427      * @param  newId The new pool id to set.
428      */
429    void setId(const unsigned int newId);
430
431    /** Set or clear the 'provided' flag.
432      *
433      * This method will set or clear the 'provided' flag. This is called
434      * by the scanner as it is scanning a start tag and marking off the
435      * attributes that have been explicitly provided.
436      *
437      * @param  newValue The new provided state to set
438      * @deprecated
439      */
440    void setProvided(const bool newValue);
441
442    /** Set the type of this attribute type.
443      *
444      * This method will set the type of the attribute. The type of an attribute
445      * controls how it is normalized and what kinds of characters it can hold.
446      *
447      * @param  newValue The new attribute type to set
448      */
449    void setType(const XMLAttDef::AttTypes newValue);
450
451    /** Set the default/fixed value of this attribute type.
452      *
453      * This method set the fixed/default value for the attribute. This value
454      * will be used when instances of this attribute type are faulted in. It
455      * <b>must</b> be a valid value for the type set by setType(). If the
456      * type is enumeration or notation, this must be one of the valid values
457      * set in the setEnumeration() call.
458      *
459      * @param  newValue The new fixed/default value to set.
460      */
461    void setValue(const XMLCh* const newValue);
462
463    /** Set the enumerated value of this attribute type.
464      *
465      * This method sets the enumerated/notation value list for this attribute
466      * type. It is a space separated set of possible values. These values must
467      * meet the constrains of the XML spec for such values of this type of
468      * attribute. This should only be set if the setType() method is used to
469      * set the type to the enumeration or notation types.
470      *
471      * @param  newValue The new enumerated/notation value list to set.
472      */
473    void setEnumeration(const XMLCh* const newValue);
474
475    /** Update the create reason for this attribute type.
476      *
477      * This method will update the 'create reason' field for this attribute
478      * decl object.
479      *
480      * @param  newReason The new create reason.
481      */
482    void setCreateReason(const CreateReasons newReason);
483
484    /**
485      * Set the attribute decl to indicate external declaration
486      *
487      * @param  aValue The new value to indicate external declaration.
488      */
489    void setExternalAttDeclaration(const bool aValue);
490
491    //@}
492
493    /***
494     * Support for Serialization/De-serialization
495     ***/
496    DECL_XSERIALIZABLE(XMLAttDef)
497
498protected :
499    // -----------------------------------------------------------------------
500    //  Hidden constructors
501    // -----------------------------------------------------------------------
502    XMLAttDef
503    (
504        const   AttTypes       type = CData
505        , const DefAttTypes    defType= Implied
506        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
507    );
508    XMLAttDef
509    (
510        const   XMLCh* const        attValue
511        , const AttTypes            type
512        , const DefAttTypes         defType
513        , const XMLCh* const        enumValues = 0
514        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
515    );
516
517
518private :
519    // -----------------------------------------------------------------------
520    //  Unimplemented constructors and operators
521    // -----------------------------------------------------------------------
522    XMLAttDef(const XMLAttDef&);
523    XMLAttDef& operator=(const XMLAttDef&);
524
525
526    // -----------------------------------------------------------------------
527    //  Private helper methods
528    // -----------------------------------------------------------------------
529    void cleanUp();
530
531
532    // -----------------------------------------------------------------------
533    //  Private data members
534    //
535    //  fDefaultType
536    //      Indicates what, if any, default stuff this attribute has.
537    //
538    //  fEnumeration
539    //      If its an enumeration, this is the list of values as space
540    //      separated values.
541    //
542    //  fId
543    //      This is the unique id of this attribute, given to it when its put
544    //      into the validator's attribute decl pool. It defaults to the
545    //      special value XMLAttrDef::fgInvalidAttrId.
546    //
547    //  fProvided
548    //      This field is really for use by the scanner. It is used to track
549    //      which of the attributes of an element were provided. Any marked
550    //      as not provided (after scanning the start tag) and having a
551    //      default type of Required, is in error.
552    //
553    //  fType
554    //      The type of attribute, which is one of the AttTypes values.
555    //
556    //  fValue
557    //      This is the value of the attribute, which is the default value
558    //      given in the attribute declaration.
559    //
560    //  fCreateReason
561    //      This flag tells us how this attribute got created.  Sometimes even
562    //      the attribute was not declared for the element, we want to fault
563    //      fault it into the pool to avoid lots of redundant errors.
564    //
565    //  fExternalAttribute
566    //      This flag indicates whether or not the attribute was declared externally.
567    // -----------------------------------------------------------------------
568    DefAttTypes     fDefaultType;
569    AttTypes        fType;
570    CreateReasons   fCreateReason;
571    bool            fProvided;
572    bool            fExternalAttribute;
573    unsigned int    fId;
574    XMLCh*          fValue;
575    XMLCh*          fEnumeration;
576    MemoryManager*  fMemoryManager;
577};
578
579
580// ---------------------------------------------------------------------------
581//  Getter methods
582// ---------------------------------------------------------------------------
583inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
584{
585    return fDefaultType;
586}
587
588inline const XMLCh* XMLAttDef::getEnumeration() const
589{
590    return fEnumeration;
591}
592
593inline unsigned int XMLAttDef::getId() const
594{
595    return fId;
596}
597
598inline bool XMLAttDef::getProvided() const
599{
600    return fProvided;
601}
602
603inline XMLAttDef::AttTypes XMLAttDef::getType() const
604{
605    return fType;
606}
607
608inline const XMLCh* XMLAttDef::getValue() const
609{
610    return fValue;
611}
612
613inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
614{
615    return fCreateReason;
616}
617
618inline bool XMLAttDef::isExternal() const
619{
620    return fExternalAttribute;
621}
622
623inline MemoryManager* XMLAttDef::getMemoryManager() const
624{
625    return fMemoryManager;
626}
627
628// ---------------------------------------------------------------------------
629//  XMLAttDef: Setter methods
630// ---------------------------------------------------------------------------
631inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
632{
633    fDefaultType = newValue;
634}
635
636inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
637{
638    if (fEnumeration)
639        fMemoryManager->deallocate(fEnumeration);
640
641    fEnumeration = XMLString::replicate(newValue, fMemoryManager);
642}
643
644inline void XMLAttDef::setId(const unsigned int newId)
645{
646    fId = newId;
647}
648
649inline void XMLAttDef::setProvided(const bool newValue)
650{
651    fProvided = newValue;
652}
653
654inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
655{
656    fType = newValue;
657}
658
659inline void XMLAttDef::setValue(const XMLCh* const newValue)
660{
661    if (fValue)
662       fMemoryManager->deallocate(fValue);
663
664    fValue = XMLString::replicate(newValue, fMemoryManager);
665}
666
667inline void
668XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
669{
670    fCreateReason = newReason;
671}
672
673inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
674{
675    fExternalAttribute = aValue;
676}
677
678XERCES_CPP_NAMESPACE_END
679
680#endif
Note: See TracBrowser for help on using the repository browser.