001: /*
002: Copyright (C) 2003 Together
003:
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008:
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013:
014: You should have received a copy of the GNU Lesser General Public
015: License along with this library; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.enhydra.xml;
020:
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.w3c.dom.Document;
025: import org.w3c.dom.DOMException;
026: import org.w3c.dom.NamedNodeMap;
027: import org.w3c.dom.Node;
028:
029: /**
030: *
031: * @version 1.0
032: */
033: class NamedNodeMapImpl implements NamedNodeMap {
034:
035: /**
036: * List of <code>Node</code>s.
037: */
038: List nodes;
039:
040: /**
041: * Constructs new <code>NamedNodeMapImpl</code> with the given list of nodes.
042: * @param nodes list of nodes.
043: */
044: public NamedNodeMapImpl(List nodes) {
045: this .nodes = nodes;
046: }
047:
048: /**
049: * Returns the count of nodes.
050: *
051: * @return the count of nodes.
052: */
053: public int getLength() {
054: return nodes.size();
055: }
056:
057: /**
058: * Returns the <code>Node</code> with the given name.
059: *
060: * @param name the node name.
061: *
062: * @return the <code>Node</code> with the given name.
063: */
064: public Node getNamedItem(String name) {
065: Iterator iter = nodes.iterator();
066: while (iter.hasNext()) {
067: Node node = (Node) iter.next();
068: if (name.equals(node.getNodeName())) {
069: return node;
070: }
071: }
072:
073: return null;
074: }
075:
076: /**
077: * Returns the <code>Node</code> with the given index.
078: *
079: * @param index index of a node.
080: * @return the <code>Node</code> with the given index.
081: */
082: public Node item(int index) {
083: Node node = (Node) nodes.get(index);
084: return node;
085: }
086:
087: public Node removeNamedItem(java.lang.String name) {
088: throw new DOMException(
089: DOMException.NO_MODIFICATION_ALLOWED_ERR,
090: "This NamedNodeMap is read-only!");
091: }
092:
093: public Node setNamedItem(Node arg) {
094: throw new DOMException(
095: DOMException.NO_MODIFICATION_ALLOWED_ERR,
096: "This NamedNodeMap is read-only!");
097: }
098:
099: public Node getNamedItemNS(String namespaceURI, String localName) {
100: return getNamedItem(localName);
101: }
102:
103: /**
104: * Equivalent to <code>setNamedItem(arg)</code>.
105: * @param arg is node
106: * @return node
107: */
108: public Node setNamedItemNS(Node arg) {
109: return setNamedItem(arg);
110: }
111:
112: /**
113: * Equivalent to <code>removeNamedItem(localName)</code>.
114: * @param namespaceURI is name space
115: * @param localName is string
116: * @return node
117: */
118: public Node removeNamedItemNS(String namespaceURI, String localName) {
119: return removeNamedItem(localName);
120: }
121:
122: }
|