Clover coverage report - dom4j - 1.5
Coverage timestamp: vr sep 3 2004 20:47:03 GMT+01:00
file stats: LOC: 223   Methods: 17
NCLOC: 100   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XMLTableColumnDefinition.java 25% 24,4% 29,4% 25,7%
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: XMLTableColumnDefinition.java,v 1.8 2004/06/25 12:34:49 maartenc Exp $
 8    */
 9   
 10    package org.dom4j.swing;
 11   
 12    import java.io.Serializable;
 13   
 14    import org.dom4j.DocumentHelper;
 15    import org.dom4j.Node;
 16    import org.dom4j.XPath;
 17   
 18    /** <p><code>XMLTableColumnDefinition</code> a column
 19    * within a table definition.</p>
 20    *
 21    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 22    * @version $Revision: 1.8 $
 23    */
 24    public class XMLTableColumnDefinition implements Serializable {
 25   
 26    public static final int OBJECT_TYPE = 0;
 27    public static final int STRING_TYPE = 1;
 28    public static final int NUMBER_TYPE = 2;
 29    public static final int NODE_TYPE = 3;
 30   
 31    /** Holds value of property type. */
 32    private int type;
 33   
 34    /** Holds value of property name. */
 35    private String name;
 36   
 37    /** Holds value of property xpath. */
 38    private XPath xpath;
 39   
 40    /** Holds the XPath used for the column name */
 41    private XPath columnNameXPath;
 42   
 43  6 public static int parseType(String typeName) {
 44  6 if ( typeName != null && typeName.length() > 0 ) {
 45  6 if ( typeName.equals( "string" ) ) {
 46  6 return STRING_TYPE;
 47    }
 48  0 else if ( typeName.equals( "number" ) ) {
 49  0 return NUMBER_TYPE;
 50    }
 51  0 else if ( typeName.equals( "node" ) ) {
 52  0 return NODE_TYPE;
 53    }
 54    }
 55  0 return OBJECT_TYPE;
 56    }
 57   
 58  0 public XMLTableColumnDefinition() {
 59    }
 60   
 61  0 public XMLTableColumnDefinition(String name, String expression, int type) {
 62  0 this.name = name;
 63  0 this.type = type;
 64  0 this.xpath = createXPath(expression);
 65    }
 66   
 67  12 public XMLTableColumnDefinition(String name, XPath xpath, int type) {
 68  12 this.name = name;
 69  12 this.xpath = xpath;
 70  12 this.type = type;
 71    }
 72   
 73  0 public XMLTableColumnDefinition(XPath columnNameXPath, XPath xpath, int type) {
 74  0 this.xpath = xpath;
 75  0 this.columnNameXPath = columnNameXPath;
 76  0 this.type = type;
 77    }
 78   
 79   
 80  0 public Class getColumnClass() {
 81  0 switch (type) {
 82  0 case STRING_TYPE:
 83  0 return String.class;
 84  0 case NUMBER_TYPE:
 85  0 return Number.class;
 86  0 case NODE_TYPE:
 87  0 return Node.class;
 88  0 default:
 89  0 return Object.class;
 90    }
 91    }
 92   
 93  32 public Object getValue(Object row) {
 94  32 switch (type) {
 95  32 case STRING_TYPE:
 96  32 return xpath.valueOf( row );
 97  0 case NUMBER_TYPE:
 98  0 return xpath.numberValueOf( row );
 99  0 case NODE_TYPE:
 100  0 return xpath.selectSingleNode( row );
 101  0 default:
 102  0 return xpath.evaluate( row );
 103    }
 104    }
 105   
 106    // Properties
 107    //-------------------------------------------------------------------------
 108   
 109    /** Getter for property type.
 110    * @return Value of property type.
 111    */
 112  0 public int getType() {
 113  0 return type;
 114    }
 115   
 116    /** Setter for property type.
 117    * @param type New value of property type.
 118    */
 119  0 public void setType(int type) {
 120  0 this.type = type;
 121    }
 122   
 123    /** Getter for property name.
 124    * @return Value of property name.
 125    */
 126  24 public String getName() {
 127  24 return name;
 128    }
 129   
 130    /** Setter for property name.
 131    * @param name New value of property name.
 132    */
 133  0 public void setName(String name) {
 134  0 this.name = name;
 135    }
 136   
 137    /** Getter for property xpath.
 138    * @return Value of property xpath.
 139    */
 140  0 public XPath getXPath() {
 141  0 return xpath;
 142    }
 143   
 144    /** Setter for property xpath.
 145    * @param xpath New value of property xpath.
 146    */
 147  0 public void setXPath(XPath xpath) {
 148  0 this.xpath = xpath;
 149    }
 150   
 151    /**
 152    * @return the XPath used to create the column name
 153    */
 154  12 public XPath getColumnNameXPath() {
 155  12 return columnNameXPath;
 156    }
 157   
 158    /** Setter for property columnNameXPath.
 159    * @param columnNameXPath New value of property xpath.
 160    */
 161  0 public void setColumnNameXPath(XPath columnNameXPath) {
 162  0 this.columnNameXPath = columnNameXPath;
 163    }
 164   
 165    // Implementation methods
 166    //-------------------------------------------------------------------------
 167  0 protected XPath createXPath(String expression) {
 168  0 return DocumentHelper.createXPath(expression);
 169    }
 170   
 171  0 protected void handleException(Exception e) {
 172    // #### should use jakarta commons-logging
 173  0 System.out.println( "Caught: " + e );
 174    }
 175    }
 176   
 177   
 178   
 179   
 180    /*
 181    * Redistribution and use of this software and associated documentation
 182    * ("Software"), with or without modification, are permitted provided
 183    * that the following conditions are met:
 184    *
 185    * 1. Redistributions of source code must retain copyright
 186    * statements and notices. Redistributions must also contain a
 187    * copy of this document.
 188    *
 189    * 2. Redistributions in binary form must reproduce the
 190    * above copyright notice, this list of conditions and the
 191    * following disclaimer in the documentation and/or other
 192    * materials provided with the distribution.
 193    *
 194    * 3. The name "DOM4J" must not be used to endorse or promote
 195    * products derived from this Software without prior written
 196    * permission of MetaStuff, Ltd. For written permission,
 197    * please contact dom4j-info@metastuff.com.
 198    *
 199    * 4. Products derived from this Software may not be called "DOM4J"
 200    * nor may "DOM4J" appear in their names without prior written
 201    * permission of MetaStuff, Ltd. DOM4J is a registered
 202    * trademark of MetaStuff, Ltd.
 203    *
 204    * 5. Due credit should be given to the DOM4J Project -
 205    * http://www.dom4j.org
 206    *
 207    * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
 208    * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
 209    * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 210    * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 211    * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 212    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 213    * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 214    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 215    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 216    * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 217    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 218    * OF THE POSSIBILITY OF SUCH DAMAGE.
 219    *
 220    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
 221    *
 222    * $Id: XMLTableColumnDefinition.java,v 1.8 2004/06/25 12:34:49 maartenc Exp $
 223    */