KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > spi > dom > NamedNodeMapImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.spi.dom;
21
22 import org.w3c.dom.*;
23 import java.util.*;
24
25 /**
26  * Read-only implementation of NamedNodeMap delegating to a Java <code>Map</code>.
27  * The underlaying map must use {@link #createKey} as its keys.
28  *
29  * @author Petr Kuzel
30  */

31 public final class NamedNodeMapImpl implements NamedNodeMap {
32
33     private final Map peer;
34
35     /** Read-only empty map. */
36     public static final NamedNodeMap EMPTY = new NamedNodeMapImpl(new HashMap(0));
37
38     /**
39      * Creates new NamedNodeMapImpl
40      * @param peer a map to delegate to. It must not be modified after this contructor call!
41      */

42     public NamedNodeMapImpl(Map peer) {
43         if (peer == null) throw new NullPointerException JavaDoc();
44         this.peer = peer;
45     }
46
47     public int getLength() {
48         return peer.size();
49     }
50     
51     public org.w3c.dom.Node JavaDoc removeNamedItem(String JavaDoc str) throws org.w3c.dom.DOMException JavaDoc {
52         throw new ROException();
53     }
54     
55     public org.w3c.dom.Node JavaDoc setNamedItemNS(org.w3c.dom.Node JavaDoc node) throws org.w3c.dom.DOMException JavaDoc {
56         throw new ROException();
57     }
58     
59     public org.w3c.dom.Node JavaDoc setNamedItem(org.w3c.dom.Node JavaDoc node) throws org.w3c.dom.DOMException JavaDoc {
60         throw new ROException();
61     }
62     
63     public org.w3c.dom.Node JavaDoc getNamedItemNS(String JavaDoc uri, String JavaDoc local) {
64         return (Node) peer.get(createKey(uri, local));
65     }
66     
67     public org.w3c.dom.Node JavaDoc item(int param) {
68         int i = 0;
69         Iterator it = peer.values().iterator();
70         while (it.hasNext()) {
71             Object JavaDoc next = it.next();
72             if (param == i) return (Node) next;
73             i++;
74         }
75         return null;
76     }
77     
78     public org.w3c.dom.Node JavaDoc getNamedItem(String JavaDoc str) {
79         return (Node) peer.get(createKey(str));
80     }
81     
82     public org.w3c.dom.Node JavaDoc removeNamedItemNS(String JavaDoc str, String JavaDoc str1) throws org.w3c.dom.DOMException JavaDoc {
83         throw new ROException();
84     }
85
86     public String JavaDoc toString() {
87         return peer.toString();
88     }
89
90     /**
91      * Create proper key for map entry
92      */

93     public static Object JavaDoc createKey(String JavaDoc qname) {
94         return qname;
95     }
96
97     /**
98      * Create proper key for map entry
99      */

100     public static Object JavaDoc createKey(String JavaDoc uri, String JavaDoc local) {
101         return uri + ":" + local; // NOI18N
102
}
103     
104 }
105
Popular Tags