IDNodeImpl.hpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:14k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. #ifndef IDNodeImpl_HEADER_GUARD_
  2. #define IDNodeImpl_HEADER_GUARD_
  3. /*
  4.  * The Apache Software License, Version 1.1
  5.  *
  6.  * Copyright (c) 2001 The Apache Software Foundation.  All rights
  7.  * reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  *
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  *
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in
  18.  *    the documentation and/or other materials provided with the
  19.  *    distribution.
  20.  *
  21.  * 3. The end-user documentation included with the redistribution,
  22.  *    if any, must include the following acknowledgment:
  23.  *       "This product includes software developed by the
  24.  *        Apache Software Foundation (http://www.apache.org/)."
  25.  *    Alternately, this acknowledgment may appear in the software itself,
  26.  *    if and wherever such third-party acknowledgments normally appear.
  27.  *
  28.  * 4. The names "Xerces" and "Apache Software Foundation" must
  29.  *    not be used to endorse or promote products derived from this
  30.  *    software without prior written permission. For written
  31.  *    permission, please contact apache@apache.org.
  32.  *
  33.  * 5. Products derived from this software may not be called "Apache",
  34.  *    nor may "Apache" appear in their name, without prior written
  35.  *    permission of the Apache Software Foundation.
  36.  *
  37.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48.  * SUCH DAMAGE.
  49.  * ====================================================================
  50.  *
  51.  * This software consists of voluntary contributions made by many
  52.  * individuals on behalf of the Apache Software Foundation, and was
  53.  * originally based on software copyright (c) 2001, International
  54.  * Business Machines, Inc., http://www.ibm.com .  For more information
  55.  * on the Apache Software Foundation, please see
  56.  * <http://www.apache.org/>.
  57.  */
  58. /*
  59.  * $Id: IDNodeImpl.hpp,v 1.3 2001/06/04 14:55:34 tng Exp $
  60.  */
  61. //
  62. //  This file is part of the internal implementation of the C++ XML DOM.
  63. //  It should NOT be included or used directly by application programs.
  64. //
  65. //  Applications should include the file <dom/DOM.hpp> for the entire
  66. //  DOM API, or DOM_*.hpp for individual DOM classes, where the class
  67. //  name is substituded for the *.
  68. //
  69. /**
  70.  * A IDNodeImpl doesn't have any children, and can therefore only be directly
  71.  * inherited by classes of nodes that never have any, such as Text nodes. For
  72.  * other types, such as Element, classes must inherit from ParentNode.
  73.  * <P>
  74.  * All nodes in a single document must originate
  75.  * in that document. (Note that this is much tighter than "must be
  76.  * same implementation") Nodes are all aware of their ownerDocument,
  77.  * and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
  78.  * <P>
  79.  * However, to save memory not all nodes always have a direct reference
  80.  * to their ownerDocument. When a node is owned by another node it relies
  81.  * on its owner to store its ownerDocument. Parent nodes always store it
  82.  * though, so there is never more than one level of indirection.
  83.  * And when a node doesn't have an owner, ownerNode refers to its
  84.  * ownerDocument.
  85.  **/
  86. #include <util/XercesDefs.hpp>
  87. class IDOM_NamedNodeMap;
  88. class IDOM_NodeList;
  89. class IDOM_Node;
  90. class IDOM_Document;
  91. class CDOM_EXPORT IDNodeImpl {
  92. public:
  93.     // data
  94.     IDOM_Node                *fOwnerNode; // typically the parent but not always!
  95.     unsigned short flags;
  96.     static const unsigned short READONLY;
  97.     static const unsigned short SYNCDATA;
  98.     static const unsigned short SYNCCHILDREN;
  99.     static const unsigned short OWNED;
  100.     static const unsigned short FIRSTCHILD;
  101.     static const unsigned short SPECIFIED;
  102.     static const unsigned short IGNORABLEWS;
  103.     static const unsigned short SETVALUE;
  104.     static const unsigned short ID_ATTR;
  105. static const unsigned short USERDATA;
  106.     static const unsigned short LEAFNODETYPE;
  107.     static const unsigned short CHILDNODE;
  108. public:
  109.     IDNodeImpl(IDOM_Node *ownerDocument);
  110.     IDNodeImpl(const IDNodeImpl &other);
  111.     ~IDNodeImpl();
  112.      IDOM_Node         *appendChild(IDOM_Node *newChild);
  113.      IDOM_NamedNodeMap * getAttributes() const;
  114.      IDOM_NodeList     * getChildNodes() const;
  115.      IDOM_Node         * getFirstChild() const;
  116.      IDOM_Node         * getLastChild() const;
  117.      const XMLCh       * getLocalName() const;
  118.      const XMLCh       * getNamespaceURI() const;
  119.      IDOM_Node         * getNextSibling() const;
  120.      const XMLCh       * getNodeValue() const;
  121.      IDOM_Document     * getOwnerDocument() const;
  122.      IDOM_Node         * getParentNode() const;
  123.      const XMLCh       * getPrefix() const;
  124.      IDOM_Node         * getPreviousSibling() const;
  125.      void              * getUserData() const;
  126.      bool                hasChildNodes() const;
  127.      IDOM_Node         * insertBefore(IDOM_Node *newChild, IDOM_Node *refChild);
  128.      void                normalize();
  129.      IDOM_Node         * removeChild(IDOM_Node *oldChild);
  130.      IDOM_Node         * replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild);
  131.      void                setNodeValue(const XMLCh *value);
  132.      void                setPrefix(const XMLCh *fPrefix);
  133.      void                setReadOnly(bool readOnly, bool deep);
  134.      void                setUserData(void *value);
  135.      bool                supports(const XMLCh *feature, const XMLCh *version) const;
  136.     static  bool         isKidOK(IDOM_Node *parent, IDOM_Node *child);
  137.     //Utility, not part of DOM Level 2 API
  138.     static const XMLCh * mapPrefix(const XMLCh *prefix,
  139.                                   const XMLCh *namespaceURI, short nType);
  140.     static const XMLCh *getXmlnsString();
  141.     static const XMLCh *getXmlnsURIString();
  142.     static const XMLCh *getXmlString();
  143.     static const XMLCh *getXmlURIString();
  144. public: // should really be protected - ALH
  145.      void setOwnerDocument(IDOM_Document *doc);
  146.     /*
  147.      * Flags setters and getters
  148.      */
  149.     inline bool isReadOnly() const {
  150.         return (flags & READONLY) != 0;
  151.     }
  152.     inline void isReadOnly(bool value) {
  153.         flags = (value ? flags | READONLY : flags & ~READONLY);
  154.     }
  155.     inline bool needsSyncData() const {
  156.         return (flags & SYNCDATA) != 0;
  157.     }
  158.     inline void needsSyncData(bool value) {
  159.         flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA);
  160.     }
  161.     inline bool needsSyncChildren() const {
  162.         return (flags & SYNCCHILDREN) != 0;
  163.     }
  164.     inline void needsSyncChildren(bool value) {
  165.         flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
  166.     }
  167.     // For Attributes, true if the attr node is attached to an element.
  168.     // For all other node types, true if the node has a parent node.
  169.     inline bool isOwned() const {
  170.         return (flags & OWNED) != 0;
  171.     }
  172.     inline void isOwned(bool value) {
  173.         flags = (value ? flags | OWNED : flags & ~OWNED);
  174.     }
  175.     inline bool isFirstChild() const {
  176.         return (flags & FIRSTCHILD) != 0;
  177.     }
  178.     inline void isFirstChild(bool value) {
  179.         flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
  180.     }
  181.     inline bool isSpecified() const {
  182.         return (flags & SPECIFIED) != 0;
  183.     }
  184.     inline void isSpecified(bool value) {
  185.         flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED);
  186.     }
  187.     inline bool ignorableWhitespace() const {
  188.         return (flags & IGNORABLEWS) != 0;
  189.     }
  190.     inline void ignorableWhitespace(bool value) {
  191.         flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
  192.     }
  193.     inline bool setValue() const {
  194.         return (flags & SETVALUE) != 0;
  195.     }
  196.     inline void setValue(bool value) {
  197.         flags = (value ? flags | SETVALUE : flags & ~SETVALUE);
  198.     }
  199.     inline bool isIdAttr() const {
  200.         return (flags & ID_ATTR) != 0;
  201.     }
  202.     inline void isIdAttr(bool value) {
  203.         flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR);
  204.     }
  205.     inline bool hasUserData() const {
  206.         return (flags & USERDATA) != 0;
  207.     }
  208.     inline void hasUserData(bool value) {
  209.         flags = (value ? flags | USERDATA : flags & ~USERDATA);
  210.     }
  211.     //
  212.     //  LeafNode is set true for node types that can not be ParentNodes (can't have children)
  213.     //    This knowledge is used to allow casting from any unknown node type to the
  214.     //    IDParentImpl or IDChildImpl parts of the node.
  215.     //
  216.     inline bool isLeafNode() const {
  217.         return (flags & LEAFNODETYPE) != 0;
  218.     }
  219.     inline void setIsLeafNode(bool value) {
  220.         flags = (value ? flags | LEAFNODETYPE : flags & ~LEAFNODETYPE);
  221.     }
  222.     //
  223.     // ChildNode is set true for node types that can be children of other nodes, and
  224.     //   therefore include a IDChildNode data member.  Note that all of the leaf
  225.     //   node types (above flag) are also ChildNodes, but not all ChildNodes are
  226.     //   leaf nodes.
  227.     inline bool isChildNode() const {
  228.         return (flags & CHILDNODE) != 0;
  229.     }
  230.     inline void setIsChildNode(bool value) {
  231.         flags = (value ? flags | CHILDNODE : flags & ~CHILDNODE);
  232.     }
  233. };
  234. // This macro lists all of the pure virtual functions declared in IDOM_Node that must
  235. //   be implemented by all node types.  Since there is no inheritance of implementation,
  236. //   using this macro in the class declaration of the node types make it easier to
  237. //   accurately get all of the functions declared.
  238. //
  239. #define IDOM_NODE_FUNCTIONS 
  240.     virtual       IDOM_Node          *appendChild(IDOM_Node *newChild) ;
  241.     virtual       IDOM_Node          *cloneNode(bool deep) const ;
  242.     virtual       IDOM_NamedNodeMap  *getAttributes() const ;
  243.     virtual       IDOM_NodeList      *getChildNodes() const ;
  244.     virtual       IDOM_Node          *getFirstChild() const ;
  245.     virtual       IDOM_Node          *getLastChild() const ;
  246.     virtual const XMLCh *             getLocalName() const ;
  247.     virtual const XMLCh *             getNamespaceURI() const ;
  248.     virtual       IDOM_Node          *getNextSibling() const ;
  249.     virtual const XMLCh              *getNodeName() const ;
  250.     virtual       short               getNodeType() const ;
  251.     virtual const XMLCh              *getNodeValue() const ;
  252.     virtual       IDOM_Document      *getOwnerDocument() const ;
  253.     virtual const XMLCh *             getPrefix() const ;
  254.     virtual       IDOM_Node          *getParentNode() const ;
  255.     virtual       IDOM_Node          *getPreviousSibling() const ;
  256.     virtual       bool                hasChildNodes() const ;
  257.     virtual       IDOM_Node          *insertBefore(IDOM_Node *newChild, IDOM_Node *refChild) ;
  258.     virtual       void                normalize() ;
  259.     virtual       IDOM_Node          *removeChild(IDOM_Node *oldChild) ;
  260.     virtual       IDOM_Node          *replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild) ;
  261.     virtual       void                setNodeValue(const XMLCh  *nodeValue) ;
  262.     virtual       bool                supports(const XMLCh *feature, const XMLCh *version) const ;
  263.     virtual       void                setPrefix(const XMLCh * prefix)
  264. /*
  265.  *  Here are dummy stubs for most of the functions introduced by IDOM_Node.
  266.  *    Each subclass of IDOM_Node will have something like this that delegates each
  267.  *    function to the appropriate implementation.
  268.  *    Functions that must be supplied by every node class are omitted.
  269.  *
  270.            IDOM_Node          *xxx::appendChild(IDOM_Node *newChild)        {return fParent.appendChild (newChild); };
  271.            IDOM_NamedNodeMap  *xxx::getAttributes() const          {return fNode.getAttributes (); };
  272.            IDOM_NodeList      *xxx::getChildNodes() const          {return fParent.getChildNodes (); };
  273.            IDOM_Node          *xxx::getFirstChild() const          {return fParent.getFirstChild (); };
  274.            IDOM_Node          *xxx::getLastChild() const              {return fParent.getLastChild (); };
  275.      const XMLCh              *xxx::getLocalName() const                    {return fNode.getLocalName (); };
  276.      const XMLCh              *xxx::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
  277.            IDOM_Node          *xxx::getNextSibling() const                  {return fChild.getNextSibling (); };
  278.      const XMLCh              *xxx::getNodeValue() const                    {return fNode.getNodeValue (); };
  279.            IDOM_Document      *xxx::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
  280.      const XMLCh              *xxx::getPrefix() const                       {return fNode.getPrefix (); };
  281.            IDOM_Node          *xxx::getParentNode() const                   {return fChild.getParentNode (this); };
  282.            IDOM_Node          *xxx::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
  283.            bool                xxx::hasChildNodes() const                   {return fParent.hasChildNodes (); };
  284.            IDOM_Node          *xxx::insertBefore(IDOM_Node *newChild, IDOM_Node *refChild)
  285.                                                                             {return fParent.insertBefore (newChild, refChild); };
  286.            void                xxx::normalize()                             {fNode.normalize (); };
  287.            IDOM_Node          *xxx::removeChild(IDOM_Node *oldChild)        {return fParent.removeChild (oldChild); };
  288.            IDOM_Node          *xxx::replaceChild(IDOM_Node *newChild, IDOM_Node *oldChild)
  289.                                                                             {return fParent.replaceChild (newChild, oldChild); };
  290.            void                xxx::setNodeValue(const XMLCh  *nodeValue)   {fNode.setNodeValue (nodeValue); };
  291.            bool                xxx::supports(const XMLCh *feature, const XMLCh *version) const
  292.                                                                             {return fNode.supports (feature, version); };
  293.            void                xxx::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
  294. */
  295. #endif