Main Page   Class Hierarchy   Compound List   File List   Compound Members  

IDDocumentImpl.hpp

00001 #ifndef IDDocumentImpl_HEADER_GUARD_
00002 #define IDDocumentImpl_HEADER_GUARD_
00003 
00004 /*
00005  * The Apache Software License, Version 1.1
00006  *
00007  * Copyright (c) 2001 The Apache Software Foundation.  All rights
00008  * reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright
00018  *    notice, this list of conditions and the following disclaimer in
00019  *    the documentation and/or other materials provided with the
00020  *    distribution.
00021  *
00022  * 3. The end-user documentation included with the redistribution,
00023  *    if any, must include the following acknowledgment:
00024  *       "This product includes software developed by the
00025  *        Apache Software Foundation (http://www.apache.org/)."
00026  *    Alternately, this acknowledgment may appear in the software itself,
00027  *    if and wherever such third-party acknowledgments normally appear.
00028  *
00029  * 4. The names "Xerces" and "Apache Software Foundation" must
00030  *    not be used to endorse or promote products derived from this
00031  *    software without prior written permission. For written
00032  *    permission, please contact apache\@apache.org.
00033  *
00034  * 5. Products derived from this software may not be called "Apache",
00035  *    nor may "Apache" appear in their name, without prior written
00036  *    permission of the Apache Software Foundation.
00037  *
00038  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00039  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00040  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00041  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00042  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00043  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00044  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00045  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00046  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00047  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00048  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00049  * SUCH DAMAGE.
00050  * ====================================================================
00051  *
00052  * This software consists of voluntary contributions made by many
00053  * individuals on behalf of the Apache Software Foundation, and was
00054  * originally based on software copyright (c) 2001, International
00055  * Business Machines, Inc., http://www.ibm.com .  For more information
00056  * on the Apache Software Foundation, please see
00057  * <http://www.apache.org/>.
00058  */
00059 
00060 /*
00061  * $Id: IDDocumentImpl.hpp,v 1.1 2002/05/11 20:07:49 bhavani Exp $
00062  */
00063 
00064 //
00065 //  This file is part of the internal implementation of the C++ XML DOM.
00066 //  It should NOT be included or used directly by application programs.
00067 //
00068 //  Applications should include the file <dom/DOM.hpp> for the entire
00069 //  DOM API, or IDOM_*.hpp for individual DOM classes, where the class
00070 //  name is substituded for the *.
00071 //
00072 
00073 #include <string.h>
00074 #include <xercesc/util/XercesDefs.hpp>
00075 #include "xercesc/util/RefVectorOf.hpp"
00076 #include "xercesc/util/RefHashTableOf.hpp"
00077 
00078 #include "IDOM_Document.hpp"
00079 #include "IDNodeImpl.hpp"
00080 #include "IDParentNode.hpp"
00081 #include "IDDeepNodeListPool.hpp"
00082 
00083 
00084 class IDAttrImpl;
00085 class IDCDATASectionImpl;
00086 class IDCommentImpl;
00087 class IDDeepNodeListImpl;
00088 class IDDocumentFragmentImpl;
00089 class IDDocumentTypeImpl;
00090 class IDDStringPool;
00091 class IDElementImpl;
00092 class IDEntityImpl;
00093 class IDEntityReferenceImpl;
00094 class IDNodeImpl;
00095 class IDNotationImpl;
00096 class IDProcessingInstructionImpl;
00097 class IDTextImpl;
00098 class IDNodeIteratorImpl;
00099 class IDTreeWalkerImpl;
00100 class IDOM_NodeFilter;
00101 class IDNodeFilterImpl;
00102 class IDOM_DOMImplementation;
00103 class IDNodeIDMap;
00104 class IDRangeImpl;
00105 class IDParentNode;
00106 class IDStringPool;
00107 
00108 typedef RefVectorOf<IDNodeIteratorImpl> NodeIterators;
00109 typedef RefVectorOf<IDTreeWalkerImpl>   TreeWalkers;
00110 typedef RefVectorOf<IDRangeImpl>        Ranges;
00111 
00112 
00113 class CDOM_EXPORT IDDocumentImpl: public IDOM_Document {
00114 public:
00115     // -----------------------------------------------------------------------
00116     //  Private data types
00117     // -----------------------------------------------------------------------
00118 
00119 
00120     IDNodeImpl                  fNode;           // Implements common node functionality.
00121     IDParentNode                fParent;         // Implements common parent node functionality
00122 
00123     IDOM_DocumentType           *fDocType;
00124     IDOM_Element                *fDocElement;
00125     IDStringPool                *fNamePool;
00126     IDNodeIDMap                 *fNodeIDMap;     // for use by GetElementsById().
00127 
00128     NodeIterators               *fIterators;
00129     TreeWalkers                 *fTreeWalkers;
00130     Ranges                      *fRanges;
00131 
00132     RefHashTableOf<void>        *fUserData;
00133     int                          fChanges;
00134 
00135     bool errorChecking;                          // Bypass error checking.
00136 
00137 
00138     // Per-Document heap Variables.
00139     //   The heap consists of one or more biggish blocks which are
00140     //   sub-allocated for individual allocations of nodes, strings, etc.
00141     //   The big blocks form a linked list, allowing them to be located for deletion.
00142     //
00143     //   There is no provision for deleting suballocated blocks, other than
00144     //     deleting the entire heap when the document is deleted.
00145     //
00146     //   There is no header on individual sub-allocated blocks.
00147     //   The header on big blocks consists only of a single back pointer to
00148     //    the previously allocated big block (our linked list of big blocks)
00149     //
00150     //
00151     //   idom_revisit - this heap should be encapsulated into its own
00152     //                  class, rather than hanging naked on Document.
00153     //
00154     void                        *fCurrentBlock;
00155     char                        *fFreePtr;
00156     unsigned int                 fFreeBytesRemaining;
00157 
00158 
00159 
00160 
00161     friend class IDNodeImpl;
00162     friend class IDNodeIteratorImpl;
00163     friend class IDTreeWalkerImpl;
00164     friend class IDRangeImpl;
00165     friend class IDDOMParser;
00166 
00167 
00168 
00169     void setDocumentType(IDOM_DocumentType *doctype);
00170 
00171 
00172 
00173 public:
00174     IDDocumentImpl();
00175     IDDocumentImpl(const XMLCh      *namespaceURI,           //DOM Level 2
00176                    const XMLCh      *qualifiedName,
00177                    IDOM_DocumentType *doctype);
00178     virtual ~IDDocumentImpl();
00179 
00180     // Add all functions that are pure virutal in IDOM_NODE
00181     IDOM_NODE_FUNCTIONS;
00182 
00183     virtual IDOM_Attr             *createAttribute(const XMLCh *name);
00184     virtual IDOM_CDATASection     *createCDATASection(const XMLCh *data);
00185     virtual IDOM_Comment          *createComment(const XMLCh *data);
00186     virtual IDOM_DocumentFragment *createDocumentFragment();
00187     virtual IDOM_DocumentType     *createDocumentType(const XMLCh *name);
00188     virtual IDOM_DocumentType     *createDocumentType(const XMLCh *qName,
00189                                                     const XMLCh *publicId,
00190                                                     const XMLCh *systemId);
00191     virtual IDOM_Element          *createElement(const XMLCh * tagName);
00192     virtual IDOM_Element          *createElementNoCheck(const XMLCh *tagName);
00193     virtual IDOM_Entity           *createEntity(const XMLCh * name);
00194     virtual IDOM_EntityReference  *createEntityReference(const XMLCh * name);
00195     virtual IDOM_Notation         *createNotation(const XMLCh * name);
00196     virtual IDOM_ProcessingInstruction *createProcessingInstruction(const XMLCh * target, const XMLCh * data);
00197     virtual IDOM_Text             *createTextNode(const XMLCh * data);
00198     virtual IDOM_DocumentType     *getDoctype() const;
00199     virtual IDOM_Element          *getDocumentElement() const;
00200     virtual IDOM_NodeList         *getElementsByTagName(const XMLCh * tagname) const;
00201     virtual IDOM_DOMImplementation *getImplementation() const;
00202     static  bool                  isXMLName(const XMLCh * s);
00203     virtual IDOM_NodeIterator     *createNodeIterator(IDOM_Node *root,
00204                                                       unsigned long whatToShow,
00205                                                       IDOM_NodeFilter* filter,
00206                                                       bool entityReferenceExpansion);
00207     virtual IDOM_TreeWalker       *createTreeWalker(IDOM_Node *root,
00208                                                     unsigned long whatToShow,
00209                                                     IDOM_NodeFilter* filter,
00210                                                     bool entityReferenceExpansion);
00211 
00212     virtual void*                  getUserData() const;
00213     virtual void                   setUserData(void* value);
00214     virtual IDOM_Range            *createRange();
00215     virtual Ranges*                getRanges() const;  //non-standard api
00216     virtual void                   removeRange(IDRangeImpl* range); //non-standard api
00217 
00218 
00219     // helper functions to prevent storing userdata pointers on every node.
00220     virtual void  setUserData(IDOM_Node* n, void* data);
00221     virtual void* getUserData(const IDOM_Node* n) const;
00222 
00223     //
00224     // Functions to keep track of document mutations, so that node list chached
00225     //   information can be invalidated.  One global changes counter per document.
00226     //
00227     virtual void                 changed();
00228     virtual int                  changes() const;
00229 
00248     inline void setErrorChecking(bool check) {
00249         errorChecking = check;
00250     }
00251 
00255     inline bool getErrorChecking() {
00256         return errorChecking;
00257     }
00258 
00259     //Introduced in DOM Level 2
00260     virtual IDOM_Node            *importNode(IDOM_Node *source, bool deep);
00261     virtual IDOM_Element         *createElementNS(const XMLCh *namespaceURI,
00262                                                      const XMLCh *qualifiedName);
00263     virtual IDOM_Attr            *createAttributeNS(const XMLCh *namespaceURI,
00264                                                      const XMLCh *qualifiedName);
00265     virtual IDOM_NodeList        *getElementsByTagNameNS(const XMLCh *namespaceURI,
00266                                                       const XMLCh *localName) const;
00267     virtual IDOM_Element         *getElementById(const XMLCh *elementId) const;
00268 
00269 
00270     //Return the index > 0 of ':' in the given qualified name qName="prefix:localName".
00271     //Return 0 if there is no ':', or -1 if qName is malformed such as ":abcd".
00272     static  int                 indexofQualifiedName(const XMLCh * qName);
00273     static  bool                isKidOK(IDOM_Node *parent, IDOM_Node *child);
00274 
00275     inline IDNodeIDMap *          getNodeIDMap() {return fNodeIDMap;};
00276 
00277 
00278     //
00279     // Memory Management Functions.  All memory is allocated by and owned by
00280     //                               a document, and is not recovered until the
00281     //                               document itself is deleted.
00282     //
00283 
00284     void        * allocate(size_t amount);
00285     XMLCh       * cloneString(const XMLCh *src);
00286     const XMLCh * getPooledString(const XMLCh *src);
00287     void          deleteHeap();
00288 
00289 
00290     // Factory methods for getting/creating node lists.
00291     // Because nothing is ever deleted, the implementation caches and recycles
00292     //  previously used instances of IDDeepNodeList
00293     //
00294     IDOM_NodeList *getDeepNodeList(const IDOM_Node *rootNode, const XMLCh *tagName);
00295     IDOM_NodeList *getDeepNodeList(const IDOM_Node *rootNode,   //DOM Level 2
00296                                                     const XMLCh *namespaceURI,
00297                                      const XMLCh *localName);
00298 
00299 private:
00300     IDDeepNodeListPool<IDDeepNodeListImpl> *fNodeListPool;
00301 };
00302 
00303 //
00304 //  Operator new.  Global overloaded version, lets any object be allocated on
00305 //                 the heap owned by a document.
00306 //
00307 inline void * operator new(size_t amt, IDOM_Document *doc)
00308 {
00309     // idom_revist.  Probably should be a checked cast.
00310     void *p = ((IDDocumentImpl *)doc)->allocate(amt);
00311     return p;
00312 }
00313 
00314 #endif

Generated on Tue Nov 19 09:36:29 2002 by doxygen1.3-rc1