00001 #ifndef NodeImpl_HEADER_GUARD_ 00002 #define NodeImpl_HEADER_GUARD_ 00003 00004 /* 00005 * The Apache Software License, Version 1.1 00006 * 00007 * Copyright (c) 1999-2000 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) 1999, 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: NodeImpl.hpp,v 1.19 2000/06/02 00:06:02 andyh 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 00090 00091 #include <util/XercesDefs.hpp> 00092 #include "NodeListImpl.hpp" 00093 #include "DOMString.hpp" 00094 00095 00096 class NamedNodeMapImpl; 00097 class NodeListImpl; 00098 class DocumentImpl; 00099 00100 // define 'null' is used extensively in the DOM implementation code, 00101 // as a consequence of its Java origins. 00102 // MSVC 5.0 compiler has problems with overloaded function resolution 00103 // when using the const int definition. 00104 // 00105 #if defined(XML_CSET) 00106 const int null = 0; 00107 #else 00108 #define null 0 00109 #endif 00110 00111 00112 class NodeImpl: public NodeListImpl { 00113 public: 00114 NodeImpl *ownerNode; // typically the parent but not always! 00115 00116 // data 00117 00118 unsigned short flags; 00119 00120 static const unsigned short READONLY; 00121 static const unsigned short SYNCDATA; 00122 static const unsigned short SYNCCHILDREN; 00123 static const unsigned short OWNED; 00124 static const unsigned short FIRSTCHILD; 00125 static const unsigned short SPECIFIED; 00126 static const unsigned short IGNORABLEWS; 00127 static const unsigned short SETVALUE; 00128 static const unsigned short ID_ATTR; 00129 00130 void *userData; 00131 00132 static int gLiveNodeImpls; // Counters for debug & tuning. 00133 static int gTotalNodeImpls; 00134 00135 public: 00136 NodeImpl(DocumentImpl *ownerDocument); 00137 NodeImpl(const NodeImpl &other); 00138 virtual ~NodeImpl(); 00139 00140 // Dynamic Cast replacement functions. 00141 virtual bool isAttrImpl(); 00142 virtual bool isCDATASectionImpl(); 00143 virtual bool isDocumentFragmentImpl(); 00144 virtual bool isDocumentImpl(); 00145 virtual bool isDocumentTypeImpl(); 00146 virtual bool isElementImpl(); 00147 virtual bool isEntityReference(); 00148 virtual bool isTextImpl(); 00149 00150 virtual void changed(); 00151 virtual int changes(); 00152 00153 virtual NodeImpl *appendChild(NodeImpl *newChild); 00154 virtual NodeImpl * cloneNode(bool deep) = 0; 00155 static void deleteIf(NodeImpl *thisNode); 00156 virtual NamedNodeMapImpl * getAttributes(); 00157 virtual NodeListImpl *getChildNodes(); 00158 virtual NodeImpl * getFirstChild(); 00159 virtual NodeImpl * getLastChild(); 00160 virtual unsigned int getLength(); 00161 virtual NodeImpl * getNextSibling(); 00162 virtual DOMString getNodeName() = 0; 00163 virtual short getNodeType() = 0; 00164 virtual DOMString getNodeValue(); 00165 virtual DocumentImpl * getOwnerDocument(); 00166 virtual NodeImpl * getParentNode(); 00167 virtual NodeImpl* getPreviousSibling(); 00168 virtual void *getUserData(); 00169 virtual bool hasChildNodes(); 00170 virtual NodeImpl *insertBefore(NodeImpl *newChild, NodeImpl *refChild); 00171 static bool isKidOK(NodeImpl *parent, NodeImpl *child); 00172 virtual NodeImpl *item(unsigned int index); 00173 virtual void referenced(); 00174 virtual NodeImpl * removeChild(NodeImpl *oldChild); 00175 virtual NodeImpl *replaceChild(NodeImpl *newChild, NodeImpl *oldChild); 00176 virtual void setNodeValue(const DOMString &value); 00177 virtual void setReadOnly(bool readOnly, bool deep); 00178 virtual void setUserData(void *value); 00179 virtual DOMString toString(); 00180 virtual void unreferenced(); 00181 00182 //Introduced in DOM Level 2 00183 virtual void normalize(); 00184 virtual bool supports(const DOMString &feature, const DOMString &version); 00185 virtual DOMString getNamespaceURI(); 00186 virtual DOMString getPrefix(); 00187 virtual DOMString getLocalName(); 00188 virtual void setPrefix(const DOMString &prefix); 00189 00190 protected: 00191 //Utility, not part of DOM Level 2 API 00192 static const DOMString& mapPrefix(const DOMString &prefix, 00193 const DOMString &namespaceURI, short nType); 00194 static DOMString getXmlnsString(); 00195 static DOMString getXmlnsURIString(); 00196 static DOMString getXmlString(); 00197 static DOMString getXmlURIString(); 00198 00199 public: // should really be protected - ALH 00200 00201 virtual void setOwnerDocument(DocumentImpl *doc); 00202 // NON-DOM 00203 // unlike getOwnerDocument this never returns null, even for Document nodes 00204 virtual DocumentImpl * getDocument(); 00205 00206 /* 00207 * Flags setters and getters 00208 */ 00209 00210 inline bool readOnly() const { 00211 return (flags & READONLY) != 0; 00212 } 00213 00214 inline void readOnly(bool value) { 00215 flags = (value ? flags | READONLY : flags & ~READONLY); 00216 } 00217 00218 inline bool syncData() const { 00219 return (flags & SYNCDATA) != 0; 00220 } 00221 00222 inline void syncData(bool value) { 00223 flags = (value ? flags | SYNCDATA : flags & ~SYNCDATA); 00224 } 00225 00226 inline bool syncChildren() const { 00227 return (flags & SYNCCHILDREN) != 0; 00228 } 00229 00230 inline void syncChildren(bool value) { 00231 flags = (value ? flags | SYNCCHILDREN : flags & ~SYNCCHILDREN); 00232 } 00233 00234 inline bool owned() const { 00235 return (flags & OWNED) != 0; 00236 } 00237 00238 inline void owned(bool value) { 00239 flags = (value ? flags | OWNED : flags & ~OWNED); 00240 } 00241 00242 inline bool firstChild() const { 00243 return (flags & FIRSTCHILD) != 0; 00244 } 00245 00246 inline void firstChild(bool value) { 00247 flags = (value ? flags | FIRSTCHILD : flags & ~FIRSTCHILD); 00248 } 00249 00250 inline bool specified() const { 00251 return (flags & SPECIFIED) != 0; 00252 } 00253 00254 inline void specified(bool value) { 00255 flags = (value ? flags | SPECIFIED : flags & ~SPECIFIED); 00256 } 00257 00258 inline bool ignorableWhitespace() const { 00259 return (flags & IGNORABLEWS) != 0; 00260 } 00261 00262 inline void ignorableWhitespace(bool value) { 00263 flags = (value ? flags | IGNORABLEWS : flags & ~IGNORABLEWS); 00264 } 00265 00266 inline bool setValue() const { 00267 return (flags & SETVALUE) != 0; 00268 } 00269 00270 inline void setValue(bool value) { 00271 flags = (value ? flags | SETVALUE : flags & ~SETVALUE); 00272 } 00273 00274 inline bool idAttr() const { 00275 return (flags & ID_ATTR) != 0; 00276 } 00277 00278 inline void idAttr(bool value) { 00279 flags = (value ? flags | ID_ATTR : flags & ~ID_ATTR); 00280 } 00281 00282 }; 00283 00284 00285 #endif