01: /*
02: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
03: *
04: * This file is part of Resin(R) Open Source
05: *
06: * Each copy or derived work must preserve the copyright notice and this
07: * notice unmodified.
08: *
09: * Resin Open Source is free software; you can redistribute it and/or modify
10: * it under the terms of the GNU General Public License as published by
11: * the Free Software Foundation; either version 2 of the License, or
12: * (at your option) any later version.
13: *
14: * Resin Open Source is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17: * of NON-INFRINGEMENT. See the GNU General Public License for more
18: * details.
19: *
20: * You should have received a copy of the GNU General Public License
21: * along with Resin Open Source; if not, write to the
22: * Free SoftwareFoundation, Inc.
23: * 59 Temple Place, Suite 330
24: * Boston, MA 02111-1307 USA
25: *
26: * @author Scott Ferguson
27: */
28:
29: package com.caucho.xml;
30:
31: import org.w3c.dom.DOMException;
32: import org.w3c.dom.NamedNodeMap;
33: import org.w3c.dom.Node;
34:
35: import java.util.HashMap;
36: import java.util.Iterator;
37:
38: class QNamedNodeMap<N> implements NamedNodeMap {
39: HashMap<String, Node> _map;
40: int _i;
41: Iterator<Node> _iter;
42:
43: QNamedNodeMap(HashMap<String, Node> map) {
44: _map = map;
45: }
46:
47: public Node getNamedItem(String name) {
48: return _map.get(name);
49: }
50:
51: public Node getNamedItemNS(String namespaceURI, String localName) {
52: return null;
53: }
54:
55: public Node setNamedItem(Node arg) throws DOMException {
56: return _map.put(arg.getNodeName(), arg);
57: }
58:
59: public Node setNamedItemNS(Node arg) {
60: return null;
61: }
62:
63: public Node removeNamedItem(String name) throws DOMException {
64: return _map.remove(name);
65: }
66:
67: public Node removeNamedItemNS(String namespaceURI, String localName) {
68: return null;
69: }
70:
71: public Node item(int index) {
72: Node value = null;
73:
74: synchronized (this ) {
75: if (_iter == null || index <= _i) {
76: _iter = _map.values().iterator();
77: _i = 0;
78: value = _iter.next();
79: }
80:
81: while (_i < index && _iter.hasNext()) {
82: value = _iter.next();
83: _i++;
84: }
85: }
86:
87: return value;
88: }
89:
90: public int getLength() {
91: return _map.size();
92: }
93:
94: public Iterator getNamedItemKeys() throws DOMException {
95: return _map.keySet().iterator();
96: }
97: }
|