KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > NodeListImpl


1 /**
2  * org/ozone-db/xml/dom/NodeListImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * 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  */

25
26 package org.ozoneDB.xml.dom;
27
28 import org.w3c.dom.*;
29 import java.io.*;
30 import java.util.Vector JavaDoc;
31
32
33 /**
34  * Used to traverse childs of a node. {@link org.w3c.dom.NodeList} is a live
35  * list, meaning that any change to the node is reflected in this list and vice
36  * versa.
37  * <P>
38  * The functionality of NodeList is implemented in {@link NodeImpl} itself
39  * using a double-linked list. This class is only provided to hide the
40  * interface of {@link NodeImpl}.
41  * <P>
42  * This class is not entirely thread-safe due to thread-safe limitations on
43  * {@link NodeImpl} itself.
44  *
45  *
46  * @version $Revision: 1.1 $ $Date: 2003/11/02 17:26:14 $
47  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
48  * @see NodeImpl
49  */

50 public final class NodeListImpl implements NodeList, Serializable {
51     
52     final static long serialVersionUID = 1;
53     
54     
55     /**
56      * Return the nth child in the node (zero based). If the child does not exist,
57      * returns null. No exception is thrown if index is negative.
58      * @param index Index of child to return (zero based)
59      * @return Child or null
60      * @see NodeImpl#getChild
61      */

62     public Node item( int index ) {
63         return index >= 0 && index < _nodes.size() ? (Node)_nodes.elementAt( index ) : null;
64     }
65     
66     
67     /**
68      * Return the number of childs in this node.
69      * @return Number of childs
70      */

71     public int getLength() {
72         return _nodes.size();
73     }
74     
75     
76     /**
77      * Constructor requires node.
78      * @param node Node to traverse
79      */

80     public NodeListImpl( Node node ) {
81         if (node == null) {
82             throw new NullPointerException JavaDoc( "Argument 'node' is null." );
83         }
84         
85         _rootNode = node;
86         _nodes = new Vector JavaDoc();
87         
88         Node child = node.getFirstChild();
89         while (child != null) {
90             _nodes.addElement( child );
91             child = child.getNextSibling();
92         }
93     }
94     
95     /**
96      * The node which this list traverses.
97      */

98     protected Node _rootNode;
99     protected Vector JavaDoc _nodes;
100     
101 }
102
Popular Tags