Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:05

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLATTR_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLATTR_HPP
0024 
0025 #include <xercesc/util/PlatformUtils.hpp>
0026 #include <xercesc/util/QName.hpp>
0027 #include <xercesc/framework/XMLAttDef.hpp>
0028 #include <xercesc/validators/datatype/DatatypeValidator.hpp>
0029 
0030 XERCES_CPP_NAMESPACE_BEGIN
0031 
0032 /**
0033  *  This class defines the information about an attribute that will come out
0034  *  of the scanner during parsing. This information does not depend upon the
0035  *  type of validator because it is not tied to any scheme/DTD type info. Its
0036  *  just the raw XML 1.0 information that will be reported about an attribute
0037  *  in the startElement() callback method of the XMLDocumentHandler class.
0038  *  Hence it is not intended to be extended or derived from. Its designed to
0039  *  be used as is.
0040  *
0041  *  The 'specified' field of this class indicates whether the attribute was
0042  *  actually present or whether it was faulted in because it had a fixed or
0043  *  default value.
0044  *
0045  *  The code receiving this information can ask its validator for more info
0046  *  about the attribute, i.e. get its declaration from the DTD/Schema info.
0047  *
0048  *  Because of the heavy use (and reuse) of instances of this class, and the
0049  *  number of string members it has, this class takes pains to not reallocate
0050  *  string members unless it has to. It keeps up with how long each buffer
0051  *  is and only reallocates if the new value won't fit.
0052  */
0053 class XMLPARSER_EXPORT XMLAttr : public XMemory
0054 {
0055 public:
0056     // -----------------------------------------------------------------------
0057     //  Constructors and Destructor
0058     // -----------------------------------------------------------------------
0059     /** @name Constructors */
0060     //@{
0061 
0062     /**
0063       * The default constructor just setsup an empty attribute to be filled
0064       * in the later. Though the initial state is a reasonable one, it is
0065       * not documented because it should not be depended on.
0066       *
0067       * @param  manager     The configurable memory manager
0068       */
0069     XMLAttr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0070 
0071     /**
0072       * This is the primary constructor which takes all of the information
0073       * required to construct a complete attribute object.
0074       *
0075       * @param  uriId       The id into the validator's URI pool of the URI
0076       *                     that the prefix mapped to. Only used if namespaces
0077       *                     are enabled/supported.
0078       *
0079       * @param  attrName    The base name of the attribute, i.e. the part
0080       *                     after any prefix.
0081       *
0082       * @param  attrPrefix  The prefix, if any, of this attribute's name. If
0083       *                     this is empty, then uriID is meaningless as well.
0084       *
0085       * @param  attrValue   The value string of the attribute, which should
0086       *                     be fully normalized by XML rules!
0087       *
0088       * @param  type        The type of the attribute. This will indicate
0089       *                     the type of normalization done and constrains
0090       *                     the value content. Make sure that the value
0091       *                     set meets the constraints!
0092       *
0093       * @param  specified   Indicates whether the attribute was explicitly
0094       *                     specified or not. If not, then it was faulted
0095       *                     in from a FIXED or DEFAULT value.
0096       *
0097       * @param  manager     The configurable memory manager
0098       * @param datatypeValidator type used to validate the attribute, 
0099       *                         if it was validated by an XML Schema
0100       * @param isSchema         true if and only if this attribute was validated
0101       *                         by an XML Schema
0102       */
0103     XMLAttr
0104     (
0105           const unsigned int        uriId
0106         , const XMLCh* const        attrName
0107         , const XMLCh* const        attrPrefix
0108         , const XMLCh* const        attrValue
0109         , const XMLAttDef::AttTypes type = XMLAttDef::CData
0110         , const bool                specified = true
0111         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
0112         , DatatypeValidator * datatypeValidator = 0
0113         , const bool isSchema = false
0114     );
0115 
0116     /**
0117       * This is the primary constructor which takes all of the information
0118       * required to construct a complete attribute object.
0119       *
0120       * @param  uriId       The id into the validator's URI pool of the URI
0121       *                     that the prefix mapped to. Only used if namespaces
0122       *                     are enabled/supported.
0123       *
0124       * @param  rawName     The raw name of the attribute.
0125       *
0126       * @param  attrValue   The value string of the attribute, which should
0127       *                     be fully normalized by XML rules!
0128       *
0129       * @param  type        The type of the attribute. This will indicate
0130       *                     the type of normalization done and constrains
0131       *                     the value content. Make sure that the value
0132       *                     set meets the constraints!
0133       *
0134       * @param  specified   Indicates whether the attribute was explicitly
0135       *                     specified or not. If not, then it was faulted
0136       *                     in from a FIXED or DEFAULT value.
0137       *
0138       * @param  manager     The configurable memory manager
0139       * @param datatypeValidator type used to validate the attribute, 
0140       *                         if it was validated by an XML Schema
0141       * @param isSchema         true if and only if this attribute was validated
0142       *                         by an XML Schema
0143       */
0144     XMLAttr
0145     (
0146         const unsigned int uriId
0147         , const XMLCh* const rawName
0148         , const XMLCh* const attrValue
0149         , const XMLAttDef::AttTypes type = XMLAttDef::CData
0150         , const bool specified = true
0151         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0152         , DatatypeValidator * datatypeValidator = 0
0153         , const bool isSchema = false
0154     );
0155 
0156     //@}
0157 
0158     /** @name Destructor */
0159     //@{
0160     ~XMLAttr();
0161     //@}
0162 
0163 
0164     // -----------------------------------------------------------------------
0165     //  Getter methods
0166     // -----------------------------------------------------------------------
0167 
0168     /** @name Getter methods */
0169     //@{
0170 
0171     /**
0172       * This method returns the attribute name in a QName format.
0173       */
0174     QName* getAttName() const;
0175 
0176     /**
0177       * This method gets a const pointer to the name of the attribute. The
0178       * form of this name is defined by the validator in use.
0179       */
0180     const XMLCh* getName() const;
0181 
0182     /**
0183       * This method will get a const pointer to the prefix string of this
0184       * attribute. Since prefixes are optional, it may be zero.
0185       */
0186     const XMLCh* getPrefix() const;
0187 
0188     /**
0189       * This method will get the QName of this attribute, which will be the
0190       * prefix if any, then a colon, then the base name. If there was no
0191       * prefix, its the same as the getName() method.
0192       */
0193     const XMLCh* getQName() const;
0194 
0195     /**
0196       * This method will get the specified flag, which indicates whether
0197       * the attribute was explicitly specified or just faulted in.
0198       */
0199     bool getSpecified() const;
0200 
0201     /**
0202       * This method will get the type of the attribute. The available types
0203       * are defined by the XML specification.
0204       */
0205     XMLAttDef::AttTypes getType() const;
0206 
0207     /**
0208       * This method will get the value of the attribute. The value can be
0209       * be an empty string, but never null if the object is correctly
0210       * set up.
0211       */
0212     const XMLCh* getValue() const;
0213 
0214     /**
0215       * This method will get the id of the URI that this attribute's prefix
0216       * mapped to. If namespaces are not on, then its value is meaningless.
0217       */
0218     unsigned int getURIId() const;
0219 
0220     //@}
0221 
0222 
0223     // -----------------------------------------------------------------------
0224     //  Setter methods
0225     // -----------------------------------------------------------------------
0226 
0227     /** @name Setter methods */
0228     //@{
0229 
0230     /**
0231       * This method is called to set up a default constructed object after
0232       * the fact, or to reuse a previously used object.
0233       *
0234       * @param  uriId       The id into the validator's URI pool of the URI
0235       *                     that the prefix mapped to. Only used if namespaces
0236       *                     are enabled/supported.
0237       *
0238       * @param  attrName    The base name of the attribute, i.e. the part
0239       *                     after any prefix.
0240       *
0241       * @param  attrPrefix  The prefix, if any, of this attribute's name. If
0242       *                     this is empty, then uriID is meaningless as well.
0243       *
0244       * @param  attrValue   The value string of the attribute, which should
0245       *                     be fully normalized by XML rules according to the
0246       *                     attribute type.
0247       *
0248       * @param  type        The type of the attribute. This will indicate
0249       *                     the type of normalization done and constrains
0250       *                     the value content. Make sure that the value
0251       *                     set meets the constraints!
0252       * @param datatypeValidator type used to validate the attribute, 
0253       *                         if it was validated by an XML Schema
0254       * @param isSchema         true if and only if this attribute was validated
0255       *                         by an XML Schema
0256       *
0257       */
0258     void set
0259     (
0260         const   unsigned int        uriId
0261         , const XMLCh* const        attrName
0262         , const XMLCh* const        attrPrefix
0263         , const XMLCh* const        attrValue
0264         , const XMLAttDef::AttTypes type = XMLAttDef::CData
0265         , DatatypeValidator * datatypeValidator = 0
0266         , const bool isSchema = false
0267     );
0268 
0269     /**
0270       * This method is called to set up a default constructed object after
0271       * the fact, or to reuse a previously used object.
0272       *
0273       * @param  uriId       The id into the validator's URI pool of the URI
0274       *                     that the prefix mapped to. Only used if namespaces
0275       *                     are enabled/supported.
0276       *
0277       * @param  attrRawName The raw name of the attribute.
0278       *
0279       * @param  attrValue   The value string of the attribute, which should
0280       *                     be fully normalized by XML rules according to the
0281       *                     attribute type.
0282       *
0283       * @param  type        The type of the attribute. This will indicate
0284       *                     the type of normalization done and constrains
0285       *                     the value content. Make sure that the value
0286       *                     set meets the constraints!
0287       * @param datatypeValidator type used to validate the attribute, 
0288       *                         if it was validated by an XML Schema
0289       * @param isSchema         true if and only if this attribute was validated
0290       *                         by an XML Schema
0291       */
0292     void set
0293     (
0294         const   unsigned int        uriId
0295         , const XMLCh* const        attrRawName
0296         , const XMLCh* const        attrValue
0297         , const XMLAttDef::AttTypes type = XMLAttDef::CData
0298         , DatatypeValidator * datatypeValidator = 0
0299         , const bool isSchema = false
0300     );
0301 
0302     /**
0303       * This method will update just the name related fields of the
0304       * attribute object. The other fields are left as is.
0305       *
0306       * @param  uriId       The id into the validator's URI pool of the URI
0307       *                     that the prefix mapped to. Only used if namespaces
0308       *                     are enabled/supported.
0309       *
0310       * @param  attrName    The base name of the attribute, i.e. the part
0311       *                     after any prefix.
0312       *
0313       * @param  attrPrefix  The prefix, if any, of this attribute's name. If
0314       *                     this is empty, then uriID is meaningless as well.
0315       */
0316     void setName
0317     (
0318         const   unsigned int        uriId
0319         , const XMLCh* const        attrName
0320         , const XMLCh* const        attrPrefix
0321     );
0322 
0323     /**
0324       * This method will update the specified state of the object.
0325       *
0326       * @param  newValue    Indicates whether the attribute was explicitly
0327       *                     specified or not. If not, then it was faulted
0328       *                     in from a FIXED or DEFAULT value.
0329       */
0330     void setSpecified(const bool newValue);
0331 
0332     /**
0333       * This method will update the attribute type of the object.
0334       *
0335       * @param  newType     The type of the attribute. This will indicate
0336       *                     the type of normalization done and constrains
0337       *                     the value content. Make sure that the value
0338       *                     set meets the constraints!
0339       */
0340     void setType(const XMLAttDef::AttTypes newType);
0341 
0342     /**
0343       * This method will update the value field of the attribute.
0344       *
0345       * @param  newValue    The value string of the attribute, which should
0346       *                     be fully normalized by XML rules according to the
0347       *                     attribute type.
0348       */
0349     void setValue(const XMLCh* const newValue);
0350 
0351     /**
0352       * This method will set the URI id field of this attribute. This is
0353       * generally only ever called internally by the parser itself during
0354       * the parsing process.
0355       *
0356       * @param  uriId       The uriId of the attribute.
0357       */
0358     void setURIId(const unsigned int uriId);
0359 
0360     //@}
0361 
0362 
0363 
0364 private :
0365     // -----------------------------------------------------------------------
0366     //  Unimplemented constructors and operators
0367     // -----------------------------------------------------------------------
0368     XMLAttr(const XMLAttr&);
0369     XMLAttr& operator=(const XMLAttr&);
0370 
0371 
0372     // -----------------------------------------------------------------------
0373     //  Private, helper methods
0374     // -----------------------------------------------------------------------
0375     void cleanUp();
0376 
0377 
0378     // -----------------------------------------------------------------------
0379     //  Private instance variables
0380     //
0381     //  fAttName
0382     //      The Attribute Name;
0383     //
0384     //  fSpecified
0385     //      True if this attribute appeared in the element; else, false if
0386     //      it was defaulted from an AttDef.
0387     //
0388     //  fType
0389     //      The attribute type enum value for this attribute. Indicates what
0390     //      type of attribute it was.
0391     //
0392     //  fValue
0393     //  fValueBufSz
0394     //      The attribute value that was given in the attribute instance, and
0395     //      its current buffer size (minus one, where the null is.)
0396     //
0397     //  fMemoryManager
0398     //      The memory manager used for dynamic memory allocation/deallocation
0399     // -----------------------------------------------------------------------
0400     bool                fSpecified;
0401     XMLAttDef::AttTypes fType;
0402     XMLSize_t           fValueBufSz;
0403     XMLCh*              fValue;
0404     QName*              fAttName;
0405     MemoryManager*      fMemoryManager;   
0406 };
0407 
0408 // ---------------------------------------------------------------------------
0409 //  XMLAttr: Constructors and Destructor
0410 // ---------------------------------------------------------------------------
0411 inline XMLAttr::~XMLAttr()
0412 {
0413     cleanUp();
0414 }
0415 
0416 
0417 // ---------------------------------------------------------------------------
0418 //  XMLAttr: Getter methods
0419 // ---------------------------------------------------------------------------
0420 inline QName* XMLAttr::getAttName() const
0421 {
0422     return fAttName;
0423 }
0424 
0425 inline const XMLCh* XMLAttr::getName() const
0426 {
0427     return fAttName->getLocalPart();
0428 }
0429 
0430 inline const XMLCh* XMLAttr::getPrefix() const
0431 {
0432     return fAttName->getPrefix();
0433 }
0434 
0435 inline bool XMLAttr::getSpecified() const
0436 {
0437     return fSpecified;
0438 }
0439 
0440 inline XMLAttDef::AttTypes XMLAttr::getType() const
0441 {
0442     return fType;
0443 }
0444 
0445 inline const XMLCh* XMLAttr::getValue() const
0446 {
0447     return fValue;
0448 }
0449 
0450 inline unsigned int XMLAttr::getURIId() const
0451 {
0452     return fAttName->getURI();
0453 }
0454 
0455 // ---------------------------------------------------------------------------
0456 //  XMLAttr: Setter methods
0457 // ---------------------------------------------------------------------------
0458 inline void XMLAttr::set(const  unsigned int        uriId
0459                         , const XMLCh* const        attrName
0460                         , const XMLCh* const        attrPrefix
0461                         , const XMLCh* const        attrValue
0462                         , const XMLAttDef::AttTypes type
0463                         , DatatypeValidator * /*datatypeValidator */
0464                         , const bool /*isSchema*/ )
0465 {
0466     // Set the name info and the value via their respective calls
0467     fAttName->setName(attrPrefix, attrName, uriId);
0468     setValue(attrValue);
0469 
0470     // And store the type
0471     fType = type;
0472 }
0473 
0474 inline void XMLAttr::set(const  unsigned int        uriId
0475                         , const XMLCh* const        attrRawName
0476                         , const XMLCh* const        attrValue
0477                         , const XMLAttDef::AttTypes type
0478                         , DatatypeValidator * /*datatypeValidator */
0479                         , const bool /*isSchema*/ )
0480 {
0481     // Set the name info and the value via their respective calls
0482     fAttName->setName(attrRawName, uriId);
0483     setValue(attrValue);
0484 
0485     // And store the type
0486     fType = type;
0487 }
0488 
0489 inline void XMLAttr::setType(const XMLAttDef::AttTypes newValue)
0490 {
0491     fType = newValue;
0492 }
0493 
0494 inline void XMLAttr::setSpecified(const bool newValue)
0495 {
0496     fSpecified = newValue;
0497 }
0498 
0499 XERCES_CPP_NAMESPACE_END
0500 
0501 #endif