|
||||
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_XMLATTDEF_HPP) 0023 #define XERCESC_INCLUDE_GUARD_XMLATTDEF_HPP 0024 0025 #include <xercesc/util/PlatformUtils.hpp> 0026 #include <xercesc/util/XMLString.hpp> 0027 #include <xercesc/util/XMemory.hpp> 0028 #include <xercesc/internal/XSerializable.hpp> 0029 0030 XERCES_CPP_NAMESPACE_BEGIN 0031 0032 class XMLAttr; 0033 0034 /** Represents the core information of an attribute definition 0035 * 0036 * This class defines the basic characteristics of an attribute, no matter 0037 * what type of validator is used. If a particular schema associates more 0038 * information with an attribute it will create a derivative of this class. 0039 * So this class provides an abstract way to get basic information on 0040 * attributes from any type of validator. 0041 * 0042 * This class supports keyed collection semantics on the fully qualified 0043 * attribute name, by providing a getKey() method to extract the key string. 0044 * getKey(), in this case, just calls the virtual method getFullName() to 0045 * get the fully qualified name, as defined by the derived class. 0046 * 0047 * Note that the 'value' of an attribute type definition is the default or 0048 * of fixed value given to it in its definition. If the attribute is of the 0049 * enumerated or notation type, it will have an 'enumeration value' as well 0050 * which is a space separated list of its possible vlaues. 0051 */ 0052 class XMLPARSER_EXPORT XMLAttDef : public XSerializable, public XMemory 0053 { 0054 public: 0055 // ----------------------------------------------------------------------- 0056 // Class specific types 0057 // 0058 // AttTypes 0059 // The list of possible types that an attribute can have, according 0060 // to the XML 1.0 spec and schema. 0061 // 0062 // DefAttTypes 0063 // The modifiers that an attribute decl can have, which indicates 0064 // whether instances of that attributes are required, implied, etc.. 0065 // 0066 // CreateReasons 0067 // This type is used to store how an attribute declaration got into 0068 // the elementdecl's attribute pool. 0069 // 0070 // ----------------------------------------------------------------------- 0071 enum AttTypes 0072 { 0073 CData = 0 0074 , ID = 1 0075 , IDRef = 2 0076 , IDRefs = 3 0077 , Entity = 4 0078 , Entities = 5 0079 , NmToken = 6 0080 , NmTokens = 7 0081 , Notation = 8 0082 , Enumeration = 9 0083 , Simple = 10 0084 , Any_Any = 11 0085 , Any_Other = 12 0086 , Any_List = 13 0087 0088 , AttTypes_Count 0089 , AttTypes_Min = 0 0090 , AttTypes_Max = 13 0091 , AttTypes_Unknown = -1 0092 }; 0093 0094 enum DefAttTypes 0095 { 0096 Default = 0 0097 , Fixed = 1 0098 , Required = 2 0099 , Required_And_Fixed = 3 0100 , Implied = 4 0101 , ProcessContents_Skip = 5 0102 , ProcessContents_Lax = 6 0103 , ProcessContents_Strict = 7 0104 , Prohibited = 8 0105 0106 , DefAttTypes_Count 0107 , DefAttTypes_Min = 0 0108 , DefAttTypes_Max = 8 0109 , DefAttTypes_Unknown = -1 0110 }; 0111 0112 enum CreateReasons 0113 { 0114 NoReason 0115 , JustFaultIn 0116 }; 0117 0118 // ----------------------------------------------------------------------- 0119 // Public static data members 0120 // ----------------------------------------------------------------------- 0121 static const unsigned int fgInvalidAttrId; 0122 0123 0124 // ----------------------------------------------------------------------- 0125 // Public, static methods 0126 // ----------------------------------------------------------------------- 0127 0128 /** @name Public, static methods */ 0129 //@{ 0130 0131 /** Get a string representation of the passed attribute type enum 0132 * 0133 * This method allows you to get a textual representation of an attribute 0134 * type, mostly for debug or display. 0135 * 0136 * @param attrType The attribute type value to get the string for. 0137 * @param manager The MemoryManager to use to allocate objects 0138 * @return A const pointer to the static string that holds the text 0139 * description of the passed type. 0140 */ 0141 static const XMLCh* getAttTypeString(const AttTypes attrType 0142 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0143 0144 /** Get a string representation of the passed def attribute type enum 0145 * 0146 * This method allows you to get a textual representation of an default 0147 * attributetype, mostly for debug or display. 0148 * 0149 * @param attrType The default attribute type value to get the string for. 0150 * @param manager The MemoryManager to use to allocate objects 0151 * @return A const pointer to the static string that holds the text 0152 * description of the passed default type. 0153 */ 0154 static const XMLCh* getDefAttTypeString(const DefAttTypes attrType 0155 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0156 0157 //@} 0158 0159 0160 // ----------------------------------------------------------------------- 0161 // Destructor 0162 // ----------------------------------------------------------------------- 0163 0164 /** @name Destructor */ 0165 //@{ 0166 0167 /** 0168 * Destructor 0169 */ 0170 virtual ~XMLAttDef(); 0171 //@} 0172 0173 0174 // ----------------------------------------------------------------------- 0175 // The virtual attribute def interface 0176 // ----------------------------------------------------------------------- 0177 0178 /** @name Virtual interface */ 0179 //@{ 0180 0181 /** Get the full name of this attribute type 0182 * 0183 * The derived class should return a const pointer to the full name of 0184 * this attribute. This will vary depending on the type of validator in 0185 * use. 0186 * 0187 * @return A const pointer to the full name of this attribute type. 0188 */ 0189 virtual const XMLCh* getFullName() const = 0; 0190 0191 /** 0192 * The derived class should implement any cleaning up required between 0193 * each use of an instance of this class for validation 0194 */ 0195 virtual void reset() = 0; 0196 0197 //@} 0198 0199 0200 // ----------------------------------------------------------------------- 0201 // Getter methods 0202 // ----------------------------------------------------------------------- 0203 0204 /** @name Getter methods */ 0205 //@{ 0206 0207 /** Get the default type of this attribute type 0208 * 0209 * This method returns the 'default type' of the attribute. Default 0210 * type in this case refers to the XML concept of a default type for 0211 * an attribute, i.e. \#FIXED, \#IMPLIED, etc... 0212 * 0213 * @return The default type enum for this attribute type. 0214 */ 0215 DefAttTypes getDefaultType() const; 0216 0217 /** Get the enumeration value (if any) of this attribute type 0218 * 0219 * If the attribute is of an enumeration or notation type, then this 0220 * method will return a const reference to a string that contains the 0221 * space separated values that can the attribute can have. 0222 * 0223 * @return A const pointer to a string that contains the space separated 0224 * legal values for this attribute. 0225 */ 0226 const XMLCh* getEnumeration() const; 0227 0228 /** Get the pool id of this attribute type 0229 * 0230 * This method will return the id of this attribute in the validator's 0231 * attribute pool. It was set by the validator when this attribute was 0232 * created. 0233 * 0234 * @return The pool id of this attribute type. 0235 */ 0236 XMLSize_t getId() const; 0237 0238 /** Get the type of this attribute 0239 * 0240 * Gets the type of this attribute. This type is represented by an enum 0241 * that converts the types of attributes allowed by XML, e.g. CDATA, NMTOKEN, 0242 * NOTATION, etc... 0243 * 0244 * @return The attribute type enumeration value for this type of 0245 * attribute. 0246 */ 0247 AttTypes getType() const; 0248 0249 /** Get the default/fixed value of this attribute (if any.) 0250 * 0251 * If the attribute defined a default/fixed value, then it is stored 0252 * and this method will retrieve it. If it has non, then a null pointer 0253 * is returned. 0254 * 0255 * @return A const pointer to the default/fixed value for this attribute 0256 * type. 0257 */ 0258 const XMLCh* getValue() const; 0259 0260 /** Get the create reason for this attribute 0261 * 0262 * This method returns an enumeration which indicates why this attribute 0263 * declaration exists. 0264 * 0265 * @return An enumerated value that indicates the reason why this attribute 0266 * was added to the attribute table. 0267 */ 0268 CreateReasons getCreateReason() const; 0269 0270 /** Indicate whether this attribute has been declared externally 0271 * 0272 * This method returns a boolean that indicates whether this attribute 0273 * has been declared externally. 0274 * 0275 * @return true if this attribute has been declared externally, else false. 0276 */ 0277 bool isExternal() const; 0278 0279 /** Get the plugged-in memory manager 0280 * 0281 * This method returns the plugged-in memory manager user for dynamic 0282 * memory allocation/deallocation. 0283 * 0284 * @return the plugged-in memory manager 0285 */ 0286 MemoryManager* getMemoryManager() const; 0287 0288 //@} 0289 0290 0291 // ----------------------------------------------------------------------- 0292 // Setter methods 0293 // ----------------------------------------------------------------------- 0294 0295 /** @name Setter methods */ 0296 //@{ 0297 0298 /** Set the default attribute type 0299 * 0300 * This method sets the default attribute type for this attribute. 0301 * This setting controls whether the attribute is required, fixed, 0302 * implied, etc... 0303 * 0304 * @param newValue The new default attribute to set 0305 */ 0306 void setDefaultType(const XMLAttDef::DefAttTypes newValue); 0307 0308 /** Set the pool id for this attribute type. 0309 * 0310 * This method sets the pool id of this attribute type. This is usually 0311 * called by the validator that creates the actual instance (which is of 0312 * a derived type known only by the validator.) 0313 * 0314 * @param newId The new pool id to set. 0315 */ 0316 void setId(const XMLSize_t newId); 0317 0318 /** Set the type of this attribute type. 0319 * 0320 * This method will set the type of the attribute. The type of an attribute 0321 * controls how it is normalized and what kinds of characters it can hold. 0322 * 0323 * @param newValue The new attribute type to set 0324 */ 0325 void setType(const XMLAttDef::AttTypes newValue); 0326 0327 /** Set the default/fixed value of this attribute type. 0328 * 0329 * This method set the fixed/default value for the attribute. This value 0330 * will be used when instances of this attribute type are faulted in. It 0331 * <b>must</b> be a valid value for the type set by setType(). If the 0332 * type is enumeration or notation, this must be one of the valid values 0333 * set in the setEnumeration() call. 0334 * 0335 * @param newValue The new fixed/default value to set. 0336 */ 0337 void setValue(const XMLCh* const newValue); 0338 0339 /** Set the enumerated value of this attribute type. 0340 * 0341 * This method sets the enumerated/notation value list for this attribute 0342 * type. It is a space separated set of possible values. These values must 0343 * meet the constrains of the XML spec for such values of this type of 0344 * attribute. This should only be set if the setType() method is used to 0345 * set the type to the enumeration or notation types. 0346 * 0347 * @param newValue The new enumerated/notation value list to set. 0348 */ 0349 void setEnumeration(const XMLCh* const newValue); 0350 0351 /** Update the create reason for this attribute type. 0352 * 0353 * This method will update the 'create reason' field for this attribute 0354 * decl object. 0355 * 0356 * @param newReason The new create reason. 0357 */ 0358 void setCreateReason(const CreateReasons newReason); 0359 0360 /** 0361 * Set the attribute decl to indicate external declaration 0362 * 0363 * @param aValue The new value to indicate external declaration. 0364 */ 0365 void setExternalAttDeclaration(const bool aValue); 0366 0367 //@} 0368 0369 /*** 0370 * Support for Serialization/De-serialization 0371 ***/ 0372 DECL_XSERIALIZABLE(XMLAttDef) 0373 0374 protected : 0375 // ----------------------------------------------------------------------- 0376 // Hidden constructors 0377 // ----------------------------------------------------------------------- 0378 XMLAttDef 0379 ( 0380 const AttTypes type = CData 0381 , const DefAttTypes defType= Implied 0382 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0383 ); 0384 XMLAttDef 0385 ( 0386 const XMLCh* const attValue 0387 , const AttTypes type 0388 , const DefAttTypes defType 0389 , const XMLCh* const enumValues = 0 0390 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager 0391 ); 0392 0393 0394 private : 0395 // ----------------------------------------------------------------------- 0396 // Unimplemented constructors and operators 0397 // ----------------------------------------------------------------------- 0398 XMLAttDef(const XMLAttDef&); 0399 XMLAttDef& operator=(const XMLAttDef&); 0400 0401 0402 // ----------------------------------------------------------------------- 0403 // Private helper methods 0404 // ----------------------------------------------------------------------- 0405 void cleanUp(); 0406 0407 0408 // ----------------------------------------------------------------------- 0409 // Private data members 0410 // 0411 // fDefaultType 0412 // Indicates what, if any, default stuff this attribute has. 0413 // 0414 // fEnumeration 0415 // If its an enumeration, this is the list of values as space 0416 // separated values. 0417 // 0418 // fId 0419 // This is the unique id of this attribute, given to it when its put 0420 // into the validator's attribute decl pool. It defaults to the 0421 // special value XMLAttrDef::fgInvalidAttrId. 0422 // 0423 // fType 0424 // The type of attribute, which is one of the AttTypes values. 0425 // 0426 // fValue 0427 // This is the value of the attribute, which is the default value 0428 // given in the attribute declaration. 0429 // 0430 // fCreateReason 0431 // This flag tells us how this attribute got created. Sometimes even 0432 // the attribute was not declared for the element, we want to fault 0433 // fault it into the pool to avoid lots of redundant errors. 0434 // 0435 // fExternalAttribute 0436 // This flag indicates whether or not the attribute was declared externally. 0437 // ----------------------------------------------------------------------- 0438 DefAttTypes fDefaultType; 0439 AttTypes fType; 0440 CreateReasons fCreateReason; 0441 bool fExternalAttribute; 0442 XMLSize_t fId; 0443 XMLCh* fValue; 0444 XMLCh* fEnumeration; 0445 MemoryManager* fMemoryManager; 0446 }; 0447 0448 0449 // --------------------------------------------------------------------------- 0450 // Getter methods 0451 // --------------------------------------------------------------------------- 0452 inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const 0453 { 0454 return fDefaultType; 0455 } 0456 0457 inline const XMLCh* XMLAttDef::getEnumeration() const 0458 { 0459 return fEnumeration; 0460 } 0461 0462 inline XMLSize_t XMLAttDef::getId() const 0463 { 0464 return fId; 0465 } 0466 0467 inline XMLAttDef::AttTypes XMLAttDef::getType() const 0468 { 0469 return fType; 0470 } 0471 0472 inline const XMLCh* XMLAttDef::getValue() const 0473 { 0474 return fValue; 0475 } 0476 0477 inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const 0478 { 0479 return fCreateReason; 0480 } 0481 0482 inline bool XMLAttDef::isExternal() const 0483 { 0484 return fExternalAttribute; 0485 } 0486 0487 inline MemoryManager* XMLAttDef::getMemoryManager() const 0488 { 0489 return fMemoryManager; 0490 } 0491 0492 // --------------------------------------------------------------------------- 0493 // XMLAttDef: Setter methods 0494 // --------------------------------------------------------------------------- 0495 inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue) 0496 { 0497 fDefaultType = newValue; 0498 } 0499 0500 inline void XMLAttDef::setEnumeration(const XMLCh* const newValue) 0501 { 0502 if (fEnumeration) 0503 fMemoryManager->deallocate(fEnumeration); 0504 0505 fEnumeration = XMLString::replicate(newValue, fMemoryManager); 0506 } 0507 0508 inline void XMLAttDef::setId(const XMLSize_t newId) 0509 { 0510 fId = newId; 0511 } 0512 0513 inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue) 0514 { 0515 fType = newValue; 0516 } 0517 0518 inline void XMLAttDef::setValue(const XMLCh* const newValue) 0519 { 0520 if (fValue) 0521 fMemoryManager->deallocate(fValue); 0522 0523 fValue = XMLString::replicate(newValue, fMemoryManager); 0524 } 0525 0526 inline void 0527 XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason) 0528 { 0529 fCreateReason = newReason; 0530 } 0531 0532 inline void XMLAttDef::setExternalAttDeclaration(const bool aValue) 0533 { 0534 fExternalAttribute = aValue; 0535 } 0536 0537 XERCES_CPP_NAMESPACE_END 0538 0539 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |