uk.ac.starlink.table
Class BeanStarTable

java.lang.Object
  |
  +--uk.ac.starlink.table.AbstractStarTable
        |
        +--uk.ac.starlink.table.RandomStarTable
              |
              +--uk.ac.starlink.table.BeanStarTable
All Implemented Interfaces:
StarTable

public class BeanStarTable
extends RandomStarTable

StarTable which displays beans. The table is constructed to display beans of a particular class, and each of its rows displays one instance of this class. It has a column for each readable property. As usual, a bean is anything which has likely-looking getter methods, though since this class uses the java.beans package any cleverer stuff held in BeanInfos will get used as well/instead.

Since:
23 Dec 2004

Constructor Summary
BeanStarTable(Class clazz)
          Constructs a new table which will hold beans which are all instances of a given class.
 
Method Summary
 Object getCell(long irow, int icol)
          The AbstractStarTable implementation of this method throws an UnsupportedOperationException, since unless otherwise provided there is no random access.
 int getColumnCount()
          Returns the number of columns in this table.
 ColumnInfo getColumnInfo(int icol)
          Returns the object describing the data in a given column.
 Object[] getData()
          Returns the array of objects which this model displays, one per row.
 Object getProperty(Object bean, int iprop)
          Returns the value of a given indexed property on a given bean.
 long getRowCount()
          The number of rows in this table.
 void setData(Object[] data)
          Populates this model with items.
 
Methods inherited from class uk.ac.starlink.table.RandomStarTable
getRowSequence, isRandom
 
Methods inherited from class uk.ac.starlink.table.AbstractStarTable
checkedLongToInt, getColumnAuxDataInfos, getName, getParameterByName, getParameters, getRow, getURL, setName, setParameter, setParameters, setURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanStarTable

public BeanStarTable(Class clazz)
              throws IntrospectionException
Constructs a new table which will hold beans which are all instances of a given class.

Parameters:
clazz - class of which all beans held by this table are members
Method Detail

setData

public void setData(Object[] data)
Populates this model with items.

Parameters:
data - array of items, one for each row. This array's runtime type must match that for which this model was constructed (on pain of ClassCastException)

getData

public Object[] getData()
Returns the array of objects which this model displays, one per row. The runtime type of the returned array matches that of the bean class this model displays.


getRowCount

public long getRowCount()
Description copied from class: RandomStarTable
The number of rows in this table. Implementations must supply a non-negative return value.

Specified by:
getRowCount in interface StarTable
Specified by:
getRowCount in class RandomStarTable
Returns:
the number of rows in the table

getColumnCount

public int getColumnCount()
Description copied from interface: StarTable
Returns the number of columns in this table.

Specified by:
getColumnCount in interface StarTable
Specified by:
getColumnCount in class AbstractStarTable
Returns:
the number of columns

getColumnInfo

public ColumnInfo getColumnInfo(int icol)
Description copied from interface: StarTable
Returns the object describing the data in a given column.

Specified by:
getColumnInfo in interface StarTable
Specified by:
getColumnInfo in class AbstractStarTable
Parameters:
icol - the column for which header information is required
Returns:
a ValueInfo object for column icol

getCell

public Object getCell(long irow,
                      int icol)
               throws IOException
Description copied from class: AbstractStarTable
The AbstractStarTable implementation of this method throws an UnsupportedOperationException, since unless otherwise provided there is no random access.

Specified by:
getCell in interface StarTable
Overrides:
getCell in class AbstractStarTable
Parameters:
irow - the index of the cell's row
icol - the index of the cell's column
Returns:
the contents of this cell
Throws:
IOException - if there is an error reading the data

getProperty

public Object getProperty(Object bean,
                          int iprop)
                   throws IOException
Returns the value of a given indexed property on a given bean. Any checked exceptions are rethrown as IOExceptions for convenience.

Parameters:
bean - the bean to interrogate
iprop - index of the property required
Returns:
value of the chosen property of bean
IOException

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.