XMLAttr.hpp

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XMLAttr.hpp 568078 2007-08-21 11:43:25Z amassari $
00020  */
00021 
00022 #if !defined(XMLATTR_HPP)
00023 #define XMLATTR_HPP
00024 
00025 #include <xercesc/util/PlatformUtils.hpp>
00026 #include <xercesc/util/QName.hpp>
00027 #include <xercesc/framework/XMLAttDef.hpp>
00028 #include <xercesc/validators/datatype/DatatypeValidator.hpp>
00029 
00030 XERCES_CPP_NAMESPACE_BEGIN
00031 
00053 class XMLPARSER_EXPORT XMLAttr : public XMemory
00054 {
00055 public:
00056     // -----------------------------------------------------------------------
00057     //  Constructors and Destructor
00058     // -----------------------------------------------------------------------
00061 
00069     XMLAttr(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00070 
00103     XMLAttr
00104     (
00105           const unsigned int        uriId
00106         , const XMLCh* const        attrName
00107         , const XMLCh* const        attrPrefix
00108         , const XMLCh* const        attrValue
00109         , const XMLAttDef::AttTypes type = XMLAttDef::CData
00110         , const bool                specified = true
00111         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
00112         , DatatypeValidator * datatypeValidator = 0
00113         , const bool isSchema = false
00114     );
00115 
00144     XMLAttr
00145     (
00146         const unsigned int uriId
00147         , const XMLCh* const rawName
00148         , const XMLCh* const attrValue
00149         , const XMLAttDef::AttTypes type = XMLAttDef::CData
00150         , const bool specified = true
00151         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00152         , DatatypeValidator * datatypeValidator = 0
00153         , const bool isSchema = false
00154     );
00155 
00157 
00160     ~XMLAttr();
00162 
00163 
00164     // -----------------------------------------------------------------------
00165     //  Getter methods
00166     // -----------------------------------------------------------------------
00167 
00170 
00174     QName* getAttName() const;
00175 
00180     const XMLCh* getName() const;
00181 
00186     const XMLCh* getPrefix() const;
00187 
00193     const XMLCh* getQName() const;
00194 
00199     bool getSpecified() const;
00200 
00205     XMLAttDef::AttTypes getType() const;
00206 
00212     const XMLCh* getValue() const;
00213 
00218     unsigned int getURIId() const;
00219 
00224     const XMLCh* getValidatingTypeURI() const;
00225 
00230     const XMLCh* getValidatingTypeName() const;
00231 
00233 
00234 
00235     // -----------------------------------------------------------------------
00236     //  Setter methods
00237     // -----------------------------------------------------------------------
00238 
00241 
00270     void set
00271     (
00272         const   unsigned int        uriId
00273         , const XMLCh* const        attrName
00274         , const XMLCh* const        attrPrefix
00275         , const XMLCh* const        attrValue
00276         , const XMLAttDef::AttTypes type = XMLAttDef::CData
00277         , DatatypeValidator * datatypeValidator = 0
00278         , const bool isSchema = false
00279     );
00280 
00304     void set
00305     (
00306         const   unsigned int        uriId
00307         , const XMLCh* const        attrRawName
00308         , const XMLCh* const        attrValue
00309         , const XMLAttDef::AttTypes type = XMLAttDef::CData
00310         , DatatypeValidator * datatypeValidator = 0
00311         , const bool isSchema = false
00312     );
00313 
00328     void setName
00329     (
00330         const   unsigned int        uriId
00331         , const XMLCh* const        attrName
00332         , const XMLCh* const        attrPrefix
00333     );
00334 
00342     void setSpecified(const bool newValue);
00343 
00352     void setType(const XMLAttDef::AttTypes newType);
00353 
00361     void setValue(const XMLCh* const newValue);
00362 
00370     void setURIId(const unsigned int uriId);
00371 
00379     void setDatatypeValidator(DatatypeValidator * datatypeValidator);
00380 
00388     void setSchemaValidated(const bool isSchema);
00389 
00391 
00392 
00393 
00394 private :
00395     // -----------------------------------------------------------------------
00396     //  Unimplemented constructors and operators
00397     // -----------------------------------------------------------------------
00398     XMLAttr(const XMLAttr&);
00399     XMLAttr& operator=(const XMLAttr&);
00400 
00401 
00402     // -----------------------------------------------------------------------
00403     //  Private, helper methods
00404     // -----------------------------------------------------------------------
00405     void cleanUp();
00406 
00407 
00408     // -----------------------------------------------------------------------
00409     //  Private instance variables
00410     //
00411     //  fAttName
00412     //      The Attribute Name;
00413     //
00414     //  fSpecified
00415     //      True if this attribute appeared in the element; else, false if
00416     //      it was defaulted from an AttDef.
00417     //
00418     //  fType
00419     //      The attribute type enum value for this attribute. Indicates what
00420     //      type of attribute it was.
00421     //
00422     //  fValue
00423     //  fValueBufSz
00424     //      The attribute value that was given in the attribute instance, and
00425     //      its current buffer size (minus one, where the null is.)
00426     //
00427     //  fMemoryManager
00428     //      The memory manager used for dynamic memory allocation/deallocation
00429     //  fDatatypeValidator
00430     //      The validator used to validate the value of this attribute.
00431     //      The attribute does not own this object, and it is only
00432     //      used in the calculation of DOMTypeInfo information.
00433     //  fIsSchemaValidated
00434     //      whether this attribute was validated by an XML Schema
00435     //
00436     // -----------------------------------------------------------------------
00437     bool                fSpecified;
00438     XMLAttDef::AttTypes fType;
00439     unsigned int        fValueBufSz;
00440     XMLCh*              fValue;
00441     QName*              fAttName;
00442     MemoryManager*      fMemoryManager;
00443     DatatypeValidator * fDatatypeValidator;
00444     bool                fIsSchemaValidated;
00445 };
00446 
00447 // ---------------------------------------------------------------------------
00448 //  XMLAttr: Constructors and Destructor
00449 // ---------------------------------------------------------------------------
00450 inline XMLAttr::~XMLAttr()
00451 {
00452     cleanUp();
00453 }
00454 
00455 
00456 // ---------------------------------------------------------------------------
00457 //  XMLAttr: Getter methods
00458 // ---------------------------------------------------------------------------
00459 inline QName* XMLAttr::getAttName() const
00460 {
00461     return fAttName;
00462 }
00463 
00464 inline const XMLCh* XMLAttr::getName() const
00465 {
00466     return fAttName->getLocalPart();
00467 }
00468 
00469 inline const XMLCh* XMLAttr::getPrefix() const
00470 {
00471     return fAttName->getPrefix();
00472 }
00473 
00474 inline bool XMLAttr::getSpecified() const
00475 {
00476     return fSpecified;
00477 }
00478 
00479 inline XMLAttDef::AttTypes XMLAttr::getType() const
00480 {
00481     return fType;
00482 }
00483 
00484 inline const XMLCh* XMLAttr::getValue() const
00485 {
00486     return fValue;
00487 }
00488 
00489 inline unsigned int XMLAttr::getURIId() const
00490 {
00491     return fAttName->getURI();
00492 }
00493 
00494 inline const XMLCh* XMLAttr::getValidatingTypeName() const
00495 {
00496     if(fIsSchemaValidated)
00497     {
00498         if(!fDatatypeValidator || fDatatypeValidator->getAnonymous())
00499             return 0; 
00500         return fDatatypeValidator->getTypeLocalName();
00501     }
00502     else
00503     {
00504         return XMLAttDef::getAttTypeString(fType, fMemoryManager);
00505     }
00506 }
00507 
00508 inline const XMLCh* XMLAttr::getValidatingTypeURI() const
00509 {
00510     if(fIsSchemaValidated)
00511     {
00512         if(!fDatatypeValidator || fDatatypeValidator->getAnonymous())
00513             return 0; 
00514         return fDatatypeValidator->getTypeUri();
00515     }
00516     else
00517     {
00518         return 0;
00519     }
00520 }
00521 
00522 // ---------------------------------------------------------------------------
00523 //  XMLAttr: Setter methods
00524 // ---------------------------------------------------------------------------
00525 inline void XMLAttr::set(const  unsigned int        uriId
00526                         , const XMLCh* const        attrName
00527                         , const XMLCh* const        attrPrefix
00528                         , const XMLCh* const        attrValue
00529                         , const XMLAttDef::AttTypes type
00530                         , DatatypeValidator * datatypeValidator 
00531                         , const bool isSchema )
00532 {
00533     // Set the name info and the value via their respective calls
00534     fAttName->setName(attrPrefix, attrName, uriId);
00535     setValue(attrValue);
00536 
00537     // And store the type
00538     fType = type;
00539 
00540     // and set up info for DOM type info 
00541     fIsSchemaValidated = isSchema;
00542     fDatatypeValidator = datatypeValidator;
00543 }
00544 
00545 inline void XMLAttr::set(const  unsigned int        uriId
00546                         , const XMLCh* const        attrRawName
00547                         , const XMLCh* const        attrValue
00548                         , const XMLAttDef::AttTypes type
00549                         , DatatypeValidator * datatypeValidator 
00550                         , const bool isSchema )
00551 {
00552     // Set the name info and the value via their respective calls
00553     fAttName->setName(attrRawName, uriId);
00554     setValue(attrValue);
00555 
00556     // And store the type
00557     fType = type;
00558 
00559     // and set up info for DOM type info 
00560     fIsSchemaValidated = isSchema;
00561     fDatatypeValidator = datatypeValidator;
00562 }
00563 
00564 inline void XMLAttr::setType(const XMLAttDef::AttTypes newValue)
00565 {
00566     fType = newValue;
00567 }
00568 
00569 inline void XMLAttr::setSpecified(const bool newValue)
00570 {
00571     fSpecified = newValue;
00572 }
00573 
00574 inline void XMLAttr::setDatatypeValidator(DatatypeValidator *datatypeValidator)
00575 {
00576     fDatatypeValidator = datatypeValidator;
00577 }
00578 
00579 inline void XMLAttr::setSchemaValidated(const bool isSchema)
00580 {
00581     fIsSchemaValidated = isSchema;
00582 }
00583 
00584 XERCES_CPP_NAMESPACE_END
00585 
00586 #endif

Generated on Thu Feb 19 11:35:44 2009 for Xerces-C++ by  doxygen 1.5.4