Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:02

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_DOMNODEIMPL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DOMNODEIMPL_HPP
0024 
0025 //
0026 //  This file is part of the internal implementation of the C++ XML DOM.
0027 //  It should NOT be included or used directly by application programs.
0028 //
0029 //  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
0030 //  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
0031 //  name is substituded for the *.
0032 //
0033 
0034 /**
0035  * A DOMNodeImpl doesn't have any children, and can therefore only be directly
0036  * inherited by classes of nodes that never have any, such as Text nodes. For
0037  * other types, such as Element, classes must inherit from ParentNode.
0038  * <P>
0039  * All nodes in a single document must originate
0040  * in that document. (Note that this is much tighter than "must be
0041  * same implementation") Nodes are all aware of their ownerDocument,
0042  * and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
0043  * <P>
0044  * However, to save memory not all nodes always have a direct reference
0045  * to their ownerDocument. When a node is owned by another node it relies
0046  * on its owner to store its ownerDocument. Parent nodes always store it
0047  * though, so there is never more than one level of indirection.
0048  * And when a node doesn't have an owner, ownerNode refers to its
0049  * ownerDocument.
0050  **/
0051 
0052 #include <xercesc/util/XercesDefs.hpp>
0053 #include <xercesc/dom/DOMUserDataHandler.hpp>
0054 
0055 XERCES_CPP_NAMESPACE_BEGIN
0056 
0057 
0058 class DOMNamedNodeMap;
0059 class DOMNodeList;
0060 class DOMNode;
0061 class DOMDocument;
0062 class DOMElement;
0063 
0064 class CDOM_EXPORT DOMNodeImpl {
0065 public:
0066 
0067     // data
0068     DOMNode                *fContainingNode; // the impl object that we're contained by
0069     DOMNode                *fOwnerNode; // typically the parent but not always!
0070 
0071     unsigned short flags;
0072 
0073     static const unsigned short READONLY;
0074     static const unsigned short SYNCDATA;
0075     static const unsigned short SYNCCHILDREN;
0076     static const unsigned short OWNED;
0077     static const unsigned short FIRSTCHILD;
0078     static const unsigned short SPECIFIED;
0079     static const unsigned short IGNORABLEWS;
0080     static const unsigned short SETVALUE;
0081     static const unsigned short ID_ATTR;
0082     static const unsigned short USERDATA;
0083     static const unsigned short LEAFNODETYPE;
0084     static const unsigned short CHILDNODE;
0085     static const unsigned short TOBERELEASED;
0086 
0087 
0088 public:
0089     DOMNodeImpl(DOMNode* containingNode, DOMNode *ownerDocument);
0090     DOMNodeImpl(DOMNode* containingNode, const DOMNodeImpl &other);
0091     ~DOMNodeImpl();
0092 
0093 private:
0094     // Make sure this can't be called to corrupt the containing node ptr.
0095     DOMNodeImpl(const DOMNodeImpl &other);
0096 
0097     DOMNode* getContainingNode();
0098     const DOMNode* getContainingNode() const;
0099 
0100 public:
0101     DOMNode         * appendChild(DOMNode *newChild);
0102     DOMNamedNodeMap * getAttributes() const;
0103     DOMNodeList     * getChildNodes() const;
0104     DOMNode         * getFirstChild() const;
0105     DOMNode         * getLastChild() const;
0106     const XMLCh     * getLocalName() const;
0107     const XMLCh     * getNamespaceURI() const;
0108     DOMNode         * getNextSibling() const;
0109     const XMLCh     * getNodeValue() const;
0110     DOMDocument     * getOwnerDocument() const;
0111     DOMNode         * getParentNode() const;
0112     const XMLCh     * getPrefix() const;
0113     DOMNode         * getPreviousSibling() const;
0114     bool              hasChildNodes() const;
0115     DOMNode         * insertBefore(DOMNode *newChild, DOMNode *refChild);
0116     void              normalize();
0117     DOMNode         * removeChild(DOMNode *oldChild);
0118     DOMNode         * replaceChild(DOMNode *newChild, DOMNode *oldChild);
0119     void              setNodeValue(const XMLCh *value);
0120     void              setPrefix(const XMLCh *fPrefix);
0121     void              setReadOnly(bool readOnly, bool deep);
0122     bool              isSupported(const XMLCh *feature, const XMLCh *version) const;
0123     bool              hasAttributes() const;
0124 
0125     // Introduced in DOM Level 3
0126     void*             setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler);
0127     void*             getUserData(const XMLCh* key) const;
0128     bool              isSameNode(const DOMNode* other) const;
0129     bool              isEqualNode(const DOMNode* arg) const;
0130     const XMLCh*      getBaseURI() const ;
0131     short             compareDocumentPosition(const DOMNode* other) const;
0132     const XMLCh*      getTextContent() const ;
0133     const XMLCh*      getTextContent(XMLCh* pzBuffer, XMLSize_t& rnBufferLength) const;
0134     void              setTextContent(const XMLCh* textContent) ;
0135     const XMLCh*      lookupPrefix(const XMLCh* namespaceURI) const ;
0136     bool              isDefaultNamespace(const XMLCh* namespaceURI) const ;
0137     const XMLCh*      lookupNamespaceURI(const XMLCh* prefix) const  ;
0138     void*             getFeature(const XMLCh* feature, const XMLCh* version) const;
0139 
0140 
0141     // Helper functions for DOM Level 3
0142     void              release();
0143     void              callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
0144                                            const DOMNode* src,
0145                                            DOMNode* dst) const;
0146     //reverses the bit pattern given by compareDocumentPosition
0147     short             reverseTreeOrderBitPattern(short pattern) const;
0148     const DOMNode*    getTreeParentNode(const DOMNode* node) const;
0149 
0150 
0151     //Utility, not part of DOM Level 2 API
0152     static  bool      isKidOK(DOMNode *parent, DOMNode *child);
0153     static const XMLCh *mapPrefix(const XMLCh *prefix,
0154                                const XMLCh *namespaceURI, short nType);
0155 
0156     static const XMLCh *getXmlnsString();
0157     static const XMLCh *getXmlnsURIString();
0158     static const XMLCh *getXmlString();
0159     static const XMLCh *getXmlURIString();
0160 
0161 public: // should really be protected - ALH
0162 
0163     DOMNode* getElementAncestor (const DOMNode* currentNode) const;
0164     const XMLCh* lookupPrefix(const XMLCh* const namespaceURI, DOMElement *el) const ;
0165     void setOwnerDocument(DOMDocument *doc);
0166 
0167     /*
0168      * Flags setters and getters
0169      */
0170 
0171     inline bool isReadOnly() const {
0172         return (flags & READONLY) != 0;
0173     }
0174 
0175     inline void isReadOnly(bool value) {
0176         flags = (value ? flags | READONLY : flags & ~READONLY);
0177     }
0178 
0179     inline bool needsSyncData() const {
0180         return (flags & SYNCDATA) != 0;
0181     }
0182 
0183     inline void needsSyncData(bool value) {
0184         flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA);
0185     }
0186 
0187     inline bool needsSyncChildren() const {
0188         return (flags & SYNCCHILDREN) != 0;
0189     }
0190 
0191     inline void needsSyncChildren(bool value) {
0192         flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
0193     }
0194 
0195     // For Attributes, true if the attr node is attached to an element.
0196     // For all other node types, true if the node has a parent node.
0197     inline bool isOwned() const {
0198         return (flags & OWNED) != 0;
0199     }
0200 
0201     inline void isOwned(bool value) {
0202         flags = (value ? flags | OWNED : flags & ~OWNED);
0203     }
0204 
0205     inline bool isFirstChild() const {
0206         return (flags & FIRSTCHILD) != 0;
0207     }
0208 
0209     inline void isFirstChild(bool value) {
0210         flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
0211     }
0212 
0213     inline bool isSpecified() const {
0214         return (flags & SPECIFIED) != 0;
0215     }
0216 
0217     inline void isSpecified(bool value) {
0218         flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED);
0219     }
0220 
0221     inline bool ignorableWhitespace() const {
0222         return (flags & IGNORABLEWS) != 0;
0223     }
0224 
0225     inline void ignorableWhitespace(bool value) {
0226         flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
0227     }
0228 
0229     inline bool setValue() const {
0230         return (flags & SETVALUE) != 0;
0231     }
0232 
0233     inline void setValue(bool value) {
0234         flags = (value ? flags | SETVALUE : flags & ~SETVALUE);
0235     }
0236 
0237     inline bool isIdAttr() const {
0238         return (flags & ID_ATTR) != 0;
0239     }
0240 
0241     inline void isIdAttr(bool value) {
0242         flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR);
0243     }
0244 
0245     inline bool hasUserData() const {
0246         return (flags & USERDATA) != 0;
0247     }
0248 
0249     inline void hasUserData(bool value) {
0250         flags = (value ? flags | USERDATA : flags & ~USERDATA);
0251     }
0252 
0253     //
0254     //  LeafNode is set true for node types that can not be ParentNodes (can't have children)
0255     //    This knowledge is used to allow casting from any unknown node type to the
0256     //    IDParentImpl or IDChildImpl parts of the node.
0257     //
0258     inline bool isLeafNode() const {
0259         return (flags & LEAFNODETYPE) != 0;
0260     }
0261 
0262     inline void setIsLeafNode(bool value) {
0263         flags = (value ? flags | LEAFNODETYPE : flags & ~LEAFNODETYPE);
0264     }
0265 
0266 
0267     //
0268     // ChildNode is set true for node types that can be children of other nodes, and
0269     //   therefore include a DOMChildNode data member.  Note that all of the leaf
0270     //   node types (above flag) are also ChildNodes, but not all ChildNodes are
0271     //   leaf nodes.
0272     inline bool isChildNode() const {
0273         return (flags & CHILDNODE) != 0;
0274     }
0275 
0276     inline void setIsChildNode(bool value) {
0277         flags = (value ? flags | CHILDNODE : flags & ~CHILDNODE);
0278     }
0279 
0280     // True if this node has to be released regardless if it has a owner or not
0281     // This is true if called from fParent->release()
0282     inline bool isToBeReleased() const {
0283         return (flags & TOBERELEASED) != 0;
0284     }
0285 
0286     inline void isToBeReleased(bool value) {
0287         flags = (value ? flags | TOBERELEASED : flags & ~TOBERELEASED);
0288     }
0289 
0290 };
0291 
0292 
0293 // This macro lists all of the pure virtual functions declared in DOMNode that must
0294 //   be implemented by all node types.  Since there is no inheritance of implementation,
0295 //   using this macro in the class declaration of the node types make it easier to
0296 //   accurately get all of the functions declared.
0297 //
0298 #define DOMNODE_FUNCTIONS \
0299     virtual       DOMNode*         appendChild(DOMNode *newChild) ;\
0300     virtual       DOMNode*         cloneNode(bool deep) const ;\
0301     virtual       DOMNamedNodeMap* getAttributes() const ;\
0302     virtual       DOMNodeList*     getChildNodes() const ;\
0303     virtual       DOMNode*         getFirstChild() const ;\
0304     virtual       DOMNode*         getLastChild() const ;\
0305     virtual const XMLCh*           getLocalName() const ;\
0306     virtual const XMLCh*           getNamespaceURI() const ;\
0307     virtual       DOMNode*         getNextSibling() const ;\
0308     virtual const XMLCh*           getNodeName() const ;\
0309     virtual       NodeType         getNodeType() const ;\
0310     virtual const XMLCh*           getNodeValue() const ;\
0311     virtual       DOMDocument*     getOwnerDocument() const ;\
0312     virtual const XMLCh*           getPrefix() const ;\
0313     virtual       DOMNode*         getParentNode() const ;\
0314     virtual       DOMNode*         getPreviousSibling() const ;\
0315     virtual       bool             hasChildNodes() const ;\
0316     virtual       DOMNode*         insertBefore(DOMNode *newChild, DOMNode *refChild) ;\
0317     virtual       void             normalize() ;\
0318     virtual       DOMNode*         removeChild(DOMNode *oldChild) ;\
0319     virtual       DOMNode*         replaceChild(DOMNode *newChild, DOMNode *oldChild) ;\
0320     virtual       void             setNodeValue(const XMLCh  *nodeValue) ;\
0321     virtual       bool             isSupported(const XMLCh *feature, const XMLCh *version) const ;\
0322     virtual       bool             hasAttributes() const ;\
0323     virtual       void             setPrefix(const XMLCh * prefix) ;\
0324     virtual       void*            setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler) ;\
0325     virtual       void*            getUserData(const XMLCh* key) const ;\
0326     virtual       bool             isSameNode(const DOMNode* other) const;\
0327     virtual       bool             isEqualNode(const DOMNode* arg) const;\
0328     virtual const XMLCh*           getBaseURI() const ;\
0329     virtual short                  compareDocumentPosition(const DOMNode* other) const ;\
0330     virtual const XMLCh*           getTextContent() const ;\
0331             const XMLCh*           getTextContent(XMLCh* pzBuffer, unsigned int& rnBufferLength) const;\
0332     virtual void                   setTextContent(const XMLCh* textContent) ;\
0333     virtual const XMLCh*           lookupPrefix(const XMLCh* namespaceURI) const  ;\
0334     virtual bool                   isDefaultNamespace(const XMLCh* namespaceURI) const;\
0335     virtual const XMLCh*           lookupNamespaceURI(const XMLCh* prefix) const  ;\
0336     virtual       void*            getFeature(const XMLCh* feature, const XMLCh* version) const ;\
0337     virtual       void             release()
0338 
0339 
0340 /*
0341  *  Here are dummy stubs for most of the functions introduced by DOMNode.
0342  *    Each subclass of DOMNode will have something like this that delegates each
0343  *    function to the appropriate implementation.
0344  *    Functions that must be supplied by every node class are omitted.
0345  *
0346            DOMNode*         xxx::appendChild(DOMNode *newChild)          {return fParent.appendChild (newChild); };
0347            DOMNamedNodeMap* xxx::getAttributes() const                   {return fNode.getAttributes (); };
0348            DOMNodeList*     xxx::getChildNodes() const                   {return fParent.getChildNodes (); };
0349            DOMNode*         xxx::getFirstChild() const                   {return fParent.getFirstChild (); };
0350            DOMNode*         xxx::getLastChild() const                    {return fParent.getLastChild (); };
0351      const XMLCh*           xxx::getLocalName() const                    {return fNode.getLocalName (); };
0352      const XMLCh*           xxx::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
0353            DOMNode*         xxx::getNextSibling() const                  {return fChild.getNextSibling (); };
0354      const XMLCh*           xxx::getNodeValue() const                    {return fNode.getNodeValue (); };
0355            DOMDocument*     xxx::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
0356      const XMLCh*           xxx::getPrefix() const                       {return fNode.getPrefix (); };
0357            DOMNode*         xxx::getParentNode() const                   {return fChild.getParentNode (this); };
0358            DOMNode*         xxx::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
0359            bool             xxx::hasChildNodes() const                   {return fParent.hasChildNodes (); };
0360            DOMNode*         xxx::insertBefore(DOMNode *newChild, DOMNode *refChild)
0361                                                                          {return fParent.insertBefore (newChild, refChild); };
0362            void             xxx::normalize()                             {fParent.normalize(); };
0363            DOMNode*         xxx::removeChild(DOMNode *oldChild)          {return fParent.removeChild (oldChild); };
0364            DOMNode*         xxx::replaceChild(DOMNode *newChild, DOMNode *oldChild)
0365                                                                          {return fParent.replaceChild (newChild, oldChild); };
0366            bool             xxx::isSupported(const XMLCh *feature, const XMLCh *version) const
0367                                                                          {return fNode.isSupported (feature, version); };
0368            void             xxx::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
0369            bool             xxx::hasAttributes() const                   {return fNode.hasAttributes(); };
0370            bool             xxx::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); };
0371            bool             xxx::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); };
0372            void*            xxx::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
0373                                                                          {return fNode.setUserData(key, data, handler); };
0374            void*            xxx::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); };
0375            const XMLCh*     xxx::getBaseURI() const                      {return fNode.getBaseURI(); };
0376            short            xxx::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); };
0377            const XMLCh*     xxx::getTextContent() const                  {return fNode.getTextContent(); };
0378            void             xxx::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
0379            const XMLCh*     xxx::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); };
0380            bool             xxx::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
0381            const XMLCh*     xxx::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); };
0382            void*            xxx::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); };
0383 
0384 
0385 */
0386 
0387 
0388 
0389 XERCES_CPP_NAMESPACE_END
0390 
0391 #endif