1 /*
2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.teamkonzept.dom4jb.dom;
19
20
21 public abstract class Node extends NodeList
22 implements org.w3c.dom.Node {
23
24 private int position;
25
26 protected final Document document;
27
28 public Node( final Document document ) {
29 this( document, null );
30 }
31
32 protected Node( final Document document, final Node parent ) {
33 super( parent );
34 this.document = document;
35 }
36
37 protected void attach( final int position, final Node parent ) {
38 this.position = position;
39 this.parent = parent;
40 }
41
42 public int getChildIndex() {
43 return this.position;
44 }
45
46 /***
47 * The <code>Document</code> object associated with this node. This is
48 * also the <code>Document</code> object used to create new nodes. When
49 * this node is a <code>Document</code> or a <code>DocumentType</code>
50 * which is not used with any <code>Document</code> yet, this is
51 * <code>null</code>.
52 */ /* @version DOM Level 2*/
53 public org.w3c.dom.Document getOwnerDocument() {
54
55 return document;
56 }
57
58 /***
59 * The node immediately following this node. If there is no such node,
60 * this returns <code>null</code>.
61 */
62 public org.w3c.dom.Node getNextSibling() {
63 return parent.item( position+1 );
64 }
65
66 /***
67 * The node immediately preceding this node. If there is no such node,
68 * this returns <code>null</code>.
69 */
70 public org.w3c.dom.Node getPreviousSibling() {
71 return parent.item( position-1 );
72 }
73
74 /***
75 * A <code>NodeList</code> that contains all children of this node. If
76 * there are no children, this is a <code>NodeList</code> containing no
77 * nodes.
78 */
79 public org.w3c.dom.NodeList getChildNodes() {
80 return this;
81 }
82
83 /***
84 * The first child of this node. If there is no such node, this returns
85 * <code>null</code>.
86 */
87 public org.w3c.dom.Node getFirstChild() {
88 return getChildNodes().item(0);
89 }
90
91 /***
92 * The last child of this node. If there is no such node, this returns
93 * <code>null</code>.
94 */
95 public org.w3c.dom.Node getLastChild() {
96 return getChildNodes().item( getChildNodes().getLength()-1 );
97 }
98
99 /***
100 * Returns whether this node has any children.
101 * @return <code>true</code> if this node has any children,
102 * <code>false</code> otherwise.
103 */
104 public boolean hasChildNodes() {
105 return getFirstChild() != null;
106 }
107
108 /***
109 * A <code>NamedNodeMap</code> containing the attributes of this node (if
110 * it is an <code>Element</code>) or <code>null</code> otherwise.
111 */
112 public org.w3c.dom.NamedNodeMap getAttributes() {
113 return null;
114 }
115
116 /***
117 * Returns whether this node (if it is an element) has any attributes.
118 * @return <code>true</code> if this node has any attributes,
119 * <code>false</code> otherwise.
120 * @since DOM Level 2
121 */
122 public boolean hasAttributes() {
123 return false;
124 }
125
126 /***
127 * The namespace URI of this node, or <code>null</code> if it is
128 * unspecified.
129 * <br>This is not a computed value that is the result of a namespace
130 * lookup based on an examination of the namespace declarations in
131 * scope. It is merely the namespace URI given at creation time.
132 * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
133 * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
134 * method, such as <code>createElement</code> from the
135 * <code>Document</code> interface, this is always <code>null</code>.Per
136 * the Namespaces in XML Specification an attribute does not inherit
137 * its namespace from the element it is attached to. If an attribute is
138 * not explicitly given a namespace, it simply has no namespace.
139 * @since DOM Level 2
140 */
141 public String getNamespaceURI() {
142 return null;
143 }
144
145 /***
146 * The namespace prefix of this node, or <code>null</code> if it is
147 * unspecified.
148 * <br>Note that setting this attribute, when permitted, changes the
149 * <code>nodeName</code> attribute, which holds the qualified name, as
150 * well as the <code>tagName</code> and <code>name</code> attributes of
151 * the <code>Element</code> and <code>Attr</code> interfaces, when
152 * applicable.
153 * <br>Note also that changing the prefix of an attribute that is known to
154 * have a default value, does not make a new attribute with the default
155 * value and the original prefix appear, since the
156 * <code>namespaceURI</code> and <code>localName</code> do not change.
157 * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
158 * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
159 * method, such as <code>createElement</code> from the
160 * <code>Document</code> interface, this is always <code>null</code>.
161 * @since DOM Level 2
162 */
163 public String getPrefix() {
164 return null;
165 }
166
167 public void setPrefix(final String prefix ) {
168 /* NOP */
169 }
170
171 /***
172 * Returns the local part of the qualified name of this node.
173 * <br>For nodes of any type other than <code>ELEMENT_NODE</code> and
174 * <code>ATTRIBUTE_NODE</code> and nodes created with a DOM Level 1
175 * method, such as <code>createElement</code> from the
176 * <code>Document</code> interface, this is always <code>null</code>.
177 * @since DOM Level 2
178 */
179 public String getLocalName() {
180 return null;
181 }
182
183 /***
184 * The value of this node, depending on its type; see the table above.
185 * When it is defined to be <code>null</code>, setting it has no effect.
186 */
187 public String getNodeValue() {
188 return null;
189 }
190
191 /***
192 * The value of this node, depending on its type; see the table above.
193 * When it is defined to be <code>null</code>, setting it has no effect.
194 */
195 public void setNodeValue(final String nodeValue) {
196 /* NOP */
197 }
198
199 /***
200 * Inserts the node <code>newChild</code> before the existing child node
201 * <code>refChild</code>. If <code>refChild</code> is <code>null</code>,
202 * insert <code>newChild</code> at the end of the list of children.
203 * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
204 * all of its children are inserted, in the same order, before
205 * <code>refChild</code>. If the <code>newChild</code> is already in the
206 * tree, it is first removed.
207 * @param newChild The node to insert.
208 * @param refChild The reference node, i.e., the node before which the
209 * new node must be inserted.
210 * @return The node being inserted.
211 */
212 public org.w3c.dom.Node insertBefore( final org.w3c.dom.Node newChild,
213 final org.w3c.dom.Node refChild ) {
214 throw new UnsupportedOperationException(
215 "Method insertBefore( Node, Node ) not yet implemented."
216 );
217 }
218
219 /***
220 * Returns a duplicate of this node, i.e., serves as a generic copy
221 * constructor for nodes. The duplicate node has no parent; (
222 * <code>parentNode</code> is <code>null</code>.).
223 * <br>Cloning an <code>Element</code> copies all attributes and their
224 * values, including those generated by the XML processor to represent
225 * defaulted attributes, but this method does not copy any text it
226 * contains unless it is a deep clone, since the text is contained in a
227 * child <code>Text</code> node. Cloning an <code>Attribute</code>
228 * directly, as opposed to be cloned as part of an <code>Element</code>
229 * cloning operation, returns a specified attribute (
230 * <code>specified</code> is <code>true</code>). Cloning any other type
231 * of node simply returns a copy of this node.
232 * <br>Note that cloning an immutable subtree results in a mutable copy,
233 * but the children of an <code>EntityReference</code> clone are readonly
234 * . In addition, clones of unspecified <code>Attr</code> nodes are
235 * specified. And, cloning <code>Document</code>,
236 * <code>DocumentType</code>, <code>Entity</code>, and
237 * <code>Notation</code> nodes is implementation dependent.
238 * @param deep If <code>true</code>, recursively clone the subtree under
239 * the specified node; if <code>false</code>, clone only the node
240 * itself (and its attributes, if it is an <code>Element</code>).
241 * @return The duplicate node.
242 */
243 public org.w3c.dom.Node cloneNode( final boolean deep ) {
244 throw new UnsupportedOperationException(
245 "Method cloneNode( boolean ) not yet implemented."
246 );
247 }
248
249 /***
250 * Replaces the child node <code>oldChild</code> with <code>newChild</code>
251 * in the list of children, and returns the <code>oldChild</code> node.
252 * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object,
253 * <code>oldChild</code> is replaced by all of the
254 * <code>DocumentFragment</code> children, which are inserted in the
255 * same order. If the <code>newChild</code> is already in the tree, it
256 * is first removed.
257 * @param newChild The new node to put in the child list.
258 * @param oldChild The node being replaced in the list.
259 * @return The node replaced.
260 */
261 public org.w3c.dom.Node replaceChild( final org.w3c.dom.Node newChild,
262 final org.w3c.dom.Node oldChild ) {
263 throw new UnsupportedOperationException(
264 "Method replaceChild( Node, Node ) not yet implemented."
265 );
266 }
267
268 /***
269 * Adds the node <code>newChild</code> to the end of the list of children
270 * of this node. If the <code>newChild</code> is already in the tree, it
271 * is first removed.
272 * @param newChild The node to add.If it is a
273 * <code>DocumentFragment</code> object, the entire contents of the
274 * document fragment are moved into the child list of this node
275 * @return The node added.
276 */
277 public org.w3c.dom.Node appendChild( final org.w3c.dom.Node newChild ) {
278 throw new UnsupportedOperationException(
279 "Method appendChild( Node ) not yet implemented."
280 );
281 }
282
283 /***
284 * Removes the child node indicated by <code>oldChild</code> from the list
285 * of children, and returns it.
286 * @param oldChild The node being removed.
287 * @return The node removed.
288 */
289 public org.w3c.dom.Node removeChild( final org.w3c.dom.Node oldChild ) {
290 throw new UnsupportedOperationException(
291 "Method removeChild( Node ) not yet implemented."
292 );
293 }
294
295 /***
296 * Tests whether the DOM implementation implements a specific feature and
297 * that feature is supported by this node.
298 * @param feature The name of the feature to test. This is the same name
299 * which can be passed to the method <code>hasFeature</code> on
300 * <code>DOMImplementation</code>.
301 * @param version This is the version number of the feature to test. In
302 * Level 2, version 1, this is the string "2.0". If the version is not
303 * specified, supporting any version of the feature will cause the
304 * method to return <code>true</code>.
305 * @return Returns <code>true</code> if the specified feature is
306 * supported on this node, <code>false</code> otherwise.
307 * @since DOM Level 2
308 */
309 public boolean isSupported( final String feature, final String version ) {
310 return DOMImplementation.IMPLEMENTATION.hasFeature( feature, version );
311 }
312
313 /***
314 * Puts all <code>Text</code> nodes in the full depth of the sub-tree
315 * underneath this <code>Node</code>, including attribute nodes, into a
316 * "normal" form where only structure (e.g., elements, comments,
317 * processing instructions, CDATA sections, and entity references)
318 * separates <code>Text</code> nodes, i.e., there are neither adjacent
319 * <code>Text</code> nodes nor empty <code>Text</code> nodes. This can
320 * be used to ensure that the DOM view of a document is the same as if
321 * it were saved and re-loaded, and is useful when operations (such as
322 * XPointer lookups) that depend on a particular document tree
323 * structure are to be used.In cases where the document contains
324 * <code>CDATASections</code>, the normalize operation alone may not be
325 * sufficient, since XPointers do not differentiate between
326 * <code>Text</code> nodes and <code>CDATASection</code> nodes.
327 */ /* @version DOM Level 2 */
328 public void normalize() {
329 /* NOP */
330 }
331
332 public abstract boolean accept(final Filter filter );
333 }
This page was automatically generated by Maven