01: /*
02: Copyright (C) 2003 Together
03:
04: This library is free software; you can redistribute it and/or
05: modify it under the terms of the GNU Lesser General Public
06: License as published by the Free Software Foundation; either
07: version 2.1 of the License, or (at your option) any later version.
08:
09: 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:
19: package org.enhydra.xml;
20:
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: import org.w3c.dom.Attr;
25: import org.w3c.dom.Document;
26: import org.w3c.dom.Node;
27: import org.w3c.dom.NodeList;
28:
29: /**
30: * @author Tweety
31: *
32: * A class representing a node in a meta-data tree, which implements
33: * the <a href="../../../../api/org/w3c/dom/NodeList.html">
34: *
35: * <p> Namespaces are ignored in this implementation. The terms "tag
36: * name" and "node name" are always considered to be synonymous.
37: *
38: * @version 1.0
39: */
40: public class NodeListImpl implements NodeList {
41:
42: /**
43: * List of <code>Node</code>s.
44: */
45: List nodes;
46:
47: /**
48: * Constructs an empty <code>NodeListImpl</code>.
49: */
50: public NodeListImpl() {
51: this .nodes = new ArrayList();
52: }
53:
54: /**
55: * Constructs <code>NodeListImpl</code> with the given list of nodes.
56: *
57: * @param nodes list of nodes.
58: */
59: public NodeListImpl(List nodes) {
60: this .nodes = nodes;
61: }
62:
63: /**
64: * Returns the count of nodes.
65: *
66: * @return the count of nodes.
67: */
68: public int getLength() {
69: return nodes.size();
70: }
71:
72: /**
73: * Returns the <code>Node</code> with the given index.
74: *
75: * @param index node index.
76: *
77: * @return the <code>Node</code> with the given index.
78: */
79: public Node item(int index) {
80: if (index < 0 || index > nodes.size()) {
81: return null;
82: }
83: return (Node) nodes.get(index);
84: }
85:
86: /**
87: * Appends the given list to the end of the existing one.
88: *
89: * @param list list to add, as <code>NodeListImpl</code>.
90: *
91: * @return this as </code>NodeList</code>.
92: */
93: public NodeList append(NodeListImpl list) {
94: this.nodes.addAll(list.nodes);
95: return this;
96: }
97:
98: }
|