|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DOMAttributeNodeMap.java | 0% | 10% | 20% | 10,5% |
|
1 | /* | |
2 | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. | |
3 | * | |
4 | * This software is open source. | |
5 | * See the bottom of this file for the licence. | |
6 | */ | |
7 | ||
8 | package org.dom4j.dom; | |
9 | ||
10 | import org.w3c.dom.Attr; | |
11 | import org.w3c.dom.DOMException; | |
12 | import org.w3c.dom.Node; | |
13 | ||
14 | /** | |
15 | * <p> | |
16 | * <code>DOMAttributeNodeMap</code> implements a W3C NameNodeMap for the | |
17 | * attributes of an element. | |
18 | * </p> | |
19 | * | |
20 | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a> | |
21 | * @version $Revision: 1.8 $ | |
22 | */ | |
23 | public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap { | |
24 | private DOMElement element; | |
25 | ||
26 | 35 | public DOMAttributeNodeMap(DOMElement element) { |
27 | 35 | this.element = element; |
28 | } | |
29 | ||
30 | // org.w3c.dom.NamedNodeMap interface | |
31 | // ------------------------------------------------------------------------- | |
32 | 0 | public void foo() throws DOMException { |
33 | 0 | DOMNodeHelper.notSupported(); |
34 | } | |
35 | ||
36 | 0 | public Node getNamedItem(String name) { |
37 | 0 | return element.getAttributeNode(name); |
38 | } | |
39 | ||
40 | 0 | public Node setNamedItem(Node arg) throws DOMException { |
41 | 0 | if (arg instanceof Attr) { |
42 | 0 | return element.setAttributeNode((org.w3c.dom.Attr) arg); |
43 | } else { | |
44 | 0 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, |
45 | "Node is not an Attr: " + arg); | |
46 | } | |
47 | } | |
48 | ||
49 | 0 | public Node removeNamedItem(String name) throws DOMException { |
50 | 0 | org.w3c.dom.Attr attr = element.getAttributeNode(name); |
51 | ||
52 | 0 | if (attr == null) { |
53 | 0 | throw new DOMException(DOMException.NOT_FOUND_ERR, |
54 | "No attribute named " + name); | |
55 | } | |
56 | ||
57 | 0 | return element.removeAttributeNode(attr); |
58 | } | |
59 | ||
60 | 0 | public Node item(int index) { |
61 | 0 | return DOMNodeHelper.asDOMAttr(element.attribute(index)); |
62 | } | |
63 | ||
64 | 35 | public int getLength() { |
65 | 35 | return element.attributeCount(); |
66 | } | |
67 | ||
68 | 0 | public Node getNamedItemNS(String namespaceURI, String localName) { |
69 | 0 | return element.getAttributeNodeNS(namespaceURI, localName); |
70 | } | |
71 | ||
72 | 0 | public Node setNamedItemNS(Node arg) throws DOMException { |
73 | 0 | if (arg instanceof Attr) { |
74 | 0 | return element.setAttributeNodeNS((org.w3c.dom.Attr) arg); |
75 | } else { | |
76 | 0 | throw new DOMException(DOMException.NOT_SUPPORTED_ERR, |
77 | "Node is not an Attr: " + arg); | |
78 | } | |
79 | } | |
80 | ||
81 | 0 | public Node removeNamedItemNS(String namespaceURI, String localName) |
82 | throws DOMException { | |
83 | 0 | org.w3c.dom.Attr attr = element.getAttributeNodeNS(namespaceURI, |
84 | localName); | |
85 | ||
86 | 0 | if (attr != null) { |
87 | 0 | return element.removeAttributeNode(attr); |
88 | } | |
89 | ||
90 | 0 | return attr; |
91 | } | |
92 | } | |
93 | ||
94 | /* | |
95 | * Redistribution and use of this software and associated documentation | |
96 | * ("Software"), with or without modification, are permitted provided that the | |
97 | * following conditions are met: | |
98 | * | |
99 | * 1. Redistributions of source code must retain copyright statements and | |
100 | * notices. Redistributions must also contain a copy of this document. | |
101 | * | |
102 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
103 | * this list of conditions and the following disclaimer in the documentation | |
104 | * and/or other materials provided with the distribution. | |
105 | * | |
106 | * 3. The name "DOM4J" must not be used to endorse or promote products derived | |
107 | * from this Software without prior written permission of MetaStuff, Ltd. For | |
108 | * written permission, please contact dom4j-info@metastuff.com. | |
109 | * | |
110 | * 4. Products derived from this Software may not be called "DOM4J" nor may | |
111 | * "DOM4J" appear in their names without prior written permission of MetaStuff, | |
112 | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd. | |
113 | * | |
114 | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org | |
115 | * | |
116 | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND | |
117 | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
118 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
119 | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE | |
120 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
121 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
122 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
123 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
124 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
125 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
126 | * POSSIBILITY OF SUCH DAMAGE. | |
127 | * | |
128 | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. | |
129 | */ |
|