KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml2 > QNamedNodeMap


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * 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.xml2;
30
31 import org.w3c.dom.DOMException JavaDoc;
32 import org.w3c.dom.NamedNodeMap JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34
35 import java.util.HashMap JavaDoc;
36 import java.util.Iterator JavaDoc;
37
38 class QNamedNodeMap<N> implements NamedNodeMap JavaDoc {
39   HashMap JavaDoc<String JavaDoc,Node JavaDoc> _map;
40   int _i;
41   Iterator JavaDoc<Node JavaDoc> _iter;
42
43   QNamedNodeMap(HashMap JavaDoc<String JavaDoc,Node JavaDoc> map)
44   {
45     _map = map;
46   }
47   
48   public Node JavaDoc getNamedItem(String JavaDoc name)
49   {
50     return _map.get(name);
51   }
52   
53   public Node JavaDoc getNamedItemNS(String JavaDoc namespaceURI, String JavaDoc localName)
54   {
55     return null;
56   }
57
58   public Node JavaDoc setNamedItem(Node JavaDoc arg) throws DOMException JavaDoc
59   {
60     return _map.put(arg.getNodeName(), arg);
61   }
62   
63   public Node JavaDoc setNamedItemNS(Node JavaDoc arg)
64   {
65     return null;
66   }
67
68   public Node JavaDoc removeNamedItem(String JavaDoc name) throws DOMException JavaDoc
69   {
70     return _map.remove(name);
71   }
72   
73   public Node JavaDoc removeNamedItemNS(String JavaDoc namespaceURI, String JavaDoc localName)
74   {
75     return null;
76   }
77
78   public Node JavaDoc item(int index)
79   {
80     Node JavaDoc 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 JavaDoc getNamedItemKeys() throws DOMException JavaDoc
104   {
105     return _map.keySet().iterator();
106   }
107 }
108
Popular Tags