001 /** 002 * www.jcoverage.com 003 * Copyright (C)2003 jcoverage ltd. 004 * 005 * This file is part of jcoverage. 006 * 007 * jcoverage is free software; you can redistribute it and/or modify 008 * it under the terms of the GNU General Public License as published 009 * by the Free Software Foundation; either version 2 of the License, 010 * or (at your option) any later version. 011 * 012 * jcoverage is distributed in the hope that it will be useful, but 013 * WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * General Public License for more details. 016 * 017 * You should have received a copy of the GNU General Public License 018 * along with jcoverage; if not, write to the Free Software 019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 020 * USA 021 * 022 */ 023 package com.jcoverage.reporting; 024 025 import org.apache.log4j.Logger; 026 027 /** 028 * Instances of this class represent an information type. 029 * Like a database column, it has a name and a type. 030 * <p> 031 * A field's value can be defined to be any Java object, an int, double or boolean. 032 */ 033 public class Column { 034 035 static Logger logger=Logger.getLogger(Column.class); 036 037 String label,classid,description; 038 Class type; 039 040 public Column(String label,Class type) { 041 this(label,"",type); 042 } 043 044 public Column(String label,String description,Class type) { 045 if (Object.class.isAssignableFrom(type) || type.equals(Integer.TYPE) || type.equals(Boolean.TYPE) || type.equals(Double.TYPE)) { 046 this.label=label; 047 this.description=description; 048 this.type=type; 049 } else { 050 throw new IllegalArgumentException("Attribute type cannot be "+type); 051 } 052 } 053 054 public boolean isAcceptableValue(Object value) { 055 if (type.equals(Integer.TYPE) && value.getClass().equals(Integer.class)) { 056 return true; 057 } 058 if (type.equals(Double.TYPE) && value.getClass().equals(Double.class)) { 059 return true; 060 } 061 if (type.equals(Boolean.TYPE) && value.getClass().equals(Boolean.class)) { 062 return true; 063 } 064 return this.type.isAssignableFrom(value.getClass()); 065 } 066 067 public Object getType() { 068 return type; 069 } 070 071 public String getLabel() { 072 return label; 073 } 074 075 public String getDescription() { 076 return description; 077 } 078 079 public String toString() { 080 return "[" + getLabel() + "]"; 081 } 082 083 }