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: | 189 |  | Methods: | 17
| NCLOC: | 93 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

BaseElement.java

10%

21,6%

23,5%

18,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.util.List;
11 |  |
12 |  | import org.dom4j.Branch;
13 |  | import org.dom4j.Document;
14 |  | import org.dom4j.Element;
15 |  | import org.dom4j.Namespace;
16 |  | import org.dom4j.QName;
17 |  |
18 |  | /**
19 |  | * <p>
20 |  | * <code>BaseElement</code> is a useful base class for implemementation
21 |  | * inheritence of an XML element.
22 |  | * </p>
23 |  | *
24 |  | * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
25 |  | * @version $Revision: 1.9 $
26 |  | */
27 |  | public class BaseElement extends AbstractElement {
28 |  | /** The <code>QName</code> for this element */
29 |  | private QName qname;
30 |  |
31 |  | /**
32 |  | * Stores the parent branch of this node which is either a Document if this
33 |  | * element is the root element in a document, or another Element if it is a
34 |  | * child of the root document, or null if it has not been added to a
35 |  | * document yet.
36 |  | */
37 |  | private Branch parentBranch;
38 |  |
39 |  | /** List of content nodes. */
40 |  | protected List content;
41 |  |
42 |  | /** list of attributes */
43 |  | protected List attributes;
44 |  |
45 | 1 | public BaseElement(String name) {
46 | 1 | this.qname = getDocumentFactory().createQName(name);
47 |  | }
48 |  |
49 | 0 | public BaseElement(QName qname) {
50 | 0 | this.qname = qname;
51 |  | }
52 |  |
53 | 0 | public BaseElement(String name, Namespace namespace) {
54 | 0 | this.qname = getDocumentFactory().createQName(name, namespace);
55 |  | }
56 |  |
57 | 0 | public Element getParent() {
58 | 0 | Element result = null;
59 |  |
60 | 0 | if (parentBranch instanceof Element) {
61 | 0 | result = (Element) parentBranch;
62 |  | }
63 |  |
64 | 0 | return result;
65 |  | }
66 |  |
67 | 0 | public void setParent(Element parent) {
68 | 0 | if (parentBranch instanceof Element || (parent != null)) {
69 | 0 | parentBranch = parent;
70 |  | }
71 |  | }
72 |  |
73 | 0 | public Document getDocument() {
74 | 0 | if (parentBranch instanceof Document) {
75 | 0 | return (Document) parentBranch;
76 | 0 | } else if (parentBranch instanceof Element) {
77 | 0 | Element parent = (Element) parentBranch;
78 |  |
79 | 0 | return parent.getDocument();
80 |  | }
81 |  |
82 | 0 | return null;
83 |  | }
84 |  |
85 | 0 | public void setDocument(Document document) {
86 | 0 | if (parentBranch instanceof Document || (document != null)) {
87 | 0 | parentBranch = document;
88 |  | }
89 |  | }
90 |  |
91 | 0 | public boolean supportsParent() {
92 | 0 | return true;
93 |  | }
94 |  |
95 | 3 | public QName getQName() {
96 | 3 | return qname;
97 |  | }
98 |  |
99 | 0 | public void setQName(QName name) {
100 | 0 | this.qname = name;
101 |  | }
102 |  |
103 | 0 | public void clearContent() {
104 | 0 | contentList().clear();
105 |  | }
106 |  |
107 | 0 | public void setContent(List content) {
108 | 0 | this.content = content;
109 |  |
110 | 0 | if (content instanceof ContentListFacade) {
111 | 0 | this.content = ((ContentListFacade) content).getBackingList();
112 |  | }
113 |  | }
114 |  |
115 | 0 | public void setAttributes(List attributes) {
116 | 0 | this.attributes = attributes;
117 |  |
118 | 0 | if (attributes instanceof ContentListFacade) {
119 | 0 | this.attributes = ((ContentListFacade) attributes).getBackingList();
120 |  | }
121 |  | }
122 |  |
123 |  | // Implementation methods
124 |  | // -------------------------------------------------------------------------
125 | 1 | protected List contentList() {
126 | 1 | if (content == null) {
127 | 1 | content = createContentList();
128 |  | }
129 |  |
130 | 1 | return content;
131 |  | }
132 |  |
133 | 1 | protected List attributeList() {
134 | 1 | if (attributes == null) {
135 | 1 | attributes = createAttributeList();
136 |  | }
137 |  |
138 | 1 | return attributes;
139 |  | }
140 |  |
141 | 0 | protected List attributeList(int size) {
142 | 0 | if (attributes == null) {
143 | 0 | attributes = createAttributeList(size);
144 |  | }
145 |  |
146 | 0 | return attributes;
147 |  | }
148 |  |
149 | 0 | protected void setAttributeList(List attributeList) {
150 | 0 | this.attributes = attributeList;
151 |  | }
152 |  | }
153 |  |
154 |  | /*
155 |  | * Redistribution and use of this software and associated documentation
156 |  | * ("Software"), with or without modification, are permitted provided that the
157 |  | * following conditions are met:
158 |  | *
159 |  | * 1. Redistributions of source code must retain copyright statements and
160 |  | * notices. Redistributions must also contain a copy of this document.
161 |  | *
162 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
163 |  | * this list of conditions and the following disclaimer in the documentation
164 |  | * and/or other materials provided with the distribution.
165 |  | *
166 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
167 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
168 |  | * written permission, please contact dom4j-info@metastuff.com.
169 |  | *
170 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
171 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
172 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
173 |  | *
174 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
175 |  | *
176 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
177 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
179 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
180 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
181 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
182 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
183 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
184 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
185 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
186 |  | * POSSIBILITY OF SUCH DAMAGE.
187 |  | *
188 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
189 |  | */