1 /**********************************************
2 * Copyright (C) 2010 Lukas Laag
3 * This file is part of lib-gwt-svg.
4 *
5 * libgwtsvg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libgwtsvg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/
17 **********************************************/
18 /*
19 * Copyright (c) 2004 World Wide Web Consortium,
20 *
21 * (Massachusetts Institute of Technology, European Research Consortium for
22 * Informatics and Mathematics, Keio University). All Rights Reserved. This
23 * work is distributed under the W3C(r) Software License [1] in the hope that
24 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 *
27 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
28 */
29 package org.vectomatic.dom.svg.impl;
30
31 import org.w3c.dom.DOMException;
32
33 import com.google.gwt.core.client.JavaScriptException;
34 import com.google.gwt.core.client.JavaScriptObject;
35 import com.google.gwt.dom.client.Node;
36
37 /**
38 * Overlay class for DOM NamedNodeMap
39 * @author laaglu
40 */
41 public class NamedNodeMap<T extends Node> extends JavaScriptObject {
42 protected NamedNodeMap() {
43 }
44 /**
45 * Retrieves a node specified by name.
46 * @param name The <code>nodeName</code> of a node to retrieve.
47 * @return A <code>Node</code> (of any type) with the specified
48 * <code>nodeName</code>, or <code>null</code> if it does not identify
49 * any node in this map.
50 */
51 public final native T getNamedItem(String name) /*-{
52 return this.getNamedItem(name);
53 }-*/;
54
55 /**
56 * Adds a node using its <code>nodeName</code> attribute. If a node with
57 * that name is already present in this map, it is replaced by the new
58 * one. Replacing a node by itself has no effect.
59 * <br>As the <code>nodeName</code> attribute is used to derive the name
60 * which the node must be stored under, multiple nodes of certain types
61 * (those that have a "special" string value) cannot be stored as the
62 * names would clash. This is seen as preferable to allowing nodes to be
63 * aliased.
64 * @param arg A node to store in this map. The node will later be
65 * accessible using the value of its <code>nodeName</code> attribute.
66 * @return If the new <code>Node</code> replaces an existing node the
67 * replaced <code>Node</code> is returned, otherwise <code>null</code>
68 * is returned.
69 * @exception DOMException
70 * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
71 * different document than the one that created this map.
72 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
73 * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
74 * <code>Attr</code> that is already an attribute of another
75 * <code>Element</code> object. The DOM user must explicitly clone
76 * <code>Attr</code> nodes to re-use them in other elements.
77 * <br>HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node
78 * doesn't belong in this NamedNodeMap. Examples would include trying
79 * to insert something other than an Attr node into an Element's map
80 * of attributes, or a non-Entity node into the DocumentType's map of
81 * Entities.
82 */
83 public final native T setNamedItem(Node arg) throws JavaScriptException /*-{
84 return this.setNamedItem(arg);
85 }-*/;
86
87 /**
88 * Removes a node specified by name. When this map contains the attributes
89 * attached to an element, if the removed attribute is known to have a
90 * default value, an attribute immediately appears containing the
91 * default value as well as the corresponding namespace URI, local name,
92 * and prefix when applicable.
93 * @param name The <code>nodeName</code> of the node to remove.
94 * @return The node removed from this map if a node with such a name
95 * exists.
96 * @exception DOMException
97 * NOT_FOUND_ERR: Raised if there is no node named <code>name</code> in
98 * this map.
99 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
100 */
101 public final native T removeNamedItem(String name) throws JavaScriptException /*-{
102 return this.removeNamedItem(name);
103 }-*/;
104
105 /**
106 * Returns the <code>index</code>th item in the map. If <code>index</code>
107 * is greater than or equal to the number of nodes in this map, this
108 * returns <code>null</code>.
109 * @param index Index into this map.
110 * @return The node at the <code>index</code>th position in the map, or
111 * <code>null</code> if that is not a valid index.
112 */
113 public final native T item(int index) /*-{
114 return this.item(index);
115 }-*/;
116
117 /**
118 * The number of nodes in this map. The range of valid child node indices
119 * is <code>0</code> to <code>length-1</code> inclusive.
120 * @return The number of nodes in this map
121 */
122 public final native int getLength() /*-{
123 return this.length;
124 }-*/;
125
126 /**
127 * Retrieves a node specified by local name and namespace URI.
128 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
129 * , applications must use the value null as the namespaceURI parameter
130 * for methods if they wish to have no namespace.
131 * @param namespaceURI The namespace URI of the node to retrieve.
132 * @param localName The local name of the node to retrieve.
133 * @return A <code>Node</code> (of any type) with the specified local
134 * name and namespace URI, or <code>null</code> if they do not
135 * identify any node in this map.
136 * @exception DOMException
137 * NOT_SUPPORTED_ERR: May be raised if the implementation does not
138 * support the feature "XML" and the language exposed through the
139 * Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
140 */
141 public final native T getNamedItemNS(String namespaceURI, String localName) throws JavaScriptException /*-{
142 return this.getNamedItem(namespaceURI, localName);
143 }-*/;
144
145 /**
146 * Adds a node using its <code>namespaceURI</code> and
147 * <code>localName</code>. If a node with that namespace URI and that
148 * local name is already present in this map, it is replaced by the new
149 * one. Replacing a node by itself has no effect.
150 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
151 * , applications must use the value null as the namespaceURI parameter
152 * for methods if they wish to have no namespace.
153 * @param arg A node to store in this map. The node will later be
154 * accessible using the value of its <code>namespaceURI</code> and
155 * <code>localName</code> attributes.
156 * @return If the new <code>Node</code> replaces an existing node the
157 * replaced <code>Node</code> is returned, otherwise <code>null</code>
158 * is returned.
159 * @exception DOMException
160 * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
161 * different document than the one that created this map.
162 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
163 * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
164 * <code>Attr</code> that is already an attribute of another
165 * <code>Element</code> object. The DOM user must explicitly clone
166 * <code>Attr</code> nodes to re-use them in other elements.
167 * <br>HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node
168 * doesn't belong in this NamedNodeMap. Examples would include trying
169 * to insert something other than an Attr node into an Element's map
170 * of attributes, or a non-Entity node into the DocumentType's map of
171 * Entities.
172 * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
173 * support the feature "XML" and the language exposed through the
174 * Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
175 */
176 public final native T setNamedItemNS(Node arg) throws JavaScriptException /*-{
177 return this.setNamedItem(arg);
178 }-*/;
179
180 /**
181 * Removes a node specified by local name and namespace URI. A removed
182 * attribute may be known to have a default value when this map contains
183 * the attributes attached to an element, as returned by the attributes
184 * attribute of the <code>Node</code> interface. If so, an attribute
185 * immediately appears containing the default value as well as the
186 * corresponding namespace URI, local name, and prefix when applicable.
187 * <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
188 * , applications must use the value null as the namespaceURI parameter
189 * for methods if they wish to have no namespace.
190 * @param namespaceURI The namespace URI of the node to remove.
191 * @param localName The local name of the node to remove.
192 * @return The node removed from this map if a node with such a local
193 * name and namespace URI exists.
194 * @exception DOMException
195 * NOT_FOUND_ERR: Raised if there is no node with the specified
196 * <code>namespaceURI</code> and <code>localName</code> in this map.
197 * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
198 * <br>NOT_SUPPORTED_ERR: May be raised if the implementation does not
199 * support the feature "XML" and the language exposed through the
200 * Document does not support XML Namespaces (such as [<a href='http://www.w3.org/TR/1999/REC-html401-19991224/'>HTML 4.01</a>]).
201 */
202 public final native T removeNamedItemNS(String namespaceURI, String localName) throws JavaScriptException /*-{
203 return this.removeNamedItem(namespaceURI, localName);
204 }-*/;
205 }