001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.tax.dom;
043:
044: import org.w3c.dom.*;
045: import org.netbeans.tax.*;
046:
047: /**
048: *
049: * @author Petr Kuzel
050: */
051: class NamedNodeMapImpl implements NamedNodeMap {
052:
053: private final TreeNamedObjectMap peer;
054:
055: /** Creates a new instance of AttrImpl */
056: public NamedNodeMapImpl(TreeNamedObjectMap peer) {
057: this .peer = peer;
058: }
059:
060: /** The number of nodes in this map. The range of valid child node indices
061: * is <code>0</code> to <code>length-1</code> inclusive.
062: *
063: */
064: public int getLength() {
065: return peer.size();
066: }
067:
068: /** Retrieves a node specified by name.
069: * @param name The <code>nodeName</code> of a node to retrieve.
070: * @return A <code>Node</code> (of any type) with the specified
071: * <code>nodeName</code>, or <code>null</code> if it does not identify
072: * any node in this map.
073: *
074: */
075: public Node getNamedItem(String name) {
076: return Wrapper.wrap((TreeObject) peer.get(name));
077: }
078:
079: /** Retrieves a node specified by local name and namespace URI.
080: * <br>Documents which do not support the "XML" feature will permit only
081: * the DOM Level 1 calls for creating/setting elements and attributes.
082: * Hence, if you specify a non-null namespace URI, these DOMs will never
083: * find a matching node.
084: * @param namespaceURI The namespace URI of the node to retrieve.
085: * @param localName The local name of the node to retrieve.
086: * @return A <code>Node</code> (of any type) with the specified local
087: * name and namespace URI, or <code>null</code> if they do not
088: * identify any node in this map.
089: * @since DOM Level 2
090: *
091: */
092: public Node getNamedItemNS(String namespaceURI, String localName) {
093: throw new UOException();
094: }
095:
096: /** Returns the <code>index</code>th item in the map. If <code>index</code>
097: * is greater than or equal to the number of nodes in this map, this
098: * returns <code>null</code>.
099: * @param index Index into this map.
100: * @return The node at the <code>index</code>th position in the map, or
101: * <code>null</code> if that is not a valid index.
102: *
103: */
104: public Node item(int index) {
105: return Wrapper.wrap((TreeObject) peer.get(index));
106: }
107:
108: /** Removes a node specified by name. When this map contains the attributes
109: * attached to an element, if the removed attribute is known to have a
110: * default value, an attribute immediately appears containing the
111: * default value as well as the corresponding namespace URI, local name,
112: * and prefix when applicable.
113: * @param name The <code>nodeName</code> of the node to remove.
114: * @return The node removed from this map if a node with such a name
115: * exists.
116: * @exception DOMException
117: * NOT_FOUND_ERR: Raised if there is no node named <code>name</code> in
118: * this map.
119: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
120: *
121: */
122: public Node removeNamedItem(String name) throws DOMException {
123: throw new ROException();
124: }
125:
126: /** Removes a node specified by local name and namespace URI. A removed
127: * attribute may be known to have a default value when this map contains
128: * the attributes attached to an element, as returned by the attributes
129: * attribute of the <code>Node</code> interface. If so, an attribute
130: * immediately appears containing the default value as well as the
131: * corresponding namespace URI, local name, and prefix when applicable.
132: * <br>Documents which do not support the "XML" feature will permit only
133: * the DOM Level 1 calls for creating/setting elements and attributes.
134: * Hence, if you specify a non-null namespace URI, these DOMs will never
135: * find a matching node.
136: * @param namespaceURI The namespace URI of the node to remove.
137: * @param localName The local name of the node to remove.
138: * @return The node removed from this map if a node with such a local
139: * name and namespace URI exists.
140: * @exception DOMException
141: * NOT_FOUND_ERR: Raised if there is no node with the specified
142: * <code>namespaceURI</code> and <code>localName</code> in this map.
143: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
144: * @since DOM Level 2
145: *
146: */
147: public Node removeNamedItemNS(String namespaceURI, String localName)
148: throws DOMException {
149: throw new ROException();
150: }
151:
152: /** Adds a node using its <code>nodeName</code> attribute. If a node with
153: * that name is already present in this map, it is replaced by the new
154: * one.
155: * <br>As the <code>nodeName</code> attribute is used to derive the name
156: * which the node must be stored under, multiple nodes of certain types
157: * (those that have a "special" string value) cannot be stored as the
158: * names would clash. This is seen as preferable to allowing nodes to be
159: * aliased.
160: * @param arg A node to store in this map. The node will later be
161: * accessible using the value of its <code>nodeName</code> attribute.
162: * @return If the new <code>Node</code> replaces an existing node the
163: * replaced <code>Node</code> is returned, otherwise <code>null</code>
164: * is returned.
165: * @exception DOMException
166: * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
167: * different document than the one that created this map.
168: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
169: * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
170: * <code>Attr</code> that is already an attribute of another
171: * <code>Element</code> object. The DOM user must explicitly clone
172: * <code>Attr</code> nodes to re-use them in other elements.
173: * <br>HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node
174: * doesn't belong in this NamedNodeMap. Examples would include trying
175: * to insert something other than an Attr node into an Element's map
176: * of attributes, or a non-Entity node into the DocumentType's map of
177: * Entities.
178: *
179: */
180: public Node setNamedItem(Node arg) throws DOMException {
181: throw new ROException();
182: }
183:
184: /** Adds a node using its <code>namespaceURI</code> and
185: * <code>localName</code>. If a node with that namespace URI and that
186: * local name is already present in this map, it is replaced by the new
187: * one.
188: * @param arg A node to store in this map. The node will later be
189: * accessible using the value of its <code>namespaceURI</code> and
190: * <code>localName</code> attributes.
191: * @return If the new <code>Node</code> replaces an existing node the
192: * replaced <code>Node</code> is returned, otherwise <code>null</code>
193: * is returned.
194: * @exception DOMException
195: * WRONG_DOCUMENT_ERR: Raised if <code>arg</code> was created from a
196: * different document than the one that created this map.
197: * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
198: * <br>INUSE_ATTRIBUTE_ERR: Raised if <code>arg</code> is an
199: * <code>Attr</code> that is already an attribute of another
200: * <code>Element</code> object. The DOM user must explicitly clone
201: * <code>Attr</code> nodes to re-use them in other elements.
202: * <br>HIERARCHY_REQUEST_ERR: Raised if an attempt is made to add a node
203: * doesn't belong in this NamedNodeMap. Examples would include trying
204: * to insert something other than an Attr node into an Element's map
205: * of attributes, or a non-Entity node into the DocumentType's map of
206: * Entities.
207: * <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
208: * support the <code>"XML"</code> feature, since namespaces were
209: * defined by XML.
210: * @since DOM Level 2
211: *
212: */
213: public Node setNamedItemNS(Node arg) throws DOMException {
214: throw new ROException();
215: }
216:
217: }
|