Newer
Older
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
Boris Kolpackov
committed
*
Boris Kolpackov
committed
*
* 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$
*/
// 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 "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/PlatformUtils.hpp>
#include <xercesc/util/XMLInitializer.hpp>
#include <stdio.h>
#include <assert.h>
//Though DOMNodeImpl does not derivate from DOMNode, it shares
//the same GetDOMNodeMemoryManager
const 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;
Boris Kolpackov
committed
//
//
static DOMNodeListImpl *gEmptyNodeList = 0; // Singleton empty node list.
Khaled Noaman
committed
Boris Kolpackov
committed
void XMLInitializer::initializeDOMNodeListImpl()
{
Boris Kolpackov
committed
gEmptyNodeList = new DOMNodeListImpl(0);
}
Boris Kolpackov
committed
void XMLInitializer::terminateDOMNodeListImpl()
{
Boris Kolpackov
committed
delete gEmptyNodeList;
gEmptyNodeList = 0;
}
// -----------------------------------------------------------------------
// DOMNodeImpl Functions
// -----------------------------------------------------------------------
DOMNodeImpl::DOMNodeImpl(DOMNode *ownerNode)
David Abram Cargill
committed
: fOwnerNode(ownerNode)
{
this->flags = 0;
Boris Kolpackov
committed
// as long as we do not have any owner, fOwnerNode is our ownerDocument
David Abram Cargill
committed
}
// This only makes a shallow copy, cloneChildren must also be called for a
// deep clone
DOMNodeImpl::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);
David Abram Cargill
committed
}
DOMNodeImpl::~DOMNodeImpl() {
David Abram Cargill
committed
}
David Abram Cargill
committed
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);
David Abram Cargill
committed
}
DOMNamedNodeMap * DOMNodeImpl::getAttributes() const {
return 0; // overridden in ElementImpl
David Abram Cargill
committed
}
DOMNodeList *DOMNodeImpl::getChildNodes() const {
Boris Kolpackov
committed
return gEmptyNodeList;
David Abram Cargill
committed
}
DOMNode * DOMNodeImpl::getFirstChild() const {
return 0; // overridden in ParentNode
David Abram Cargill
committed
}
DOMNode * DOMNodeImpl::getLastChild() const
{
return 0; // overridden in ParentNode
David Abram Cargill
committed
}
DOMNode * DOMNodeImpl::getNextSibling() const {
return 0; // overridden in ChildNode
David Abram Cargill
committed
}
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;
}
David Abram Cargill
committed
}
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
David Abram Cargill
committed
}
DOMNode* DOMNodeImpl::getPreviousSibling() const
{
return 0; // overridden in ChildNode
David Abram Cargill
committed
}
bool DOMNodeImpl::hasChildNodes() const
{
Loading
Loading full blame...