1 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 { 45 _map = map; 46 } 47 48 public Node getNamedItem(String name) 49 { 50 return _map.get(name); 51 } 52 53 public Node getNamedItemNS(String namespaceURI, String localName) 54 { 55 return null; 56 } 57 58 public Node setNamedItem(Node arg) throws DOMException 59 { 60 return _map.put(arg.getNodeName(), arg); 61 } 62 63 public Node setNamedItemNS(Node arg) 64 { 65 return null; 66 } 67 68 public Node removeNamedItem(String name) throws DOMException 69 { 70 return _map.remove(name); 71 } 72 73 public Node removeNamedItemNS(String namespaceURI, String localName) 74 { 75 return null; 76 } 77 78 public Node item(int index) 79 { 80 Node value = null; 81 82 synchronized (this) { 83 if (_iter == null || index <= _i) { 84 _iter = _map.values().iterator(); 85 _i = 0; 86 value = _iter.next(); 87 } 88 89 while (_i < index && _iter.hasNext()) { 90 value = _iter.next(); 91 _i++; 92 } 93 } 94 95 return value; 96 } 97 98 public int getLength() 99 { 100 return _map.size(); 101 } 102 103 public Iterator getNamedItemKeys() throws DOMException 104 { 105 return _map.keySet().iterator(); 106 } 107 } 108 | Popular Tags |