Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00

file stats: | LOC: | 191 |  | Methods: | 19
| NCLOC: | 104 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

AbstractAttribute.java

60%

71,7%

57,9%

66,7%

1 |  | /*
2 |  | * Copyright 2001-2005 (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 |  |
8 |  | package org.dom4j.tree;
9 |  |
10 |  | import java.io.IOException;
11 |  | import java.io.Writer;
12 |  |
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;
18 |  |
19 |  | /**
20 |  | * <p>
21 |  | * <code>AbstractNamespace</code> is an abstract base class for tree
22 |  | * implementors to use for implementation inheritence.
23 |  | * </p>
24 |  | *
25 |  | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
26 |  | * @version $Revision: 1.21 $
27 |  | */
28 |  | public abstract class AbstractAttribute extends AbstractNode implements
29 |  | Attribute {
30 | 15 | public short getNodeType() {
31 | 15 | return ATTRIBUTE_NODE;
32 |  | }
33 |  |
34 | 0 | public void setNamespace(Namespace namespace) {
35 | 0 | String msg = "This Attribute is read only and cannot be changed";
36 | 0 | throw new UnsupportedOperationException(msg);
37 |  | }
38 |  |
39 | 305 | public String getText() {
40 | 305 | return getValue();
41 |  | }
42 |  |
43 | 0 | public void setText(String text) {
44 | 0 | setValue(text);
45 |  | }
46 |  |
47 | 0 | public void setValue(String value) {
48 | 0 | String msg = "This Attribute is read only and cannot be changed";
49 | 0 | throw new UnsupportedOperationException(msg);
50 |  | }
51 |  |
52 | 0 | public Object getData() {
53 | 0 | return getValue();
54 |  | }
55 |  |
56 | 0 | public void setData(Object data) {
57 | 0 | setValue((data == null) ? null : data.toString());
58 |  | }
59 |  |
60 | 52550 | public String toString() {
61 | 52550 | return super.toString() + " [Attribute: name " + getQualifiedName()
62 |  | + " value \"" + getValue() + "\"]";
63 |  | }
64 |  |
65 | 9 | public String asXML() {
66 | 9 | return getQualifiedName() + "=\"" + getValue() + "\"";
67 |  | }
68 |  |
69 | 0 | public void write(Writer writer) throws IOException {
70 | 0 | writer.write(getQualifiedName());
71 | 0 | writer.write("=\"");
72 | 0 | writer.write(getValue());
73 | 0 | writer.write("\"");
74 |  | }
75 |  |
76 | 0 | public void accept(Visitor visitor) {
77 | 0 | visitor.visit(this);
78 |  | }
79 |  |
80 |  | // QName methods
81 | 4320 | public Namespace getNamespace() {
82 | 4320 | return getQName().getNamespace();
83 |  | }
84 |  |
85 | 10975 | public String getName() {
86 | 10975 | return getQName().getName();
87 |  | }
88 |  |
89 | 15 | public String getNamespacePrefix() {
90 | 15 | return getQName().getNamespacePrefix();
91 |  | }
92 |  |
93 | 5153 | public String getNamespaceURI() {
94 | 5153 | return getQName().getNamespaceURI();
95 |  | }
96 |  |
97 | 61936 | public String getQualifiedName() {
98 | 61936 | return getQName().getQualifiedName();
99 |  | }
100 |  |
101 | 5 | public String getPath(Element context) {
102 | 5 | StringBuffer result = new StringBuffer();
103 |  |
104 | 5 | Element parent = getParent();
105 |  |
106 | 5 | if ((parent != null) && (parent != context)) {
107 | 5 | result.append(parent.getPath(context));
108 | 5 | result.append("/");
109 |  | }
110 |  |
111 | 5 | result.append("@");
112 |  |
113 | 5 | String uri = getNamespaceURI();
114 | 5 | String prefix = getNamespacePrefix();
115 |  |
116 | 5 | if ((uri == null) || (uri.length() == 0) || (prefix == null)
117 |  | || (prefix.length() == 0)) {
118 | 4 | result.append(getName());
119 |  | } else {
120 | 1 | result.append(getQualifiedName());
121 |  | }
122 |  |
123 | 5 | return result.toString();
124 |  | }
125 |  |
126 | 5 | public String getUniquePath(Element context) {
127 | 5 | StringBuffer result = new StringBuffer();
128 |  |
129 | 5 | Element parent = getParent();
130 |  |
131 | 5 | if ((parent != null) && (parent != context)) {
132 | 5 | result.append(parent.getUniquePath(context));
133 | 5 | result.append("/");
134 |  | }
135 |  |
136 | 5 | result.append("@");
137 |  |
138 | 5 | String uri = getNamespaceURI();
139 | 5 | String prefix = getNamespacePrefix();
140 |  |
141 | 5 | if ((uri == null) || (uri.length() == 0) || (prefix == null)
142 |  | || (prefix.length() == 0)) {
143 | 4 | result.append(getName());
144 |  | } else {
145 | 1 | result.append(getQualifiedName());
146 |  | }
147 |  |
148 | 5 | return result.toString();
149 |  | }
150 |  |
151 | 0 | protected Node createXPathResult(Element parent) {
152 | 0 | return new DefaultAttribute(parent, getQName(), getValue());
153 |  | }
154 |  | }
155 |  |
156 |  | /*
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:
160 |  | *
161 |  | * 1. Redistributions of source code must retain copyright statements and
162 |  | * notices. Redistributions must also contain a copy of this document.
163 |  | *
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.
167 |  | *
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.
171 |  | *
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.
175 |  | *
176 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
177 |  | *
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.
189 |  | *
190 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
191 |  | */