KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom4j > o3impl > AbstractAttribute


1 /*
2  * Copyright 2001 (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  * $Id: AbstractAttribute.java,v 1.2 2003/06/10 16:18:35 per_nyfelt Exp $
8  */

9
10 package org.ozoneDB.xml.dom4j.o3impl;
11
12 import org.dom4j.*;
13
14 import java.io.IOException JavaDoc;
15 import java.io.Writer JavaDoc;
16
17 /** <p><code>AbstractNamespace</code> is an abstract base class for
18  * tree implementors to use for implementation inheritence.</p>
19  *
20  * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
21  * @version $Revision: 1.2 $
22  */

23 public abstract class AbstractAttribute extends AbstractNode implements Attribute {
24
25     public short getNodeType() {
26         return ATTRIBUTE_NODE;
27     }
28
29
30     public void setNamespace(Namespace namespace) {
31         throw new UnsupportedOperationException JavaDoc("This Attribute is read only and cannot be changed");
32     }
33
34     public String JavaDoc getText() {
35         return getValue();
36     }
37
38     public void setText(String JavaDoc text) {
39         setValue(text);
40     }
41
42     public void setValue(String JavaDoc value) {
43         throw new UnsupportedOperationException JavaDoc("This Attribute is read only and cannot be changed");
44     }
45
46     public Object JavaDoc getData() {
47         return getValue();
48     }
49
50     public void setData(Object JavaDoc data) {
51         setValue(data == null ? null : data.toString());
52     }
53
54     public String JavaDoc toString() {
55         return super.toString() + " [Attribute: name " + getQualifiedName()
56                 + " value \"" + getValue() + "\"]";
57     }
58
59     public String JavaDoc asXML() {
60         return getQualifiedName() + "=\"" + getValue() + "\"";
61     }
62
63     public void write(Writer JavaDoc writer) throws IOException JavaDoc {
64         writer.write(getQualifiedName());
65         writer.write("=\"");
66         writer.write(getValue());
67         writer.write("\"");
68     }
69
70     public void accept(Visitor visitor) {
71         visitor.visit(this);
72     }
73
74     // QName methods
75

76     public Namespace getNamespace() {
77         return getQName().getNamespace();
78     }
79
80     public String JavaDoc getName() {
81         return getQName().getName();
82     }
83
84     public String JavaDoc getNamespacePrefix() {
85         return getQName().getNamespacePrefix();
86     }
87
88     public String JavaDoc getNamespaceURI() {
89         return getQName().getNamespaceURI();
90     }
91
92     public String JavaDoc getQualifiedName() {
93         return getQName().getQualifiedName();
94     }
95
96     public String JavaDoc getPath(Element context) {
97         Element parent = getParent();
98         return (parent != null && parent != context)
99                 ? parent.getPath(context) + "/@" + getName()
100                 : "@" + getName();
101     }
102
103     public String JavaDoc getUniquePath(Element context) {
104         Element parent = getParent();
105         return (parent != null && parent != context)
106                 ? parent.getUniquePath(context) + "/@" + getName()
107                 : "@" + getName();
108     }
109
110     protected Node createXPathResult(Element parent) {
111         return new DefaultAttribute(parent, getQName(), getValue());
112     }
113 }
114
115
116 /*
117  * Redistribution and use of this software and associated documentation
118  * ("Software"), with or without modification, are permitted provided
119  * that the following conditions are met:
120  *
121  * 1. Redistributions of source code must retain copyright
122  * statements and notices. Redistributions must also contain a
123  * copy of this document.
124  *
125  * 2. Redistributions in binary form must reproduce the
126  * above copyright notice, this list of conditions and the
127  * following disclaimer in the documentation and/or other
128  * materials provided with the distribution.
129  *
130  * 3. The name "DOM4J" must not be used to endorse or promote
131  * products derived from this Software without prior written
132  * permission of MetaStuff, Ltd. For written permission,
133  * please contact dom4j-info@metastuff.com.
134  *
135  * 4. Products derived from this Software may not be called "DOM4J"
136  * nor may "DOM4J" appear in their names without prior written
137  * permission of MetaStuff, Ltd. DOM4J is a registered
138  * trademark of MetaStuff, Ltd.
139  *
140  * 5. Due credit should be given to the DOM4J Project
141  * (http://dom4j.org/).
142  *
143  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
144  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
145  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
146  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
147  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
148  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
149  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
150  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
151  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
152  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
153  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
154  * OF THE POSSIBILITY OF SUCH DAMAGE.
155  *
156  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
157  *
158  * $Id: AbstractAttribute.java,v 1.2 2003/06/10 16:18:35 per_nyfelt Exp $
159  */

160
Popular Tags