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

Revision 358, 23.0 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: XMLAttr.hpp,v $
19 * Revision 1.11  2004/09/20 14:47:13  amassari
20 * Mark some methods as deprecated
21 *
22 * Revision 1.10  2004/09/08 13:55:58  peiyongz
23 * Apache License Version 2.0
24 *
25 * Revision 1.9  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.8  2003/11/24 05:19:37  neilg
29 * update XMLAttr class to carry information needed by DOMTypeInfo
30 *
31 * Revision 1.7  2003/05/22 02:10:51  knoaman
32 * Default the memory manager.
33 *
34 * Revision 1.6  2003/05/16 21:36:55  knoaman
35 * Memory manager implementation: Modify constructors to pass in the memory manager.
36 *
37 * Revision 1.5  2003/05/15 18:26:07  knoaman
38 * Partial implementation of the configurable memory manager.
39 *
40 * Revision 1.4  2002/11/28 20:12:45  knoaman
41 * Allow creating/setting of XMLAttr using a rawname (i.e. 'prefix:localpart').
42 *
43 * Revision 1.3  2002/11/04 15:00:21  tng
44 * C++ Namespace Support.
45 *
46 * Revision 1.2  2002/02/20 18:17:01  tng
47 * [Bug 5977] Warnings on generating apiDocs.
48 *
49 * Revision 1.1.1.1  2002/02/01 22:21:50  peiyongz
50 * sane_include
51 *
52 * Revision 1.9  2001/11/02 14:21:18  knoaman
53 * Add support for identity constraints.
54 *
55 * Revision 1.8  2001/05/11 13:25:31  tng
56 * Copyright update.
57 *
58 * Revision 1.7  2001/02/27 18:33:55  tng
59 * Schema: Use QName in XMLAttr.
60 *
61 * Revision 1.6  2000/04/10 22:42:53  roddey
62 * Extended the buffer reuse to the QName field, to further increase
63 * performance of attribute heavy applications.
64 *
65 * Revision 1.5  2000/03/02 19:54:24  roddey
66 * This checkin includes many changes done while waiting for the
67 * 1.1.0 code to be finished. I can't list them all here, but a list is
68 * available elsewhere.
69 *
70 * Revision 1.4  2000/02/24 20:00:22  abagchi
71 * Swat for removing Log from API docs
72 *
73 * Revision 1.3  2000/02/15 01:21:30  roddey
74 * Some initial documentation improvements. More to come...
75 *
76 * Revision 1.2  2000/02/06 07:47:47  rahulj
77 * Year 2K copyright swat.
78 *
79 * Revision 1.1.1.1  1999/11/09 01:08:28  twl
80 * Initial checkin
81 *
82 * Revision 1.2  1999/11/08 20:44:35  rahul
83 * Swat for adding in Product name and CVS comment log variable.
84 *
85 */
86
87#if !defined(XMLATTR_HPP)
88#define XMLATTR_HPP
89
90#include <xercesc/util/PlatformUtils.hpp>
91#include <xercesc/util/QName.hpp>
92#include <xercesc/framework/XMLAttDef.hpp>
93#include <xercesc/validators/datatype/DatatypeValidator.hpp>
94
95XERCES_CPP_NAMESPACE_BEGIN
96
97/**
98 *  This class defines the information about an attribute that will come out
99 *  of the scanner during parsing. This information does not depend upon the
100 *  type of validator because it is not tied to any scheme/DTD type info. Its
101 *  just the raw XML 1.0 information that will be reported about an attribute
102 *  in the startElement() callback method of the XMLDocumentHandler class.
103 *  Hence it is not intended to be extended or derived from. Its designed to
104 *  be used as is.
105 *
106 *  The 'specified' field of this class indicates whether the attribute was
107 *  actually present or whether it was faulted in because it had a fixed or
108 *  default value.
109 *
110 *  The code receiving this information can ask its validator for more info
111 *  about the attribute, i.e. get its declaration from the DTD/Schema info.
112 *
113 *  Because of the heavy use (and reuse) of instances of this class, and the
114 *  number of string members it has, this class takes pains to not reallocate
115 *  string members unless it has to. It keeps up with how long each buffer
116 *  is and only reallocates if the new value won't fit.
117 */
118class XMLPARSER_EXPORT XMLAttr : public XMemory
119{
120public:
121    // -----------------------------------------------------------------------
122    //  Constructors and Destructor
123    // -----------------------------------------------------------------------
124    /** @name Constructors */
125    //@{
126
127    /**
128      * The default constructor just setsup an empty attribute to be filled
129      * in the later. Though the initial state is a reasonable one, it is
130      * not documented because it should not be depended on.
131      *
132      * @param  manager     The configurable memory manager
133      */
134    XMLAttr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
135
136    /**
137      * This is the primary constructor which takes all of the information
138      * required to construct a complete attribute object.
139      *
140      * @param  uriId       The id into the validator's URI pool of the URI
141      *                     that the prefix mapped to. Only used if namespaces
142      *                     are enabled/supported.
143      *
144      * @param  attrName    The base name of the attribute, i.e. the part
145      *                     after any prefix.
146      *
147      * @param  attrPrefix  The prefix, if any, of this attribute's name. If
148      *                     this is empty, then uriID is meaningless as well.
149      *
150      * @param  attrValue   The value string of the attribute, which should
151      *                     be fully normalized by XML rules!
152      *
153      * @param  type        The type of the attribute. This will indicate
154      *                     the type of normalization done and constrains
155      *                     the value content. Make sure that the value
156      *                     set meets the constraints!
157      *
158      * @param  specified   Indicates whether the attribute was explicitly
159      *                     specified or not. If not, then it was faulted
160      *                     in from a FIXED or DEFAULT value.
161      *
162      * @param  manager     The configurable memory manager
163      * @param datatypeValidator type used to validate the attribute,
164      *                         if it was validated by an XML Schema
165      * @param isSchema         true if and only if this attribute was validated
166      *                         by an XML Schema
167      */
168    XMLAttr
169    (
170          const unsigned int        uriId
171        , const XMLCh* const        attrName
172        , const XMLCh* const        attrPrefix
173        , const XMLCh* const        attrValue
174        , const XMLAttDef::AttTypes type = XMLAttDef::CData
175        , const bool                specified = true
176        , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
177        , DatatypeValidator * datatypeValidator = 0
178        , const bool isSchema = false
179    );
180
181    /**
182      * This is the primary constructor which takes all of the information
183      * required to construct a complete attribute object.
184      *
185      * @param  uriId       The id into the validator's URI pool of the URI
186      *                     that the prefix mapped to. Only used if namespaces
187      *                     are enabled/supported.
188      *
189      * @param  rawName     The raw name of the attribute.
190      *
191      * @param  attrValue   The value string of the attribute, which should
192      *                     be fully normalized by XML rules!
193      *
194      * @param  type        The type of the attribute. This will indicate
195      *                     the type of normalization done and constrains
196      *                     the value content. Make sure that the value
197      *                     set meets the constraints!
198      *
199      * @param  specified   Indicates whether the attribute was explicitly
200      *                     specified or not. If not, then it was faulted
201      *                     in from a FIXED or DEFAULT value.
202      *
203      * @param  manager     The configurable memory manager
204      * @param datatypeValidator type used to validate the attribute,
205      *                         if it was validated by an XML Schema
206      * @param isSchema         true if and only if this attribute was validated
207      *                         by an XML Schema
208      */
209    XMLAttr
210    (
211        const unsigned int uriId
212        , const XMLCh* const rawName
213        , const XMLCh* const attrValue
214        , const XMLAttDef::AttTypes type = XMLAttDef::CData
215        , const bool specified = true
216        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
217        , DatatypeValidator * datatypeValidator = 0
218        , const bool isSchema = false
219    );
220
221    //@}
222
223    /** @name Destructor */
224    //@{
225    ~XMLAttr();
226    //@}
227
228
229    // -----------------------------------------------------------------------
230    //  Getter methods
231    // -----------------------------------------------------------------------
232
233    /** @name Getter methods */
234    //@{
235
236    /**
237      * This methode returns the attribute name in a QName format.
238      */
239    QName* getAttName() const;
240
241    /**
242      * This method gets a const pointer tot he name of the attribute. The
243      * form of this name is defined by the validator in use.
244      */
245    const XMLCh* getName() const;
246
247    /**
248      * This method will get a const pointer to the prefix string of this
249      * attribute. Since prefixes are optional, it may be zero.
250      */
251    const XMLCh* getPrefix() const;
252
253    /**
254      * This method will get the QName of this attribute, which will be the
255      * prefix if any, then a colon, then the base name. If there was no
256      * prefix, its the same as the getName() method.
257      */
258    const XMLCh* getQName() const;
259
260    /**
261      * This method will get the specified flag, which indicates whether
262      * the attribute was explicitly specified or just faulted in.
263      */
264    bool getSpecified() const;
265
266    /**
267      * This method will get the type of the attribute. The available types
268      * are defined by the XML specification.
269      */
270    XMLAttDef::AttTypes getType() const;
271
272    /**
273      * This method will get the value of the attribute. The value can be
274      * be an empty string, but never null if the object is correctly
275      * set up.
276      */
277    const XMLCh* getValue() const;
278
279    /**
280      * This method will get the id of the URI that this attribute's prefix
281      * mapped to. If namespaces are not on, then its value is meaningless.
282      */
283    unsigned int getURIId() const;
284
285    /**
286     * @return the uri part of DOM Level 3 TypeInfo
287     * @deprecated
288     */
289    const XMLCh* getValidatingTypeURI() const;
290
291    /**
292     * @return the name part of DOM Level 3 TypeInfo
293     * @deprecated
294     */
295    const XMLCh* getValidatingTypeName() const;
296
297    //@}
298
299
300    // -----------------------------------------------------------------------
301    //  Setter methods
302    // -----------------------------------------------------------------------
303
304    /** @name Setter methods */
305    //@{
306
307    /**
308      * This method is called to set up a default constructed object after
309      * the fact, or to reuse a previously used object.
310      *
311      * @param  uriId       The id into the validator's URI pool of the URI
312      *                     that the prefix mapped to. Only used if namespaces
313      *                     are enabled/supported.
314      *
315      * @param  attrName    The base name of the attribute, i.e. the part
316      *                     after any prefix.
317      *
318      * @param  attrPrefix  The prefix, if any, of this attribute's name. If
319      *                     this is empty, then uriID is meaningless as well.
320      *
321      * @param  attrValue   The value string of the attribute, which should
322      *                     be fully normalized by XML rules according to the
323      *                     attribute type.
324      *
325      * @param  type        The type of the attribute. This will indicate
326      *                     the type of normalization done and constrains
327      *                     the value content. Make sure that the value
328      *                     set meets the constraints!
329      * @param datatypeValidator type used to validate the attribute,
330      *                         if it was validated by an XML Schema
331      * @param isSchema         true if and only if this attribute was validated
332      *                         by an XML Schema
333      *
334      */
335    void set
336    (
337        const   unsigned int        uriId
338        , const XMLCh* const        attrName
339        , const XMLCh* const        attrPrefix
340        , const XMLCh* const        attrValue
341        , const XMLAttDef::AttTypes type = XMLAttDef::CData
342        , DatatypeValidator * datatypeValidator = 0
343        , const bool isSchema = false
344    );
345
346    /**
347      * This method is called to set up a default constructed object after
348      * the fact, or to reuse a previously used object.
349      *
350      * @param  uriId       The id into the validator's URI pool of the URI
351      *                     that the prefix mapped to. Only used if namespaces
352      *                     are enabled/supported.
353      *
354      * @param  attrRawName The raw name of the attribute.
355      *
356      * @param  attrValue   The value string of the attribute, which should
357      *                     be fully normalized by XML rules according to the
358      *                     attribute type.
359      *
360      * @param  type        The type of the attribute. This will indicate
361      *                     the type of normalization done and constrains
362      *                     the value content. Make sure that the value
363      *                     set meets the constraints!
364      * @param datatypeValidator type used to validate the attribute,
365      *                         if it was validated by an XML Schema
366      * @param isSchema         true if and only if this attribute was validated
367      *                         by an XML Schema
368      */
369    void set
370    (
371        const   unsigned int        uriId
372        , const XMLCh* const        attrRawName
373        , const XMLCh* const        attrValue
374        , const XMLAttDef::AttTypes type = XMLAttDef::CData
375        , DatatypeValidator * datatypeValidator = 0
376        , const bool isSchema = false
377    );
378
379    /**
380      * This method will update just the name related fields of the
381      * attribute object. The other fields are left as is.
382      *
383      * @param  uriId       The id into the validator's URI pool of the URI
384      *                     that the prefix mapped to. Only used if namespaces
385      *                     are enabled/supported.
386      *
387      * @param  attrName    The base name of the attribute, i.e. the part
388      *                     after any prefix.
389      *
390      * @param  attrPrefix  The prefix, if any, of this attribute's name. If
391      *                     this is empty, then uriID is meaningless as well.
392      */
393    void setName
394    (
395        const   unsigned int        uriId
396        , const XMLCh* const        attrName
397        , const XMLCh* const        attrPrefix
398    );
399
400    /**
401      * This method will update the specified state of the object.
402      *
403      * @param  newValue    Indicates whether the attribute was explicitly
404      *                     specified or not. If not, then it was faulted
405      *                     in from a FIXED or DEFAULT value.
406      */
407    void setSpecified(const bool newValue);
408
409    /**
410      * This method will update the attribute type of the object.
411      *
412      * @param  newType     The type of the attribute. This will indicate
413      *                     the type of normalization done and constrains
414      *                     the value content. Make sure that the value
415      *                     set meets the constraints!
416      */
417    void setType(const XMLAttDef::AttTypes newType);
418
419    /**
420      * This method will update the value field of the attribute.
421      *
422      * @param  newValue    The value string of the attribute, which should
423      *                     be fully normalized by XML rules according to the
424      *                     attribute type.
425      */
426    void setValue(const XMLCh* const newValue);
427
428    /**
429      * This method will set the URI id field of this attribute. This is
430      * generally only ever called internally by the parser itself during
431      * the parsing process.
432      *
433      * @param  uriId       The uriId of the attribute.
434      */
435    void setURIId(const unsigned int uriId);
436
437    /**
438      * This method will update the datatype validator that was used
439      * to assess the validity of the value of this attribute.
440      * @param datatypeValidator        DatatypeValidator used to assess the validity
441      *             of this attribute's value
442      * @deprecated
443      */
444    void setDatatypeValidator(DatatypeValidator * datatypeValidator);
445
446    /**
447      * This method will define whether the attribute was
448      * validated by an XML Schema
449      * @param isSchema     true indicates that this attribute was validated
450      *         by an XML Schema; false indicates otherwise
451      * @deprecated
452      */
453    void setSchemaValidated(const bool isSchema);
454
455    //@}
456
457
458
459private :
460    // -----------------------------------------------------------------------
461    //  Unimplemented constructors and operators
462    // -----------------------------------------------------------------------
463    XMLAttr(const XMLAttr&);
464    XMLAttr& operator=(const XMLAttr&);
465
466
467    // -----------------------------------------------------------------------
468    //  Private, helper methods
469    // -----------------------------------------------------------------------
470    void cleanUp();
471
472
473    // -----------------------------------------------------------------------
474    //  Private instance variables
475    //
476    //  fAttName
477    //      The Attribute Name;
478    //
479    //  fSpecified
480    //      True if this attribute appeared in the element; else, false if
481    //      it was defaulted from an AttDef.
482    //
483    //  fType
484    //      The attribute type enum value for this attribute. Indicates what
485    //      type of attribute it was.
486    //
487    //  fValue
488    //  fValueBufSz
489    //      The attribute value that was given in the attribute instance, and
490    //      its current buffer size (minus one, where the null is.)
491    //
492    //  fMemoryManager
493    //      The memory manager used for dynamic memory allocation/deallocation
494    //  fDatatypeValidator
495    //      The validator used to validate the value of this attribute.
496    //      The attribute does not own this object, and it is only
497    //      used in the calculation of DOMTypeInfo information.
498    //  fIsSchemaValidated
499    //      whether this attribute was validated by an XML Schema
500    //
501    // -----------------------------------------------------------------------
502    bool                fSpecified;
503    XMLAttDef::AttTypes fType;
504    unsigned int        fValueBufSz;
505    XMLCh*              fValue;
506    QName*              fAttName;
507    MemoryManager*      fMemoryManager;
508    DatatypeValidator * fDatatypeValidator;
509    bool                fIsSchemaValidated;
510};
511
512// ---------------------------------------------------------------------------
513//  XMLAttr: Constructors and Destructor
514// ---------------------------------------------------------------------------
515inline XMLAttr::~XMLAttr()
516{
517    cleanUp();
518}
519
520
521// ---------------------------------------------------------------------------
522//  XMLAttr: Getter methods
523// ---------------------------------------------------------------------------
524inline QName* XMLAttr::getAttName() const
525{
526    return fAttName;
527}
528
529inline const XMLCh* XMLAttr::getName() const
530{
531    return fAttName->getLocalPart();
532}
533
534inline const XMLCh* XMLAttr::getPrefix() const
535{
536    return fAttName->getPrefix();
537}
538
539inline bool XMLAttr::getSpecified() const
540{
541    return fSpecified;
542}
543
544inline XMLAttDef::AttTypes XMLAttr::getType() const
545{
546    return fType;
547}
548
549inline const XMLCh* XMLAttr::getValue() const
550{
551    return fValue;
552}
553
554inline unsigned int XMLAttr::getURIId() const
555{
556    return fAttName->getURI();
557}
558
559inline const XMLCh* XMLAttr::getValidatingTypeName() const
560{
561    if(fIsSchemaValidated)
562    {
563        if(!fDatatypeValidator || fDatatypeValidator->getAnonymous())
564            return 0;
565        return fDatatypeValidator->getTypeLocalName();
566    }
567    else
568    {
569        return XMLAttDef::getAttTypeString(fType, fMemoryManager);
570    }
571}
572
573inline const XMLCh* XMLAttr::getValidatingTypeURI() const
574{
575    if(fIsSchemaValidated)
576    {
577        if(!fDatatypeValidator || fDatatypeValidator->getAnonymous())
578            return 0;
579        return fDatatypeValidator->getTypeUri();
580    }
581    else
582    {
583        return 0;
584    }
585}
586
587// ---------------------------------------------------------------------------
588//  XMLAttr: Setter methods
589// ---------------------------------------------------------------------------
590inline void XMLAttr::set(const  unsigned int        uriId
591                        , const XMLCh* const        attrName
592                        , const XMLCh* const        attrPrefix
593                        , const XMLCh* const        attrValue
594                        , const XMLAttDef::AttTypes type
595                        , DatatypeValidator * datatypeValidator
596                        , const bool isSchema )
597{
598    // Set the name info and the value via their respective calls
599    fAttName->setName(attrPrefix, attrName, uriId);
600    setValue(attrValue);
601
602    // And store the type
603    fType = type;
604
605    // and set up info for DOM type info
606    fIsSchemaValidated = isSchema;
607    fDatatypeValidator = datatypeValidator;
608}
609
610inline void XMLAttr::set(const  unsigned int        uriId
611                        , const XMLCh* const        attrRawName
612                        , const XMLCh* const        attrValue
613                        , const XMLAttDef::AttTypes type
614                        , DatatypeValidator * datatypeValidator
615                        , const bool isSchema )
616{
617    // Set the name info and the value via their respective calls
618    fAttName->setName(attrRawName, uriId);
619    setValue(attrValue);
620
621    // And store the type
622    fType = type;
623
624    // and set up info for DOM type info
625    fIsSchemaValidated = isSchema;
626    fDatatypeValidator = datatypeValidator;
627}
628
629inline void XMLAttr::setType(const XMLAttDef::AttTypes newValue)
630{
631    fType = newValue;
632}
633
634inline void XMLAttr::setSpecified(const bool newValue)
635{
636    fSpecified = newValue;
637}
638
639inline void XMLAttr::setDatatypeValidator(DatatypeValidator *datatypeValidator)
640{
641    fDatatypeValidator = datatypeValidator;
642}
643
644inline void XMLAttr::setSchemaValidated(const bool isSchema)
645{
646    fIsSchemaValidated = isSchema;
647}
648
649XERCES_CPP_NAMESPACE_END
650
651#endif
Note: See TracBrowser for help on using the repository browser.