001: /*
002: * @(#)HashMapNode.java 1.36 02/03/21
003: *
004: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
005: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
006: */
007: package org.enhydra.xml;
008:
009: import java.util.Iterator;
010: import java.util.List;
011:
012: import org.w3c.dom.DOMException;
013: import org.w3c.dom.NamedNodeMap;
014: import org.w3c.dom.Node;
015:
016: /**
017: * A class representing a node in a meta-data tree, which implements
018: * the <a href="../../../../api/org/w3c/dom/NamedNodeMap.html">
019: *
020: * @version 1.0
021: */
022: class NamedNodeMapImpl implements NamedNodeMap {
023:
024: /**
025: * List of <code>Node</code>s.
026: */
027: List nodes;
028:
029: /**
030: * Constructs new <code>NamedNodeMapImpl</code> with the given list of nodes.
031: *
032: * @param nodes list of nodes.
033: */
034: public NamedNodeMapImpl(List nodes) {
035: this .nodes = nodes;
036: }
037:
038: /**
039: * Returns the count of nodes.
040: *
041: * @return the count of nodes.
042: */
043: public int getLength() {
044: return nodes.size();
045: }
046:
047: /**
048: * Returns the <code>Node</code> with the given name.
049: *
050: * @param name the node name.
051: *
052: * @return the <code>Node</code> with the given name.
053: */
054: public Node getNamedItem(String name) {
055: Iterator iter = nodes.iterator();
056: while (iter.hasNext()) {
057: Node node = (Node) iter.next();
058: if (name.equals(node.getNodeName())) {
059: return node;
060: }
061: }
062:
063: return null;
064: }
065:
066: /**
067: * Returns the <code>Node</code> with the given index.
068: *
069: * @param index index of a node.
070: * @return the <code>Node</code> with the given index.
071: */
072: public Node item(int index) {
073: Node node = (Node) nodes.get(index);
074: return node;
075: }
076:
077: /**
078: * Modification of the items is not allowed !
079: * Removes the item with the given name.
080: *
081: * @param name item name.
082: * @return the <code>Node</code> with the given name.
083: */
084: public Node removeNamedItem(java.lang.String name) {
085: throw new DOMException(
086: DOMException.NO_MODIFICATION_ALLOWED_ERR,
087: "This NamedNodeMap is read-only!");
088: }
089:
090: /**
091: * Modification of the items is not allowed !
092: * Sets the item with the given name.
093: *
094: * @param arg <code>Node</code>.
095: * @return Sets the item with the given name.
096: */
097: public Node setNamedItem(Node arg) {
098: throw new DOMException(
099: DOMException.NO_MODIFICATION_ALLOWED_ERR,
100: "This NamedNodeMap is read-only!");
101: }
102:
103: /**
104: * Equivalent to <code>getNamedItem(localName)</code>.
105: */
106: public Node getNamedItemNS(String namespaceURI, String localName) {
107: return getNamedItem(localName);
108: }
109:
110: /**
111: * Equivalent to <code>setNamedItem(arg)</code>.
112: */
113: public Node setNamedItemNS(Node arg) {
114: return setNamedItem(arg);
115: }
116:
117: /**
118: * Equivalent to <code>removeNamedItem(localName)</code>.
119: */
120: public Node removeNamedItemNS(String namespaceURI, String localName) {
121: return removeNamedItem(localName);
122: }
123:
124: }
|