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: | 185 |  | Methods: | 18
| NCLOC: | 92 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

BeanAttributeList.java

25%

35,7%

27,8%

31,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.bean;
9 |  |
10 |  | import java.util.AbstractList;
11 |  |
12 |  | import org.dom4j.Attribute;
13 |  | import org.dom4j.QName;
14 |  |
15 |  | /**
16 |  | * <p>
17 |  | * <code>BeanAttributeList</code> implements a list of Attributes which are
18 |  | * the properties of a JavaBean.
19 |  | * </p>
20 |  | *
21 |  | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
22 |  | * @version $Revision: 1.9 $
23 |  | */
24 |  | public class BeanAttributeList extends AbstractList {
25 |  | /** The BeanElement that this */
26 |  | private BeanElement parent;
27 |  |
28 |  | /** The BeanElement that this */
29 |  | private BeanMetaData beanMetaData;
30 |  |
31 |  | /** The attributes */
32 |  | private BeanAttribute[] attributes;
33 |  |
34 | 0 | public BeanAttributeList(BeanElement parent, BeanMetaData beanMetaData) {
35 | 0 | this.parent = parent;
36 | 0 | this.beanMetaData = beanMetaData;
37 | 0 | this.attributes = new BeanAttribute[beanMetaData.attributeCount()];
38 |  | }
39 |  |
40 | 2 | public BeanAttributeList(BeanElement parent) {
41 | 2 | this.parent = parent;
42 |  |
43 | 2 | Object data = parent.getData();
44 | 2 | Class beanClass = (data != null) ? data.getClass() : null;
45 | 2 | this.beanMetaData = BeanMetaData.get(beanClass);
46 | 2 | this.attributes = new BeanAttribute[beanMetaData.attributeCount()];
47 |  | }
48 |  |
49 | 2 | public Attribute attribute(String name) {
50 | 2 | int index = beanMetaData.getIndex(name);
51 |  |
52 | 2 | return attribute(index);
53 |  | }
54 |  |
55 | 0 | public Attribute attribute(QName qname) {
56 | 0 | int index = beanMetaData.getIndex(qname);
57 |  |
58 | 0 | return attribute(index);
59 |  | }
60 |  |
61 | 2 | public BeanAttribute attribute(int index) {
62 | 2 | if ((index >= 0) && (index <= attributes.length)) {
63 | 2 | BeanAttribute attribute = attributes[index];
64 |  |
65 | 2 | if (attribute == null) {
66 | 2 | attribute = createAttribute(parent, index);
67 | 2 | attributes[index] = attribute;
68 |  | }
69 |  |
70 | 2 | return attribute;
71 |  | }
72 |  |
73 | 0 | return null;
74 |  | }
75 |  |
76 | 0 | public BeanElement getParent() {
77 | 0 | return parent;
78 |  | }
79 |  |
80 | 0 | public QName getQName(int index) {
81 | 0 | return beanMetaData.getQName(index);
82 |  | }
83 |  |
84 | 0 | public Object getData(int index) {
85 | 0 | return beanMetaData.getData(index, parent.getData());
86 |  | }
87 |  |
88 | 2 | public void setData(int index, Object data) {
89 | 2 | beanMetaData.setData(index, parent.getData(), data);
90 |  | }
91 |  |
92 |  | // List interface
93 |  | // -------------------------------------------------------------------------
94 | 0 | public int size() {
95 | 0 | return attributes.length;
96 |  | }
97 |  |
98 | 0 | public Object get(int index) {
99 | 0 | BeanAttribute attribute = attributes[index];
100 |  |
101 | 0 | if (attribute == null) {
102 | 0 | attribute = createAttribute(parent, index);
103 | 0 | attributes[index] = attribute;
104 |  | }
105 |  |
106 | 0 | return attribute;
107 |  | }
108 |  |
109 | 0 | public boolean add(Object object) {
110 | 0 | throw new UnsupportedOperationException("add(Object) unsupported");
111 |  | }
112 |  |
113 | 0 | public void add(int index, Object object) {
114 | 0 | throw new UnsupportedOperationException("add(int,Object) unsupported");
115 |  | }
116 |  |
117 | 0 | public Object set(int index, Object object) {
118 | 0 | throw new UnsupportedOperationException("set(int,Object) unsupported");
119 |  | }
120 |  |
121 | 0 | public boolean remove(Object object) {
122 | 0 | return false;
123 |  | }
124 |  |
125 | 0 | public Object remove(int index) {
126 | 0 | BeanAttribute attribute = (BeanAttribute) get(index);
127 | 0 | Object oldValue = attribute.getValue();
128 | 0 | attribute.setValue(null);
129 |  |
130 | 0 | return oldValue;
131 |  | }
132 |  |
133 | 0 | public void clear() {
134 | 0 | for (int i = 0, size = attributes.length; i < size; i++) {
135 | 0 | BeanAttribute attribute = attributes[i];
136 |  |
137 | 0 | if (attribute != null) {
138 | 0 | attribute.setValue(null);
139 |  | }
140 |  | }
141 |  | }
142 |  |
143 |  | // Implementation methods
144 |  | // -------------------------------------------------------------------------
145 | 2 | protected BeanAttribute createAttribute(BeanElement element, int index) {
146 | 2 | return new BeanAttribute(this, index);
147 |  | }
148 |  | }
149 |  |
150 |  | /*
151 |  | * Redistribution and use of this software and associated documentation
152 |  | * ("Software"), with or without modification, are permitted provided that the
153 |  | * following conditions are met:
154 |  | *
155 |  | * 1. Redistributions of source code must retain copyright statements and
156 |  | * notices. Redistributions must also contain a copy of this document.
157 |  | *
158 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
159 |  | * this list of conditions and the following disclaimer in the documentation
160 |  | * and/or other materials provided with the distribution.
161 |  | *
162 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
163 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
164 |  | * written permission, please contact dom4j-info@metastuff.com.
165 |  | *
166 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
167 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
168 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
169 |  | *
170 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
171 |  | *
172 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
173 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
175 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
176 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
177 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
178 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
179 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
180 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
181 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
182 |  | * POSSIBILITY OF SUCH DAMAGE.
183 |  | *
184 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
185 |  | */