Main Page   Class Hierarchy   Compound List   File List   Compound Members  

IDNodeImpl.hpp

00001 #ifndef IDNodeImpl_HEADER_GUARD_
00002 #define IDNodeImpl_HEADER_GUARD_
00003 
00004 /*
00005  * The Apache Software License, Version 1.1
00006  *
00007  * Copyright (c) 2001-2002 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: IDNodeImpl.hpp,v 1.1 2002/05/11 20:10:24 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 DOM_*.hpp for individual DOM classes, where the class
00070 //  name is substituded for the *.
00071 //
00072 
00091 #include <xercesc/util/XercesDefs.hpp>
00092 
00093 class IDOM_NamedNodeMap;
00094 class IDOM_NodeList;
00095 class IDOM_Node;
00096 class IDOM_Document;
00097 
00098 class CDOM_EXPORT IDNodeImpl {
00099 public:
00100 
00101     // data
00102     IDOM_Node                *fOwnerNode; // typically the parent but not always!
00103     unsigned short flags;
00104 
00105     static const unsigned short READONLY;
00106     static const unsigned short SYNCDATA;
00107     static const unsigned short SYNCCHILDREN;
00108     static const unsigned short OWNED;
00109     static const unsigned short FIRSTCHILD;
00110     static const unsigned short SPECIFIED;
00111     static const unsigned short IGNORABLEWS;
00112     static const unsigned short SETVALUE;
00113     static const unsigned short ID_ATTR;
00114         static const unsigned short USERDATA;
00115     static const unsigned short LEAFNODETYPE;
00116     static const unsigned short CHILDNODE;
00117 
00118 
00119 public:
00120     IDNodeImpl(IDOM_Node *ownerDocument);
00121     IDNodeImpl(const IDNodeImpl &other);
00122     ~IDNodeImpl();
00123 
00124      IDOM_Node         *appendChild(IDOM_Node *newChild);
00125      IDOM_NamedNodeMap * getAttributes() const;
00126      IDOM_NodeList     * getChildNodes() const;
00127      IDOM_Node         * getFirstChild() const;
00128      IDOM_Node         * getLastChild() const;
00129      const XMLCh       * getLocalName() const;
00130      const XMLCh       * getNamespaceURI() const;
00131      IDOM_Node         * getNextSibling() const;
00132      const XMLCh       * getNodeValue() const;
00133      IDOM_Document     * getOwnerDocument() const;
00134      IDOM_Node         * getParentNode() const;
00135      const XMLCh       * getPrefix() const;
00136      IDOM_Node         * getPreviousSibling() const;
00137      void              * getUserData() const;
00138      bool                hasChildNodes() const;
00139      IDOM_Node         * insertBefore(IDOM_Node *newChild, IDOM_Node *refChild);
00140      void                normalize();
00141      IDOM_Node         * removeChild(IDOM_Node *oldChild);
00142      IDOM_Node         * replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild);
00143      void                setNodeValue(const XMLCh *value);
00144      void                setPrefix(const XMLCh *fPrefix);
00145      void                setReadOnly(bool readOnly, bool deep);
00146      void                setUserData(void *value);
00147      bool                isSupported(const XMLCh *feature, const XMLCh *version) const;
00148      bool                hasAttributes() const;
00149 
00150     static  bool         isKidOK(IDOM_Node *parent, IDOM_Node *child);
00151 
00152     //Utility, not part of DOM Level 2 API
00153     static const XMLCh * mapPrefix(const XMLCh *prefix,
00154                                           const XMLCh *namespaceURI, short nType);
00155 
00156     static const XMLCh *getXmlnsString();
00157     static const XMLCh *getXmlnsURIString();
00158     static const XMLCh *getXmlString();
00159     static const XMLCh *getXmlURIString();
00160 
00161 public: // should really be protected - ALH
00162 
00163      void setOwnerDocument(IDOM_Document *doc);
00164 
00165     /*
00166      * Flags setters and getters
00167      */
00168 
00169     inline bool isReadOnly() const {
00170         return (flags & READONLY) != 0;
00171     }
00172 
00173     inline void isReadOnly(bool value) {
00174         flags = (value ? flags | READONLY : flags & ~READONLY);
00175     }
00176 
00177     inline bool needsSyncData() const {
00178         return (flags & SYNCDATA) != 0;
00179     }
00180 
00181     inline void needsSyncData(bool value) {
00182         flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA);
00183     }
00184 
00185     inline bool needsSyncChildren() const {
00186         return (flags & SYNCCHILDREN) != 0;
00187     }
00188 
00189     inline void needsSyncChildren(bool value) {
00190         flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
00191     }
00192 
00193     // For Attributes, true if the attr node is attached to an element.
00194     // For all other node types, true if the node has a parent node.
00195     inline bool isOwned() const {
00196         return (flags & OWNED) != 0;
00197     }
00198 
00199     inline void isOwned(bool value) {
00200         flags = (value ? flags | OWNED : flags & ~OWNED);
00201     }
00202 
00203     inline bool isFirstChild() const {
00204         return (flags & FIRSTCHILD) != 0;
00205     }
00206 
00207     inline void isFirstChild(bool value) {
00208         flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
00209     }
00210 
00211     inline bool isSpecified() const {
00212         return (flags & SPECIFIED) != 0;
00213     }
00214 
00215     inline void isSpecified(bool value) {
00216         flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED);
00217     }
00218 
00219     inline bool ignorableWhitespace() const {
00220         return (flags & IGNORABLEWS) != 0;
00221     }
00222 
00223     inline void ignorableWhitespace(bool value) {
00224         flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
00225     }
00226 
00227     inline bool setValue() const {
00228         return (flags & SETVALUE) != 0;
00229     }
00230 
00231     inline void setValue(bool value) {
00232         flags = (value ? flags | SETVALUE : flags & ~SETVALUE);
00233     }
00234 
00235     inline bool isIdAttr() const {
00236         return (flags & ID_ATTR) != 0;
00237     }
00238 
00239     inline void isIdAttr(bool value) {
00240         flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR);
00241     }
00242 
00243     inline bool hasUserData() const {
00244         return (flags & USERDATA) != 0;
00245     }
00246 
00247     inline void hasUserData(bool value) {
00248         flags = (value ? flags | USERDATA : flags & ~USERDATA);
00249     }
00250 
00251     //
00252     //  LeafNode is set true for node types that can not be ParentNodes (can't have children)
00253     //    This knowledge is used to allow casting from any unknown node type to the
00254     //    IDParentImpl or IDChildImpl parts of the node.
00255     //
00256     inline bool isLeafNode() const {
00257         return (flags & LEAFNODETYPE) != 0;
00258     }
00259 
00260     inline void setIsLeafNode(bool value) {
00261         flags = (value ? flags | LEAFNODETYPE : flags & ~LEAFNODETYPE);
00262     }
00263 
00264 
00265     //
00266     // ChildNode is set true for node types that can be children of other nodes, and
00267     //   therefore include a IDChildNode data member.  Note that all of the leaf
00268     //   node types (above flag) are also ChildNodes, but not all ChildNodes are
00269     //   leaf nodes.
00270     inline bool isChildNode() const {
00271         return (flags & CHILDNODE) != 0;
00272     }
00273 
00274     inline void setIsChildNode(bool value) {
00275         flags = (value ? flags | CHILDNODE : flags & ~CHILDNODE);
00276     }
00277 };
00278 
00279 
00280 // This macro lists all of the pure virtual functions declared in IDOM_Node that must
00281 //   be implemented by all node types.  Since there is no inheritance of implementation,
00282 //   using this macro in the class declaration of the node types make it easier to
00283 //   accurately get all of the functions declared.
00284 //
00285 #define IDOM_NODE_FUNCTIONS \
00286     virtual       IDOM_Node          *appendChild(IDOM_Node *newChild) ;\
00287     virtual       IDOM_Node          *cloneNode(bool deep) const ;\
00288     virtual       IDOM_NamedNodeMap  *getAttributes() const ;\
00289     virtual       IDOM_NodeList      *getChildNodes() const ;\
00290     virtual       IDOM_Node          *getFirstChild() const ;\
00291     virtual       IDOM_Node          *getLastChild() const ;\
00292     virtual const XMLCh *             getLocalName() const ;\
00293     virtual const XMLCh *             getNamespaceURI() const ;\
00294     virtual       IDOM_Node          *getNextSibling() const ;\
00295     virtual const XMLCh              *getNodeName() const ;\
00296     virtual       short               getNodeType() const ;\
00297     virtual const XMLCh              *getNodeValue() const ;\
00298     virtual       IDOM_Document      *getOwnerDocument() const ;\
00299     virtual const XMLCh *             getPrefix() const ;\
00300     virtual       IDOM_Node          *getParentNode() const ;\
00301     virtual       IDOM_Node          *getPreviousSibling() const ;\
00302     virtual       bool                hasChildNodes() const ;\
00303     virtual       IDOM_Node          *insertBefore(IDOM_Node *newChild, IDOM_Node *refChild) ;\
00304     virtual       void                normalize() ;\
00305     virtual       IDOM_Node          *removeChild(IDOM_Node *oldChild) ;\
00306     virtual       IDOM_Node          *replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild) ;\
00307     virtual       void                setNodeValue(const XMLCh  *nodeValue) ;\
00308     virtual       bool                isSupported(const XMLCh *feature, const XMLCh *version) const ;\
00309     virtual       bool                hasAttributes() const ;\
00310     virtual       void                setPrefix(const XMLCh * prefix)
00311 
00312 
00313 /*
00314  *  Here are dummy stubs for most of the functions introduced by IDOM_Node.
00315  *    Each subclass of IDOM_Node will have something like this that delegates each
00316  *    function to the appropriate implementation.
00317  *    Functions that must be supplied by every node class are omitted.
00318  *
00319            IDOM_Node          *xxx::appendChild(IDOM_Node *newChild)        {return fParent.appendChild (newChild); };
00320            IDOM_NamedNodeMap  *xxx::getAttributes() const                               {return fNode.getAttributes (); };
00321            IDOM_NodeList      *xxx::getChildNodes() const                               {return fParent.getChildNodes (); };
00322            IDOM_Node          *xxx::getFirstChild() const                               {return fParent.getFirstChild (); };
00323            IDOM_Node          *xxx::getLastChild() const                            {return fParent.getLastChild (); };
00324      const XMLCh              *xxx::getLocalName() const                    {return fNode.getLocalName (); };
00325      const XMLCh              *xxx::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
00326            IDOM_Node          *xxx::getNextSibling() const                  {return fChild.getNextSibling (); };
00327      const XMLCh              *xxx::getNodeValue() const                    {return fNode.getNodeValue (); };
00328            IDOM_Document      *xxx::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
00329      const XMLCh              *xxx::getPrefix() const                       {return fNode.getPrefix (); };
00330            IDOM_Node          *xxx::getParentNode() const                   {return fChild.getParentNode (this); };
00331            IDOM_Node          *xxx::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
00332            bool                xxx::hasChildNodes() const                   {return fParent.hasChildNodes (); };
00333            IDOM_Node          *xxx::insertBefore(IDOM_Node *newChild, IDOM_Node *refChild)
00334                                                                             {return fParent.insertBefore (newChild, refChild); };
00335            void                xxx::normalize()                             {fNode.normalize (); };
00336            IDOM_Node          *xxx::removeChild(IDOM_Node *oldChild)        {return fParent.removeChild (oldChild); };
00337            IDOM_Node          *xxx::replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild)
00338                                                                             {return fParent.replaceChild (newChild, oldChild); };
00339            void                xxx::setNodeValue(const XMLCh  *nodeValue)   {fNode.setNodeValue (nodeValue); };
00340            bool                xxx::supports(const XMLCh *feature, const XMLCh *version) const
00341                                                                             {return fNode.supports (feature, version); };
00342            void                xxx::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
00343 
00344 */
00345 
00346 
00347 
00348 #endif

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