http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Download
Installation
Build

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
PDF Document

CVS Repository
Mail Archive

API Docs for SAX and DOM
 

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

XMLElementDecl.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Xerces" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache\@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation, and was
00051  * originally based on software copyright (c) 1999, International
00052  * Business Machines, Inc., http://www.ibm.com .  For more information
00053  * on the Apache Software Foundation, please see
00054  * <http://www.apache.org/>.
00055  */
00056 
00057 /*
00058  * $Log: XMLElementDecl.hpp,v $
00059  * Revision 1.16  2001/06/21 14:25:28  knoaman
00060  * Fix for bug 1946
00061  *
00062  * Revision 1.15  2001/05/11 13:25:32  tng
00063  * Copyright update.
00064  *
00065  * Revision 1.14  2001/05/03 20:34:22  tng
00066  * Schema: SchemaValidator update
00067  *
00068  * Revision 1.13  2001/04/19 18:16:52  tng
00069  * Schema: SchemaValidator update, and use QName in Content Model
00070  *
00071  * Revision 1.12  2001/03/21 21:56:02  tng
00072  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
00073  *
00074  * Revision 1.11  2001/03/21 19:29:29  tng
00075  * Schema: Content Model Updates, by Pei Yong Zhang.
00076  *
00077  * Revision 1.10  2001/02/26 19:29:13  tng
00078  * Schema: add virtual method getURI(), getContentSpec and setContenSpec in XMLElementDecl, and DTDElementDecl.
00079  *
00080  * Revision 1.9  2001/02/26 19:21:30  tng
00081  * Schema: add parameter prefix in findElem and findAttr.
00082  *
00083  * Revision 1.8  2000/12/14 18:49:57  tng
00084  * Fix API document generation warning: "Warning: end of member group without matching begin"
00085  *
00086  * Revision 1.7  2000/11/30 18:22:38  andyh
00087  * reuseValidator - fix bugs (spurious errors) that occured on reuse due to
00088  * pools already containing some items.  Fixed by Tinny Ng.
00089  *
00090  * Revision 1.6  2000/05/11 23:11:32  andyh
00091  * Add missing validity checks for stand-alone documents, character range
00092  * and Well-formed parsed entities.  Changes contributed by Sean MacRoibeaird
00093  * <sean.Macroibeaird@ireland.sun.com>
00094  *
00095  * Revision 1.5  2000/02/24 20:00:23  abagchi
00096  * Swat for removing Log from API docs
00097  *
00098  * Revision 1.4  2000/02/16 19:48:56  roddey
00099  * More documentation updates
00100  *
00101  * Revision 1.3  2000/02/15 01:21:30  roddey
00102  * Some initial documentation improvements. More to come...
00103  *
00104  * Revision 1.2  2000/02/06 07:47:48  rahulj
00105  * Year 2K copyright swat.
00106  *
00107  * Revision 1.1.1.1  1999/11/09 01:08:32  twl
00108  * Initial checkin
00109  *
00110  * Revision 1.2  1999/11/08 20:44:38  rahul
00111  * Swat for adding in Product name and CVS comment log variable.
00112  *
00113  */
00114 
00115 #if !defined(XMLELEMENTDECL_HPP)
00116 #define XMLELEMENTDECL_HPP
00117 
00118 #include <util/XMLString.hpp>
00119 #include <framework/XMLAttr.hpp>
00120 #include <framework/XMLAttDefList.hpp>
00121 #include <framework/XMLContentModel.hpp>
00122 
00123 class ContentSpecNode;
00124 
00140 class  XMLElementDecl
00141 {
00142  public:
00143     // -----------------------------------------------------------------------
00144     //  Class specific types
00145     //
00146     //  CreateReasons
00147     //      This type is used to store how an element declaration got into
00148     //      the grammar's element pool. They are faulted in for various
00149     //      reasons.
00150     //
00151     //  LookupOpts
00152     //      These are the values used by the attribute lookup methods.
00153     //
00154     //  CharDataOpts
00155     //      This is used to indicate how this type of element reacts to
00156     //      character data as content.
00157     // -----------------------------------------------------------------------
00158     enum CreateReasons
00159     {
00160         NoReason
00161         , Declared
00162         , AttList
00163         , InContentModel
00164         , AsRootElem
00165         , JustFaultIn
00166     };
00167 
00168     enum LookupOpts
00169     {
00170         AddIfNotFound
00171         , FailIfNotFound
00172     };
00173 
00174     enum CharDataOpts
00175     {
00176         NoCharData
00177         , SpacesOk
00178         , AllCharData
00179     };
00180 
00181 
00182     // -----------------------------------------------------------------------
00183     //  Public static data
00184     //
00185     //  fgInvalidElemId
00186     //      A value to represent an invalid element node id.
00187     //
00188     //  fgPCDataElemId
00189     //      This is the value to use to represent a PCDATA node when an
00190     //      element id is required.
00191     //
00192     //  fgPCDataElemName
00193     //      This is the value to use to represent a PCDATA node when an
00194     //      element name is required.
00195     // -----------------------------------------------------------------------
00196     static const unsigned int   fgInvalidElemId;
00197     static const unsigned int   fgPCDataElemId;
00198     static const XMLCh          fgPCDataElemName[];
00199 
00200 
00201 
00202     // -----------------------------------------------------------------------
00203     //  Destructor
00204     // -----------------------------------------------------------------------
00207     virtual ~XMLElementDecl();
00209 
00210 
00211     // -----------------------------------------------------------------------
00212     //  The virtual element decl interface
00213     // -----------------------------------------------------------------------
00214 
00217 
00246     virtual XMLAttDef* findAttr
00247     (
00248         const   XMLCh* const    qName
00249         , const unsigned int    uriId
00250         , const XMLCh* const    baseName
00251         , const XMLCh* const    prefix
00252         , const LookupOpts      options
00253         ,       bool&           wasAdded
00254     )   const = 0;
00255 
00267     virtual XMLAttDefList& getAttDefList() const = 0;
00268 
00276     virtual CharDataOpts getCharDataOpts() const = 0;
00277 
00284     virtual bool hasAttDefs() const = 0;
00285 
00293     virtual bool resetDefs() = 0;
00294 
00302     virtual const ContentSpecNode* getContentSpec() const = 0;
00303 
00309     virtual ContentSpecNode* getContentSpec() = 0;
00310 
00320     virtual void setContentSpec(ContentSpecNode* toAdopt) = 0;
00321 
00323 
00324 
00325     // -----------------------------------------------------------------------
00326     //  Getter methods
00327     // -----------------------------------------------------------------------
00328 
00331 
00339     const XMLCh* getBaseName() const;
00340     XMLCh* getBaseName();
00341 
00348     const unsigned int getURI() const;
00349 
00357     const QName* getElementName() const;
00358     QName* getElementName();
00359 
00368     const XMLCh* getFullName() const;
00369 
00381     XMLContentModel* getContentModel();
00382 
00393 
00394     CreateReasons getCreateReason() const;
00395 
00405     unsigned int getId() const;
00406 
00416     bool isDeclared() const;
00417 
00425 
00426     bool isExternal() const;
00427 
00429 
00430 
00431     // -----------------------------------------------------------------------
00432     //  Setter methods
00433     // -----------------------------------------------------------------------
00434 
00437 
00448       void setElementName(const XMLCh* const       prefix
00449                         , const XMLCh* const       localPart
00450                         , const int                uriId );
00451 
00461       void setElementName(const XMLCh* const    rawName
00462                         , const int             uriId );
00463 
00472       void setElementName(QName* const    elementName);
00473 
00485     void setContentModel(XMLContentModel* const newModelToAdopt);
00486 
00497     void setCreateReason(const CreateReasons newReason);
00498 
00505     void setId(const unsigned int newId);
00506 
00507 
00511     void setExternalElemDeclaration(const bool aValue);
00512 
00514 
00515 
00516     // -----------------------------------------------------------------------
00517     //  Miscellaneous methods
00518     // -----------------------------------------------------------------------
00519 
00522 
00535     const XMLCh* getFormattedContentModel ()   const;
00536 
00538 
00539 
00540 protected :
00541     // -----------------------------------------------------------------------
00542     //  Hidden constructors
00543     // -----------------------------------------------------------------------
00544     XMLElementDecl();
00545 
00546 
00547     // -----------------------------------------------------------------------
00548     //  Protected, virtual methods
00549     // -----------------------------------------------------------------------
00550     virtual XMLContentModel* makeContentModel() = 0;
00551     virtual XMLCh* formatContentModel ()   const = 0;
00552 
00553 
00554 private :
00555     // -----------------------------------------------------------------------
00556     //  Unimplemented constructors and operators
00557     // -----------------------------------------------------------------------
00558     XMLElementDecl(const XMLElementDecl&);
00559     void operator=(const XMLElementDecl&);
00560 
00561 
00562     // -----------------------------------------------------------------------
00563     //  Data members
00564     //
00565     //  fElementName
00566     //      This is the name of the element decl.
00567     //
00568     //  fContentModel
00569     //      The content model object for this element. It is stored here via
00570     //      its abstract interface.
00571     //
00572     //  fCreateReason
00573     //      We sometimes have to put an element decl object into the elem
00574     //      decl pool before the element's declaration is seen, such as when
00575     //      its used in another element's content model or an att list is
00576     //      seen for it. This flag tells us whether its been declared, and
00577     //      if not why it had to be created.
00578     //
00579     //  fFormattedModel
00580     //      This is a faulted in member. When the outside world asks for
00581     //      our content model as a string, we format it and fault it into
00582     //      this field (to avoid doing the formatted over and over.)
00583     //
00584     //  fId
00585     //      The unique id of this element. This is created by the derived
00586     //      class, or more accurately the grammar that owns the objects
00587     //      of the derived types. But, since they all have to have them, we
00588     //      let them all store the id here. It is defaulted to have the
00589     //      value fgInvalidElem until explicitly set.
00590     //
00591     //  fExternalElement
00592     //      This flag indicates whether or the element was declared externally.
00593     // -----------------------------------------------------------------------
00594     QName*              fElementName;
00595     XMLContentModel*    fContentModel;
00596     CreateReasons       fCreateReason;
00597     XMLCh*              fFormattedModel;
00598     unsigned int        fId;
00599     bool                fExternalElement;
00600 };
00601 
00602 
00603 // ---------------------------------------------------------------------------
00604 //  XMLElementDecl: Getter methods
00605 // ---------------------------------------------------------------------------
00606 inline const XMLCh* XMLElementDecl::getBaseName() const
00607 {
00608     return fElementName->getLocalPart();
00609 }
00610 
00611 inline XMLCh* XMLElementDecl::getBaseName()
00612 {
00613     return fElementName->getLocalPart();
00614 }
00615 
00616 inline const unsigned int XMLElementDecl::getURI() const
00617 {
00618     return fElementName->getURI();
00619 }
00620 
00621 inline const QName* XMLElementDecl::getElementName() const
00622 {
00623     return fElementName;
00624 }
00625 
00626 inline QName* XMLElementDecl::getElementName()
00627 {
00628     return fElementName;
00629 }
00630 
00631 inline const XMLCh* XMLElementDecl::getFullName() const
00632 {
00633     return fElementName->getRawName();
00634 }
00635 
00636 inline XMLContentModel* XMLElementDecl::getContentModel()
00637 {
00638     if (!fContentModel)
00639         fContentModel = makeContentModel();
00640     return fContentModel;
00641 }
00642 
00643 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const
00644 {
00645     return fCreateReason;
00646 }
00647 
00648 inline unsigned int XMLElementDecl::getId() const
00649 {
00650     return fId;
00651 }
00652 
00653 inline bool XMLElementDecl::isDeclared() const
00654 {
00655     return (fCreateReason == Declared);
00656 }
00657 
00658 
00659 inline bool XMLElementDecl::isExternal() const
00660 {
00661     return fExternalElement;
00662 }
00663 
00664 
00665 // ---------------------------------------------------------------------------
00666 //  XMLElementDecl: Setter methods
00667 // ---------------------------------------------------------------------------
00668 inline void
00669 XMLElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
00670 {
00671     delete fContentModel;
00672     fContentModel = newModelToAdopt;
00673 }
00674 
00675 inline void
00676 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)
00677 {
00678     fCreateReason = newReason;
00679 }
00680 
00681 inline void XMLElementDecl::setId(const unsigned int newId)
00682 {
00683     fId = newId;
00684 }
00685 
00686 
00687 inline void XMLElementDecl::setExternalElemDeclaration(const bool aValue)
00688 {
00689     fExternalElement = aValue;
00690 }
00691 
00692 #endif


Copyright © 2000 The Apache Software Foundation. All Rights Reserved.