01: /**
02: * org/ozone-db/xml/dom/NodeListImpl.java
03: *
04: * The contents of this file are subject to the OpenXML Public
05: * License Version 1.0; you may not use this file except in compliance
06: * with the License. You may obtain a copy of the License at
07: * http://www.openxml.org/license.html
08: *
09: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15: *
16: * The Initial Developer of this code under the License is Assaf Arkin.
17: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18: * All Rights Reserved.
19: */
20:
21: /**
22: * Changes for Persistent DOM running with ozone are
23: * Copyright 1999 by SMB GmbH. All rights reserved.
24: */package org.ozoneDB.xml.dom;
25:
26: import org.w3c.dom.*;
27: import java.io.*;
28: import java.util.Vector;
29:
30: /**
31: * Used to traverse childs of a node. {@link org.w3c.dom.NodeList} is a live
32: * list, meaning that any change to the node is reflected in this list and vice
33: * versa.
34: * <P>
35: * The functionality of NodeList is implemented in {@link NodeImpl} itself
36: * using a double-linked list. This class is only provided to hide the
37: * interface of {@link NodeImpl}.
38: * <P>
39: * This class is not entirely thread-safe due to thread-safe limitations on
40: * {@link NodeImpl} itself.
41: *
42: *
43: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
44: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
45: * @see NodeImpl
46: */
47: public final class NodeListImpl implements NodeList, Serializable {
48:
49: final static long serialVersionUID = 1;
50:
51: /**
52: * Return the nth child in the node (zero based). If the child does not exist,
53: * returns null. No exception is thrown if index is negative.
54: * @param index Index of child to return (zero based)
55: * @return Child or null
56: * @see NodeImpl#getChild
57: */
58: public Node item(int index) {
59: return index >= 0 && index < _nodes.size() ? (Node) _nodes
60: .elementAt(index) : null;
61: }
62:
63: /**
64: * Return the number of childs in this node.
65: * @return Number of childs
66: */
67: public int getLength() {
68: return _nodes.size();
69: }
70:
71: /**
72: * Constructor requires node.
73: * @param node Node to traverse
74: */
75: public NodeListImpl(Node node) {
76: if (node == null) {
77: throw new NullPointerException("Argument 'node' is null.");
78: }
79:
80: _rootNode = node;
81: _nodes = new Vector();
82:
83: Node child = node.getFirstChild();
84: while (child != null) {
85: _nodes.addElement(child);
86: child = child.getNextSibling();
87: }
88: }
89:
90: /**
91: * The node which this list traverses.
92: */
93: protected Node _rootNode;
94: protected Vector _nodes;
95:
96: }
|