www.alphaworks.ibm.comwww.ibm.com/developerwww.ibm.com

Home

Readme
Download

Build







Migration

Releases

Feedback

Y2K Compliance


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.15  2001/05/11 13:25:32  tng
00060  * Copyright update.
00061  *
00062  * Revision 1.14  2001/05/03 20:34:22  tng
00063  * Schema: SchemaValidator update
00064  *
00065  * Revision 1.13  2001/04/19 18:16:52  tng
00066  * Schema: SchemaValidator update, and use QName in Content Model
00067  *
00068  * Revision 1.12  2001/03/21 21:56:02  tng
00069  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
00070  *
00071  * Revision 1.11  2001/03/21 19:29:29  tng
00072  * Schema: Content Model Updates, by Pei Yong Zhang.
00073  *
00074  * Revision 1.10  2001/02/26 19:29:13  tng
00075  * Schema: add virtual method getURI(), getContentSpec and setContenSpec in XMLElementDecl, and DTDElementDecl.
00076  *
00077  * Revision 1.9  2001/02/26 19:21:30  tng
00078  * Schema: add parameter prefix in findElem and findAttr.
00079  *
00080  * Revision 1.8  2000/12/14 18:49:57  tng
00081  * Fix API document generation warning: "Warning: end of member group without matching begin"
00082  *
00083  * Revision 1.7  2000/11/30 18:22:38  andyh
00084  * reuseValidator - fix bugs (spurious errors) that occured on reuse due to
00085  * pools already containing some items.  Fixed by Tinny Ng.
00086  *
00087  * Revision 1.6  2000/05/11 23:11:32  andyh
00088  * Add missing validity checks for stand-alone documents, character range
00089  * and Well-formed parsed entities.  Changes contributed by Sean MacRoibeaird
00090  * <sean.Macroibeaird@ireland.sun.com>
00091  *
00092  * Revision 1.5  2000/02/24 20:00:23  abagchi
00093  * Swat for removing Log from API docs
00094  *
00095  * Revision 1.4  2000/02/16 19:48:56  roddey
00096  * More documentation updates
00097  *
00098  * Revision 1.3  2000/02/15 01:21:30  roddey
00099  * Some initial documentation improvements. More to come...
00100  *
00101  * Revision 1.2  2000/02/06 07:47:48  rahulj
00102  * Year 2K copyright swat.
00103  *
00104  * Revision 1.1.1.1  1999/11/09 01:08:32  twl
00105  * Initial checkin
00106  *
00107  * Revision 1.2  1999/11/08 20:44:38  rahul
00108  * Swat for adding in Product name and CVS comment log variable.
00109  *
00110  */
00111 
00112 #if !defined(XMLELEMENTDECL_HPP)
00113 #define XMLELEMENTDECL_HPP
00114 
00115 #include <util/XMLString.hpp>
00116 #include <framework/XMLAttr.hpp>
00117 #include <framework/XMLAttDefList.hpp>
00118 #include <framework/XMLContentModel.hpp>
00119 
00120 class ContentSpecNode;
00121 
00137 class  XMLElementDecl
00138 {
00139  public:
00140     // -----------------------------------------------------------------------
00141     //  Class specific types
00142     //
00143     //  CreateReasons
00144     //      This type is used to store how an element declaration got into
00145     //      the grammar's element pool. They are faulted in for various
00146     //      reasons.
00147     //
00148     //  LookupOpts
00149     //      These are the values used by the attribute lookup methods.
00150     //
00151     //  CharDataOpts
00152     //      This is used to indicate how this type of element reacts to
00153     //      character data as content.
00154     // -----------------------------------------------------------------------
00155     enum CreateReasons
00156     {
00157         NoReason
00158         , Declared
00159         , AttList
00160         , InContentModel
00161         , AsRootElem
00162         , JustFaultIn
00163     };
00164 
00165     enum LookupOpts
00166     {
00167         AddIfNotFound
00168         , FailIfNotFound
00169     };
00170 
00171     enum CharDataOpts
00172     {
00173         NoCharData
00174         , SpacesOk
00175         , AllCharData
00176     };
00177 
00178 
00179     // -----------------------------------------------------------------------
00180     //  Public static data
00181     //
00182     //  fgInvalidElemId
00183     //      A value to represent an invalid element node id.
00184     //
00185     //  fgPCDataElemId
00186     //      This is the value to use to represent a PCDATA node when an
00187     //      element id is required.
00188     //
00189     //  fgPCDataElemName
00190     //      This is the value to use to represent a PCDATA node when an
00191     //      element name is required.
00192     // -----------------------------------------------------------------------
00193     static const unsigned int   fgInvalidElemId;
00194     static const unsigned int   fgPCDataElemId;
00195     static const XMLCh          fgPCDataElemName[];
00196 
00197 
00198 
00199     // -----------------------------------------------------------------------
00200     //  Destructor
00201     // -----------------------------------------------------------------------
00204     virtual ~XMLElementDecl();
00206 
00207 
00208     // -----------------------------------------------------------------------
00209     //  The virtual element decl interface
00210     // -----------------------------------------------------------------------
00211 
00214 
00243     virtual XMLAttDef* findAttr
00244     (
00245         const   XMLCh* const    qName
00246         , const unsigned int    uriId
00247         , const XMLCh* const    baseName
00248         , const XMLCh* const    prefix
00249         , const LookupOpts      options
00250         ,       bool&           wasAdded
00251     )   const = 0;
00252 
00264     virtual XMLAttDefList& getAttDefList() const = 0;
00265 
00273     virtual CharDataOpts getCharDataOpts() const = 0;
00274 
00281     virtual bool hasAttDefs() const = 0;
00282 
00290     virtual bool resetDefs() = 0;
00291 
00299     virtual const ContentSpecNode* getContentSpec() const = 0;
00300 
00306     virtual ContentSpecNode* getContentSpec() = 0;
00307 
00317     virtual void setContentSpec(ContentSpecNode* toAdopt) = 0;
00318 
00320 
00321 
00322     // -----------------------------------------------------------------------
00323     //  Getter methods
00324     // -----------------------------------------------------------------------
00325 
00328 
00336     const XMLCh* getBaseName() const;
00337     XMLCh* getBaseName();
00338 
00345     const unsigned int getURI() const;
00346 
00354     const QName* getElementName() const;
00355     QName* getElementName();
00356 
00365     const XMLCh* getFullName() const;
00366 
00378     XMLContentModel* getContentModel();
00379 
00390 
00391     CreateReasons getCreateReason() const;
00392 
00402     unsigned int getId() const;
00403 
00413     bool isDeclared() const;
00414 
00422 
00423     bool isExternal() const;
00424 
00426 
00427 
00428     // -----------------------------------------------------------------------
00429     //  Setter methods
00430     // -----------------------------------------------------------------------
00431 
00434 
00445       void setElementName(const XMLCh* const       prefix
00446                         , const XMLCh* const       localPart
00447                         , const int                uriId );
00448 
00458       void setElementName(const XMLCh* const    rawName
00459                         , const int             uriId );
00460 
00469       void setElementName(QName* const    elementName);
00470 
00482     void setContentModel(XMLContentModel* const newModelToAdopt);
00483 
00494     void setCreateReason(const CreateReasons newReason);
00495 
00502     void setId(const unsigned int newId);
00503 
00504 
00508     void setExternalElemDeclaration();
00509 
00511 
00512 
00513     // -----------------------------------------------------------------------
00514     //  Miscellaneous methods
00515     // -----------------------------------------------------------------------
00516 
00519 
00532     const XMLCh* getFormattedContentModel ()   const;
00533 
00535 
00536 
00537 protected :
00538     // -----------------------------------------------------------------------
00539     //  Hidden constructors
00540     // -----------------------------------------------------------------------
00541     XMLElementDecl();
00542 
00543 
00544     // -----------------------------------------------------------------------
00545     //  Protected, virtual methods
00546     // -----------------------------------------------------------------------
00547     virtual XMLContentModel* makeContentModel() = 0;
00548     virtual XMLCh* formatContentModel ()   const = 0;
00549 
00550 
00551 private :
00552     // -----------------------------------------------------------------------
00553     //  Unimplemented constructors and operators
00554     // -----------------------------------------------------------------------
00555     XMLElementDecl(const XMLElementDecl&);
00556     void operator=(const XMLElementDecl&);
00557 
00558 
00559     // -----------------------------------------------------------------------
00560     //  Data members
00561     //
00562     //  fElementName
00563     //      This is the name of the element decl.
00564     //
00565     //  fContentModel
00566     //      The content model object for this element. It is stored here via
00567     //      its abstract interface.
00568     //
00569     //  fCreateReason
00570     //      We sometimes have to put an element decl object into the elem
00571     //      decl pool before the element's declaration is seen, such as when
00572     //      its used in another element's content model or an att list is
00573     //      seen for it. This flag tells us whether its been declared, and
00574     //      if not why it had to be created.
00575     //
00576     //  fFormattedModel
00577     //      This is a faulted in member. When the outside world asks for
00578     //      our content model as a string, we format it and fault it into
00579     //      this field (to avoid doing the formatted over and over.)
00580     //
00581     //  fId
00582     //      The unique id of this element. This is created by the derived
00583     //      class, or more accurately the grammar that owns the objects
00584     //      of the derived types. But, since they all have to have them, we
00585     //      let them all store the id here. It is defaulted to have the
00586     //      value fgInvalidElem until explicitly set.
00587     //
00588     //  fExternalElement
00589     //      This flag indicates whether or the element was declared externally.
00590     // -----------------------------------------------------------------------
00591     QName*              fElementName;
00592     XMLContentModel*    fContentModel;
00593     CreateReasons       fCreateReason;
00594     XMLCh*              fFormattedModel;
00595     unsigned int        fId;
00596     bool                fExternalElement;
00597 };
00598 
00599 
00600 // ---------------------------------------------------------------------------
00601 //  XMLElementDecl: Getter methods
00602 // ---------------------------------------------------------------------------
00603 inline const XMLCh* XMLElementDecl::getBaseName() const
00604 {
00605     return fElementName->getLocalPart();
00606 }
00607 
00608 inline XMLCh* XMLElementDecl::getBaseName()
00609 {
00610     return fElementName->getLocalPart();
00611 }
00612 
00613 inline const unsigned int XMLElementDecl::getURI() const
00614 {
00615     return fElementName->getURI();
00616 }
00617 
00618 inline const QName* XMLElementDecl::getElementName() const
00619 {
00620     return fElementName;
00621 }
00622 
00623 inline QName* XMLElementDecl::getElementName()
00624 {
00625     return fElementName;
00626 }
00627 
00628 inline const XMLCh* XMLElementDecl::getFullName() const
00629 {
00630     return fElementName->getRawName();
00631 }
00632 
00633 inline XMLContentModel* XMLElementDecl::getContentModel()
00634 {
00635     if (!fContentModel)
00636         fContentModel = makeContentModel();
00637     return fContentModel;
00638 }
00639 
00640 inline XMLElementDecl::CreateReasons XMLElementDecl::getCreateReason() const
00641 {
00642     return fCreateReason;
00643 }
00644 
00645 inline unsigned int XMLElementDecl::getId() const
00646 {
00647     return fId;
00648 }
00649 
00650 inline bool XMLElementDecl::isDeclared() const
00651 {
00652     return (fCreateReason == Declared);
00653 }
00654 
00655 
00656 inline bool XMLElementDecl::isExternal() const
00657 {
00658     return fExternalElement;
00659 }
00660 
00661 
00662 // ---------------------------------------------------------------------------
00663 //  XMLElementDecl: Setter methods
00664 // ---------------------------------------------------------------------------
00665 inline void
00666 XMLElementDecl::setContentModel(XMLContentModel* const newModelToAdopt)
00667 {
00668     delete fContentModel;
00669     fContentModel = newModelToAdopt;
00670 }
00671 
00672 inline void
00673 XMLElementDecl::setCreateReason(const XMLElementDecl::CreateReasons newReason)
00674 {
00675     fCreateReason = newReason;
00676 }
00677 
00678 inline void XMLElementDecl::setId(const unsigned int newId)
00679 {
00680     fId = newId;
00681 }
00682 
00683 
00684 inline void XMLElementDecl::setExternalElemDeclaration()
00685 {
00686     fExternalElement = true;
00687 }
00688 
00689 #endif


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