1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include "XalanSourceTreeElement.hpp"
19 
20 
21 
22 #include <xalanc/XalanDOM/XalanDOMException.hpp>
23 
24 
25 
26 #include <xalanc/PlatformSupport/DOMStringHelper.hpp>
27 
28 
29 
30 #include "XalanSourceTreeAttr.hpp"
31 #include "XalanSourceTreeComment.hpp"
32 #include "XalanSourceTreeDocument.hpp"
33 #include "XalanSourceTreeDocumentFragment.hpp"
34 #include "XalanSourceTreeProcessingInstruction.hpp"
35 #include "XalanSourceTreeText.hpp"
36 #include "XalanSourceTreeHelper.hpp"
37 
38 
39 
40 namespace XALAN_CPP_NAMESPACE {
41 
42 
43 
44 const XalanDOMString        XalanSourceTreeElement::s_emptyString(XalanMemMgrs::getDummyMemMgr());
45 
46 
47 
XalanSourceTreeElement(MemoryManager & theManager,const XalanDOMString & theTagName,XalanSourceTreeDocument * theOwnerDocument,XalanNode * theParentNode,XalanNode * thePreviousSibling,XalanNode * theNextSibling,IndexType theIndex)48 XalanSourceTreeElement::XalanSourceTreeElement(
49             MemoryManager&              theManager,
50             const XalanDOMString&       theTagName,
51             XalanSourceTreeDocument*    theOwnerDocument,
52             XalanNode*                  theParentNode,
53             XalanNode*                  thePreviousSibling,
54             XalanNode*                  theNextSibling,
55             IndexType                   theIndex) :
56     XalanElement(),
57     m_tagName(theTagName),
58     m_memoryManager(theManager),
59     m_ownerDocument(theOwnerDocument),
60     m_parentNode(theParentNode),
61     m_previousSibling(thePreviousSibling),
62     m_nextSibling(theNextSibling),
63     m_firstChild(0),
64     m_index(theIndex)
65 {
66 }
67 
68 
69 
~XalanSourceTreeElement()70 XalanSourceTreeElement::~XalanSourceTreeElement()
71 {
72 }
73 
74 
75 /*
76 XalanSourceTreeElement::XalanSourceTreeElement(
77             MemoryManager&              theManager,
78             const XalanSourceTreeElement&   theSource,
79             bool                                deep) :
80     XalanElement(theSource),
81     m_tagName(theSource.m_tagName),
82     m_memoryManager(theManager),
83     m_ownerDocument(theSource.m_ownerDocument),
84     m_parentNode(0),
85     m_previousSibling(0),
86     m_nextSibling(0),
87     m_firstChild(theSource.m_firstChild == 0 ? 0 : theSource.m_firstChild->cloneNode(deep)),
88     m_index(0)
89 {
90 }
91 */
92 
93 
94 const XalanDOMString&
getNodeName() const95 XalanSourceTreeElement::getNodeName() const
96 {
97     return m_tagName;
98 }
99 
100 
101 
102 const XalanDOMString&
getNodeValue() const103 XalanSourceTreeElement::getNodeValue() const
104 {
105     return s_emptyString;
106 }
107 
108 
109 
110 XalanSourceTreeElement::NodeType
getNodeType() const111 XalanSourceTreeElement::getNodeType() const
112 {
113     return ELEMENT_NODE;
114 }
115 
116 
117 
118 XalanNode*
getParentNode() const119 XalanSourceTreeElement::getParentNode() const
120 {
121     if (m_parentNode != 0)
122     {
123         return m_parentNode;
124     }
125     else
126     {
127         return m_ownerDocument;
128     }
129 }
130 
131 
132 
133 const XalanNodeList*
getChildNodes() const134 XalanSourceTreeElement::getChildNodes() const
135 {
136     throw XalanDOMException(XalanDOMException::NOT_SUPPORTED_ERR);
137 
138     // Dummy return value...
139     return 0;
140 }
141 
142 
143 
144 XalanNode*
getFirstChild() const145 XalanSourceTreeElement::getFirstChild() const
146 {
147     return m_firstChild;
148 }
149 
150 
151 
152 XalanNode*
getLastChild() const153 XalanSourceTreeElement::getLastChild() const
154 {
155     return XalanSourceTreeHelper::getLastSibling(m_firstChild);
156 }
157 
158 
159 
160 XalanNode*
getPreviousSibling() const161 XalanSourceTreeElement::getPreviousSibling() const
162 {
163     return m_previousSibling;
164 }
165 
166 
167 
168 XalanNode*
getNextSibling() const169 XalanSourceTreeElement::getNextSibling() const
170 {
171     return m_nextSibling;
172 }
173 
174 
175 
176 XalanDocument*
getOwnerDocument() const177 XalanSourceTreeElement::getOwnerDocument() const
178 {
179     return m_ownerDocument;
180 }
181 
182 
183 
184 bool
isIndexed() const185 XalanSourceTreeElement::isIndexed() const
186 {
187     return true;
188 }
189 
190 
191 
192 XalanSourceTreeElement::IndexType
getIndex() const193 XalanSourceTreeElement::getIndex() const
194 {
195     return m_index;
196 }
197 
198 
199 
200 const XalanDOMString&
getTagName() const201 XalanSourceTreeElement::getTagName() const
202 {
203     return m_tagName;
204 }
205 
206 
207 
208 void
setParent(XalanSourceTreeDocumentFragment * theParent)209 XalanSourceTreeElement::setParent(XalanSourceTreeDocumentFragment*  theParent)
210 {
211     m_parentNode = theParent;
212 }
213 
214 
215 
216 void
setPreviousSibling(XalanSourceTreeComment * thePreviousSibling)217 XalanSourceTreeElement::setPreviousSibling(XalanSourceTreeComment*  thePreviousSibling)
218 {
219     m_previousSibling = thePreviousSibling;
220 }
221 
222 
223 
224 void
setPreviousSibling(XalanSourceTreeElement * thePreviousSibling)225 XalanSourceTreeElement::setPreviousSibling(XalanSourceTreeElement*  thePreviousSibling)
226 {
227     m_previousSibling = thePreviousSibling;
228 }
229 
230 
231 
232 void
setPreviousSibling(XalanSourceTreeProcessingInstruction * thePreviousSibling)233 XalanSourceTreeElement::setPreviousSibling(XalanSourceTreeProcessingInstruction*    thePreviousSibling)
234 {
235     m_previousSibling = thePreviousSibling;
236 }
237 
238 
239 
240 void
setPreviousSibling(XalanSourceTreeText * thePreviousSibling)241 XalanSourceTreeElement::setPreviousSibling(XalanSourceTreeText*     thePreviousSibling)
242 {
243     m_previousSibling = thePreviousSibling;
244 }
245 
246 
247 
248 void
appendSiblingNode(XalanSourceTreeComment * theSibling)249 XalanSourceTreeElement::appendSiblingNode(XalanSourceTreeComment*   theSibling)
250 {
251     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
252 }
253 
254 
255 
256 void
appendSiblingNode(XalanSourceTreeElement * theSibling)257 XalanSourceTreeElement::appendSiblingNode(XalanSourceTreeElement*   theSibling)
258 {
259     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
260 }
261 
262 
263 
264 void
appendSiblingNode(XalanSourceTreeProcessingInstruction * theSibling)265 XalanSourceTreeElement::appendSiblingNode(XalanSourceTreeProcessingInstruction*     theSibling)
266 {
267     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
268 }
269 
270 
271 
272 void
appendSiblingNode(XalanSourceTreeText * theSibling)273 XalanSourceTreeElement::appendSiblingNode(XalanSourceTreeText*  theSibling)
274 {
275     XalanSourceTreeHelper::appendSibling(this, m_nextSibling, theSibling);
276 }
277 
278 
279 
280 void
appendChildNode(XalanSourceTreeComment * theChild)281 XalanSourceTreeElement::appendChildNode(XalanSourceTreeComment*     theChild)
282 {
283     XalanSourceTreeHelper::appendSiblingToChild(this, m_firstChild, theChild);
284 }
285 
286 
287 
288 void
appendChildNode(XalanSourceTreeElement * theChild)289 XalanSourceTreeElement::appendChildNode(XalanSourceTreeElement*     theChild)
290 {
291     XalanSourceTreeHelper::appendSiblingToChild(this, m_firstChild, theChild);
292 }
293 
294 
295 
296 void
appendChildNode(XalanSourceTreeProcessingInstruction * theChild)297 XalanSourceTreeElement::appendChildNode(XalanSourceTreeProcessingInstruction*   theChild)
298 {
299     XalanSourceTreeHelper::appendSiblingToChild(this, m_firstChild, theChild);
300 }
301 
302 
303 
304 void
appendChildNode(XalanSourceTreeText * theChild)305 XalanSourceTreeElement::appendChildNode(XalanSourceTreeText*    theChild)
306 {
307     XalanSourceTreeHelper::appendSiblingToChild(this, m_firstChild, theChild);
308 }
309 
310 
311 
312 }
313