# XMLElementDecl.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: XMLElementDecl.hpp 676911 2008-07-15 13:27:32Z amassari $
    00020  */
    00021
    00022 #if !defined(XERCESC_INCLUDE_GUARD_XMLELEMENTDECL_HPP)
    00023 #define XERCESC_INCLUDE_GUARD_XMLELEMENTDECL_HPP
    00024
    00025 #include <xercesc/framework/XMLAttr.hpp>
    00026 #include <xercesc/framework/XMLAttDefList.hpp>
    00027 #include <xercesc/util/XMLString.hpp>
    00028 #include <xercesc/util/PlatformUtils.hpp>
    00029 #include <xercesc/internal/XSerializable.hpp>
    00030
    00031 XERCES_CPP_NAMESPACE_BEGIN
    00032
    00033 class ContentSpecNode;
    00034 class XMLContentModel;
    00035
    00051 class XMLPARSER_EXPORT XMLElementDecl : public XSerializable, public XMemory
    00052 {
    00053  public:
    00054     // -----------------------------------------------------------------------
    00055     //  Class specific types
    00056     //
    00057     //  CreateReasons
    00058     //      This type is used to store how an element declaration got into
    00059     //      the grammar's element pool. They are faulted in for various
    00060     //      reasons.
    00061     //
    00062     //  LookupOpts
    00063     //      These are the values used by the attribute lookup methods.
    00064     //
    00065     //  CharDataOpts
    00066     //      This is used to indicate how this type of element reacts to
    00067     //      character data as content.
    00068     // -----------------------------------------------------------------------
    00069     enum CreateReasons
    00070     {
    00071         NoReason
    00072         , Declared
    00073         , AttList
    00074         , InContentModel
    00075         , AsRootElem
    00076         , JustFaultIn
    00077     };
    00078
    00079     enum CharDataOpts
    00080     {
    00081         NoCharData
    00082         , SpacesOk
    00083         , AllCharData
    00084     };
    00085
    00086
    00087     // -----------------------------------------------------------------------
    00088     //  Public static data
    00089     //
    00090     //  fgInvalidElemId
    00091     //      A value to represent an invalid element node id.
    00092     //
    00093     //  fgPCDataElemId
    00094     //      This is the value to use to represent a PCDATA node when an
    00095     //      element id is required.
    00096     //
    00097     //  fgPCDataElemName
    00098     //      This is the value to use to represent a PCDATA node when an
    00099     //      element name is required.
    00100     // -----------------------------------------------------------------------
    00101     static const unsigned int   fgInvalidElemId;
    00102     static const unsigned int   fgPCDataElemId;
    00103     static const XMLCh          fgPCDataElemName[];
    00104
    00105
    00106
    00107     // -----------------------------------------------------------------------
    00108     //  Destructor
    00109     // -----------------------------------------------------------------------
    00112     virtual ~XMLElementDecl();
    00114
    00115
    00116     // -----------------------------------------------------------------------
    00117     //  The virtual element decl interface
    00118     // -----------------------------------------------------------------------
    00119
    00122
    00134     virtual XMLAttDefList& getAttDefList() const = 0;
    00135
    00143     virtual CharDataOpts getCharDataOpts() const = 0;
    00144
    00151     virtual bool hasAttDefs() const = 0;
    00152
    00160     virtual const ContentSpecNode* getContentSpec() const = 0;
    00161
    00167     virtual ContentSpecNode* getContentSpec() = 0;
    00168
    00178     virtual void setContentSpec(ContentSpecNode* toAdopt) = 0;
    00179
    00191     virtual XMLContentModel* getContentModel() = 0;
    00192
    00204     virtual void setContentModel(XMLContentModel* const newModelToAdopt) = 0;
    00205
    00218     virtual const XMLCh* getFormattedContentModel ()   const = 0;
    00219
    00221
    00222
    00223     // -----------------------------------------------------------------------
    00224     //  Getter methods
    00225     // -----------------------------------------------------------------------
    00226
    00229
    00237     const XMLCh* getBaseName() const;
    00238     XMLCh* getBaseName();
    00239
    00246     unsigned int getURI() const;
    00247
    00255     const QName* getElementName() const;
    00256     QName* getElementName();
    00257
    00266     const XMLCh* getFullName() const;
    00267
    00279     CreateReasons getCreateReason() const;
    00280
    00290     XMLSize_t getId() const;
    00291
    00301     bool isDeclared() const;
    00302
    00311     bool isExternal() const;
    00312
    00320     MemoryManager* getMemoryManager() const;
    00321
    00323
    00324
    00325     // -----------------------------------------------------------------------
    00326     //  Setter methods
    00327     // -----------------------------------------------------------------------
    00328
    00331
    00342       void setElementName(const XMLCh* const       prefix
    00343                         , const XMLCh* const       localPart
    00344                         , const int                uriId );
    00345
    00355       void setElementName(const XMLCh* const    rawName
    00356                         , const int             uriId );
    00357
    00366       void setElementName(const QName* const    elementName);
    00367
    00378     void setCreateReason(const CreateReasons newReason);
    00379
    00386     void setId(const XMLSize_t newId);
    00387
    00388
    00392     void setExternalElemDeclaration(const bool aValue);
    00393
    00395
    00396
    00397     // -----------------------------------------------------------------------
    00398     //  Miscellaneous methods
    00399     // -----------------------------------------------------------------------
    00400
    00403
    00405
    00406     /***
    00407      * Support for Serialization/De-serialization
    00408      ***/
    00409     DECL_XSERIALIZABLE(XMLElementDecl)
    00410
    00411     enum objectType
    00412     {
    00413         Schema
    00414       , DTD
    00415       , UnKnown
    00416     };
    00417
    00418     virtual XMLElementDecl::objectType  getObjectType() const = 0;
    00419
    00420     static void            storeElementDecl(XSerializeEngine&        serEng
    00421                                           , XMLElementDecl*    const element);
    00422
    00423     static XMLElementDecl* loadElementDecl(XSerializeEngine& serEng);
    00424
    00425 protected :
    00426     // -----------------------------------------------------------------------
    00427     //  Hidden constructors
    00428     // -----------------------------------------------------------------------
    00429     XMLElementDecl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    00430
    00431 private :
    00432     // -----------------------------------------------------------------------
    00433     //  Unimplemented constructors and operators
    00434     // -----------------------------------------------------------------------
    00435     XMLElementDecl(const XMLElementDecl&);
    00436     XMLElementDecl& operator=(const XMLElementDecl&);
    00437
    00438
    00439     // -----------------------------------------------------------------------
    00440     //  Data members
    00441     //
    00442     //  fElementName
    00443     //      This is the name of the element decl.
    00444     //
    00445     //  fCreateReason
    00446     //      We sometimes have to put an element decl object into the elem
    00447     //      decl pool before the element's declaration is seen, such as when
    00448     //      its used in another element's content model or an att list is
    00449     //      seen for it. This flag tells us whether its been declared, and
    00450     //      if not why it had to be created.
    00451     //
    00452     //  fId
    00453     //      The unique id of this element. This is created by the derived
    00454     //      class, or more accurately the grammar that owns the objects
    00455     //      of the derived types. But, since they all have to have them, we
    00456     //      let them all store the id here. It is defaulted to have the
    00457     //      value fgInvalidElem until explicitly set.
    00458     //
    00459     //  fExternalElement
    00460     //      This flag indicates whether or the element was declared externally.
    00461     // -----------------------------------------------------------------------
    00462     MemoryManager*      fMemoryManager;
    00463     QName*              fElementName;
    00464     CreateReasons       fCreateReason;
    00465     XMLSize_t           fId;
    00466     bool                fExternalElement;
    00467 };
    00468
    00469
    00470 // ---------------------------------------------------------------------------
    00471 //  XMLElementDecl: Getter methods
    00472 // ---------------------------------------------------------------------------
    00473 inline const XMLCh* XMLElementDecl::getBaseName() const
    00474 {
    00475     return fElementName->getLocalPart();
    00476 }
    00477
    00478 inline XMLCh* XMLElementDecl::getBaseName()
    00479 {
    00480     return fElementName->getLocalPart();
    00481 }
    00482
    00483 inline unsigned int XMLElementDecl::getURI() const
    00484 {
    00485     return fElementName->getURI();
    00486 }
    00487
    00488 inline const QName* XMLElementDecl::getElementName() const
    00489 {
    00490     return fElementName;
    00491 }
    00492
    00493 inline QName* XMLElementDecl::getElementName()
    00494 {
    00495     return fElementName;
    00496 }
    00497
    00498 inline const XMLCh* XMLElementDecl::getFullName() const
    00499 {
    00500     return fElementName->getRawName();
    00501 }
    00502
    00503 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const
    00504 {
    00505     return fCreateReason;
    00506 }
    00507
    00508 inline XMLSize_t XMLElementDecl::getId() const
    00509 {
    00510     return fId;
    00511 }
    00512
    00513 inline bool XMLElementDecl::isDeclared() const
    00514 {
    00515     return (fCreateReason == Declared);
    00516 }
    00517
    00518
    00519 inline bool XMLElementDecl::isExternal() const
    00520 {
    00521     return fExternalElement;
    00522 }
    00523
    00524 inline MemoryManager* XMLElementDecl::getMemoryManager() const
    00525 {
    00526     return fMemoryManager;
    00527 }
    00528
    00529
    00530 // ---------------------------------------------------------------------------
    00531 //  XMLElementDecl: Setter methods
    00532 // ---------------------------------------------------------------------------
    00533 inline void
    00534 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)
    00535 {
    00536     fCreateReason = newReason;
    00537 }
    00538
    00539 inline void XMLElementDecl::setId(const XMLSize_t newId)
    00540 {
    00541     fId = newId;
    00542 }
    00543
    00544
    00545 inline void XMLElementDecl::setExternalElemDeclaration(const bool aValue)
    00546 {
    00547     fExternalElement = aValue;
    00548 }
    00549
    00550 XERCES_CPP_NAMESPACE_END
    00551
    00552 #endif