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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback
Bug-Todo

Download
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.8  2000/12/14 18:49:57  tng

00060  * Fix API document generation warning: "Warning: end of member group without matching begin"

00061  *
00062  * Revision 1.7  2000/11/30 18:22:38  andyh

00063  * reuseValidator - fix bugs (spurious errors) that occured on reuse due to

00064  * pools already containing some items.  Fixed by Tinny Ng.

00065  *
00066  * Revision 1.6  2000/05/11 23:11:32  andyh

00067  * Add missing validity checks for stand-alone documents, character range

00068  * and Well-formed parsed entities.  Changes contributed by Sean MacRoibeaird

00069  * <sean.Macroibeaird@ireland.sun.com>

00070  *
00071  * Revision 1.5  2000/02/24 20:00:23  abagchi

00072  * Swat for removing Log from API docs

00073  *
00074  * Revision 1.4  2000/02/16 19:48:56  roddey

00075  * More documentation updates

00076  *
00077  * Revision 1.3  2000/02/15 01:21:30  roddey

00078  * Some initial documentation improvements. More to come...

00079  *
00080  * Revision 1.2  2000/02/06 07:47:48  rahulj

00081  * Year 2K copyright swat.

00082  *
00083  * Revision 1.1.1.1  1999/11/09 01:08:32  twl

00084  * Initial checkin

00085  *
00086  * Revision 1.2  1999/11/08 20:44:38  rahul

00087  * Swat for adding in Product name and CVS comment log variable.

00088  *
00089  */
00090 
00091 #if !defined(XMLELEMENTDECL_HPP)
00092 #define XMLELEMENTDECL_HPP
00093 
00094 #include <util/XMLString.hpp>
00095 #include <framework/XMLAttr.hpp>
00096 #include <framework/XMLAttDefList.hpp>
00097 #include <framework/XMLContentModel.hpp>
00098 
00099 class XMLValidator;
00100 
00123 class  XMLElementDecl
00124 {
00125  public:
00126     // -----------------------------------------------------------------------
00127     //  Class specific types
00128     //
00129     //  CreateReasons
00130     //      This type is used to store how an element declaration got into
00131     //      the validator's element pool. They are faulted in for various
00132     //      reasons.
00133     //
00134     //  LookupOpts
00135     //      These are the values used by the attribute lookup methods.
00136     //
00137     //  CharDataOpts
00138     //      This is used to indicate how this type of element reacts to
00139     //      character data as content.
00140     // -----------------------------------------------------------------------
00141     enum CreateReasons
00142     {
00143         NoReason
00144         , Declared
00145         , AttList
00146         , InContentModel
00147         , AsRootElem
00148         , JustFaultIn
00149     };
00150 
00151     enum LookupOpts
00152     {
00153         AddIfNotFound
00154         , FailIfNotFound
00155     };
00156 
00157     enum CharDataOpts
00158     {
00159         NoCharData
00160         , SpacesOk
00161         , AllCharData
00162     };
00163 
00164 
00165     // -----------------------------------------------------------------------
00166     //  Public static data
00167     //
00168     //  fgInvalidElemId
00169     //      A value to represent an invalid element node id.
00170     //
00171     //  fgPCDataElemId
00172     //      This is the value to use to represent a PCDATA node when an
00173     //      element id is required.
00174     //
00175     //  fgPCDataElemName
00176     //      This is the value to use to represent a PCDATA node when an
00177     //      element name is required.
00178     // -----------------------------------------------------------------------
00179     static const unsigned int   fgInvalidElemId;
00180     static const unsigned int   fgPCDataElemId;
00181     static const XMLCh          fgPCDataElemName[];
00182 
00183 
00184 
00185     // -----------------------------------------------------------------------
00186     //  Destructor
00187     // -----------------------------------------------------------------------
00190     virtual ~XMLElementDecl();
00192 
00193 
00194     // -----------------------------------------------------------------------
00195     //  The virtual element decl interface
00196     // -----------------------------------------------------------------------
00197 
00200 
00226     virtual XMLAttDef* findAttr
00227     (
00228         const   XMLCh* const    qName
00229         , const unsigned int    uriId
00230         , const XMLCh* const    baseName
00231         , const LookupOpts      options
00232         ,       bool&           wasAdded
00233     )   const = 0;
00234 
00246     virtual XMLAttDefList& getAttDefList() const = 0;
00247 
00256     virtual const XMLCh* getBaseName() const = 0;
00257 
00265     virtual CharDataOpts getCharDataOpts() const = 0;
00266 
00275     virtual const XMLCh* getFullName() const = 0;
00276 
00283     virtual bool hasAttDefs() const = 0;
00284 
00292     virtual bool resetDefs() = 0;
00293 
00295 
00296 
00297     // -----------------------------------------------------------------------
00298     //  Getter methods
00299     // -----------------------------------------------------------------------
00300 
00303 
00315     const XMLContentModel* getContentModel() const;
00316 
00322     XMLContentModel* getContentModel();
00323 
00334     CreateReasons getCreateReason() const;
00335 
00345     unsigned int getId() const;
00346 
00356     bool isDeclared() const;
00357 
00365 
00366     bool isExternal() const;
00367 
00369 
00370 
00371     // -----------------------------------------------------------------------
00372     //  Setter methods
00373     // -----------------------------------------------------------------------
00374 
00377 
00389     void setContentModel(XMLContentModel* const newModelToAdopt);
00390 
00401     void setCreateReason(const CreateReasons newReason);
00402 
00409     void setId(const unsigned int newId);
00410 
00411 
00415     void setExternalElemDeclaration();
00416 
00418 
00419 
00420     // -----------------------------------------------------------------------
00421     //  Miscellaneous methods
00422     // -----------------------------------------------------------------------
00423 
00426 
00446     const XMLCh* getFormattedContentModel
00447     (
00448         const   XMLValidator&   validator
00449     )   const;
00450 
00459     const XMLCh* getKey() const;
00460 
00462 
00463 
00464 protected :
00465     // -----------------------------------------------------------------------
00466     //  Hidden constructors
00467     // -----------------------------------------------------------------------
00468     XMLElementDecl();
00469 
00470 
00471     // -----------------------------------------------------------------------
00472     //  Protected, virtual methods
00473     // -----------------------------------------------------------------------
00474     virtual XMLContentModel* makeContentModel() const = 0;
00475     virtual XMLCh* formatContentModel
00476     (
00477         const   XMLValidator&   validator
00478     )   const = 0;
00479 
00480 
00481 private :
00482     // -----------------------------------------------------------------------
00483     //  Unimplemented constructors and operators
00484     // -----------------------------------------------------------------------
00485     XMLElementDecl(const XMLElementDecl&);
00486     void operator=(const XMLElementDecl&);
00487 
00488 
00489     // -----------------------------------------------------------------------
00490     //  Data members
00491     //
00492     //  fContentModel
00493     //      The content model object for this element. It is stored here via
00494     //      its abstract interface.
00495     //
00496     //  fCreateReason
00497     //      We sometimes have to put an element decl object into the elem
00498     //      decl pool before the element's declaration is seen, such as when
00499     //      its used in another element's content model or an att list is
00500     //      seen for it. This flag tells us whether its been declared, and
00501     //      if not why it had to be created.
00502     //
00503     //  fFormattedModel
00504     //      This is a faulted in member. When the outside world asks for
00505     //      our content model as a string, we format it and fault it into
00506     //      this field (to avoid doing the formatted over and over.)
00507     //
00508     //  fId
00509     //      The unique id of this element. This is created by the derived
00510     //      class, or more accurately the validator that owns the objects
00511     //      of the derived types. But, since they all have to have them, we
00512     //      let them all store the id here. It is defaulted to have the
00513     //      value fgInvalidElem until explicitly set.
00514     //
00515     //  fExternalElement
00516     //      This flag indicates whether or the element was declared externally.
00517     // -----------------------------------------------------------------------
00518     XMLContentModel*    fContentModel;
00519     CreateReasons       fCreateReason;
00520     XMLCh*              fFormattedModel;
00521     unsigned int        fId;
00522     bool                fExternalElement;
00523 };
00524 
00525 
00526 // ---------------------------------------------------------------------------
00527 //  XMLElementDecl: Miscellaneous methods
00528 // ---------------------------------------------------------------------------
00529 inline const XMLCh* XMLElementDecl::getKey() const

