2
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
4
* This software is open source.
5
* See the bottom of this file for the licence.
8
package org.dom4j.tree;
10
import java.io.IOException;
11
import java.io.Writer;
13
import org.dom4j.Attribute;
14
import org.dom4j.Element;
15
import org.dom4j.Namespace;
16
import org.dom4j.Node;
17
import org.dom4j.Visitor;
21
* <code>AbstractNamespace</code> is an abstract base class for tree
22
* implementors to use for implementation inheritence.
25
* @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
26
* @version $Revision: 1.21 $
28
public abstract class AbstractAttribute extends AbstractNode implements
30
public short getNodeType() {
31
return ATTRIBUTE_NODE;
34
public void setNamespace(Namespace namespace) {
35
String msg = "This Attribute is read only and cannot be changed";
36
throw new UnsupportedOperationException(msg);
39
public String getText() {
43
public void setText(String text) {
47
public void setValue(String value) {
48
String msg = "This Attribute is read only and cannot be changed";
49
throw new UnsupportedOperationException(msg);
52
public Object getData() {
56
public void setData(Object data) {
57
setValue((data == null) ? null : data.toString());
60
public String toString() {
61
return super.toString() + " [Attribute: name " + getQualifiedName()
62
+ " value \"" + getValue() + "\"]";
65
public String asXML() {
66
return getQualifiedName() + "=\"" + getValue() + "\"";
69
public void write(Writer writer) throws IOException {
70
writer.write(getQualifiedName());
72
writer.write(getValue());
76
public void accept(Visitor visitor) {
81
public Namespace getNamespace() {
82
return getQName().getNamespace();
85
public String getName() {
86
return getQName().getName();
89
public String getNamespacePrefix() {
90
return getQName().getNamespacePrefix();
93
public String getNamespaceURI() {
94
return getQName().getNamespaceURI();
97
public String getQualifiedName() {
98
return getQName().getQualifiedName();
101
public String getPath(Element context) {
102
StringBuffer result = new StringBuffer();
104
Element parent = getParent();
106
if ((parent != null) && (parent != context)) {
107
result.append(parent.getPath(context));
113
String uri = getNamespaceURI();
114
String prefix = getNamespacePrefix();
116
if ((uri == null) || (uri.length() == 0) || (prefix == null)
117
|| (prefix.length() == 0)) {
118
result.append(getName());
120
result.append(getQualifiedName());
123
return result.toString();
126
public String getUniquePath(Element context) {
127
StringBuffer result = new StringBuffer();
129
Element parent = getParent();
131
if ((parent != null) && (parent != context)) {
132
result.append(parent.getUniquePath(context));
138
String uri = getNamespaceURI();
139
String prefix = getNamespacePrefix();
141
if ((uri == null) || (uri.length() == 0) || (prefix == null)
142
|| (prefix.length() == 0)) {
143
result.append(getName());
145
result.append(getQualifiedName());
148
return result.toString();
151
protected Node createXPathResult(Element parent) {
152
return new DefaultAttribute(parent, getQName(), getValue());
157
* Redistribution and use of this software and associated documentation
158
* ("Software"), with or without modification, are permitted provided that the
159
* following conditions are met:
161
* 1. Redistributions of source code must retain copyright statements and
162
* notices. Redistributions must also contain a copy of this document.
164
* 2. Redistributions in binary form must reproduce the above copyright notice,
165
* this list of conditions and the following disclaimer in the documentation
166
* and/or other materials provided with the distribution.
168
* 3. The name "DOM4J" must not be used to endorse or promote products derived
169
* from this Software without prior written permission of MetaStuff, Ltd. For
170
* written permission, please contact dom4j-info@metastuff.com.
172
* 4. Products derived from this Software may not be called "DOM4J" nor may
173
* "DOM4J" appear in their names without prior written permission of MetaStuff,
174
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
176
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
178
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
179
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
182
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
183
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
184
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
185
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
186
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
187
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
188
* POSSIBILITY OF SUCH DAMAGE.
190
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.