source: NonGTP/Xerces/xercesc/dom/impl/DOMNodeImpl.hpp @ 188

Revision 188, 19.4 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1#ifndef DOMNodeImpl_HEADER_GUARD_
2#define DOMNodeImpl_HEADER_GUARD_
3
4/*
5 * The Apache Software License, Version 1.1
6 *
7 * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
8 * reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in
19 *    the documentation and/or other materials provided with the
20 *    distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 *    if any, must include the following acknowledgment:
24 *       "This product includes software developed by the
25 *        Apache Software Foundation (http://www.apache.org/)."
26 *    Alternately, this acknowledgment may appear in the software itself,
27 *    if and wherever such third-party acknowledgments normally appear.
28 *
29 * 4. The names "Xerces" and "Apache Software Foundation" must
30 *    not be used to endorse or promote products derived from this
31 *    software without prior written permission. For written
32 *    permission, please contact apache\@apache.org.
33 *
34 * 5. Products derived from this software may not be called "Apache",
35 *    nor may "Apache" appear in their name, without prior written
36 *    permission of the Apache Software Foundation.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This software consists of voluntary contributions made by many
53 * individuals on behalf of the Apache Software Foundation, and was
54 * originally based on software copyright (c) 2001, International
55 * Business Machines, Inc., http://www.ibm.com .  For more information
56 * on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
58 */
59
60/*
61 * $Id: DOMNodeImpl.hpp,v 1.12 2003/04/02 22:30:01 peiyongz Exp $
62 */
63
64//
65//  This file is part of the internal implementation of the C++ XML DOM.
66//  It should NOT be included or used directly by application programs.
67//
68//  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
69//  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
70//  name is substituded for the *.
71//
72
73/**
74 * A DOMNodeImpl doesn't have any children, and can therefore only be directly
75 * inherited by classes of nodes that never have any, such as Text nodes. For
76 * other types, such as Element, classes must inherit from ParentNode.
77 * <P>
78 * All nodes in a single document must originate
79 * in that document. (Note that this is much tighter than "must be
80 * same implementation") Nodes are all aware of their ownerDocument,
81 * and attempts to mismatch will throw WRONG_DOCUMENT_ERR.
82 * <P>
83 * However, to save memory not all nodes always have a direct reference
84 * to their ownerDocument. When a node is owned by another node it relies
85 * on its owner to store its ownerDocument. Parent nodes always store it
86 * though, so there is never more than one level of indirection.
87 * And when a node doesn't have an owner, ownerNode refers to its
88 * ownerDocument.
89 **/
90
91#include <xercesc/util/XercesDefs.hpp>
92#include <xercesc/dom/DOMUserDataHandler.hpp>
93
94XERCES_CPP_NAMESPACE_BEGIN
95
96
97class DOMNamedNodeMap;
98class DOMNodeList;
99class DOMNode;
100class DOMDocument;
101class DOMElement;
102
103class CDOM_EXPORT DOMNodeImpl {
104public:
105
106    // data
107    DOMNode                *fOwnerNode; // typically the parent but not always!
108
109    unsigned short flags;
110
111    static const unsigned short READONLY;
112    static const unsigned short SYNCDATA;
113    static const unsigned short SYNCCHILDREN;
114    static const unsigned short OWNED;
115    static const unsigned short FIRSTCHILD;
116    static const unsigned short SPECIFIED;
117    static const unsigned short IGNORABLEWS;
118    static const unsigned short SETVALUE;
119    static const unsigned short ID_ATTR;
120    static const unsigned short USERDATA;
121    static const unsigned short LEAFNODETYPE;
122    static const unsigned short CHILDNODE;
123    static const unsigned short TOBERELEASED;
124
125
126public:
127    DOMNodeImpl(DOMNode *ownerDocument);
128    DOMNodeImpl(const DOMNodeImpl &other);
129    ~DOMNodeImpl();
130
131    DOMNode         * appendChild(DOMNode *newChild);
132    DOMNamedNodeMap * getAttributes() const;
133    DOMNodeList     * getChildNodes() const;
134    DOMNode         * getFirstChild() const;
135    DOMNode         * getLastChild() const;
136    const XMLCh     * getLocalName() const;
137    const XMLCh     * getNamespaceURI() const;
138    DOMNode         * getNextSibling() const;
139    const XMLCh     * getNodeValue() const;
140    DOMDocument     * getOwnerDocument() const;
141    DOMNode         * getParentNode() const;
142    const XMLCh     * getPrefix() const;
143    DOMNode         * getPreviousSibling() const;
144    bool              hasChildNodes() const;
145    DOMNode         * insertBefore(DOMNode *newChild, DOMNode *refChild);
146    void              normalize();
147    DOMNode         * removeChild(DOMNode *oldChild);
148    DOMNode         * replaceChild(DOMNode *newChild, DOMNode *oldChild);
149    void              setNodeValue(const XMLCh *value);
150    void              setPrefix(const XMLCh *fPrefix);
151    void              setReadOnly(bool readOnly, bool deep);
152    bool              isSupported(const XMLCh *feature, const XMLCh *version) const;
153    bool              hasAttributes() const;
154
155    // Introduced in DOM Level 3
156    void*             setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler);
157    void*             getUserData(const XMLCh* key) const;
158    bool              isSameNode(const DOMNode* other) const;
159    bool              isEqualNode(const DOMNode* arg) const;
160    const XMLCh*      getBaseURI() const ;
161    short             compareTreePosition(const DOMNode* other) const;
162    const XMLCh*      getTextContent() const ;
163    const XMLCh*      getTextContent(XMLCh* pzBuffer, unsigned int& rnBufferLength) const;
164    void              setTextContent(const XMLCh* textContent) ;
165    const XMLCh*      lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const ;
166    bool              isDefaultNamespace(const XMLCh* namespaceURI) const ;
167    const XMLCh*      lookupNamespaceURI(const XMLCh* prefix) const  ;
168    DOMNode*          getInterface(const XMLCh* feature) ;
169
170
171    // Helper functions for DOM Level 3
172    void              release();
173    void              callUserDataHandlers(DOMUserDataHandler::DOMOperationType operation,
174                                           const DOMNode* src,
175                                           const DOMNode* dst) const;
176    //reverses the bit pattern given by compareTreePosition
177    short             reverseTreeOrderBitPattern(short pattern) const;
178
179
180    //Utility, not part of DOM Level 2 API
181    static  bool      isKidOK(DOMNode *parent, DOMNode *child);
182    static const XMLCh *mapPrefix(const XMLCh *prefix,
183                               const XMLCh *namespaceURI, short nType);
184
185    static const XMLCh *getXmlnsString();
186    static const XMLCh *getXmlnsURIString();
187    static const XMLCh *getXmlString();
188    static const XMLCh *getXmlURIString();
189
190public: // should really be protected - ALH
191
192      DOMNode* getElementAncestor (const DOMNode* currentNode) const;
193      const XMLCh* lookupNamespacePrefix(const XMLCh* const namespaceURI, bool useDefaultx, DOMElement *el) const ;
194     void setOwnerDocument(DOMDocument *doc);
195
196    /*
197     * Flags setters and getters
198     */
199
200    inline bool isReadOnly() const {
201        return (flags & READONLY) != 0;
202    }
203
204    inline void isReadOnly(bool value) {
205        flags = (value ? flags | READONLY : flags & ~READONLY);
206    }
207
208    inline bool needsSyncData() const {
209        return (flags & SYNCDATA) != 0;
210    }
211
212    inline void needsSyncData(bool value) {
213        flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA);
214    }
215
216    inline bool needsSyncChildren() const {
217        return (flags & SYNCCHILDREN) != 0;
218    }
219
220    inline void needsSyncChildren(bool value) {
221        flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN);
222    }
223
224    // For Attributes, true if the attr node is attached to an element.
225    // For all other node types, true if the node has a parent node.
226    inline bool isOwned() const {
227        return (flags & OWNED) != 0;
228    }
229
230    inline void isOwned(bool value) {
231        flags = (value ? flags | OWNED : flags & ~OWNED);
232    }
233
234    inline bool isFirstChild() const {
235        return (flags & FIRSTCHILD) != 0;
236    }
237
238    inline void isFirstChild(bool value) {
239        flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD);
240    }
241
242    inline bool isSpecified() const {
243        return (flags & SPECIFIED) != 0;
244    }
245
246    inline void isSpecified(bool value) {
247        flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED);
248    }
249
250    inline bool ignorableWhitespace() const {
251        return (flags & IGNORABLEWS) != 0;
252    }
253
254    inline void ignorableWhitespace(bool value) {
255        flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS);
256    }
257
258    inline bool setValue() const {
259        return (flags & SETVALUE) != 0;
260    }
261
262    inline void setValue(bool value) {
263        flags = (value ? flags | SETVALUE : flags & ~SETVALUE);
264    }
265
266    inline bool isIdAttr() const {
267        return (flags & ID_ATTR) != 0;
268    }
269
270    inline void isIdAttr(bool value) {
271        flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR);
272    }
273
274    inline bool hasUserData() const {
275        return (flags & USERDATA) != 0;
276    }
277
278    inline void hasUserData(bool value) {
279        flags = (value ? flags | USERDATA : flags & ~USERDATA);
280    }
281
282    //
283    //  LeafNode is set true for node types that can not be ParentNodes (can't have children)
284    //    This knowledge is used to allow casting from any unknown node type to the
285    //    IDParentImpl or IDChildImpl parts of the node.
286    //
287    inline bool isLeafNode() const {
288        return (flags & LEAFNODETYPE) != 0;
289    }
290
291    inline void setIsLeafNode(bool value) {
292        flags = (value ? flags | LEAFNODETYPE : flags & ~LEAFNODETYPE);
293    }
294
295
296    //
297    // ChildNode is set true for node types that can be children of other nodes, and
298    //   therefore include a DOMChildNode data member.  Note that all of the leaf
299    //   node types (above flag) are also ChildNodes, but not all ChildNodes are
300    //   leaf nodes.
301    inline bool isChildNode() const {
302        return (flags & CHILDNODE) != 0;
303    }
304
305    inline void setIsChildNode(bool value) {
306        flags = (value ? flags | CHILDNODE : flags & ~CHILDNODE);
307    }
308
309    // True if this node has to be released regardless if it has a owner or not
310    // This is true if called from fParent->release()
311    inline bool isToBeReleased() const {
312        return (flags & TOBERELEASED) != 0;
313    }
314
315    inline void isToBeReleased(bool value) {
316        flags = (value ? flags | TOBERELEASED : flags & ~TOBERELEASED);
317    }
318
319};
320
321
322// This macro lists all of the pure virtual functions declared in DOMNode that must
323//   be implemented by all node types.  Since there is no inheritance of implementation,
324//   using this macro in the class declaration of the node types make it easier to
325//   accurately get all of the functions declared.
326//
327#define DOMNODE_FUNCTIONS \
328    virtual       DOMNode*         appendChild(DOMNode *newChild) ;\
329    virtual       DOMNode*         cloneNode(bool deep) const ;\
330    virtual       DOMNamedNodeMap* getAttributes() const ;\
331    virtual       DOMNodeList*     getChildNodes() const ;\
332    virtual       DOMNode*         getFirstChild() const ;\
333    virtual       DOMNode*         getLastChild() const ;\
334    virtual const XMLCh*           getLocalName() const ;\
335    virtual const XMLCh*           getNamespaceURI() const ;\
336    virtual       DOMNode*         getNextSibling() const ;\
337    virtual const XMLCh*           getNodeName() const ;\
338    virtual       short            getNodeType() const ;\
339    virtual const XMLCh*           getNodeValue() const ;\
340    virtual       DOMDocument*     getOwnerDocument() const ;\
341    virtual const XMLCh*           getPrefix() const ;\
342    virtual       DOMNode*         getParentNode() const ;\
343    virtual       DOMNode*         getPreviousSibling() const ;\
344    virtual       bool             hasChildNodes() const ;\
345    virtual       DOMNode*         insertBefore(DOMNode *newChild, DOMNode *refChild) ;\
346    virtual       void             normalize() ;\
347    virtual       DOMNode*         removeChild(DOMNode *oldChild) ;\
348    virtual       DOMNode*         replaceChild(DOMNode *newChild, DOMNode *oldChild) ;\
349    virtual       void             setNodeValue(const XMLCh  *nodeValue) ;\
350    virtual       bool             isSupported(const XMLCh *feature, const XMLCh *version) const ;\
351    virtual       bool             hasAttributes() const ;\
352    virtual       void             setPrefix(const XMLCh * prefix) ;\
353    virtual       void*            setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler) ;\
354    virtual       void*            getUserData(const XMLCh* key) const ;\
355    virtual       bool             isSameNode(const DOMNode* other) const;\
356    virtual       bool             isEqualNode(const DOMNode* arg) const;\
357    virtual const XMLCh*           getBaseURI() const ;\
358    virtual short                  compareTreePosition(const DOMNode* other) const ;\
359    virtual const XMLCh*           getTextContent() const ;\
360            const XMLCh*           getTextContent(XMLCh* pzBuffer, unsigned int& rnBufferLength) const;\
361    virtual void                   setTextContent(const XMLCh* textContent) ;\
362    virtual const XMLCh*           lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const  ;\
363    virtual bool                   isDefaultNamespace(const XMLCh* namespaceURI) const;\
364    virtual const XMLCh*           lookupNamespaceURI(const XMLCh* prefix) const  ;\
365    virtual       DOMNode*         getInterface(const XMLCh* feature) ;\
366    virtual       void             release()
367
368
369/*
370 *  Here are dummy stubs for most of the functions introduced by DOMNode.
371 *    Each subclass of DOMNode will have something like this that delegates each
372 *    function to the appropriate implementation.
373 *    Functions that must be supplied by every node class are omitted.
374 *
375           DOMNode*         xxx::appendChild(DOMNode *newChild)          {return fParent.appendChild (newChild); };
376           DOMNamedNodeMap* xxx::getAttributes() const                   {return fNode.getAttributes (); };
377           DOMNodeList*     xxx::getChildNodes() const                   {return fParent.getChildNodes (); };
378           DOMNode*         xxx::getFirstChild() const                   {return fParent.getFirstChild (); };
379           DOMNode*         xxx::getLastChild() const                    {return fParent.getLastChild (); };
380     const XMLCh*           xxx::getLocalName() const                    {return fNode.getLocalName (); };
381     const XMLCh*           xxx::getNamespaceURI() const                 {return fNode.getNamespaceURI (); };
382           DOMNode*         xxx::getNextSibling() const                  {return fChild.getNextSibling (); };
383     const XMLCh*           xxx::getNodeValue() const                    {return fNode.getNodeValue (); };
384           DOMDocument*     xxx::getOwnerDocument() const                {return fNode.getOwnerDocument (); };
385     const XMLCh*           xxx::getPrefix() const                       {return fNode.getPrefix (); };
386           DOMNode*         xxx::getParentNode() const                   {return fChild.getParentNode (this); };
387           DOMNode*         xxx::getPreviousSibling() const              {return fChild.getPreviousSibling (this); };
388           bool             xxx::hasChildNodes() const                   {return fParent.hasChildNodes (); };
389           DOMNode*         xxx::insertBefore(DOMNode *newChild, DOMNode *refChild)
390                                                                         {return fParent.insertBefore (newChild, refChild); };
391           void             xxx::normalize()                             {fParent.normalize(); };
392           DOMNode*         xxx::removeChild(DOMNode *oldChild)          {return fParent.removeChild (oldChild); };
393           DOMNode*         xxx::replaceChild(DOMNode *newChild, DOMNode *oldChild)
394                                                                         {return fParent.replaceChild (newChild, oldChild); };
395           bool             xxx::isSupported(const XMLCh *feature, const XMLCh *version) const
396                                                                         {return fNode.isSupported (feature, version); };
397           void             xxx::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); };
398           bool             xxx::hasAttributes() const                   {return fNode.hasAttributes(); };
399           bool             xxx::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); };
400           bool             xxx::isEqualNode(const DOMNode* arg) const   {return fNode.isEqualNode(arg); };
401           void*            xxx::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
402                                                                         {return fNode.setUserData(key, data, handler); };
403           void*            xxx::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); };
404           const XMLCh*     xxx::getBaseURI() const                      {return fNode.getBaseURI(); };
405           short            xxx::compareTreePosition(const DOMNode* other) const {return fNode.compareTreePosition(other); };
406           const XMLCh*     xxx::getTextContent() const                  {return fNode.getTextContent(); };
407           void             xxx::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); };
408           const XMLCh*     xxx::lookupNamespacePrefix(const XMLCh* namespaceURI, bool useDefault) const {return fNode.lookupNamespacePrefix(namespaceURI, useDefault); };
409           bool             xxx::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); };
410           const XMLCh*     xxx::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); };
411           DOMNode*         xxx::getInterface(const XMLCh* feature)      {return fNode.getInterface(feature); };
412
413
414*/
415
416
417
418XERCES_CPP_NAMESPACE_END
419
420#endif
Note: See TracBrowser for help on using the repository browser.