00530 {
00531     //
00532     //  We just call the virtual method, since only the derived class knows
00533     //  what form the full name should take.
00534     //
00535     return getFullName();
00536 }
00537 
00538 
00539 // ---------------------------------------------------------------------------
00540 //  XMLElementDecl: Getter methods
00541 // ---------------------------------------------------------------------------
00542 inline XMLContentModel* XMLElementDecl::getContentModel()

00543 {
00544     if (!fContentModel)
00545         fContentModel = makeContentModel();
00546     return fContentModel;
00547 }
00548 
00549 inline const XMLContentModel* XMLElementDecl::getContentModel() const

00550 {
00551     // Fault in the content model (which requires a cast off of const)
00552     if (!fContentModel)
00553         ((XMLElementDecl*)this)->fContentModel = makeContentModel();
00554     return fContentModel;
00555 }
00556 
00557 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const

00558 {
00559     return fCreateReason;
00560 }
00561 
00562 inline unsigned int XMLElementDecl::getId() const

00563 {
00564     return fId;
00565 }
00566 
00567 inline bool XMLElementDecl::isDeclared() const

00568 {
00569     return (fCreateReason == Declared);
00570 }
00571 
00572 
00573 inline bool XMLElementDecl::isExternal() const

00574 {
00575     return fExternalElement;
00576 }
00577 
00578 
00579 // ---------------------------------------------------------------------------
00580 //  XMLElementDecl: Setter methods
00581 // ---------------------------------------------------------------------------
00582 inline void
00583 XMLElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)

00584 {
00585     delete fContentModel;
00586     fContentModel = newModelToAdopt;
00587 }
00588 
00589 inline void
00590 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)

00591 {
00592     fCreateReason = newReason;
00593 }
00594 
00595 inline void XMLElementDecl::setId(const unsigned int newId)

00596 {
00597     fId = newId;
00598 }
00599 
00600 
00601 inline void XMLElementDecl::setExternalElemDeclaration()

00602 {
00603     fExternalElement = true;
00604 }
00605 
00606 #endif


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