1
2
3
4
5
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 public DOMAttributeNodeMap(DOMElement element) {
27 this.element = element;
28 }
29
30
31
32 public void foo() throws DOMException {
33 DOMNodeHelper.notSupported();
34 }
35
36 public Node getNamedItem(String name) {
37 return element.getAttributeNode(name);
38 }
39
40 public Node setNamedItem(Node arg) throws DOMException {
41 if (arg instanceof Attr) {
42 return element.setAttributeNode((org.w3c.dom.Attr) arg);
43 } else {
44 throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
45 "Node is not an Attr: " + arg);
46 }
47 }
48
49 public Node removeNamedItem(String name) throws DOMException {
50 org.w3c.dom.Attr attr = element.getAttributeNode(name);
51
52 if (attr == null) {
53 throw new DOMException(DOMException.NOT_FOUND_ERR,
54 "No attribute named " + name);
55 }
56
57 return element.removeAttributeNode(attr);
58 }
59
60 public Node item(int index) {
61 return DOMNodeHelper.asDOMAttr(element.attribute(index));
62 }
63
64 public int getLength() {
65 return element.attributeCount();
66 }
67
68 public Node getNamedItemNS(String namespaceURI, String localName) {
69 return element.getAttributeNodeNS(namespaceURI, localName);
70 }
71
72 public Node setNamedItemNS(Node arg) throws DOMException {
73 if (arg instanceof Attr) {
74 return element.setAttributeNodeNS((org.w3c.dom.Attr) arg);
75 } else {
76 throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
77 "Node is not an Attr: " + arg);
78 }
79 }
80
81 public Node removeNamedItemNS(String namespaceURI, String localName)
82 throws DOMException {
83 org.w3c.dom.Attr attr = element.getAttributeNodeNS(namespaceURI,
84 localName);
85
86 if (attr != null) {
87 return element.removeAttributeNode(attr);
88 }
89
90 return attr;
91 }
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129