# XMLAttDef.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: XMLAttDef.hpp 676911 2008-07-15 13:27:32Z amassari $
    00020  */
    00021
    00022 #if !defined(XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP)
    00023 #define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP
    00024
    00025 #include <xercesc/util/PlatformUtils.hpp>
    00026 #include <xercesc/util/XMLString.hpp>
    00027 #include <xercesc/util/XMemory.hpp>
    00028 #include <xercesc/internal/XSerializable.hpp>
    00029
    00030 XERCES_CPP_NAMESPACE_BEGIN
    00031
    00032 class XMLAttr;
    00033
    00052 class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory
    00053 {
    00054 public:
    00055     // -----------------------------------------------------------------------
    00056     //  Class specific types
    00057     //
    00058     //  AttTypes
    00059     //      The list of possible types that an attribute can have, according
    00060     //      to the XML 1.0 spec and schema.
    00061     //
    00062     //  DefAttTypes
    00063     //      The modifiers that an attribute decl can have, which indicates
    00064     //      whether instances of that attributes are required, implied, etc..
    00065     //
    00066     //  CreateReasons
    00067     //      This type is used to store how an attribute declaration got into
    00068     //      the elementdecl's attribute pool.
    00069     //
    00070     // -----------------------------------------------------------------------
    00071     enum AttTypes
    00072     {
    00073         CData               = 0
    00074         , ID                = 1
    00075         , IDRef             = 2
    00076         , IDRefs            = 3
    00077         , Entity            = 4
    00078         , Entities          = 5
    00079         , NmToken           = 6
    00080         , NmTokens          = 7
    00081         , Notation          = 8
    00082         , Enumeration       = 9
    00083         , Simple            = 10
    00084         , Any_Any           = 11
    00085         , Any_Other         = 12
    00086         , Any_List          = 13
    00087
    00088         , AttTypes_Count
    00089         , AttTypes_Min      = 0
    00090         , AttTypes_Max      = 13
    00091         , AttTypes_Unknown  = -1
    00092     };
    00093
    00094     enum DefAttTypes
    00095     {
    00096         Default                  = 0
    00097         , Fixed                  = 1
    00098         , Required               = 2
    00099         , Required_And_Fixed     = 3
    00100         , Implied                = 4
    00101         , ProcessContents_Skip   = 5
    00102         , ProcessContents_Lax    = 6
    00103         , ProcessContents_Strict = 7
    00104         , Prohibited             = 8
    00105
    00106         , DefAttTypes_Count
    00107         , DefAttTypes_Min   = 0
    00108         , DefAttTypes_Max   = 8
    00109         , DefAttTypes_Unknown = -1
    00110     };
    00111
    00112     enum CreateReasons
    00113     {
    00114         NoReason
    00115         , JustFaultIn
    00116     };
    00117
    00118     // -----------------------------------------------------------------------
    00119     //  Public static data members
    00120     // -----------------------------------------------------------------------
    00121     static const unsigned int fgInvalidAttrId;
    00122
    00123
    00124     // -----------------------------------------------------------------------
    00125     //  Public, static methods
    00126     // -----------------------------------------------------------------------
    00127
    00130
    00141     static const XMLCh* getAttTypeString(const AttTypes attrType
    00142         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00143
    00154     static const XMLCh* getDefAttTypeString(const DefAttTypes attrType
    00155         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00156
    00158
    00159
    00160     // -----------------------------------------------------------------------
    00161     //  Destructor
    00162     // -----------------------------------------------------------------------
    00163
    00166
    00170     virtual ~XMLAttDef();
    00172
    00173
    00174     // -----------------------------------------------------------------------
    00175     //  The virtual attribute def interface
    00176     // -----------------------------------------------------------------------
    00177
    00180
    00189     virtual const XMLCh* getFullName() const = 0;
    00190
    00195     virtual void reset() = 0;
    00196
    00198
    00199
    00200     // -----------------------------------------------------------------------
    00201     //  Getter methods
    00202     // -----------------------------------------------------------------------
    00203
    00206
    00215     DefAttTypes getDefaultType() const;
    00216
    00226     const XMLCh* getEnumeration() const;
    00227
    00236     XMLSize_t getId() const;
    00237
    00247     AttTypes getType() const;
    00248
    00258     const XMLCh* getValue() const;
    00259
    00268     CreateReasons getCreateReason() const;
    00269
    00277     bool isExternal() const;
    00278
    00286     MemoryManager* getMemoryManager() const;
    00287
    00289
    00290
    00291     // -----------------------------------------------------------------------
    00292     //  Setter methods
    00293     // -----------------------------------------------------------------------
    00294
    00297
    00306     void setDefaultType(const XMLAttDef::DefAttTypes newValue);
    00307
    00316     void setId(const XMLSize_t newId);
    00317
    00325     void setType(const XMLAttDef::AttTypes newValue);
    00326
    00337     void setValue(const XMLCh* const newValue);
    00338
    00349     void setEnumeration(const XMLCh* const newValue);
    00350
    00358     void setCreateReason(const CreateReasons newReason);
    00359
    00365     void setExternalAttDeclaration(const bool aValue);
    00366
    00368
    00369     /***
    00370      * Support for Serialization/De-serialization
    00371      ***/
    00372     DECL_XSERIALIZABLE(XMLAttDef)
    00373
    00374 protected :
    00375     // -----------------------------------------------------------------------
    00376     //  Hidden constructors
    00377     // -----------------------------------------------------------------------
    00378     XMLAttDef
    00379     (
    00380         const   AttTypes       type = CData
    00381         , const DefAttTypes    defType= Implied
    00382         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00383     );
    00384     XMLAttDef
    00385     (
    00386         const   XMLCh* const        attValue
    00387         , const AttTypes            type
    00388         , const DefAttTypes         defType
    00389         , const XMLCh* const        enumValues = 0
    00390         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00391     );
    00392
    00393
    00394 private :
    00395     // -----------------------------------------------------------------------
    00396     //  Unimplemented constructors and operators
    00397     // -----------------------------------------------------------------------
    00398     XMLAttDef(const XMLAttDef&);
    00399     XMLAttDef& operator=(const XMLAttDef&);
    00400
    00401
    00402     // -----------------------------------------------------------------------
    00403     //  Private helper methods
    00404     // -----------------------------------------------------------------------
    00405     void cleanUp();
    00406
    00407
    00408     // -----------------------------------------------------------------------
    00409     //  Private data members
    00410     //
    00411     //  fDefaultType
    00412     //      Indicates what, if any, default stuff this attribute has.
    00413     //
    00414     //  fEnumeration
    00415     //      If its an enumeration, this is the list of values as space
    00416     //      separated values.
    00417     //
    00418     //  fId
    00419     //      This is the unique id of this attribute, given to it when its put
    00420     //      into the validator's attribute decl pool. It defaults to the
    00421     //      special value XMLAttrDef::fgInvalidAttrId.
    00422     //
    00423     //  fType
    00424     //      The type of attribute, which is one of the AttTypes values.
    00425     //
    00426     //  fValue
    00427     //      This is the value of the attribute, which is the default value
    00428     //      given in the attribute declaration.
    00429     //
    00430     //  fCreateReason
    00431     //      This flag tells us how this attribute got created.  Sometimes even
    00432     //      the attribute was not declared for the element, we want to fault
    00433     //      fault it into the pool to avoid lots of redundant errors.
    00434     //
    00435     //  fExternalAttribute
    00436     //      This flag indicates whether or not the attribute was declared externally.
    00437     // -----------------------------------------------------------------------
    00438     DefAttTypes     fDefaultType;
    00439     AttTypes        fType;
    00440     CreateReasons   fCreateReason;
    00441     bool            fExternalAttribute;
    00442     XMLSize_t       fId;
    00443     XMLCh*          fValue;
    00444     XMLCh*          fEnumeration;
    00445     MemoryManager*  fMemoryManager;
    00446 };
    00447
    00448
    00449 // ---------------------------------------------------------------------------
    00450 //  Getter methods
    00451 // ---------------------------------------------------------------------------
    00452 inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
    00453 {
    00454     return fDefaultType;
    00455 }
    00456
    00457 inline const XMLCh* XMLAttDef::getEnumeration() const
    00458 {
    00459     return fEnumeration;
    00460 }
    00461
    00462 inline XMLSize_t XMLAttDef::getId() const
    00463 {
    00464     return fId;
    00465 }
    00466
    00467 inline XMLAttDef::AttTypes XMLAttDef::getType() const
    00468 {
    00469     return fType;
    00470 }
    00471
    00472 inline const XMLCh* XMLAttDef::getValue() const
    00473 {
    00474     return fValue;
    00475 }
    00476
    00477 inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
    00478 {
    00479     return fCreateReason;
    00480 }
    00481
    00482 inline bool XMLAttDef::isExternal() const
    00483 {
    00484     return fExternalAttribute;
    00485 }
    00486
    00487 inline MemoryManager* XMLAttDef::getMemoryManager() const
    00488 {
    00489     return fMemoryManager;
    00490 }
    00491
    00492 // ---------------------------------------------------------------------------
    00493 //  XMLAttDef: Setter methods
    00494 // ---------------------------------------------------------------------------
    00495 inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
    00496 {
    00497     fDefaultType = newValue;
    00498 }
    00499
    00500 inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
    00501 {
    00502     if (fEnumeration)
    00503         fMemoryManager->deallocate(fEnumeration);
    00504
    00505     fEnumeration = XMLString::replicate(newValue, fMemoryManager);
    00506 }
    00507
    00508 inline void XMLAttDef::setId(const XMLSize_t newId)
    00509 {
    00510     fId = newId;
    00511 }
    00512
    00513 inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
    00514 {
    00515     fType = newValue;
    00516 }
    00517
    00518 inline void XMLAttDef::setValue(const XMLCh* const newValue)
    00519 {
    00520     if (fValue)
    00521        fMemoryManager->deallocate(fValue);
    00522
    00523     fValue = XMLString::replicate(newValue, fMemoryManager);
    00524 }
    00525
    00526 inline void
    00527 XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
    00528 {
    00529     fCreateReason = newReason;
    00530 }
    00531
    00532 inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
    00533 {
    00534     fExternalAttribute = aValue;
    00535 }
    00536
    00537 XERCES_CPP_NAMESPACE_END
    00538
    00539 #endif