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