dom4j - 1.6.1

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

file stats: | LOC: | 271 |  | Methods: | 34
| NCLOC: | 161 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

AbstractNode.java

75%

70%

61,8%

67,9%

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.Serializable;
12 |  | import java.io.Writer;
13 |  | import java.util.List;
14 |  |
15 |  | import org.dom4j.Document;
16 |  | import org.dom4j.DocumentFactory;
17 |  | import org.dom4j.Element;
18 |  | import org.dom4j.Node;
19 |  | import org.dom4j.NodeFilter;
20 |  | import org.dom4j.XPath;
21 |  | import org.dom4j.rule.Pattern;
22 |  |
23 |  | /**
24 |  | * <p>
25 |  | * <code>AbstractNode</code> is an abstract base class for tree implementors
26 |  | * to use for implementation inheritence.
27 |  | * </p>
28 |  | *
29 |  | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
30 |  | * @version $Revision: 1.31 $
31 |  | */
32 |  | public abstract class AbstractNode implements Node, Cloneable, Serializable {
33 |  | protected static final String[] NODE_TYPE_NAMES = {"Node", "Element",
34 |  | "Attribute", "Text", "CDATA", "Entity", "Entity",
35 |  | "ProcessingInstruction", "Comment", "Document", "DocumentType",
36 |  | "DocumentFragment", "Notation", "Namespace", "Unknown" };
37 |  |
38 |  | /** The <code>DocumentFactory</code> instance used by default */
39 |  | private static final DocumentFactory DOCUMENT_FACTORY = DocumentFactory
40 |  | .getInstance();
41 |  |
42 | 250254 | public AbstractNode() {
43 |  | }
44 |  |
45 | 0 | public short getNodeType() {
46 | 0 | return UNKNOWN_NODE;
47 |  | }
48 |  |
49 | 130 | public String getNodeTypeName() {
50 | 130 | int type = getNodeType();
51 |  |
52 | 130 | if ((type < 0) || (type >= NODE_TYPE_NAMES.length)) {
53 | 0 | return "Unknown";
54 |  | }
55 |  |
56 | 130 | return NODE_TYPE_NAMES[type];
57 |  | }
58 |  |
59 | 94 | public Document getDocument() {
60 | 94 | Element element = getParent();
61 |  |
62 | 94 | return (element != null) ? element.getDocument() : null;
63 |  | }
64 |  |
65 | 12305 | public void setDocument(Document document) {
66 |  | }
67 |  |
68 | 12545 | public Element getParent() {
69 | 12545 | return null;
70 |  | }
71 |  |
72 | 6102 | public void setParent(Element parent) {
73 |  | }
74 |  |
75 | 107 | public boolean supportsParent() {
76 | 107 | return false;
77 |  | }
78 |  |
79 | 7 | public boolean isReadOnly() {
80 | 7 | return true;
81 |  | }
82 |  |
83 | 0 | public boolean hasContent() {
84 | 0 | return false;
85 |  | }
86 |  |
87 | 18 | public String getPath() {
88 | 18 | return getPath(null);
89 |  | }
90 |  |
91 | 20 | public String getUniquePath() {
92 | 20 | return getUniquePath(null);
93 |  | }
94 |  |
95 | 349 | public Object clone() {
96 | 349 | if (isReadOnly()) {
97 | 7 | return this;
98 |  | } else {
99 | 342 | try {
100 | 342 | Node answer = (Node) super.clone();
101 | 342 | answer.setParent(null);
102 | 342 | answer.setDocument(null);
103 |  |
104 | 342 | return answer;
105 |  | } catch (CloneNotSupportedException e) {
106 |  | // should never happen
107 | 0 | throw new RuntimeException("This should never happen. Caught: "
108 |  | + e);
109 |  | }
110 |  | }
111 |  | }
112 |  |
113 | 1517 | public Node detach() {
114 | 1517 | Element parent = getParent();
115 |  |
116 | 1517 | if (parent != null) {
117 | 1515 | parent.remove(this);
118 |  | } else {
119 | 2 | Document document = getDocument();
120 |  |
121 | 2 | if (document != null) {
122 | 2 | document.remove(this);
123 |  | }
124 |  | }
125 |  |
126 | 1517 | setParent(null);
127 | 1517 | setDocument(null);
128 |  |
129 | 1517 | return this;
130 |  | }
131 |  |
132 | 0 | public String getName() {
133 | 0 | return null;
134 |  | }
135 |  |
136 | 0 | public void setName(String name) {
137 | 0 | throw new UnsupportedOperationException("This node cannot be modified");
138 |  | }
139 |  |
140 | 0 | public String getText() {
141 | 0 | return null;
142 |  | }
143 |  |
144 | 1538 | public String getStringValue() {
145 | 1538 | return getText();
146 |  | }
147 |  |
148 | 0 | public void setText(String text) {
149 | 0 | throw new UnsupportedOperationException("This node cannot be modified");
150 |  | }
151 |  |
152 | 0 | public void write(Writer writer) throws IOException {
153 | 0 | writer.write(asXML());
154 |  | }
155 |  |
156 |  | // XPath methods
157 | 4 | public Object selectObject(String xpathExpression) {
158 | 4 | XPath xpath = createXPath(xpathExpression);
159 |  |
160 | 2 | return xpath.evaluate(this);
161 |  | }
162 |  |
163 | 227 | public List selectNodes(String xpathExpression) {
164 | 227 | XPath xpath = createXPath(xpathExpression);
165 |  |
166 | 227 | return xpath.selectNodes(this);
167 |  | }
168 |  |
169 | 1 | public List selectNodes(String xpathExpression,
170 |  | String comparisonXPathExpression) {
171 | 1 | return selectNodes(xpathExpression, comparisonXPathExpression, false);
172 |  | }
173 |  |
174 | 2 | public List selectNodes(String xpathExpression,
175 |  | String comparisonXPathExpression, boolean removeDuplicates) {
176 | 2 | XPath xpath = createXPath(xpathExpression);
177 | 2 | XPath sortBy = createXPath(comparisonXPathExpression);
178 |  |
179 | 2 | return xpath.selectNodes(this, sortBy, removeDuplicates);
180 |  | }
181 |  |
182 | 66 | public Node selectSingleNode(String xpathExpression) {
183 | 66 | XPath xpath = createXPath(xpathExpression);
184 |  |
185 | 66 | return xpath.selectSingleNode(this);
186 |  | }
187 |  |
188 | 81 | public String valueOf(String xpathExpression) {
189 | 81 | XPath xpath = createXPath(xpathExpression);
190 |  |
191 | 81 | return xpath.valueOf(this);
192 |  | }
193 |  |
194 | 0 | public Number numberValueOf(String xpathExpression) {
195 | 0 | XPath xpath = createXPath(xpathExpression);
196 |  |
197 | 0 | return xpath.numberValueOf(this);
198 |  | }
199 |  |
200 | 0 | public boolean matches(String patternText) {
201 | 0 | NodeFilter filter = createXPathFilter(patternText);
202 |  |
203 | 0 | return filter.matches(this);
204 |  | }
205 |  |
206 | 526 | public XPath createXPath(String xpathExpression) {
207 | 526 | return getDocumentFactory().createXPath(xpathExpression);
208 |  | }
209 |  |
210 | 0 | public NodeFilter createXPathFilter(String patternText) {
211 | 0 | return getDocumentFactory().createXPathFilter(patternText);
212 |  | }
213 |  |
214 | 0 | public Pattern createPattern(String patternText) {
215 | 0 | return getDocumentFactory().createPattern(patternText);
216 |  | }
217 |  |
218 | 107 | public Node asXPathResult(Element parent) {
219 | 107 | if (supportsParent()) {
220 | 0 | return this;
221 |  | }
222 |  |
223 | 107 | return createXPathResult(parent);
224 |  | }
225 |  |
226 | 0 | protected DocumentFactory getDocumentFactory() {
227 | 0 | return DOCUMENT_FACTORY;
228 |  | }
229 |  |
230 | 0 | protected Node createXPathResult(Element parent) {
231 | 0 | throw new RuntimeException("asXPathResult() not yet implemented fully "
232 |  | + "for: " + this);
233 |  | }
234 |  | }
235 |  |
236 |  | /*
237 |  | * Redistribution and use of this software and associated documentation
238 |  | * ("Software"), with or without modification, are permitted provided that the
239 |  | * following conditions are met:
240 |  | *
241 |  | * 1. Redistributions of source code must retain copyright statements and
242 |  | * notices. Redistributions must also contain a copy of this document.
243 |  | *
244 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
245 |  | * this list of conditions and the following disclaimer in the documentation
246 |  | * and/or other materials provided with the distribution.
247 |  | *
248 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
249 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
250 |  | * written permission, please contact dom4j-info@metastuff.com.
251 |  | *
252 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
253 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
254 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
255 |  | *
256 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
257 |  | *
258 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
259 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
260 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
262 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
263 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
264 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
265 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
266 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
267 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
268 |  | * POSSIBILITY OF SUCH DAMAGE.
269 |  | *
270 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
271 |  | */