source: icXML/icXML-devel/src/icxercesc/framework/XMLAttr.hpp @ 2720

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

Initial check-in of icXML 0.8 source files

File size: 24.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: XMLAttr.hpp 932887 2010-04-11 13:04:59Z borisk $
11 */
12
13#if !defined(XERCESC_INCLUDE_GUARD_XMLATTR_HPP)
14#define XERCESC_INCLUDE_GUARD_XMLATTR_HPP
15
16#include <xercesc/util/PlatformUtils.hpp>
17#include <xercesc/util/QName.hpp>
18#include <xercesc/framework/XMLAttDef.hpp>
19#include <xercesc/validators/datatype/DatatypeValidator.hpp>
20#include <icxmlc/XMLConfig.hpp>
21
22XERCES_CPP_NAMESPACE_BEGIN
23
24class XMLScanner;
25class IGXMLScanner;
26
27/**
28 *  This class defines the information about an attribute that will come out
29 *  of the scanner during parsing. This information does not depend upon the
30 *  type of validator because it is not tied to any scheme/DTD type info. Its
31 *  just the raw XML 1.0 information that will be reported about an attribute
32 *  in the startElement() callback method of the XMLDocumentHandler class.
33 *  Hence it is not intended to be extended or derived from. Its designed to
34 *  be used as is.
35 *
36 *  The 'specified' field of this class indicates whether the attribute was
37 *  actually present or whether it was faulted in because it had a fixed or
38 *  default value.
39 *
40 *  The code receiving this information can ask its validator for more info
41 *  about the attribute, i.e. get its declaration from the DTD/Schema info.
42 *
43 *  Because of the heavy use (and reuse) of instances of this class, and the
44 *  number of string members it has, this class takes pains to not reallocate
45 *  string members unless it has to. It keeps up with how long each buffer
46 *  is and only reallocates if the new value won't fit.
47 */
48class XMLPARSER_EXPORT XMLAttr : public XMemory
49{
50    friend class XMLScanner;
51    friend class IGXMLScanner;
52
53public:
54        // -----------------------------------------------------------------------
55        //  Constructors and Destructor
56        // -----------------------------------------------------------------------
57        /** @name Constructors */
58        //@{
59
60        /**
61          * The default constructor just setsup an empty attribute to be filled
62          * in the later. Though the initial state is a reasonable one, it is
63          * not documented because it should not be depended on.
64          *
65          * @param  manager     The configurable memory manager
66          */
67        XMLAttr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
68
69        /**
70          * This is the primary constructor which takes all of the information
71          * required to construct a complete attribute object.
72          *
73          * @param  uriId       The id into the validator's URI pool of the URI
74          *                     that the prefix mapped to. Only used if namespaces
75          *                     are enabled/supported.
76          *
77          * @param  attrName    The base name of the attribute, i.e. the part
78          *                     after any prefix.
79          *
80          * @param  attrPrefix  The prefix, if any, of this attribute's name. If
81          *                     this is empty, then uriID is meaningless as well.
82          *
83          * @param  attrValue   The value string of the attribute, which should
84          *                     be fully normalized by XML rules!
85          *
86          * @param  type        The type of the attribute. This will indicate
87          *                     the type of normalization done and constrains
88          *                     the value content. Make sure that the value
89          *                     set meets the constraints!
90          *
91          * @param  specified   Indicates whether the attribute was explicitly
92          *                     specified or not. If not, then it was faulted
93          *                     in from a FIXED or DEFAULT value.
94          *
95          * @param  manager     The configurable memory manager
96          * @param datatypeValidator type used to validate the attribute,
97          *                         if it was validated by an XML Schema
98          * @param isSchema         true if and only if this attribute was validated
99          *                         by an XML Schema
100          */
101        XMLAttr
102        (
103                  const unsigned int        uriId
104                , const XMLCh* const        attrName
105                , const XMLCh* const        attrPrefix
106                , const XMLCh* const        attrValue
107                , const XMLAttDef::AttTypes type = XMLAttDef::CData
108                , const bool                specified = true
109                , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
110                , DatatypeValidator * datatypeValidator = 0
111                , const bool isSchema = false
112        );
113
114        /**
115          * This is the primary constructor which takes all of the information
116          * required to construct a complete attribute object.
117          *
118          * @param  uriId       The id into the validator's URI pool of the URI
119          *                     that the prefix mapped to. Only used if namespaces
120          *                     are enabled/supported.
121          *
122          * @param  rawName     The raw name of the attribute.
123          *
124          * @param  attrValue   The value string of the attribute, which should
125          *                     be fully normalized by XML rules!
126          *
127          * @param  type        The type of the attribute. This will indicate
128          *                     the type of normalization done and constrains
129          *                     the value content. Make sure that the value
130          *                     set meets the constraints!
131          *
132          * @param  specified   Indicates whether the attribute was explicitly
133          *                     specified or not. If not, then it was faulted
134          *                     in from a FIXED or DEFAULT value.
135          *
136          * @param  manager     The configurable memory manager
137          * @param datatypeValidator type used to validate the attribute,
138          *                         if it was validated by an XML Schema
139          * @param isSchema         true if and only if this attribute was validated
140          *                         by an XML Schema
141          */
142        XMLAttr
143        (
144                const unsigned int uriId
145                , const XMLCh* const rawName
146                , const XMLCh* const attrValue
147                , const XMLAttDef::AttTypes type = XMLAttDef::CData
148                , const bool specified = true
149                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
150                , DatatypeValidator * datatypeValidator = 0
151                , const bool isSchema = false
152        );
153
154
155        /**
156          * This is the primary constructor which takes all of the information
157          * required to construct a complete attribute object.
158          *
159          * @param  qName       The precomputed qName that is stored in the symbol table
160          *
161          * @param  attrValue   The value string of the attribute, which should
162          *                     be fully normalized by XML rules!
163          *
164          * @param  type        The type of the attribute. This will indicate
165          *                     the type of normalization done and constrains
166          *                     the value content. Make sure that the value
167          *                     set meets the constraints!
168          *
169          * @param  specified   Indicates whether the attribute was explicitly
170          *                     specified or not. If not, then it was faulted
171          *                     in from a FIXED or DEFAULT value.
172          *
173          * @param  manager     The configurable memory manager
174          * @param datatypeValidator type used to validate the attribute,
175          *                         if it was validated by an XML Schema
176          * @param isSchema         true if and only if this attribute was validated
177          *                         by an XML Schema
178          */
179        XMLAttr
180        (
181                const QName * qName
182                , const XMLCh* const attrValue
183                , const XMLAttDef::AttTypes type = XMLAttDef::CData
184                , const bool                specified = true
185                , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
186                , DatatypeValidator * datatypeValidator = 0
187                , const bool isSchema = false
188        );
189
190    /**
191      * This is the primary constructor which takes all of the information
192      * required to construct a complete attribute object.
193      *
194      * @param  qName       The precomputed qName that is stored in the symbol table
195      *
196      * @param  attrValue   The value string of the attribute, which should
197      *                     be fully normalized by XML rules!
198      *
199      * @param  attrLength  The length of the attribute value string
200      *
201      * @param  type        The type of the attribute. This will indicate
202      *                     the type of normalization done and constrains
203      *                     the value content. Make sure that the value
204      *                     set meets the constraints!
205      *
206      * @param  specified   Indicates whether the attribute was explicitly
207      *                     specified or not. If not, then it was faulted
208      *                     in from a FIXED or DEFAULT value.
209      *
210      * @param  manager     The configurable memory manager
211      * @param datatypeValidator type used to validate the attribute,
212      *                         if it was validated by an XML Schema
213      * @param isSchema         true if and only if this attribute was validated
214      *                         by an XML Schema
215      */
216    XMLAttr
217    (
218        const QName *               qName
219        , const XMLCh* const        attrValue
220        , const XMLSize_t           attrLength
221        , const XMLAttDef::AttTypes type = XMLAttDef::CData
222        , const bool                specified = true
223        , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
224        , DatatypeValidator *       datatypeValidator = 0
225        , const bool                isSchema = false
226    );
227
228
229        //@}
230
231        /** @name Destructor */
232        //@{
233        ~XMLAttr();
234        //@}
235
236
237        // -----------------------------------------------------------------------
238        //  Getter methods
239        // -----------------------------------------------------------------------
240
241        /** @name Getter methods */
242        //@{
243
244        /**
245          * This method returns the attribute name in a QName format.
246          */
247        QName* getAttName() const;
248
249        /**
250          * This method gets a const pointer to the name of the attribute. The
251          * form of this name is defined by the validator in use.
252          */
253        const XMLCh* getName() const;
254
255        /**
256          * This method will get a const pointer to the prefix string of this
257          * attribute. Since prefixes are optional, it may be zero.
258          */
259        const XMLCh* getPrefix() const;
260
261        /**
262          * This method will get the QName of this attribute, which will be the
263          * prefix if any, then a colon, then the base name. If there was no
264          * prefix, its the same as the getName() method.
265          */
266        const XMLCh* getQName() const;
267
268        /**
269          * This method will get the specified flag, which indicates whether
270          * the attribute was explicitly specified or just faulted in.
271          */
272        bool getSpecified() const;
273
274        /**
275          * This method will get the type of the attribute. The available types
276          * are defined by the XML specification.
277          */
278        XMLAttDef::AttTypes getType() const;
279
280        /**
281          * This method will get the value of the attribute. The value can be
282          * be an empty string, but never null if the object is correctly
283          * set up.
284          */
285        const XMLCh* getValue() const;
286
287        /**
288          * This method will return the length of this attribute's value.
289          */
290        const XMLSize_t getValueLen() const;
291
292        /**
293          * This method will get the id of the URI that this attribute's prefix
294          * mapped to. If namespaces are not on, then its value is meaningless.
295          */
296        unsigned int getURIId() const;
297
298        //@}
299
300
301        // -----------------------------------------------------------------------
302        //  Setter methods
303        // -----------------------------------------------------------------------
304
305        /** @name Setter methods */
306        //@{
307
308        /**
309          * This method is called to set up a default constructed object after
310          * the fact, or to reuse a previously used object.
311          *
312          * @param  uriId       The id into the validator's URI pool of the URI
313          *                     that the prefix mapped to. Only used if namespaces
314          *                     are enabled/supported.
315          *
316          * @param  attrName    The base name of the attribute, i.e. the part
317          *                     after any prefix.
318          *
319          * @param  attrPrefix  The prefix, if any, of this attribute's name. If
320          *                     this is empty, then uriID is meaningless as well.
321          *
322          * @param  attrValue   The value string of the attribute, which should
323          *                     be fully normalized by XML rules according to the
324          *                     attribute type.
325          *
326          * @param  type        The type of the attribute. This will indicate
327          *                     the type of normalization done and constrains
328          *                     the value content. Make sure that the value
329          *                     set meets the constraints!
330          * @param datatypeValidator type used to validate the attribute,
331          *                         if it was validated by an XML Schema
332          * @param isSchema         true if and only if this attribute was validated
333          *                         by an XML Schema
334          *
335          */
336        void set
337        (
338                const   unsigned int        uriId
339                , const XMLCh* const        attrName
340                , const XMLCh* const        attrPrefix
341                , const XMLCh* const        attrValue
342                , const XMLAttDef::AttTypes type = XMLAttDef::CData
343                , DatatypeValidator * datatypeValidator = 0
344                , const bool isSchema = false
345        );
346
347        /**
348          * This method is called to set up a default constructed object after
349          * the fact, or to reuse a previously used object.
350          *
351          * @param  uriId       The id into the validator's URI pool of the URI
352          *                     that the prefix mapped to. Only used if namespaces
353          *                     are enabled/supported.
354          *
355          * @param  attrRawName The raw name of the attribute.
356          *
357          * @param  attrValue   The value string of the attribute, which should
358          *                     be fully normalized by XML rules according to the
359          *                     attribute type.
360          *
361          * @param  type        The type of the attribute. This will indicate
362          *                     the type of normalization done and constrains
363          *                     the value content. Make sure that the value
364          *                     set meets the constraints!
365          * @param datatypeValidator type used to validate the attribute,
366          *                         if it was validated by an XML Schema
367          * @param isSchema         true if and only if this attribute was validated
368          *                         by an XML Schema
369          */
370        void set
371        (
372                const   unsigned int        uriId
373                , const XMLCh* const        attrRawName
374                , const XMLCh* const        attrValue
375                , const XMLAttDef::AttTypes type = XMLAttDef::CData
376                , DatatypeValidator * datatypeValidator = 0
377                , const bool isSchema = false
378        );
379
380        /**
381          * This method is called to set up a default constructed object after
382          * the fact, or to reuse a previously used object.
383          *
384          * @param  qName       The precomputed qName that is stored in the symbol table
385          * @param  attrValue   The value string of the attribute, which should
386          *                     be fully normalized by XML rules according to the
387          *                     attribute type.
388          *
389          * @param  type        The type of the attribute. This will indicate
390          *                     the type of normalization done and constrains
391          *                     the value content. Make sure that the value
392          *                     set meets the constraints!
393          * @param datatypeValidator type used to validate the attribute,
394          *                         if it was validated by an XML Schema
395          * @param isSchema         true if and only if this attribute was validated
396          *                         by an XML Schema
397          *
398          */
399        void set
400        (
401        const QName *               qName
402        , const XMLCh * const       attrValue
403                , const XMLAttDef::AttTypes type = XMLAttDef::CData
404        , DatatypeValidator *       datatypeValidator = 0
405        , const bool                isSchema = false
406        );
407
408    /**
409      * This method is called to set up a default constructed object after
410      * the fact, or to reuse a previously used object.
411      *
412      * @param  qName       The precomputed qName that is stored in the symbol table
413      *
414      * @param  attrValue   The value string of the attribute, which should
415      *                     be fully normalized by XML rules according to the
416      *                     attribute type.
417      *
418      * @param  attrLength  The length of the attribute string
419      *
420      * @param  type        The type of the attribute. This will indicate
421      *                     the type of normalization done and constrains
422      *                     the value content. Make sure that the value
423      *                     set meets the constraints!
424      * @param datatypeValidator type used to validate the attribute,
425      *                         if it was validated by an XML Schema
426      * @param isSchema         true if and only if this attribute was validated
427      *                         by an XML Schema
428      *
429      */
430    void set
431    (
432        const QName *               qName
433        , const XMLCh * const       attrValue
434        , const XMLSize_t           attrLength
435        , const XMLAttDef::AttTypes type = XMLAttDef::CData
436        , DatatypeValidator *       datatypeValidator = 0
437        , const bool                isSchema = false
438    );
439
440        /**
441          * This method will update just the name related fields of the
442          * attribute object. The other fields are left as is.
443          *
444          * @param  uriId       The id into the validator's URI pool of the URI
445          *                     that the prefix mapped to. Only used if namespaces
446          *                     are enabled/supported.
447          *
448          * @param  attrName    The base name of the attribute, i.e. the part
449          *                     after any prefix.
450          *
451          * @param  attrPrefix  The prefix, if any, of this attribute's name. If
452          *                     this is empty, then uriID is meaningless as well.
453          */
454        void setName
455        (
456                const   unsigned int        uriId
457                , const XMLCh* const        attrName
458                , const XMLCh* const        attrPrefix
459        );
460
461        /**
462          * This method will update the specified state of the object.
463          *
464          * @param  newValue    Indicates whether the attribute was explicitly
465          *                     specified or not. If not, then it was faulted
466          *                     in from a FIXED or DEFAULT value.
467          */
468        void setSpecified(const bool newValue);
469
470        /**
471          * This method will update the attribute type of the object.
472          *
473          * @param  newType     The type of the attribute. This will indicate
474          *                     the type of normalization done and constrains
475          *                     the value content. Make sure that the value
476          *                     set meets the constraints!
477          */
478        void setType(const XMLAttDef::AttTypes newType);
479
480        /**
481          * This method will update the value field of the attribute.
482          *
483          * @param  newValue    The value string of the attribute, which should
484          *                     be fully normalized by XML rules according to the
485          *                     attribute type.
486          */
487        void setValue(const XMLCh* const newValue);
488
489        /**
490          * This method will update the value field of the attribute.
491          *
492          * @param  newValue    The value string of the attribute, which should
493          *                     be fully normalized by XML rules according to the
494          *                     attribute type.
495          */
496        void setValue(const XMLCh* const newValue, const XMLSize_t length);
497
498#if 0
499        /**
500          * This method will update the value field of the attribute.
501          *
502          * @param  newValue    The value string of the attribute, which should
503          *                     be fully normalized by XML rules according to the
504          *                     attribute type.
505          */
506        void setValue(const XMLBuffer & newValue);
507#endif
508
509        /**
510          * This method will set the URI id field of this attribute. This is
511          * generally only ever called internally by the parser itself during
512          * the parsing process.
513          *
514          * @param  uriId       The uriId of the attribute.
515          */
516        void setURIId(const unsigned int uriId);
517
518        //@}
519
520private :
521        // -----------------------------------------------------------------------
522        //  Unimplemented constructors and operators
523        // -----------------------------------------------------------------------
524        XMLAttr(const XMLAttr&);
525        XMLAttr& operator=(const XMLAttr&);
526
527
528        // -----------------------------------------------------------------------
529        //  Private, helper methods
530        // -----------------------------------------------------------------------
531        void cleanUp();
532
533
534        // -----------------------------------------------------------------------
535        //  Private instance variables
536        //
537        //  fAttName
538        //      The Attribute Name;
539        //
540        //  fSpecified
541        //      True if this attribute appeared in the element; else, false if
542        //      it was defaulted from an AttDef.
543        //
544        //  fType
545        //      The attribute type enum value for this attribute. Indicates what
546        //      type of attribute it was.
547        //
548        //  fValue
549        //  fValueBufSz
550        //      The attribute value that was given in the attribute instance, and
551        //      its current buffer size (minus one, where the null is.)
552        //
553        //  fMemoryManager
554        //      The memory manager used for dynamic memory allocation/deallocation
555        // -----------------------------------------------------------------------
556        bool                fSpecified;
557        XMLAttDef::AttTypes fType;
558        XMLSize_t           fValueLen;
559        const XMLCh*        fValue;
560        QName*              fAttName;
561        MemoryManager*      fMemoryManager;
562};
563
564// ---------------------------------------------------------------------------
565//  XMLAttr: Constructors and Destructor
566// ---------------------------------------------------------------------------
567inline XMLAttr::~XMLAttr()
568{
569        cleanUp();
570}
571
572
573// ---------------------------------------------------------------------------
574//  XMLAttr: Getter methods
575// ---------------------------------------------------------------------------
576inline QName* XMLAttr::getAttName() const
577{
578        return fAttName;
579}
580
581inline const XMLCh* XMLAttr::getName() const
582{
583        return fAttName->getLocalPart();
584}
585
586inline const XMLCh* XMLAttr::getPrefix() const
587{
588        return fAttName->getPrefix();
589}
590
591inline bool XMLAttr::getSpecified() const
592{
593        return fSpecified;
594}
595
596inline XMLAttDef::AttTypes XMLAttr::getType() const
597{
598        return fType;
599}
600
601inline const XMLCh* XMLAttr::getValue() const
602{
603        return fValue;
604}
605
606inline const XMLSize_t XMLAttr::getValueLen() const
607{
608        return fValueLen;
609}
610
611inline unsigned int XMLAttr::getURIId() const
612{
613        return fAttName->getURI();
614}
615
616// ---------------------------------------------------------------------------
617//  XMLAttr: Setter methods
618// ---------------------------------------------------------------------------
619
620inline void XMLAttr::set( const QName *             qName
621                                                , const XMLCh* const        attrValue
622                                                , const XMLAttDef::AttTypes type
623                                                , DatatypeValidator * /*datatypeValidator */
624                                                , const bool /*isSchema*/ )
625{
626        fAttName = const_cast<QName *>(qName);
627        setValue(attrValue);
628        fType = type;
629}
630
631inline void XMLAttr::set( const QName *             qName
632                        , const XMLCh* const        attrValue
633                        , const XMLSize_t           attrLength
634                        , const XMLAttDef::AttTypes type
635                        , DatatypeValidator * /*datatypeValidator */
636                        , const bool /*isSchema*/ )
637{
638    fAttName = const_cast<QName *>(qName);
639    setValue(attrValue, attrLength);
640    fType = type;
641}
642
643inline void XMLAttr::setType(const XMLAttDef::AttTypes newValue)
644{
645        fType = newValue;
646}
647
648inline void XMLAttr::setSpecified(const bool newValue)
649{
650        fSpecified = newValue;
651}
652
653// ---------------------------------------------------------------------------
654//  ICXML DEPRECATED FUNCTIONS!
655// ---------------------------------------------------------------------------
656
657inline void XMLAttr::set( const unsigned int
658                                                , const XMLCh* const
659                                                , const XMLCh* const
660                                                , const XMLCh* const
661                                                , const XMLAttDef::AttTypes
662                                                , DatatypeValidator *
663                                                , const bool  )
664{
665        DEPRECATED_FEATURE_IN_ICXML;
666}
667
668inline void XMLAttr::set(const  unsigned int
669                                                , const XMLCh* const
670                                                , const XMLCh* const
671                                                , const XMLAttDef::AttTypes
672                                                , DatatypeValidator *
673                                                , const bool  )
674{
675        DEPRECATED_FEATURE_IN_ICXML;
676}
677
678#ifdef PRINT_DEBUG_MESSAGE
679static std::ostream & operator << (std::ostream & out, const XMLAttr & attr)
680{
681    out << '('
682        << attr.getAttName() << ','
683        << attr.getValue() << ','
684        << attr.getURIId() << ','
685        << attr.getSpecified() << ','
686        << attr.getType() << ','
687        << ')';
688    return out;
689}
690
691static std::ostream & operator << (std::ostream & out, const XMLAttr * attr)
692{
693    if (likely(attr != 0))
694    {
695        out << *attr;
696    }
697    return out;
698}
699
700
701XERCES_CPP_NAMESPACE_END
702
703#include <xercesc/util/RefVectorOf.hpp>
704
705XERCES_CPP_NAMESPACE_BEGIN
706
707static std::ostream & operator << (std::ostream & out, const RefVectorOf<XMLAttr> & attrs)
708{
709    char leadingChar = '{';
710    for (XMLSize_t index = 0; index < attrs.size(); index++)
711    {
712        out << leadingChar << attrs.elementAt(index);
713        leadingChar = ',';
714    }
715    out << ((leadingChar == '{') ? '0' : '}');
716
717    return out;
718}
719#endif
720
721XERCES_CPP_NAMESPACE_END
722
723#endif
Note: See TracBrowser for help on using the repository browser.