|
||||
File indexing completed on 2025-01-18 10:14:53
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_XMLELEMENTDECL_HPP) 0023 #define XERCESC_INCLUDE_GUARD_XMLELEMENTDECL_HPP 0024 0025 #include <xercesc/framework/XMLAttr.hpp> 0026 #include <xercesc/framework/XMLAttDefList.hpp> 0027 #include <xercesc/util/XMLString.hpp> 0028 #include <xercesc/util/PlatformUtils.hpp> 0029 #include <xercesc/internal/XSerializable.hpp> 0030 0031 XERCES_CPP_NAMESPACE_BEGIN 0032 0033 class ContentSpecNode; 0034 class XMLContentModel; 0035 0036 /** 0037 * This class defines the core information of an element declaration. Each 0038 * validator (DTD, Schema, etc...) will have its own information that it 0039 * associations with the declaration of an element, but they must all share 0040 * at least this core information, i.e. they must all derive from this 0041 * class. The set of info enforced at this level is driven by the needs of 0042 * XML 1.0 spec validation and well formedness checks. 0043 * 0044 * This class defines some special element id values for invalid elements 0045 * and PCDATA elements, as well as a string for the special PCDATA element 0046 * name. All validators must honor these special values in order to allow 0047 * content models to work generically (i.e. to let code know when its dealing 0048 * with invalid or PCDATA element ids without having to know what type of 0049 * validator its messing with.) 0050 */ 0051 class XMLPARSER_EXPORT XMLElementDecl : public XSerializable, public XMemory 0052 { 0053 public: 0054 // ----------------------------------------------------------------------- 0055 // Class specific types 0056 // 0057 // CreateReasons 0058 // This type is used to store how an element declaration got into 0059 // the grammar's element pool. They are faulted in for various 0060 // reasons. 0061 // 0062 // LookupOpts 0063 // These are the values used by the attribute lookup methods. 0064 // 0065 // CharDataOpts 0066 // This is used to indicate how this type of element reacts to 0067 // character data as content. 0068 // ----------------------------------------------------------------------- 0069 enum CreateReasons 0070 { 0071 NoReason 0072 , Declared 0073 , AttList 0074 , InContentModel 0075 , AsRootElem 0076 , JustFaultIn 0077 }; 0078 0079 enum CharDataOpts 0080 { 0081 NoCharData 0082 , SpacesOk 0083 , AllCharData 0084 }; 0085 0086 0087 // ----------------------------------------------------------------------- 0088 // Public static data 0089 // 0090 // fgInvalidElemId 0091 // A value to represent an invalid element node id. 0092 // 0093 // fgPCDataElemId 0094 // This is the value to use to represent a PCDATA node when an 0095 // element id is required. 0096 // 0097 // fgPCDataElemName 0098 // This is the value to use to represent a PCDATA node when an 0099 // element name is required. 0100 // ----------------------------------------------------------------------- 0101 static const unsigned int fgInvalidElemId; 0102 static const unsigned int fgPCDataElemId; 0103 static const XMLCh fgPCDataElemName[]; 0104 0105 0106 0107 // ----------------------------------------------------------------------- 0108 // Destructor 0109 // ----------------------------------------------------------------------- 0110 /** @name Destructor */ 0111 //@{ 0112 virtual ~XMLElementDecl(); 0113 //@} 0114 0115 0116 // ----------------------------------------------------------------------- 0117 // The virtual element decl interface 0118 // ----------------------------------------------------------------------- 0119 0120 /** @name Virual ElementDecl interface */ 0121 //@{ 0122 0123 /** Get a list of attributes defined for this element. 0124 * 0125 * The derived class should return a reference to some member object which 0126 * implements the XMLAttDefList interface. This object gives the scanner the 0127 * ability to look through the attributes defined for this element. 0128 * 0129 * It is done this way for efficiency, though of course this is not thread 0130 * safe. The scanner guarantees that it won't ever call this method in any 0131 * nested way, but the outside world must be careful about when it calls 0132 * this method, and optimally never would. 0133 */ 0134 virtual XMLAttDefList& getAttDefList() const = 0; 0135 0136 /** The character data options for this element type 0137 * 0138 * The derived class should return an appropriate character data opts value 0139 * which correctly represents its tolerance towards whitespace or character 0140 * data inside of its instances. This allows the scanner to do all of the 0141 * validation of character data. 0142 */ 0143 virtual CharDataOpts getCharDataOpts() const = 0; 0144 0145 /** Indicate whether this element type defined any attributes 0146 * 0147 * The derived class should return a boolean that indicates whether this 0148 * element has any attributes defined for it or not. This is an optimization 0149 * that allows the scanner to skip some work if no attributes exist. 0150 */ 0151 virtual bool hasAttDefs() const = 0; 0152 0153 /** Get a pointer to the content spec node 0154 * 0155 * This method will return a const pointer to the content spec node object 0156 * of this element. 0157 * 0158 * @return A const pointer to the element's content spec node 0159 */ 0160 virtual const ContentSpecNode* getContentSpec() const = 0; 0161 0162 /** Get a pointer to the content spec node 0163 * 0164 * This method is identical to the previous one, except that it is non 0165 * const. 0166 */ 0167 virtual ContentSpecNode* getContentSpec() = 0; 0168 0169 /** Set the content spec node object for this element type 0170 * 0171 * This method will adopt the based content spec node object. This is called 0172 * by the actual validator which is parsing its DTD or Schema or whatever 0173 * and store it on the element decl object via this method. 0174 * 0175 * @param toAdopt This method will adopt the passed content node spec 0176 * object. Any previous object is destroyed. 0177 */ 0178 virtual void setContentSpec(ContentSpecNode* toAdopt) = 0; 0179 0180 /** Get a pointer to the abstract content model 0181 * 0182 * This method will return a const pointer to the content model object 0183 * of this element. This class is a simple abstraction that allows an 0184 * element to define and use multiple, specialized content model types 0185 * internally but still allow the outside world to do simple stuff with 0186 * them. 0187 * 0188 * @return A pointer to the element's content model, via the basic 0189 * abstract content model type. 0190 */ 0191 virtual XMLContentModel* getContentModel() = 0; 0192 0193 /** Set the content model object for this element type 0194 * 0195 * This method will adopt the based content model object. This is called 0196 * by the actual validator which is parsing its DTD or Schema or whatever 0197 * a creating an element decl. It will build what it feels is the correct 0198 * content model type object and store it on the element decl object via 0199 * this method. 0200 * 0201 * @param newModelToAdopt This method will adopt the passed content model 0202 * object. Any previous object is destroyed. 0203 */ 0204 virtual void setContentModel(XMLContentModel* const newModelToAdopt) = 0; 0205 0206 /** Geta formatted string of the content model 0207 * 0208 * This method is a convenience method which will create a formatted 0209 * representation of the content model of the element. It will not always 0210 * exactly recreate the original model, since some normalization or 0211 * or reformatting may occur. But, it will be a technically accurate 0212 * representation of the original content model. 0213 * 0214 * @return A pointer to an internal buffer which contains the formatted 0215 * content model. The caller does not own this buffer and should 0216 * copy it if it needs to be kept around. 0217 */ 0218 virtual const XMLCh* getFormattedContentModel () const = 0; 0219 0220 //@} 0221 0222 0223 // ----------------------------------------------------------------------- 0224 // Getter methods 0225 // ----------------------------------------------------------------------- 0226 0227 /** @name Getter methods */ 0228 //@{ 0229 0230 /** Get the base name of this element type. 0231 * 0232 * Return the base name part of the element's name. This is the 0233 * same regardless of whether namespaces are enabled or not. 0234 * 0235 * @return A const pointer to the base name of the element decl. 0236 */ 0237 const XMLCh* getBaseName() const; 0238 XMLCh* getBaseName(); 0239 0240 /** Get the URI id of this element type. 0241 * 0242 * Return the URI Id of this element. 0243 * 0244 * @return The URI Id of the element decl, or the emptyNamespaceId if not applicable. 0245 */ 0246 unsigned int getURI() const; 0247 0248 /** Get the QName of this element type. 0249 * 0250 * Return the QName part of the element's name. This is the 0251 * same regardless of whether namespaces are enabled or not. 0252 * 0253 * @return A const pointer to the QName of the element decl. 0254 */ 0255 const QName* getElementName() const; 0256 QName* getElementName(); 0257 0258 /** Get the full name of this element type. 0259 * 0260 * Return the full name of the element. If namespaces 0261 * are not enabled, then this is the qName. Else it is the {uri}baseName 0262 * form. For those validators that always require namespace processing, it 0263 * will always be in the latter form because namespace processing will always 0264 * be on. 0265 */ 0266 const XMLCh* getFullName() const; 0267 0268 /** Get the create reason for this element type 0269 * 0270 * This method returns an enumeration which indicates why this element 0271 * declaration exists. Elements can be used before they are actually 0272 * declared, so they will often be faulted into the pool and marked as 0273 * to why they are there. 0274 * 0275 * @return An enumerated value that indicates the reason why this element 0276 * was added to the element decl pool. 0277 */ 0278 0279 CreateReasons getCreateReason() const; 0280 0281 /** Get the element decl pool id for this element type 0282 * 0283 * This method will return the element decl pool id of this element 0284 * declaration. This uniquely identifies this element type within the 0285 * parse event that it is declared within. This value is assigned by the 0286 * grammar whose decl pool this object belongs to. 0287 * 0288 * @return The element decl id of this element declaration. 0289 */ 0290 XMLSize_t getId() const; 0291 0292 /** Indicate whether this element type has been declared yet 0293 * 0294 * This method returns a boolean that indicates whether this element 0295 * has been declared yet. There are a number of reasons why an element 0296 * declaration can be faulted in, but eventually it must be declared or 0297 * its an error. See the CreateReasons enumeration. 0298 * 0299 * @return true if this element has been declared, else false. 0300 */ 0301 bool isDeclared() const; 0302 0303 /** Indicate whether this element type has been declared externally 0304 * 0305 * This method returns a boolean that indicates whether this element 0306 * has been declared externally. 0307 * 0308 * @return true if this element has been declared externally, else false. 0309 */ 0310 0311 bool isExternal() const; 0312 0313 /** Get the memory manager 0314 * 0315 * This method returns the configurable memory manager used by the 0316 * element declaration for dynamic allocation/deallocation. 0317 * 0318 * @return the memory manager 0319 */ 0320 MemoryManager* getMemoryManager() const; 0321 0322 //@} 0323 0324 0325 // ----------------------------------------------------------------------- 0326 // Setter methods 0327 // ----------------------------------------------------------------------- 0328 0329 /** @name Setter methods */ 0330 //@{ 0331 0332 /** Set the element name object for this element type 0333 * 0334 * This method will adopt the based content spec node object. This is called 0335 * by the actual validator which is parsing its DTD or Schema or whatever 0336 * and store it on the element decl object via this method. 0337 * 0338 * @param prefix Prefix of the element 0339 * @param localPart Base Name of the element 0340 * @param uriId The uriId of the element 0341 */ 0342 void setElementName(const XMLCh* const prefix 0343 , const XMLCh* const localPart 0344 , const int uriId ); 0345 0346 /** Set the element name object for this element type 0347 * 0348 * This method will adopt the based content spec node object. This is called 0349 * by the actual validator which is parsing its DTD or Schema or whatever 0350 * and store it on the element decl object via this method. 0351 * 0352 * @param rawName Full Name of the element 0353 * @param uriId The uriId of the element 0354 */ 0355 void setElementName(const XMLCh* const rawName 0356 , const int uriId ); 0357 0358 /** Set the element name object for this element type 0359 * 0360 * This method will adopt the based content spec node object. This is called 0361 * by the actual validator which is parsing its DTD or Schema or whatever 0362 * and store it on the element decl object via this method. 0363 * 0364 * @param elementName QName of the element 0365 */ 0366 void setElementName(const QName* const elementName); 0367 0368 /** Update the create reason for this element type. 0369 * 0370 * This method will update the 'create reason' field for this element 0371 * decl object. As the validator parses its DTD, Schema, etc... it will 0372 * encounter various references to an element declaration, which will 0373 * cause the element declaration to either be declared or to be faulted 0374 * into the pool in preparation for some future declaration. As it does 0375 * so,it will update this field to indicate the current status of the 0376 * decl object. 0377 */ 0378 void setCreateReason(const CreateReasons newReason); 0379 0380 /** Set the element decl pool id for this element type 0381 * 0382 * This method will set the pool id of this element decl. This is called 0383 * by the grammar which created this object, and will provide this 0384 * decl object with a unique id within the parse event that created it. 0385 */ 0386 void setId(const XMLSize_t newId); 0387 0388 0389 /** Set the element decl to indicate external declaration 0390 * 0391 */ 0392 void setExternalElemDeclaration(const bool aValue); 0393 0394 //@} 0395 0396 0397 // ----------------------------------------------------------------------- 0398 // Miscellaneous methods 0399 // ----------------------------------------------------------------------- 0400 0401 /** @name Miscellaneous methods */ 0402 //@{ 0403 0404 //@} 0405 0406 /*** 0407 * Support for Serialization/De-serialization 0408 ***/ 0409 DECL_XSERIALIZABLE(XMLElementDecl) 0410 0411 enum objectType 0412 { 0413 Schema 0414 , DTD 0415 , UnKnown 0416 }; 0417 0418 virtual XMLElementDecl::objectType getObjectType() const = 0; 0419 0420 static void storeElementDecl(XSerializeEngine& serEng 0421 , XMLElementDecl* const element); 0422 0423 static XMLElementDecl* loadElementDecl(XSerializeEngine& serEng); 0424 0425 protected : 0426 // ----------------------------------------------------------------------- 0427 // Hidden constructors 0428 // ----------------------------------------------------------------------- 0429 XMLElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); 0430 0431 private : 0432 // ----------------------------------------------------------------------- 0433 // Unimplemented constructors and operators 0434 // ----------------------------------------------------------------------- 0435 XMLElementDecl(const XMLElementDecl&); 0436 XMLElementDecl& operator=(const XMLElementDecl&); 0437 0438 0439 // ----------------------------------------------------------------------- 0440 // Data members 0441 // 0442 // fElementName 0443 // This is the name of the element decl. 0444 // 0445 // fCreateReason 0446 // We sometimes have to put an element decl object into the elem 0447 // decl pool before the element's declaration is seen, such as when 0448 // its used in another element's content model or an att list is 0449 // seen for it. This flag tells us whether its been declared, and 0450 // if not why it had to be created. 0451 // 0452 // fId 0453 // The unique id of this element. This is created by the derived 0454 // class, or more accurately the grammar that owns the objects 0455 // of the derived types. But, since they all have to have them, we 0456 // let them all store the id here. It is defaulted to have the 0457 // value fgInvalidElem until explicitly set. 0458 // 0459 // fExternalElement 0460 // This flag indicates whether or the element was declared externally. 0461 // ----------------------------------------------------------------------- 0462 MemoryManager* fMemoryManager; 0463 QName* fElementName; 0464 CreateReasons fCreateReason; 0465 XMLSize_t fId; 0466 bool fExternalElement; 0467 }; 0468 0469 0470 // --------------------------------------------------------------------------- 0471 // XMLElementDecl: Getter methods 0472 // --------------------------------------------------------------------------- 0473 inline const XMLCh* XMLElementDecl::getBaseName() const 0474 { 0475 return fElementName->getLocalPart(); 0476 } 0477 0478 inline XMLCh* XMLElementDecl::getBaseName() 0479 { 0480 return fElementName->getLocalPart(); 0481 } 0482 0483 inline unsigned int XMLElementDecl::getURI() const 0484 { 0485 return fElementName->getURI(); 0486 } 0487 0488 inline const QName* XMLElementDecl::getElementName() const 0489 { 0490 return fElementName; 0491 } 0492 0493 inline QName* XMLElementDecl::getElementName() 0494 { 0495 return fElementName; 0496 } 0497 0498 inline const XMLCh* XMLElementDecl::getFullName() const 0499 { 0500 return fElementName->getRawName(); 0501 } 0502 0503 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const 0504 { 0505 return fCreateReason; 0506 } 0507 0508 inline XMLSize_t XMLElementDecl::getId() const 0509 { 0510 return fId; 0511 } 0512 0513 inline bool XMLElementDecl::isDeclared() const 0514 { 0515 return (fCreateReason == Declared); 0516 } 0517 0518 0519 inline bool XMLElementDecl::isExternal() const 0520 { 0521 return fExternalElement; 0522 } 0523 0524 inline MemoryManager* XMLElementDecl::getMemoryManager() const 0525 { 0526 return fMemoryManager; 0527 } 0528 0529 0530 // --------------------------------------------------------------------------- 0531 // XMLElementDecl: Setter methods 0532 // --------------------------------------------------------------------------- 0533 inline void 0534 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason) 0535 { 0536 fCreateReason = newReason; 0537 } 0538 0539 inline void XMLElementDecl::setId(const XMLSize_t newId) 0540 { 0541 fId = newId; 0542 } 0543 0544 0545 inline void XMLElementDecl::setExternalElemDeclaration(const bool aValue) 0546 { 0547 fExternalElement = aValue; 0548 } 0549 0550 XERCES_CPP_NAMESPACE_END 0551 0552 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |