GME  13
DOMEntityReferenceImpl.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: DOMEntityReferenceImpl.cpp 678381 2008-07-21 10:15:01Z borisk $
00020  */
00021 
00022 #include "DOMDocumentImpl.hpp"
00023 #include "DOMDocumentTypeImpl.hpp"
00024 #include "DOMEntityImpl.hpp"
00025 #include "DOMEntityReferenceImpl.hpp"
00026 
00027 #include <xercesc/dom/DOMException.hpp>
00028 #include <xercesc/dom/DOMNode.hpp>
00029 #include <xercesc/dom/DOMNamedNodeMap.hpp>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 DOMEntityReferenceImpl::DOMEntityReferenceImpl(DOMDocument *ownerDoc,
00034                                          const XMLCh *entityName)
00035     : fNode(ownerDoc), fParent(ownerDoc), fBaseURI(0)
00036 {
00037     fName = ((DOMDocumentImpl*)fParent.fOwnerDocument)->getPooledString(entityName);
00038     // EntityReference behaves as a read-only node, since its contents
00039     // reflect the Entity it refers to -- but see setNodeName().
00040     //retrieve the corresponding entity content
00041 
00042     if (ownerDoc) {
00043         if (ownerDoc->getDoctype()) {
00044             if (ownerDoc->getDoctype()->getEntities()) {
00045                 DOMEntityImpl* entity = (DOMEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
00046                 if (entity) {
00047                     fBaseURI = entity->getBaseURI();
00048                     DOMEntityReference* refEntity = entity->getEntityRef();
00049                     if (refEntity) {
00050                         fParent.cloneChildren(refEntity);
00051                     }
00052                 }
00053             }
00054         }
00055     }
00056 
00057     fNode.setReadOnly(true, true);
00058 }
00059 
00060 
00061 DOMEntityReferenceImpl::DOMEntityReferenceImpl(DOMDocument *ownerDoc,
00062                                          const XMLCh *entityName,
00063                                          bool cloneChild)
00064     : fNode(ownerDoc), fParent(ownerDoc), fBaseURI(0)
00065 {
00066     fName = ((DOMDocumentImpl*)fParent.fOwnerDocument)->getPooledString(entityName);
00067     // EntityReference behaves as a read-only node, since its contents
00068     // reflect the Entity it refers to -- but see setNodeName().
00069     //retrieve the corresponding entity content
00070 
00071     if (ownerDoc) {
00072         if (ownerDoc->getDoctype()) {
00073             if (ownerDoc->getDoctype()->getEntities()) {
00074                 DOMEntityImpl* entity = (DOMEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
00075                 if (entity) {
00076                     fBaseURI = entity->getBaseURI();
00077                     if (cloneChild) {
00078                         DOMEntityReference* refEntity = entity->getEntityRef();
00079                         if (refEntity) {
00080                             fParent.cloneChildren(refEntity);
00081                         }
00082                     }
00083                 }
00084             }
00085         }
00086     }
00087 
00088     fNode.setReadOnly(true, true);
00089 }
00090 
00091 DOMEntityReferenceImpl::DOMEntityReferenceImpl(const DOMEntityReferenceImpl &other,
00092                                          bool deep)
00093     : DOMEntityReference(other),
00094       fNode(other.fNode),
00095       fParent(other.fParent),
00096       fChild(other.fChild),
00097       fName(other.fName),
00098       fBaseURI(other.fBaseURI)
00099 {
00100     if (deep)
00101         fParent.cloneChildren(&other);
00102     fNode.setReadOnly(true, true);
00103 }
00104 
00105 
00106 
00107 DOMEntityReferenceImpl::~DOMEntityReferenceImpl()
00108 {
00109 }
00110 
00111 DOMNode *DOMEntityReferenceImpl::cloneNode(bool deep) const
00112 {
00113     DOMNode* newNode = new (fParent.fOwnerDocument, DOMMemoryManager::ENTITY_REFERENCE_OBJECT) DOMEntityReferenceImpl(*this, deep);
00114     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
00115     return newNode;
00116 }
00117 
00118 
00119 const XMLCh * DOMEntityReferenceImpl::getNodeName() const
00120 {
00121     return fName;
00122 }
00123 
00124 
00125 DOMNode::NodeType DOMEntityReferenceImpl::getNodeType() const {
00126     return DOMNode::ENTITY_REFERENCE_NODE;
00127 }
00128 
00129 
00130 
00135 void DOMEntityReferenceImpl::setNodeValue(const XMLCh *x)
00136 {
00137     fNode.setNodeValue(x);
00138 }
00139 
00140 
00149 void DOMEntityReferenceImpl::setReadOnly(bool readOnl,bool deep)
00150 {
00151     if(((DOMDocumentImpl *)fParent.fOwnerDocument)->getErrorChecking() && readOnl==false)
00152         throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
00153     fNode.setReadOnly(readOnl,deep);
00154 }
00155 
00156 
00157 void DOMEntityReferenceImpl::release()
00158 {
00159     if (fNode.isOwned() && !fNode.isToBeReleased())
00160         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00161 
00162     DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;
00163     if (doc) {
00164         fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
00165         fParent.release();
00166         doc->release(this, DOMMemoryManager::ENTITY_REFERENCE_OBJECT);
00167     }
00168     else {
00169         // shouldn't reach here
00170         throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
00171     }
00172 }
00173 
00174 const XMLCh* DOMEntityReferenceImpl::getBaseURI() const
00175 {
00176     return fBaseURI;
00177 }
00178 
00179 
00180 
00181 //
00182 //   Delegate functions from Node to the appropriate implementation.
00183 //
00184 
00185 
00186            DOMNode*         DOMEntityReferenceImpl::appendChild(DOMNode *newChild)          {return fParent.appendChild (newChild); }
00187            DOMNamedNodeMap* DOMEntityReferenceImpl::getAttributes() const                   {return fNode.getAttributes (); }
00188            DOMNodeList*     DOMEntityReferenceImpl::getChildNodes() const                   {return fParent.getChildNodes (); }
00189            DOMNode*         DOMEntityReferenceImpl::getFirstChild() const                   {return fParent.getFirstChild (); }
00190            DOMNode*         DOMEntityReferenceImpl::getLastChild() const                    {return fParent.getLastChild (); }
00191      const XMLCh*           DOMEntityReferenceImpl::getLocalName() const                    {return fNode.getLocalName (); }
00192      const XMLCh*           DOMEntityReferenceImpl::getNamespaceURI() const                 {return fNode.getNamespaceURI (); }
00193            DOMNode*         DOMEntityReferenceImpl::getNextSibling() const                  {return fChild.getNextSibling (); }
00194      const XMLCh*           DOMEntityReferenceImpl::getNodeValue() const                    {return fNode.getNodeValue (); }
00195            DOMDocument*     DOMEntityReferenceImpl::getOwnerDocument() const                {return fParent.fOwnerDocument; }
00196      const XMLCh*           DOMEntityReferenceImpl::getPrefix() const                       {return fNode.getPrefix (); }
00197            DOMNode*         DOMEntityReferenceImpl::getParentNode() const                   {return fChild.getParentNode (this); }
00198            DOMNode*         DOMEntityReferenceImpl::getPreviousSibling() const              {return fChild.getPreviousSibling (this); }
00199            bool             DOMEntityReferenceImpl::hasChildNodes() const                   {return fParent.hasChildNodes (); }
00200            DOMNode*         DOMEntityReferenceImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
00201                                                                                             {return fParent.insertBefore (newChild, refChild); }
00202            void             DOMEntityReferenceImpl::normalize()                             {fParent.normalize (); }
00203            DOMNode*         DOMEntityReferenceImpl::removeChild(DOMNode *oldChild)          {return fParent.removeChild (oldChild); }
00204            DOMNode*         DOMEntityReferenceImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
00205                                                                                             {return fParent.replaceChild (newChild, oldChild); }
00206            bool             DOMEntityReferenceImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
00207                                                                                             {return fNode.isSupported (feature, version); }
00208            void             DOMEntityReferenceImpl::setPrefix(const XMLCh  *prefix)         {fNode.setPrefix(prefix); }
00209            bool             DOMEntityReferenceImpl::hasAttributes() const                   {return fNode.hasAttributes(); }
00210            bool             DOMEntityReferenceImpl::isSameNode(const DOMNode* other) const  {return fNode.isSameNode(other); }
00211            bool             DOMEntityReferenceImpl::isEqualNode(const DOMNode* arg) const   {return fParent.isEqualNode(arg); }
00212            void*            DOMEntityReferenceImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
00213                                                                                             {return fNode.setUserData(key, data, handler); }
00214            void*            DOMEntityReferenceImpl::getUserData(const XMLCh* key) const     {return fNode.getUserData(key); }
00215            short            DOMEntityReferenceImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
00216            const XMLCh*     DOMEntityReferenceImpl::getTextContent() const                  {return fNode.getTextContent(); }
00217            void             DOMEntityReferenceImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
00218            const XMLCh*     DOMEntityReferenceImpl::lookupPrefix(const XMLCh* namespaceURI) const  {return fNode.lookupPrefix(namespaceURI); }
00219            bool             DOMEntityReferenceImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
00220            const XMLCh*     DOMEntityReferenceImpl::lookupNamespaceURI(const XMLCh* prefix) const  {return fNode.lookupNamespaceURI(prefix); }
00221            void*            DOMEntityReferenceImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
00222 
00223 XERCES_CPP_NAMESPACE_END