source: icXML/icXML-devel/src/icxercesc/framework/XMLAttDef.hpp @ 2721

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

Fix imports in icXML modified Xerces files

File size: 17.5 KB
Line 
1/*
2 * Unless required by applicable law or agreed to in writing, software
3 * distributed under the License is distributed on an "AS IS" BASIS,
4 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 * See the License for the specific language governing permissions and
6 * limitations under the License.
7 */
8
9/*
10 * $Id: XMLAttDef.hpp 932887 2010-04-11 13:04:59Z borisk $
11 */
12
13#if !defined(XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP)
14#define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP
15
16#include <icxercesc/util/PlatformUtils.hpp>
17#include <icxercesc/util/XMLString.hpp>
18#include <xercesc/util/XMemory.hpp>
19#include <xercesc/internal/XSerializable.hpp>
20#include <icxmlc/XMLConfig.hpp>
21
22XERCES_CPP_NAMESPACE_BEGIN
23
24class XMLAttr;
25class QName;
26
27/** Represents the core information of an attribute definition
28 *
29 *  This class defines the basic characteristics of an attribute, no matter
30 *  what type of validator is used. If a particular schema associates more
31 *  information with an attribute it will create a derivative of this class.
32 *  So this class provides an abstract way to get basic information on
33 *  attributes from any type of validator.
34 *
35 *  This class supports keyed collection semantics on the fully qualified
36 *  attribute name, by providing a getKey() method to extract the key string.
37 *  getKey(), in this case, just calls the virtual method getFullName() to
38 *  get the fully qualified name, as defined by the derived class.
39 *
40 *  Note that the 'value' of an attribute type definition is the default or
41 *  of fixed value given to it in its definition. If the attribute is of the
42 *  enumerated or notation type, it will have an 'enumeration value' as well
43 *  which is a space separated list of its possible vlaues.
44 */
45class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
46{
47public:
48        // -----------------------------------------------------------------------
49        //  Class specific types
50        //
51        //  AttTypes
52        //      The list of possible types that an attribute can have, according
53        //      to the XML 1.0 spec and schema.
54        //
55        //  DefAttTypes
56        //      The modifiers that an attribute decl can have, which indicates
57        //      whether instances of that attributes are required, implied, etc..
58        //
59        //  CreateReasons
60        //      This type is used to store how an attribute declaration got into
61        //      the elementdecl's attribute pool.
62        //
63        // -----------------------------------------------------------------------
64        enum AttTypes
65        {
66                CData               = 0
67                , ID                = 1
68                , IDRef             = 2
69                , IDRefs            = 3
70                , Entity            = 4
71                , Entities          = 5
72                , NmToken           = 6
73                , NmTokens          = 7
74                , Notation          = 8
75                , Enumeration       = 9
76                , Simple            = 10
77                , Any_Any           = 11
78                , Any_Other         = 12
79                , Any_List          = 13
80
81                , AttTypes_Count
82                , AttTypes_Min      = 0
83                , AttTypes_Max      = 13
84                , AttTypes_Unknown  = -1
85        };
86
87        enum DefAttTypes
88        {
89                Default                  = 0
90                , Fixed                  = 1
91                , Required               = 2
92                , Required_And_Fixed     = 3
93                , Implied                = 4
94                , ProcessContents_Skip   = 5
95                , ProcessContents_Lax    = 6
96                , ProcessContents_Strict = 7
97                , Prohibited             = 8
98
99                , DefAttTypes_Count
100                , DefAttTypes_Min   = 0
101                , DefAttTypes_Max   = 8
102                , DefAttTypes_Unknown = -1
103        };
104
105        enum CreateReasons
106        {
107                NoReason
108                , JustFaultIn
109        };
110
111        // -----------------------------------------------------------------------
112        //  Public static data members
113        // -----------------------------------------------------------------------
114        static const unsigned int fgInvalidAttrId;
115
116
117        // -----------------------------------------------------------------------
118        //  Public, static methods
119        // -----------------------------------------------------------------------
120
121        /** @name Public, static methods */
122        //@{
123
124        /** Get a string representation of the passed attribute type enum
125          *
126          * This method allows you to get a textual representation of an attribute
127          * type, mostly for debug or display.
128          *
129          * @param attrType The attribute type value to get the string for.
130          * @param manager The MemoryManager to use to allocate objects
131          * @return A const pointer to the static string that holds the text
132          *         description of the passed type.
133          */
134        static const XMLCh* getAttTypeString(const AttTypes attrType
135                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
136
137        /** Get a string representation of the passed def attribute type enum
138          *
139          * This method allows you to get a textual representation of an default
140          * attributetype, mostly for debug or display.
141          *
142          * @param attrType The default attribute type value to get the string for.
143          * @param manager The MemoryManager to use to allocate objects
144          * @return A const pointer to the static string that holds the text
145          *         description of the passed default type.
146          */
147        static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
148                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
149
150        //@}
151
152
153        // -----------------------------------------------------------------------
154        //  Destructor
155        // -----------------------------------------------------------------------
156
157        /** @name Destructor */
158        //@{
159
160        /**
161          *  Destructor
162          */
163        virtual ~XMLAttDef();
164        //@}
165
166
167        // -----------------------------------------------------------------------
168        //  The virtual attribute def interface
169        // -----------------------------------------------------------------------
170
171        /** @name Virtual interface */
172        //@{
173
174        /** Get the full name of this attribute type
175          *
176          * The derived class should return a const pointer to the full name of
177          * this attribute. This will vary depending on the type of validator in
178          * use.
179          *
180          * @return A const pointer to the full name of this attribute type.
181          */
182        virtual const XMLCh* getFullName() const = 0;
183
184
185        virtual QName* getAttName() const = 0;
186
187        /**
188         * The derived class should implement any cleaning up required between
189         * each use of an instance of this class for validation
190         */
191        virtual void reset() = 0;
192
193        //@}
194
195
196        // -----------------------------------------------------------------------
197        //  Getter methods
198        // -----------------------------------------------------------------------
199
200        /** @name Getter methods */
201        //@{
202
203        /** Get the default type of this attribute type
204          *
205          * This method returns the 'default type' of the attribute. Default
206          * type in this case refers to the XML concept of a default type for
207          * an attribute, i.e. \#FIXED, \#IMPLIED, etc...
208          *
209          * @return The default type enum for this attribute type.
210          */
211        DefAttTypes getDefaultType() const;
212
213        /** Get the enumeration value (if any) of this attribute type
214          *
215          * If the attribute is of an enumeration or notation type, then this
216          * method will return a const reference to a string that contains the
217          * space separated values that can the attribute can have.
218          *
219          * @return A const pointer to a string that contains the space separated
220          *         legal values for this attribute.
221          */
222        const XMLCh* getEnumeration() const;
223
224        /** Get the pool id of this attribute type
225          *
226          * This method will return the id of this attribute in the validator's
227          * attribute pool. It was set by the validator when this attribute was
228          * created.
229          *
230          * @return The pool id of this attribute type.
231          */
232        XMLSize_t getId() const;
233
234        /** Get the type of this attribute
235          *
236          * Gets the type of this attribute. This type is represented by an enum
237          * that converts the types of attributes allowed by XML, e.g. CDATA, NMTOKEN,
238          * NOTATION, etc...
239          *
240          * @return The attribute type enumeration value for this type of
241          *         attribute.
242          */
243        AttTypes getType() const;
244
245        /** Get the default/fixed value of this attribute (if any.)
246          *
247          * If the attribute defined a default/fixed value, then it is stored
248          * and this method will retrieve it. If it has non, then a null pointer
249          * is returned.
250          *
251          * @return A const pointer to the default/fixed value for this attribute
252          *         type.
253          */
254        const XMLCh* getValue() const;
255
256        /** Get the create reason for this attribute
257          *
258          * This method returns an enumeration which indicates why this attribute
259          * declaration exists.
260          *
261          * @return An enumerated value that indicates the reason why this attribute
262          * was added to the attribute table.
263          */
264        CreateReasons getCreateReason() const;
265
266        /** Indicate whether this attribute has been declared externally
267          *
268          * This method returns a boolean that indicates whether this attribute
269          * has been declared externally.
270          *
271          * @return true if this attribute has been declared externally, else false.
272          */
273        bool isExternal() const;
274
275        /** Get the plugged-in memory manager
276          *
277          * This method returns the plugged-in memory manager user for dynamic
278          * memory allocation/deallocation.
279          *
280          * @return the plugged-in memory manager
281          */
282        MemoryManager* getMemoryManager() const;
283
284        //@}
285
286        /** Get the last occurrence of this attribute
287          *
288          * @return The element id that this attribute was last associated with
289          */
290        unsigned int getLastOccurrence() const;
291
292        // -----------------------------------------------------------------------
293        //  Setter methods
294        // -----------------------------------------------------------------------
295
296        /** @name Setter methods */
297        //@{
298
299        /** Set the default attribute type
300          *
301          * This method sets the default attribute type for this attribute.
302          * This setting controls whether the attribute is required, fixed,
303          * implied, etc...
304          *
305          * @param  newValue The new default attribute to set
306          */
307        void setDefaultType(const XMLAttDef::DefAttTypes newValue);
308
309        /** Set the pool id for this attribute type.
310          *
311          * This method sets the pool id of this attribute type. This is usually
312          * called by the validator that creates the actual instance (which is of
313          * a derived type known only by the validator.)
314          *
315          * @param  newId The new pool id to set.
316          */
317        void setId(const XMLSize_t newId);
318
319        /** Set the type of this attribute type.
320          *
321          * This method will set the type of the attribute. The type of an attribute
322          * controls how it is normalized and what kinds of characters it can hold.
323          *
324          * @param  newValue The new attribute type to set
325          */
326        void setType(const XMLAttDef::AttTypes newValue);
327
328        /** Set the default/fixed value of this attribute type.
329          *
330          * This method set the fixed/default value for the attribute. This value
331          * will be used when instances of this attribute type are faulted in. It
332          * <b>must</b> be a valid value for the type set by setType(). If the
333          * type is enumeration or notation, this must be one of the valid values
334          * set in the setEnumeration() call.
335          *
336          * @param  newValue The new fixed/default value to set.
337          */
338        void setValue(const XMLCh* const newValue);
339
340        /** Set the enumerated value of this attribute type.
341          *
342          * This method sets the enumerated/notation value list for this attribute
343          * type. It is a space separated set of possible values. These values must
344          * meet the constrains of the XML spec for such values of this type of
345          * attribute. This should only be set if the setType() method is used to
346          * set the type to the enumeration or notation types.
347          *
348          * @param  newValue The new enumerated/notation value list to set.
349          */
350        void setEnumeration(const XMLCh* const newValue);
351
352        /** Update the create reason for this attribute type.
353          *
354          * This method will update the 'create reason' field for this attribute
355          * decl object.
356          *
357          * @param  newReason The new create reason.
358          */
359        void setCreateReason(const CreateReasons newReason);
360
361        /**
362          * Set the attribute decl to indicate external declaration
363          *
364          * @param  aValue The new value to indicate external declaration.
365          */
366        void setExternalAttDeclaration(const bool aValue);
367
368        /** Set the last occurrence of this attribute
369
370          * @param element id associated with this attribute definition
371          */
372        void setLastOccurrence(const unsigned int elementId);
373
374        //@}
375
376        /***
377         * Support for Serialization/De-serialization
378         ***/
379        DECL_XSERIALIZABLE(XMLAttDef)
380
381protected :
382        // -----------------------------------------------------------------------
383        //  Hidden constructors
384        // -----------------------------------------------------------------------
385        XMLAttDef
386        (
387                const   AttTypes       type = CData
388                , const DefAttTypes    defType= Implied
389                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
390        );
391        XMLAttDef
392        (
393                const   XMLCh* const        attValue
394                , const AttTypes            type
395                , const DefAttTypes         defType
396                , const XMLCh* const        enumValues = 0
397                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
398        );
399
400
401private :
402        // -----------------------------------------------------------------------
403        //  Unimplemented constructors and operators
404        // -----------------------------------------------------------------------
405        XMLAttDef(const XMLAttDef&);
406        XMLAttDef& operator=(const XMLAttDef&);
407
408
409        // -----------------------------------------------------------------------
410        //  Private helper methods
411        // -----------------------------------------------------------------------
412        void cleanUp();
413
414
415        // -----------------------------------------------------------------------
416        //  Private data members
417        //
418        //  fDefaultType
419        //      Indicates what, if any, default stuff this attribute has.
420        //
421        //  fEnumeration
422        //      If its an enumeration, this is the list of values as space
423        //      separated values.
424        //
425        //  fId
426        //      This is the unique id of this attribute, given to it when its put
427        //      into the validator's attribute decl pool. It defaults to the
428        //      special value XMLAttrDef::fgInvalidAttrId.
429        //
430        //  fType
431        //      The type of attribute, which is one of the AttTypes values.
432        //
433        //  fValue
434        //      This is the value of the attribute, which is the default value
435        //      given in the attribute declaration.
436        //
437        //  fCreateReason
438        //      This flag tells us how this attribute got created.  Sometimes even
439        //      the attribute was not declared for the element, we want to fault
440        //      fault it into the pool to avoid lots of redundant errors.
441        //
442        //  fExternalAttribute
443        //      This flag indicates whether or not the attribute was declared externally.
444        // -----------------------------------------------------------------------
445        DefAttTypes     fDefaultType;
446        AttTypes        fType;
447        CreateReasons   fCreateReason;
448        bool            fExternalAttribute;
449        XMLSize_t       fId;
450        XMLCh*          fValue;
451        XMLCh*          fEnumeration;
452        unsigned int    fLastOccurrence;
453        MemoryManager*  fMemoryManager;
454};
455
456
457// ---------------------------------------------------------------------------
458//  Getter methods
459// ---------------------------------------------------------------------------
460inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
461{
462        return fDefaultType;
463}
464
465inline const XMLCh* XMLAttDef::getEnumeration() const
466{
467        return fEnumeration;
468}
469
470inline XMLSize_t XMLAttDef::getId() const
471{
472        return fId;
473}
474
475inline XMLAttDef::AttTypes XMLAttDef::getType() const
476{
477        return fType;
478}
479
480inline const XMLCh* XMLAttDef::getValue() const
481{
482        return fValue;
483}
484
485inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
486{
487        return fCreateReason;
488}
489
490inline bool XMLAttDef::isExternal() const
491{
492        return fExternalAttribute;
493}
494
495inline MemoryManager* XMLAttDef::getMemoryManager() const
496{
497        return fMemoryManager;
498}
499
500/** Get the last occurrence of this attribute
501  *
502  * @return The element id that this attribute was last associated with
503  */
504inline unsigned int XMLAttDef::getLastOccurrence() const
505{
506        return fLastOccurrence;
507}
508
509// ---------------------------------------------------------------------------
510//  XMLAttDef: Setter methods
511// ---------------------------------------------------------------------------
512inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
513{
514        fDefaultType = newValue;
515}
516
517inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
518{
519        if (fEnumeration)
520                fMemoryManager->deallocate(fEnumeration);
521
522        fEnumeration = XMLString::replicate(newValue, fMemoryManager);
523}
524
525inline void XMLAttDef::setId(const XMLSize_t newId)
526{
527        fId = newId;
528}
529
530inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
531{
532        fType = newValue;
533}
534
535inline void XMLAttDef::setValue(const XMLCh* const newValue)
536{
537        if (fValue)
538           fMemoryManager->deallocate(fValue);
539
540        fValue = XMLString::replicate(newValue, fMemoryManager);
541}
542
543inline void
544XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
545{
546        fCreateReason = newReason;
547}
548
549inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
550{
551        fExternalAttribute = aValue;
552}
553
554inline void XMLAttDef::setLastOccurrence(const unsigned int elementId)
555{
556        fLastOccurrence = elementId;
557}
558
559#ifdef PRINT_DEBUG_MESSAGE
560static std::ostream & operator << (std::ostream & out, const XMLAttDef * def)
561{
562        if (def)
563        {
564                out << "(XMLAttDef:"
565                        << def->getAttName()
566                        << ',' << def->getAttTypeString(def->getType())
567                        << ',' << def->getDefAttTypeString(def->getDefaultType())
568                        << ',' << def->getEnumeration()
569                        << ',';
570
571                switch (def->getCreateReason())
572                {
573                        case XMLAttDef::NoReason: out << "NoReason"; break;
574                        case XMLAttDef::JustFaultIn: out << "JustFaultIn"; break;
575                        default: out << "Unknown";
576                }
577
578                out << ',' << def->getValue()
579                        << ')';
580        }
581        return out;
582}
583
584static std::ostream & operator << (std::ostream & out, RefHashTableOf<XMLAttDef>* defs)
585{
586        out << '{';
587
588        if (defs && !defs->isEmpty())
589        {
590                RefHashTableOfEnumerator<XMLAttDef> itr(defs, false);
591
592                const XMLCh * key = (const XMLCh*)itr.nextElementKey();
593                out << '(' << key << ':' << defs->get(key) << ')';
594                while (itr.hasMoreElements())
595                {
596                        key = (const XMLCh*)itr.nextElementKey();
597                        out << ",(" << key << ':' << defs->get(key) << ')';
598                }
599
600        }
601        out << '}';
602
603        return out;
604}
605
606#endif
607
608XERCES_CPP_NAMESPACE_END
609
610#endif
Note: See TracBrowser for help on using the repository browser.