1
2
3
4
5
6
7
8
9
10 package org.dom4j.dom;
11
12 import org.w3c.dom.Attr;
13 import org.w3c.dom.DOMException;
14 import org.w3c.dom.Node;
15
16 /*** <p><code>DOMAttributeNodeMap</code> implements a W3C NameNodeMap
17 * for the attributes of an element.</p>
18 *
19 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
20 * @version $Revision: 1.6 $
21 */
22 public class DOMAttributeNodeMap implements org.w3c.dom.NamedNodeMap {
23
24 private DOMElement element;
25
26 public DOMAttributeNodeMap(DOMElement element) {
27 this.element = element;
28 }
29
30
31
32
33 public void foo() throws DOMException {
34 DOMNodeHelper.notSupported();
35 }
36
37 public Node getNamedItem(String name) {
38 return element.getAttributeNode(name);
39 }
40
41 public Node setNamedItem(Node arg) throws DOMException {
42 if ( arg instanceof Attr ) {
43 return element.setAttributeNode( (org.w3c.dom.Attr) arg );
44 }
45 else {
46 throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg );
47 }
48 }
49
50 public Node removeNamedItem(String name) throws DOMException {
51 org.w3c.dom.Attr attr = element.getAttributeNode(name);
52 if ( attr == null ) {
53 throw new DOMException(DOMException.NOT_FOUND_ERR,
54 "No attribute named " + name);
55 }
56 return element.removeAttributeNode( attr );
57 }
58
59 public Node item(int index) {
60 return DOMNodeHelper.asDOMAttr( element.attribute(index) );
61 }
62
63 public int getLength() {
64 return element.attributeCount();
65 }
66
67 public Node getNamedItemNS(String namespaceURI, String localName) {
68 return element.getAttributeNodeNS( namespaceURI, localName );
69 }
70
71 public Node setNamedItemNS(Node arg) throws DOMException {
72 if ( arg instanceof Attr ) {
73 return element.setAttributeNodeNS( (org.w3c.dom.Attr) arg );
74 }
75 else {
76 throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Node is not an Attr: " + arg );
77 }
78 }
79
80 public Node removeNamedItemNS(String namespaceURI, String localName) throws DOMException {
81 org.w3c.dom.Attr attr = element.getAttributeNodeNS( namespaceURI, localName );
82 if ( attr != null ) {
83 return element.removeAttributeNode( attr );
84 }
85 return attr;
86 }
87
88 }
89
90
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
130
131
132
133
134
135
136