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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback

PDF Document

Download
Dev Snapshots
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-2000 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.6  2000/05/11 23:11:32  andyh
00060  * Add missing validity checks for stand-alone documents, character range
00061  * and Well-formed parsed entities.  Changes contributed by Sean MacRoibeaird
00062  * <sean.Macroibeaird@ireland.sun.com>
00063  *
00064  * Revision 1.5  2000/02/24 20:00:23  abagchi
00065  * Swat for removing Log from API docs
00066  *
00067  * Revision 1.4  2000/02/16 19:48:56  roddey
00068  * More documentation updates
00069  *
00070  * Revision 1.3  2000/02/15 01:21:30  roddey
00071  * Some initial documentation improvements. More to come...
00072  *
00073  * Revision 1.2  2000/02/06 07:47:48  rahulj
00074  * Year 2K copyright swat.
00075  *
00076  * Revision 1.1.1.1  1999/11/09 01:08:32  twl
00077  * Initial checkin
00078  *
00079  * Revision 1.2  1999/11/08 20:44:38  rahul
00080  * Swat for adding in Product name and CVS comment log variable.
00081  *
00082  */
00083 
00084 #if !defined(XMLELEMENTDECL_HPP)
00085 #define XMLELEMENTDECL_HPP
00086 
00087 #include <util/XMLString.hpp>
00088 #include <framework/XMLAttr.hpp>
00089 #include <framework/XMLAttDefList.hpp>
00090 #include <framework/XMLContentModel.hpp>
00091 
00092 class XMLValidator;
00093 
00116 class  XMLElementDecl
00117 {
00118  public:
00119     // -----------------------------------------------------------------------
00120     //  Class specific types
00121     //
00122     //  CreateReasons
00123     //      This type is used to store how an element declaration got into
00124     //      the validator's element pool. They are faulted in for various
00125     //      reasons.
00126     //
00127     //  LookupOpts
00128     //      These are the values used by the attribute lookup methods.
00129     //
00130     //  CharDataOpts
00131     //      This is used to indicate how this type of element reacts to
00132     //      character data as content.
00133     // -----------------------------------------------------------------------
00134     enum CreateReasons
00135     {
00136         NoReason
00137         , Declared
00138         , AttList
00139         , InContentModel
00140         , AsRootElem
00141     };
00142 
00143     enum LookupOpts
00144     {
00145         AddIfNotFound
00146         , FailIfNotFound
00147     };
00148 
00149     enum CharDataOpts
00150     {
00151         NoCharData
00152         , SpacesOk
00153         , AllCharData
00154     };
00155 
00156 
00157     // -----------------------------------------------------------------------
00158     //  Public static data
00159     //
00160     //  fgInvalidElemId
00161     //      A value to represent an invalid element node id.
00162     //
00163     //  fgPCDataElemId
00164     //      This is the value to use to represent a PCDATA node when an
00165     //      element id is required.
00166     //
00167     //  fgPCDataElemName
00168     //      This is the value to use to represent a PCDATA node when an
00169     //      element name is required.
00170     // -----------------------------------------------------------------------
00171     static const unsigned int   fgInvalidElemId;
00172     static const unsigned int   fgPCDataElemId;
00173     static const XMLCh          fgPCDataElemName[];
00174 
00175 
00176 
00177     // -----------------------------------------------------------------------
00178     //  Destructor
00179     // -----------------------------------------------------------------------
00181     //@{
00182     virtual ~XMLElementDecl();
00183     //@}
00184 
00185 
00186     // -----------------------------------------------------------------------
00187     //  The virtual element decl interface
00188     // -----------------------------------------------------------------------
00189 
00191     //@{
00192 
00218     virtual XMLAttDef* findAttr
00219     (
00220         const   XMLCh* const    qName
00221         , const unsigned int    uriId
00222         , const XMLCh* const    baseName
00223         , const LookupOpts      options
00224         ,       bool&           wasAdded
00225     )   const = 0;
00226 
00238     virtual XMLAttDefList& getAttDefList() const = 0;
00239 
00248     virtual const XMLCh* getBaseName() const = 0;
00249 
00257     virtual CharDataOpts getCharDataOpts() const = 0;
00258 
00267     virtual const XMLCh* getFullName() const = 0;
00268 
00275     virtual bool hasAttDefs() const = 0;
00276 
00284     virtual bool resetDefs() = 0;
00285 
00286     //@}
00287 
00288 
00289     // -----------------------------------------------------------------------
00290     //  Getter methods
00291     // -----------------------------------------------------------------------
00292 
00294     //{@
00295 
00307     const XMLContentModel* getContentModel() const;
00308 
00314     XMLContentModel* getContentModel();
00315 
00326     CreateReasons getCreateReason() const;
00327 
00337     unsigned int getId() const;
00338 
00348     bool isDeclared() const;
00349 
00357 
00358     bool isExternal() const;
00359 
00360     //@}
00361 
00362 
00363     // -----------------------------------------------------------------------
00364     //  Setter methods
00365     // -----------------------------------------------------------------------
00366 
00368     //{@
00369 
00381     void setContentModel(XMLContentModel* const newModelToAdopt);
00382 
00393     void setCreateReason(const CreateReasons newReason);
00394 
00401     void setId(const unsigned int newId);
00402 
00403 
00407     void setExternalElemDeclaration();
00408 
00409     //@}
00410 
00411 
00412     // -----------------------------------------------------------------------
00413     //  Miscellaneous methods
00414     // -----------------------------------------------------------------------
00415 
00417     //{@
00418 
00438     const XMLCh* getFormattedContentModel
00439     (
00440         const   XMLValidator&   validator
00441     )   const;
00442 
00451     const XMLCh* getKey() const;
00452 
00453     //@}
00454 
00455 
00456 protected :
00457     // -----------------------------------------------------------------------
00458     //  Hidden constructors
00459     // -----------------------------------------------------------------------
00460     XMLElementDecl();
00461 
00462 
00463     // -----------------------------------------------------------------------
00464     //  Protected, virtual methods
00465     // -----------------------------------------------------------------------
00466     virtual XMLContentModel* makeContentModel() const = 0;
00467     virtual XMLCh* formatContentModel
00468     (
00469         const   XMLValidator&   validator
00470     )   const = 0;
00471 
00472 
00473 private :
00474     // -----------------------------------------------------------------------
00475     //  Unimplemented constructors and operators
00476     // -----------------------------------------------------------------------
00477     XMLElementDecl(const XMLElementDecl&);
00478     void operator=(const XMLElementDecl&);
00479 
00480 
00481     // -----------------------------------------------------------------------
00482     //  Data members
00483     //
00484     //  fContentModel
00485     //      The content model object for this element. It is stored here via
00486     //      its abstract interface.
00487     //
00488     //  fCreateReason
00489     //      We sometimes have to put an element decl object into the elem
00490     //      decl pool before the element's declaration is seen, such as when
00491     //      its used in another element's content model or an att list is
00492     //      seen for it. This flag tells us whether its been declared, and
00493     //      if not why it had to be created.
00494     //
00495     //  fFormattedModel
00496     //      This is a faulted in member. When the outside world asks for
00497     //      our content model as a string, we format it and fault it into
00498     //      this field (to avoid doing the formatted over and over.)
00499     //
00500     //  fId
00501     //      The unique id of this element. This is created by the derived
00502     //      class, or more accurately the validator that owns the objects
00503     //      of the derived types. But, since they all have to have them, we
00504     //      let them all store the id here. It is defaulted to have the
00505     //      value fgInvalidElem until explicitly set.
00506     //
00507     //  fExternalElement
00508     //      This flag indicates whether or the element was declared externally.
00509     // -----------------------------------------------------------------------
00510     XMLContentModel*    fContentModel;
00511     CreateReasons       fCreateReason;
00512     XMLCh*              fFormattedModel;
00513     unsigned int        fId;
00514     bool                fExternalElement;
00515 };
00516 
00517 
00518 // ---------------------------------------------------------------------------
00519 //  XMLElementDecl: Miscellaneous methods
00520 // ---------------------------------------------------------------------------
00521 inline const XMLCh* XMLElementDecl::getKey() const
00522 {
00523     //
00524     //  We just call the virtual method, since only the derived class knows
00525     //  what form the full name should take.
00526     //
00527     return getFullName();
00528 }
00529 
00530 
00531 // ---------------------------------------------------------------------------
00532 //  XMLElementDecl: Getter methods
00533 // ---------------------------------------------------------------------------
00534 inline XMLContentModel* XMLElementDecl::getContentModel()
00535 {
00536     if (!fContentModel)
00537         fContentModel = makeContentModel();
00538     return fContentModel;
00539 }
00540 
00541 inline const XMLContentModel* XMLElementDecl::getContentModel() const
00542 {
00543     // Fault in the content model (which requires a cast off of const)
00544     if (!fContentModel)
00545         ((XMLElementDecl*)this)->fContentModel = makeContentModel();
00546     return fContentModel;
00547 }
00548 
00549 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const
00550 {
00551     return fCreateReason;
00552 }
00553 
00554 inline unsigned int XMLElementDecl::getId() const
00555 {
00556     return fId;
00557 }
00558 
00559 inline bool XMLElementDecl::isDeclared() const
00560 {
00561     return (fCreateReason == Declared);
00562 }
00563 
00564 
00565 inline bool XMLElementDecl::isExternal() const
00566 {
00567     return fExternalElement;
00568 }
00569 
00570 
00571 // ---------------------------------------------------------------------------
00572 //  XMLElementDecl: Setter methods
00573 // ---------------------------------------------------------------------------
00574 inline void
00575 XMLElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
00576 {
00577     delete fContentModel;
00578     fContentModel = newModelToAdopt;
00579 }
00580 
00581 inline void
00582 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)
00583 {
00584     fCreateReason = newReason;
00585 }
00586 
00587 inline void XMLElementDecl::setId(const unsigned int newId)
00588 {
00589     fId = newId;
00590 }
00591 
00592 
00593 inline void XMLElementDecl::setExternalElemDeclaration()
00594 {
00595     fExternalElement = true;
00596 }
00597 
00598 #endif


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