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