1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * $Id$
20 */
21
22 #include "DOMDocumentFragmentImpl.hpp"
23 #include "DOMDocumentImpl.hpp"
24 #include "DOMCasts.hpp"
25 #include <xercesc/dom/DOMNode.hpp>
26 #include <xercesc/dom/DOMException.hpp>
27 #include <xercesc/util/XMLUniDefs.hpp>
28
29 XERCES_CPP_NAMESPACE_BEGIN
30
DOMDocumentFragmentImpl(DOMDocument * masterDoc)31 DOMDocumentFragmentImpl::DOMDocumentFragmentImpl(DOMDocument *masterDoc)
32 : fNode(this, masterDoc), fParent(this, masterDoc)
33 {
34 }
35
36
DOMDocumentFragmentImpl(const DOMDocumentFragmentImpl & other,bool deep)37 DOMDocumentFragmentImpl::DOMDocumentFragmentImpl(const DOMDocumentFragmentImpl &other,
38 bool deep)
39 : fNode(this, other.fNode), fParent(this, other.fParent)
40 {
41 if (deep)
42 castToParentImpl(this)->cloneChildren(&other);
43 }
44
45
~DOMDocumentFragmentImpl()46 DOMDocumentFragmentImpl::~DOMDocumentFragmentImpl()
47 {
48 }
49
50
51
cloneNode(bool deep) const52 DOMNode *DOMDocumentFragmentImpl::cloneNode(bool deep) const
53 {
54 DOMNode* newNode = new (castToNodeImpl(this)->getOwnerDocument(), DOMMemoryManager::DOCUMENT_FRAGMENT_OBJECT) DOMDocumentFragmentImpl(*this, deep);
55 fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
56 return newNode;
57 }
58
59
getNodeName() const60 const XMLCh * DOMDocumentFragmentImpl::getNodeName() const {
61 static const XMLCh name[] = {chPound, chLatin_d, chLatin_o, chLatin_c, chLatin_u, chLatin_m,
62 chLatin_e, chLatin_n, chLatin_t, chDash,
63 chLatin_f, chLatin_r, chLatin_a, chLatin_g, chLatin_m, chLatin_e, chLatin_n, chLatin_t, 0};
64 return name;
65 }
66
67
getNodeType() const68 DOMNode::NodeType DOMDocumentFragmentImpl::getNodeType() const {
69 return DOMNode::DOCUMENT_FRAGMENT_NODE;
70 }
71
72
setNodeValue(const XMLCh * x)73 void DOMDocumentFragmentImpl::setNodeValue(const XMLCh *x)
74 {
75 fNode.setNodeValue(x);
76 }
77
78
release()79 void DOMDocumentFragmentImpl::release()
80 {
81 if (fNode.isOwned() && !fNode.isToBeReleased())
82 throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
83
84 DOMDocumentImpl* doc = (DOMDocumentImpl*) getOwnerDocument();
85 if (doc) {
86 fNode.callUserDataHandlers(DOMUserDataHandler::NODE_DELETED, 0, 0);
87 fParent.release();
88 doc->release(this, DOMMemoryManager::DOCUMENT_FRAGMENT_OBJECT);
89 }
90 else {
91 // shouldn't reach here
92 throw DOMException(DOMException::INVALID_ACCESS_ERR,0, GetDOMNodeMemoryManager);
93 }
94 }
95
96 //
97 // Delegation stubs for inherited functions.
98 //
appendChild(DOMNode * newChild)99 DOMNode* DOMDocumentFragmentImpl::appendChild(DOMNode *newChild) {return fParent.appendChild (newChild); }
getAttributes() const100 DOMNamedNodeMap* DOMDocumentFragmentImpl::getAttributes() const {return fNode.getAttributes (); }
getChildNodes() const101 DOMNodeList* DOMDocumentFragmentImpl::getChildNodes() const {return fParent.getChildNodes (); }
getFirstChild() const102 DOMNode* DOMDocumentFragmentImpl::getFirstChild() const {return fParent.getFirstChild (); }
getLastChild() const103 DOMNode* DOMDocumentFragmentImpl::getLastChild() const {return fParent.getLastChild (); }
getLocalName() const104 const XMLCh* DOMDocumentFragmentImpl::getLocalName() const {return fNode.getLocalName (); }
getNamespaceURI() const105 const XMLCh* DOMDocumentFragmentImpl::getNamespaceURI() const {return fNode.getNamespaceURI (); }
getNextSibling() const106 DOMNode* DOMDocumentFragmentImpl::getNextSibling() const {return fNode.getNextSibling (); }
getNodeValue() const107 const XMLCh* DOMDocumentFragmentImpl::getNodeValue() const {return fNode.getNodeValue (); }
getOwnerDocument() const108 DOMDocument* DOMDocumentFragmentImpl::getOwnerDocument() const {return fParent.fOwnerDocument; }
getPrefix() const109 const XMLCh* DOMDocumentFragmentImpl::getPrefix() const {return fNode.getPrefix (); }
getParentNode() const110 DOMNode* DOMDocumentFragmentImpl::getParentNode() const {return fNode.getParentNode (); }
getPreviousSibling() const111 DOMNode* DOMDocumentFragmentImpl::getPreviousSibling() const {return fNode.getPreviousSibling (); }
hasChildNodes() const112 bool DOMDocumentFragmentImpl::hasChildNodes() const {return fParent.hasChildNodes (); }
insertBefore(DOMNode * newChild,DOMNode * refChild)113 DOMNode* DOMDocumentFragmentImpl::insertBefore(DOMNode *newChild, DOMNode *refChild)
114 {return fParent.insertBefore (newChild, refChild); }
normalize()115 void DOMDocumentFragmentImpl::normalize() {fParent.normalize (); }
removeChild(DOMNode * oldChild)116 DOMNode* DOMDocumentFragmentImpl::removeChild(DOMNode *oldChild) {return fParent.removeChild (oldChild); }
replaceChild(DOMNode * newChild,DOMNode * oldChild)117 DOMNode* DOMDocumentFragmentImpl::replaceChild(DOMNode *newChild, DOMNode *oldChild)
118 {return fParent.replaceChild (newChild, oldChild); }
isSupported(const XMLCh * feature,const XMLCh * version) const119 bool DOMDocumentFragmentImpl::isSupported(const XMLCh *feature, const XMLCh *version) const
120 {return fNode.isSupported (feature, version); }
setPrefix(const XMLCh * prefix)121 void DOMDocumentFragmentImpl::setPrefix(const XMLCh *prefix) {fNode.setPrefix(prefix); }
hasAttributes() const122 bool DOMDocumentFragmentImpl::hasAttributes() const {return fNode.hasAttributes(); }
isSameNode(const DOMNode * other) const123 bool DOMDocumentFragmentImpl::isSameNode(const DOMNode* other) const {return fNode.isSameNode(other); }
isEqualNode(const DOMNode * arg) const124 bool DOMDocumentFragmentImpl::isEqualNode(const DOMNode* arg) const {return fParent.isEqualNode(arg); }
setUserData(const XMLCh * key,void * data,DOMUserDataHandler * handler)125 void* DOMDocumentFragmentImpl::setUserData(const XMLCh* key, void* data, DOMUserDataHandler* handler)
126 {return fNode.setUserData(key, data, handler); }
getUserData(const XMLCh * key) const127 void* DOMDocumentFragmentImpl::getUserData(const XMLCh* key) const {return fNode.getUserData(key); }
getBaseURI() const128 const XMLCh* DOMDocumentFragmentImpl::getBaseURI() const {return fNode.getBaseURI(); }
compareDocumentPosition(const DOMNode * other) const129 short DOMDocumentFragmentImpl::compareDocumentPosition(const DOMNode* other) const {return fNode.compareDocumentPosition(other); }
getTextContent() const130 const XMLCh* DOMDocumentFragmentImpl::getTextContent() const {return fNode.getTextContent(); }
setTextContent(const XMLCh * textContent)131 void DOMDocumentFragmentImpl::setTextContent(const XMLCh* textContent){fNode.setTextContent(textContent); }
lookupPrefix(const XMLCh * namespaceURI) const132 const XMLCh* DOMDocumentFragmentImpl::lookupPrefix(const XMLCh* namespaceURI) const {return fNode.lookupPrefix(namespaceURI); }
isDefaultNamespace(const XMLCh * namespaceURI) const133 bool DOMDocumentFragmentImpl::isDefaultNamespace(const XMLCh* namespaceURI) const {return fNode.isDefaultNamespace(namespaceURI); }
lookupNamespaceURI(const XMLCh * prefix) const134 const XMLCh* DOMDocumentFragmentImpl::lookupNamespaceURI(const XMLCh* prefix) const {return fNode.lookupNamespaceURI(prefix); }
getFeature(const XMLCh * feature,const XMLCh * version) const135 void* DOMDocumentFragmentImpl::getFeature(const XMLCh* feature, const XMLCh* version) const {return fNode.getFeature(feature, version); }
136
137 // Macro-in implementation accessors.
138 DOMNODEIMPL_IMPL(DOMDocumentFragmentImpl);
139 DOMPARENTIMPL_IMPL(DOMDocumentFragmentImpl);
140
141 XERCES_CPP_NAMESPACE_END
142