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

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

Changes to icxercesc files

File size: 19.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 <icxercesc/util/QName.hpp>
20#include <xercesc/internal/XSerializable.hpp>
21#include <icxmlc/XMLConfig.hpp>
22
23XERCES_CPP_NAMESPACE_BEGIN
24
25class XMLAttr;
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(XMLStringPool* const     qNameManager);
386
387    XMLAttDef(const XMLAttDef &        other);
388
389    XMLAttDef
390    (
391        QName *                        attName
392        , const XMLAttDef::AttTypes    type
393        , const XMLAttDef::DefAttTypes defType
394    );
395
396    XMLAttDef
397    (
398          const XMLCh* const           prefix
399        , const XMLCh* const           localPart
400        , const int                    uriId
401        , const XMLAttDef::AttTypes    type
402        , const XMLAttDef::DefAttTypes defType
403        , XMLStringPool* const         qNameManager
404    );
405
406    XMLAttDef
407    (
408          const XMLCh* const           prefix
409        , const XMLCh* const           localPart
410        , const int                    uriId
411        , const XMLCh* const           attValue
412        , const XMLAttDef::AttTypes    type
413        , const XMLAttDef::DefAttTypes defType
414        , const XMLCh* const           enumValues
415        , XMLStringPool* const         qNameManager
416    );
417
418    XMLAttDef
419    (
420        const   XMLCh* const           attName
421        , const XMLAttDef::AttTypes    type
422        , const XMLAttDef::DefAttTypes defType
423        , XMLStringPool* const         qNameManager
424    );
425
426    XMLAttDef
427    (
428        const   XMLCh* const           attName
429        , const XMLCh* const           attValue
430        , const XMLAttDef::AttTypes    type
431        , const XMLAttDef::DefAttTypes defType
432        , const XMLCh* const           enumValues
433        , XMLStringPool* const         qNameManager
434    );
435
436    // -----------------------------------------------------------------------
437    //  Deprecated constructors
438    // -----------------------------------------------------------------------
439    XMLAttDef
440    (
441        const   AttTypes       type = CData
442        , const DefAttTypes    defType= Implied
443        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
444    );
445
446    XMLAttDef
447    (
448        const   XMLCh* const        attValue
449        , const AttTypes            type
450        , const DefAttTypes         defType
451        , const XMLCh* const        enumValues = 0
452        , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
453    );
454
455
456private :
457        // -----------------------------------------------------------------------
458        //  Unimplemented constructors and operators
459        // -----------------------------------------------------------------------
460        XMLAttDef& operator=(const XMLAttDef&);
461
462
463        // -----------------------------------------------------------------------
464        //  Private helper methods
465        // -----------------------------------------------------------------------
466        void cleanUp();
467
468protected :
469        // -----------------------------------------------------------------------
470        //  Private data members
471        //
472    //  fAttName
473    //      This is the name of the attribute.
474    //
475        //  fDefaultType
476        //      Indicates what, if any, default stuff this attribute has.
477        //
478        //  fEnumeration
479        //      If its an enumeration, this is the list of values as space
480        //      separated values.
481        //
482        //  fId
483        //      This is the unique id of this attribute, given to it when its put
484        //      into the validator's attribute decl pool. It defaults to the
485        //      special value XMLAttrDef::fgInvalidAttrId.
486        //
487        //  fType
488        //      The type of attribute, which is one of the AttTypes values.
489        //
490        //  fValue
491        //      This is the value of the attribute, which is the default value
492        //      given in the attribute declaration.
493        //
494        //  fCreateReason
495        //      This flag tells us how this attribute got created.  Sometimes even
496        //      the attribute was not declared for the element, we want to fault
497        //      fault it into the pool to avoid lots of redundant errors.
498        //
499        //  fExternalAttribute
500        //      This flag indicates whether or not the attribute was declared externally.
501        // -----------------------------------------------------------------------
502    QName               fAttName;
503    DefAttTypes         fDefaultType;
504    AttTypes            fType;
505    CreateReasons       fCreateReason;
506    bool                fExternalAttribute;
507    XMLSize_t           fId;
508    XMLCh*              fValue;
509    XMLCh*              fEnumeration;
510    unsigned int        fLastOccurrence;
511};
512
513
514// ---------------------------------------------------------------------------
515//  Getter methods
516// ---------------------------------------------------------------------------
517inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
518{
519        return fDefaultType;
520}
521
522inline const XMLCh* XMLAttDef::getEnumeration() const
523{
524        return fEnumeration;
525}
526
527inline XMLSize_t XMLAttDef::getId() const
528{
529        return fId;
530}
531
532inline XMLAttDef::AttTypes XMLAttDef::getType() const
533{
534        return fType;
535}
536
537inline const XMLCh* XMLAttDef::getValue() const
538{
539        return fValue;
540}
541
542inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
543{
544        return fCreateReason;
545}
546
547inline bool XMLAttDef::isExternal() const
548{
549        return fExternalAttribute;
550}
551
552inline MemoryManager* XMLAttDef::getMemoryManager() const
553{
554    return fAttName.getMemoryManager();
555}
556
557/** Get the last occurrence of this attribute
558  *
559  * @return The element id that this attribute was last associated with
560  */
561inline unsigned int XMLAttDef::getLastOccurrence() const
562{
563        return fLastOccurrence;
564}
565
566// ---------------------------------------------------------------------------
567//  XMLAttDef: Setter methods
568// ---------------------------------------------------------------------------
569inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
570{
571        fDefaultType = newValue;
572}
573
574inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
575{
576        if (fEnumeration)
577        getMemoryManager()->deallocate(fEnumeration);
578    fEnumeration = XMLString::replicate(newValue, getMemoryManager());
579}
580
581inline void XMLAttDef::setId(const XMLSize_t newId)
582{
583        fId = newId;
584}
585
586inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
587{
588        fType = newValue;
589}
590
591inline void XMLAttDef::setValue(const XMLCh* const newValue)
592{
593        if (fValue)
594       getMemoryManager()->deallocate(fValue);
595    fValue = XMLString::replicate(newValue, getMemoryManager());
596}
597
598inline void
599XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
600{
601        fCreateReason = newReason;
602}
603
604inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
605{
606        fExternalAttribute = aValue;
607}
608
609inline void XMLAttDef::setLastOccurrence(const unsigned int elementId)
610{
611        fLastOccurrence = elementId;
612}
613
614#ifdef PRINT_DEBUG_MESSAGE
615static std::ostream & operator << (std::ostream & out, const XMLAttDef * def)
616{
617        if (def)
618        {
619                out << "(XMLAttDef:"
620                        << def->getAttName()
621                        << ',' << def->getAttTypeString(def->getType())
622                        << ',' << def->getDefAttTypeString(def->getDefaultType())
623                        << ',' << def->getEnumeration()
624                        << ',';
625
626                switch (def->getCreateReason())
627                {
628                        case XMLAttDef::NoReason: out << "NoReason"; break;
629                        case XMLAttDef::JustFaultIn: out << "JustFaultIn"; break;
630                        default: out << "Unknown";
631                }
632
633                out << ',' << def->getValue()
634                        << ')';
635        }
636        return out;
637}
638
639static std::ostream & operator << (std::ostream & out, RefHashTableOf<XMLAttDef>* defs)
640{
641        out << '{';
642
643        if (defs && !defs->isEmpty())
644        {
645                RefHashTableOfEnumerator<XMLAttDef> itr(defs, false);
646
647                const XMLCh * key = (const XMLCh*)itr.nextElementKey();
648                out << '(' << key << ':' << defs->get(key) << ')';
649                while (itr.hasMoreElements())
650                {
651                        key = (const XMLCh*)itr.nextElementKey();
652                        out << ",(" << key << ':' << defs->get(key) << ')';
653                }
654
655        }
656        out << '}';
657
658        return out;
659}
660
661#endif
662
663XERCES_CPP_NAMESPACE_END
664
665#endif
Note: See TracBrowser for help on using the repository browser.