1
2
3
4
5
6
7
8 package org.dom4j.dom;
9
10 import org.dom4j.Element;
11 import org.dom4j.QName;
12 import org.dom4j.tree.DefaultAttribute;
13
14 import org.w3c.dom.DOMException;
15 import org.w3c.dom.Document;
16 import org.w3c.dom.NamedNodeMap;
17 import org.w3c.dom.NodeList;
18
19 /***
20 * <p>
21 * <code>DOMAttribute</code> implements a doubly linked attribute which
22 * supports the W3C DOM API.
23 * </p>
24 *
25 * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
26 * @version $Revision: 1.14 $
27 */
28 public class DOMAttribute extends DefaultAttribute implements org.w3c.dom.Attr {
29 public DOMAttribute(QName qname) {
30 super(qname);
31 }
32
33 public DOMAttribute(QName qname, String value) {
34 super(qname, value);
35 }
36
37 public DOMAttribute(Element parent, QName qname, String value) {
38 super(parent, qname, value);
39 }
40
41
42
43 public boolean supports(String feature, String version) {
44 return DOMNodeHelper.supports(this, feature, version);
45 }
46
47 public String getNamespaceURI() {
48 return getQName().getNamespaceURI();
49 }
50
51 public String getPrefix() {
52 return getQName().getNamespacePrefix();
53 }
54
55 public void setPrefix(String prefix) throws DOMException {
56 DOMNodeHelper.setPrefix(this, prefix);
57 }
58
59 public String getLocalName() {
60 return getQName().getName();
61 }
62
63 public String getNodeName() {
64 return getName();
65 }
66
67
68
69
70 public String getNodeValue() throws DOMException {
71 return DOMNodeHelper.getNodeValue(this);
72 }
73
74 public void setNodeValue(String nodeValue) throws DOMException {
75 DOMNodeHelper.setNodeValue(this, nodeValue);
76 }
77
78 public org.w3c.dom.Node getParentNode() {
79
80
81
82 return null;
83 }
84
85 public NodeList getChildNodes() {
86 return DOMNodeHelper.getChildNodes(this);
87 }
88
89 public org.w3c.dom.Node getFirstChild() {
90 return DOMNodeHelper.getFirstChild(this);
91 }
92
93 public org.w3c.dom.Node getLastChild() {
94 return DOMNodeHelper.getLastChild(this);
95 }
96
97 public org.w3c.dom.Node getPreviousSibling() {
98 return DOMNodeHelper.getPreviousSibling(this);
99 }
100
101 public org.w3c.dom.Node getNextSibling() {
102 return DOMNodeHelper.getNextSibling(this);
103 }
104
105 public NamedNodeMap getAttributes() {
106 return null;
107 }
108
109 public Document getOwnerDocument() {
110 return DOMNodeHelper.getOwnerDocument(this);
111 }
112
113 public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
114 org.w3c.dom.Node refChild) throws DOMException {
115 checkNewChildNode(newChild);
116
117 return DOMNodeHelper.insertBefore(this, newChild, refChild);
118 }
119
120 public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
121 org.w3c.dom.Node oldChild) throws DOMException {
122 checkNewChildNode(newChild);
123
124 return DOMNodeHelper.replaceChild(this, newChild, oldChild);
125 }
126
127 public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild)
128 throws DOMException {
129 return DOMNodeHelper.removeChild(this, oldChild);
130 }
131
132 public org.w3c.dom.Node appendChild(org.w3c.dom.Node newChild)
133 throws DOMException {
134 checkNewChildNode(newChild);
135
136 return DOMNodeHelper.appendChild(this, newChild);
137 }
138
139 private void checkNewChildNode(org.w3c.dom.Node newChild)
140 throws DOMException {
141 final int nodeType = newChild.getNodeType();
142
143 if (!((nodeType == org.w3c.dom.Node.TEXT_NODE)
144 || (nodeType == org.w3c.dom.Node.ENTITY_REFERENCE_NODE))) {
145 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
146 "The node cannot be a child of attribute");
147 }
148 }
149
150 public boolean hasChildNodes() {
151 return DOMNodeHelper.hasChildNodes(this);
152 }
153
154 public org.w3c.dom.Node cloneNode(boolean deep) {
155 return DOMNodeHelper.cloneNode(this, deep);
156 }
157
158 public void normalize() {
159 DOMNodeHelper.normalize(this);
160 }
161
162 public boolean isSupported(String feature, String version) {
163 return DOMNodeHelper.isSupported(this, feature, version);
164 }
165
166 public boolean hasAttributes() {
167 return DOMNodeHelper.hasAttributes(this);
168 }
169
170
171
172
173 public boolean getSpecified() {
174 return true;
175 }
176
177
178
179 public org.w3c.dom.Element getOwnerElement() {
180 return DOMNodeHelper.asDOMElement(getParent());
181 }
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219