GME  13
DOMEntityImpl.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: DOMEntityImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
00020  */
00021 
00022 #include <xercesc/dom/DOMException.hpp>
00023 #include <xercesc/dom/DOMNode.hpp>
00024 #include <xercesc/dom/DOMEntityReference.hpp>
00025 #include "DOMEntityImpl.hpp"
00026 #include "DOMDocumentImpl.hpp"
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00030 DOMEntityImpl::DOMEntityImpl(DOMDocument *ownerDoc, const XMLCh *eName)
00031    : fNode(ownerDoc),
00032      fParent(ownerDoc),
00033      fPublicId(0),
00034      fSystemId(0),
00035      fNotationName(0),
00036      fRefEntity(0),
00037      fInputEncoding(0),
00038      fXmlEncoding(0),
00039      fXmlVersion(0),
00040      fBaseURI(0),
00041      fEntityRefNodeCloned(false)
00042 {
00043     fName        = ((DOMDocumentImpl *)ownerDoc)->getPooledString(eName);
00044     fNode.setReadOnly(true, true);
00045 }
00046 
00047 
00048 DOMEntityImpl::DOMEntityImpl(const DOMEntityImpl &other, bool deep)
00049     : DOMEntity(other),
00050       fNode(other.fNode),
00051       fParent(other.fParent),
00052       fName(other.fName),
00053       fPublicId(other.fPublicId),
00054       fSystemId(other.fSystemId),
00055       fNotationName(other.fNotationName),
00056       fRefEntity(other.fRefEntity),
00057       fInputEncoding(other.fInputEncoding),
00058       fXmlEncoding(other.fXmlEncoding),
00059       fXmlVersion(other.fXmlVersion),
00060       fBaseURI(other.fBaseURI),
00061       fEntityRefNodeCloned(false)
00062 {
00063     if (deep)
00064         fParent.cloneChildren(&other);
00065     fNode.setReadOnly(true, true);
00066 }
00067 
00068 
00069 DOMEntityImpl::~DOMEntityImpl() {
00070 }
00071 
00072 
00073 DOMNode *DOMEntityImpl::cloneNode(bool deep) const
00074 {
00075     DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ENTITY_OBJECT) DOMEntityImpl(*this, deep);
00076     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
00077     return newNode;
00078 }
00079 
00080 
00081 const XMLCh * DOMEntityImpl::getNodeName() const {
00082     return fName;
00083 }
00084 
00085 
00086 DOMNode::NodeType DOMEntityImpl::getNodeType() const {
00087     return DOMNode::ENTITY_NODE;
00088 }
00089 
00090 
00091 const XMLCh * DOMEntityImpl::getNotationName() const
00092 {
00093     return fNotationName;
00094 }
00095 
00096 
00097 const XMLCh * DOMEntityImpl::getPublicId() const {
00098     return fPublicId;
00099 }
00100 
00101 
00102 const XMLCh * DOMEntityImpl::getSystemId() const
00103 {
00104     return fSystemId;
00105 }
00106 
00107 
00108 const XMLCh* DOMEntityImpl::getBaseURI() const
00109 {
00110     return fBaseURI;
00111 }
00112 
00113 
00114 void DOMEntityImpl::setNodeValue(const XMLCh *arg)
00115 {
00116     fNode.setNodeValue(arg);
00117 }
00118 
00119 
00120 void DOMEntityImpl::setNotationName(const XMLCh *arg)
00121 {
00122     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00123     fNotationName = doc->cloneString(arg);
00124 }
00125 
00126 
00127 void DOMEntityImpl::setPublicId(const XMLCh *arg)
00128 {
00129     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00130     fPublicId = doc->cloneString(arg);
00131 }
00132 
00133 
00134 void DOMEntityImpl::setSystemId(const XMLCh *arg)
00135 {
00136     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00137     fSystemId = doc->cloneString(arg);
00138 }
00139 
00140 
00141 void DOMEntityImpl::setBaseURI(const XMLCh* baseURI) {
00142     if (baseURI && *baseURI) {
00143         XMLCh* temp = (XMLCh*) ((DOMDocumentImpl *)fParent.fOwnerDocument)->allocate((XMLString::stringLen(baseURI) + 9)*sizeof(XMLCh));
00144         XMLString::fixURI(baseURI, temp);
00145         fBaseURI = temp;
00146     }
00147     else
00148         fBaseURI = 0;
00149 }
00150 
00151 
00152 void   DOMEntityImpl::setEntityRef(DOMEntityReference* other)
00153 {
00154     fRefEntity = other;
00155 }
00156 
00157 
00158 DOMEntityReference*  DOMEntityImpl::getEntityRef() const
00159 {
00160     return fRefEntity;
00161 }
00162 
00163 void  DOMEntityImpl::cloneEntityRefTree() const
00164 {
00165     if (fEntityRefNodeCloned)
00166         return;
00167 
00168     // cast off const.  This method is const because it is
00169     //   called from a bunch of logically const methods, like
00170     //   getFirstChild().
00171     DOMEntityImpl *ncThis = (DOMEntityImpl *)this;
00172 
00173     //lazily clone the entityRef tree to this entity
00174     if (fParent.fFirstChild != 0)
00175         return;
00176 
00177     if (!fRefEntity)
00178         return;
00179 
00180     ncThis->fEntityRefNodeCloned = true;
00181     ncThis->fNode.setReadOnly(false, true);
00182     ncThis->fParent.cloneChildren(fRefEntity);
00183     ncThis->fNode.setReadOnly(true, true);
00184 }
00185 
00186 DOMNode * DOMEntityImpl::getFirstChild() const
00187 {
00188     cloneEntityRefTree();
00189     return fParent.fFirstChild;
00190 }
00191 
00192 DOMNode *   DOMEntityImpl::getLastChild() const
00193 {
00194     cloneEntityRefTree();
00195     return fParent.getLastChild();
00196 }
00197 
00198 DOMNodeList* DOMEntityImpl::getChildNodes() const
00199 {
00200     cloneEntityRefTree();
00201     return this->fParent.getChildNodes();
00202 
00203 }
00204 
00205 bool DOMEntityImpl::hasChildNodes() const
00206 {
00207     cloneEntityRefTree();
00208     return fParent.fFirstChild!=0;
00209 }
00210 
00211 
00212 void DOMEntityImpl::release()
00213 {
00214     if (fNode.isOwned() && !fNode.isToBeReleased())
00215         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00216 
00217     DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
00218     if (doc) {
00219         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
00220         fParent.release();
00221         doc->release(this, DOMMemoryManager::ENTITY_OBJECT);
00222     }
00223     else {
00224         // shouldn't reach here
00225         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00226     }
00227 }
00228 
00229 //
00230 //  Functions inherited from Node
00231 //
00232 
00233            DOMNode*         DOMEntityImpl::appendChild(DOMNode *newChild)          {cloneEntityRefTree(); return fParent.appendChild (newChild); }
00234            DOMNamedNodeMap* DOMEntityImpl::getAttributes() const                   {return fNode.getAttributes (); }
00235      const XMLCh*           DOMEntityImpl::getLocalName() const                    {return fNode.getLocalName (); }
00236      const XMLCh*           DOMEntityImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); }
00237            DOMNode*         DOMEntityImpl::getNextSibling() const                  {return fNode.getNextSibling (); }
00238      const XMLCh*           DOMEntityImpl::getNodeValue() const                    {return fNode.getNodeValue (); }
00239            DOMDocument*     DOMEntityImpl::getOwnerDocument() const                {return fParent.fOwnerDocument; }
00240      const XMLCh*           DOMEntityImpl::getPrefix() const                       {return fNode.getPrefix (); }
00241            DOMNode*         DOMEntityImpl::getParentNode() const                   {return fNode.getParentNode (); }
00242            DOMNode*         DOMEntityImpl::getPreviousSibling() const              {return fNode.getPreviousSibling (); }
00243            DOMNode*         DOMEntityImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
00244                                                                                    {cloneEntityRefTree(); return fParent.insertBefore (newChild, refChild); }
00245            void             DOMEntityImpl::normalize()                             {cloneEntityRefTree(); fParent.normalize (); }
00246            DOMNode*         DOMEntityImpl::removeChild(DOMNode *oldChild)          {cloneEntityRefTree(); return fParent.removeChild (oldChild); }
00247            DOMNode*         DOMEntityImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
00248                                                                                    {cloneEntityRefTree(); return fParent.replaceChild (newChild, oldChild); }
00249            bool             DOMEntityImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
00250                                                                                    {return fNode.isSupported (feature, version); }
00251            void             DOMEntityImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); }
00252            bool             DOMEntityImpl::hasAttributes() const                   {return fNode.hasAttributes(); }
00253            bool             DOMEntityImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); }
00254            bool             DOMEntityImpl::isEqualNode(const DOMNode* arg) const   {cloneEntityRefTree(); return fParent.isEqualNode(arg); }
00255            void*            DOMEntityImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
00256                                                                                    {return fNode.setUserData(key, data, handler); }
00257            void*            DOMEntityImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); }
00258            short            DOMEntityImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
00259            const XMLCh*     DOMEntityImpl::getTextContent() const                  {return fNode.getTextContent(); }
00260            void             DOMEntityImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
00261            const XMLCh*     DOMEntityImpl::lookupPrefix(const XMLCh* namespaceURI) const  {return fNode.lookupPrefix(namespaceURI); }
00262            bool             DOMEntityImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
00263            const XMLCh*     DOMEntityImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); }
00264            void*            DOMEntityImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
00265 
00266 
00267 //Introduced in DOM Level 3
00268 const XMLCh* DOMEntityImpl::getInputEncoding() const {
00269     return fInputEncoding;
00270 }
00271 
00272 void DOMEntityImpl::setInputEncoding(const XMLCh* actualEncoding){
00273     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00274     fInputEncoding = doc->cloneString(actualEncoding);
00275 }
00276 
00277 const XMLCh* DOMEntityImpl::getXmlEncoding() const {
00278     return fXmlEncoding;
00279 }
00280 
00281 void DOMEntityImpl::setXmlEncoding(const XMLCh* encoding){
00282     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00283     fXmlEncoding = doc->cloneString(encoding);
00284 }
00285 
00286 const XMLCh* DOMEntityImpl::getXmlVersion() const {
00287     return fXmlVersion;
00288 }
00289 
00290 void DOMEntityImpl::setXmlVersion(const XMLCh* version){
00291     DOMDocumentImpl *doc = (DOMDocumentImpl *)fParent.fOwnerDocument;
00292     fXmlVersion = doc->cloneString(version);
00293 }
00294 
00295 XERCES_CPP_NAMESPACE_END