KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > NamedNodeMapImpl


1 /*
2  * @(#)HashMapNode.java 1.36 02/03/21
3  *
4  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package org.enhydra.xml;
8
9 import java.util.Iterator JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.w3c.dom.DOMException JavaDoc;
13 import org.w3c.dom.NamedNodeMap JavaDoc;
14 import org.w3c.dom.Node JavaDoc;
15
16
17 /**
18  * A class representing a node in a meta-data tree, which implements
19  * the <a HREF="../../../../api/org/w3c/dom/NamedNodeMap.html">
20  *
21  * @version 1.0
22  */

23 class NamedNodeMapImpl implements NamedNodeMap JavaDoc {
24
25     /**
26      * List of <code>Node</code>s.
27      */

28     List JavaDoc nodes;
29
30
31     /**
32      * Constructs new <code>NamedNodeMapImpl</code> with the given list of nodes.
33      *
34      * @param nodes list of nodes.
35      */

36     public NamedNodeMapImpl(List JavaDoc nodes) {
37         this.nodes = nodes;
38     }
39
40     /**
41      * Returns the count of nodes.
42      *
43      * @return the count of nodes.
44      */

45     public int getLength() {
46         return nodes.size();
47     }
48
49
50     /**
51      * Returns the <code>Node</code> with the given name.
52      *
53      * @param name the node name.
54      *
55      * @return the <code>Node</code> with the given name.
56      */

57     public Node JavaDoc getNamedItem(String JavaDoc name) {
58         Iterator JavaDoc iter = nodes.iterator();
59         while (iter.hasNext()) {
60             Node JavaDoc node = (Node JavaDoc)iter.next();
61             if (name.equals(node.getNodeName())) {
62                 return node;
63             }
64         }
65
66         return null;
67     }
68
69     /**
70      * Returns the <code>Node</code> with the given index.
71      *
72      * @param index index of a node.
73      * @return the <code>Node</code> with the given index.
74      */

75     public Node JavaDoc item(int index) {
76         Node JavaDoc node = (Node JavaDoc) nodes.get(index);
77         return node;
78     }
79
80
81     /**
82      * Modification of the items is not allowed !
83      * Removes the item with the given name.
84      *
85      * @param name item name.
86      * @return the <code>Node</code> with the given name.
87      */

88     public Node JavaDoc removeNamedItem(java.lang.String JavaDoc name) {
89         throw new DOMException JavaDoc(DOMException.NO_MODIFICATION_ALLOWED_ERR, "This NamedNodeMap is read-only!");
90     }
91
92
93     /**
94      * Modification of the items is not allowed !
95      * Sets the item with the given name.
96      *
97      * @param arg <code>Node</code>.
98      * @return Sets the item with the given name.
99      */

100     public Node JavaDoc setNamedItem(Node JavaDoc arg) {
101         throw new DOMException JavaDoc(DOMException.NO_MODIFICATION_ALLOWED_ERR, "This NamedNodeMap is read-only!");
102     }
103
104
105     /**
106      * Equivalent to <code>getNamedItem(localName)</code>.
107      */

108     public Node JavaDoc getNamedItemNS(String JavaDoc namespaceURI, String JavaDoc localName) {
109         return getNamedItem(localName);
110     }
111
112
113     /**
114      * Equivalent to <code>setNamedItem(arg)</code>.
115      */

116     public Node JavaDoc setNamedItemNS(Node JavaDoc arg) {
117         return setNamedItem(arg);
118     }
119
120
121     /**
122      * Equivalent to <code>removeNamedItem(localName)</code>.
123      */

124     public Node JavaDoc removeNamedItemNS(String JavaDoc namespaceURI, String JavaDoc localName) {
125         return removeNamedItem(localName);
126     }
127     
128 }
129
Popular Tags