domnodeimpl.cpp
来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 1,113 行 · 第 1/3 页
CPP
1,113 行
/* * Copyright 2001-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Id: DOMNodeImpl.cpp,v 1.34 2004/09/08 13:55:52 peiyongz Exp $ */// This class doesn't support having any children, and implements the behavior// of an empty NodeList as far getChildNodes is concerned.// The ParentNode subclass overrides this behavior.#include "DOMCasts.hpp"#include "DOMDocumentTypeImpl.hpp"#include "DOMElementImpl.hpp"#include "DOMAttrImpl.hpp"#include <xercesc/dom/DOMImplementation.hpp>#include <xercesc/dom/DOMException.hpp>#include <xercesc/util/XMLUniDefs.hpp>#include <xercesc/util/XMLRegisterCleanup.hpp>#include <xercesc/util/PlatformUtils.hpp>#include <stdio.h>#include <assert.h>XERCES_CPP_NAMESPACE_BEGIN//Though DOMNodeImpl does not derivate from DOMNode, it shares//the same GetDOMNodeMemoryManagerconst unsigned short DOMNodeImpl::READONLY = 0x1<<0;const unsigned short DOMNodeImpl::SYNCDATA = 0x1<<1;const unsigned short DOMNodeImpl::SYNCCHILDREN = 0x1<<2;const unsigned short DOMNodeImpl::OWNED = 0x1<<3;const unsigned short DOMNodeImpl::FIRSTCHILD = 0x1<<4;const unsigned short DOMNodeImpl::SPECIFIED = 0x1<<5;const unsigned short DOMNodeImpl::IGNORABLEWS = 0x1<<6;const unsigned short DOMNodeImpl::SETVALUE = 0x1<<7;const unsigned short DOMNodeImpl::ID_ATTR = 0x1<<8;const unsigned short DOMNodeImpl::USERDATA = 0x1<<9;const unsigned short DOMNodeImpl::LEAFNODETYPE = 0x1<<10;const unsigned short DOMNodeImpl::CHILDNODE = 0x1<<11;const unsigned short DOMNodeImpl::TOBERELEASED = 0x1<<12;// -----------------------------------------------------------------------// Reset the singleton gEmptyNodeList// -----------------------------------------------------------------------static DOMNodeListImpl *gEmptyNodeList = 0; // make a singleton empty node liststatic XMLMutex* gEmptyNodeListMutex = 0;static XMLRegisterCleanup emptyNodeListCleanup;static void reinitEmptyNodeList(){ delete gEmptyNodeList; gEmptyNodeList = 0; delete gEmptyNodeListMutex; gEmptyNodeListMutex = 0;}// -----------------------------------------------------------------------// DOMNodeImpl Functions// -----------------------------------------------------------------------DOMNodeImpl::DOMNodeImpl(DOMNode *ownerNode): fOwnerNode(ownerNode){ this->flags = 0; // as long as we do not have any owner, fOwnerNode is our ownerDocument }// This only makes a shallow copy, cloneChildren must also be called for a// deep cloneDOMNodeImpl::DOMNodeImpl(const DOMNodeImpl &other){ this->flags = other.flags; this->isReadOnly(false); // Need to break the association w/ original parent this->fOwnerNode = other.getOwnerDocument(); this->isOwned(false);}DOMNodeImpl::~DOMNodeImpl() {}DOMNode * DOMNodeImpl::appendChild(DOMNode *){ // Only node types that don't allow children will use this default function. // Others will go to DOMParentNode::appendChild. throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMNodeMemoryManager); return 0; // return insertBefore(newChild, 0);}DOMNamedNodeMap * DOMNodeImpl::getAttributes() const { return 0; // overridden in ElementImpl}DOMNodeList *DOMNodeImpl::getChildNodes() const { if (!gEmptyNodeList) { if (!gEmptyNodeListMutex) { XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!gEmptyNodeListMutex) gEmptyNodeListMutex = new XMLMutex; } // Use a faux scope to synchronize while we do this { XMLMutexLock lock(gEmptyNodeListMutex); if (!gEmptyNodeList) { gEmptyNodeList = new DOMNodeListImpl(0); emptyNodeListCleanup.registerCleanup(reinitEmptyNodeList); } } } return (DOMNodeList *)gEmptyNodeList;}DOMNode * DOMNodeImpl::getFirstChild() const { return 0; // overridden in ParentNode}DOMNode * DOMNodeImpl::getLastChild() const{ return 0; // overridden in ParentNode}DOMNode * DOMNodeImpl::getNextSibling() const { return 0; // overridden in ChildNode}const XMLCh * DOMNodeImpl::getNodeValue() const { return 0; // Overridden by anything that has a value}//// Unlike the external getOwnerDocument, this one returns the owner document// for document nodes as well as all of the other node types.//DOMDocument *DOMNodeImpl::getOwnerDocument() const{ if (!this->isLeafNode()) { DOMElementImpl *ep = (DOMElementImpl *)castToNode(this); return ep->fParent.fOwnerDocument; } // Leaf node types - those that cannot have children, like Text. if (isOwned()) { DOMDocument* ownerDoc = fOwnerNode->getOwnerDocument(); if (!ownerDoc) { assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE); return (DOMDocument *)fOwnerNode; } else { return ownerDoc; } } else { assert (fOwnerNode->getNodeType() == DOMNode::DOCUMENT_NODE); return (DOMDocument *)fOwnerNode; }}void DOMNodeImpl::setOwnerDocument(DOMDocument *doc) { // if we have an owner we rely on it to have it right // otherwise fOwnerNode is our ownerDocument if (!isOwned()) { // revisit. Problem with storage for doctype nodes that were created // on the system heap in advance of having a document. fOwnerNode = doc; }}DOMNode * DOMNodeImpl::getParentNode() const{ return 0; // overridden in ChildNode}DOMNode* DOMNodeImpl::getPreviousSibling() const{ return 0; // overridden in ChildNode}bool DOMNodeImpl::hasChildNodes() const{ return false;}DOMNode *DOMNodeImpl::insertBefore(DOMNode *, DOMNode *) { throw DOMException(DOMException::HIERARCHY_REQUEST_ERR, 0, GetDOMNodeMemoryManager); return 0;}DOMNode *DOMNodeImpl::removeChild(DOMNode *){ throw DOMException(DOMException::NOT_FOUND_ERR, 0, GetDOMNodeMemoryManager); return 0;}DOMNode *DOMNodeImpl::replaceChild(DOMNode *, DOMNode *){ throw DOMException(DOMException::HIERARCHY_REQUEST_ERR,0, GetDOMNodeMemoryManager); return 0;}void DOMNodeImpl::setNodeValue(const XMLCh *){ // Default behavior is to do nothing, overridden in some subclasses}void DOMNodeImpl::setReadOnly(bool readOnl, bool deep){ this->isReadOnly(readOnl); if (deep) { for (DOMNode *mykid = castToNode(this)->getFirstChild(); mykid != 0; mykid = mykid->getNextSibling()) { short kidNodeType = mykid->getNodeType(); switch (kidNodeType) { case DOMNode::ENTITY_REFERENCE_NODE: break; case DOMNode::ELEMENT_NODE: ((DOMElementImpl*) mykid)->setReadOnly(readOnl, true); break; case DOMNode::DOCUMENT_TYPE_NODE: ((DOMDocumentTypeImpl*) mykid)->setReadOnly(readOnl, true); break; default: castToNodeImpl(mykid)->setReadOnly(readOnl, true); break; } } }}//Introduced in DOM Level 2void DOMNodeImpl::normalize(){ // does nothing by default, overridden by subclasses}bool DOMNodeImpl::isSupported(const XMLCh *feature, const XMLCh *version) const{ return DOMImplementation::getImplementation()->hasFeature(feature, version);}const XMLCh *DOMNodeImpl::getNamespaceURI() const{ return 0;}const XMLCh *DOMNodeImpl::getPrefix() const{ return 0;}const XMLCh *DOMNodeImpl::getLocalName() const{ return 0;}void DOMNodeImpl::setPrefix(const XMLCh *){ throw DOMException(DOMException::NAMESPACE_ERR, 0, GetDOMNodeMemoryManager);}bool DOMNodeImpl::hasAttributes() const { return 0; // overridden in ElementImpl}const XMLCh *DOMNodeImpl::getXmlString() {return XMLUni::fgXMLString;}const XMLCh *DOMNodeImpl::getXmlURIString() {return XMLUni::fgXMLURIName;}const XMLCh *DOMNodeImpl::getXmlnsString() {return XMLUni::fgXMLNSString;}const XMLCh *DOMNodeImpl::getXmlnsURIString() {return XMLUni::fgXMLNSURIName;}//Return a URI mapped from the given prefix and namespaceURI as below// prefix namespaceURI output//---------------------------------------------------// "xml" xmlURI xmlURI// "xml" otherwise NAMESPACE_ERR// "xmlns" xmlnsURI xmlnsURI (nType = ATTRIBUTE_NODE only)// "xmlns" otherwise NAMESPACE_ERR (nType = ATTRIBUTE_NODE only)// != null null or "" NAMESPACE_ERR// else any namesapceURIconst XMLCh* DOMNodeImpl::mapPrefix(const XMLCh *prefix, const XMLCh *namespaceURI, short nType){ if (prefix == 0) return namespaceURI; if (XMLString::equals(prefix, XMLUni::fgXMLString)) { if (XMLString::equals(namespaceURI, XMLUni::fgXMLURIName)) return XMLUni::fgXMLURIName; throw DOMException(DOMException::NAMESPACE_ERR, 0); } else if (nType == DOMNode::ATTRIBUTE_NODE && XMLString::equals(prefix, XMLUni::fgXMLNSString)) { if (XMLString::equals(namespaceURI, XMLUni::fgXMLNSURIName)) return XMLUni::fgXMLNSURIName; throw DOMException(DOMException::NAMESPACE_ERR, 0); } else if (namespaceURI == 0 || *namespaceURI == 0) { throw DOMException(DOMException::NAMESPACE_ERR, 0); } else return namespaceURI; return namespaceURI;}//Introduced in DOM Level 3void* DOMNodeImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler){ if (!data && !hasUserData()) return 0; hasUserData(true); return ((DOMDocumentImpl*)getOwnerDocument())->setUserData(this, key, data, handler);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?