Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

csv.util
Class BeanReader

java.lang.Object
  extended by csv.util.BeanReader
All Implemented Interfaces:
java.util.Iterator<java.lang.Object>

public class BeanReader
extends java.lang.Object
implements java.util.Iterator<java.lang.Object>

Reads beans from the underlying table stream.

Author:
ralph

Constructor Summary
  BeanReader(java.lang.Class<?> beanClass, TableReader reader)
          Constructor.
protected BeanReader(java.lang.Class<?> beanClass, TableReader reader, boolean evaluateHeaderRow, java.lang.String[] attributes)
          Internal Constructor.
  BeanReader(java.lang.Class<?> beanClass, TableReader reader, java.lang.String[] attributes)
          Constructor.
 
Method Summary
 void close()
          Closes the reader.
 java.lang.Object convertToBean(java.lang.Object[] columns)
          Constructs new bean from values in array.
protected  java.lang.String getAttributeName(int columnIndex)
          Returns the attribute name of specified column
 java.lang.String[] getAttributes()
          Returns the attributes that will be used for each column index.
protected  java.lang.reflect.Method getMethod(java.lang.String attribute)
          Returns the correct setter method object for the given attribute.
protected  java.lang.String getMethodName(java.lang.String attribute)
          This implementation returns the name of setter method for the given attribute
 boolean hasNext()
          Returns true when there are more beans to be returned.
 boolean isEvaluateHeaderRow()
          Returns true if attribute names will be evaluated from header row.
protected  boolean isValidSetterMethod(java.lang.reflect.Method method)
          Returns true if method conforms to JavaBean style of a Setter.
 java.lang.Object next()
          Returns the next bean from the table reader.
 void readHeaderRow()
          Reads the next row from stream and sets the attribute names.
 void remove()
          Method not supported.
 void reset()
          Resets the reader.
protected  void setAttributes(java.lang.String[] attributes)
          Sets the attribute names to be set for each column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanReader

public BeanReader(java.lang.Class<?> beanClass,
                  TableReader reader)
Constructor. Use this constructor when underlying reader will deliver the attribute names in first record.

Parameters:
beanClass - the beanClass
reader - the underlying reader to read bean properties from

BeanReader

public BeanReader(java.lang.Class<?> beanClass,
                  TableReader reader,
                  java.lang.String[] attributes)
Constructor. Use this constructor if underlying reader does NOT deliver attribute names.

Parameters:
beanClass - the beanClass
reader - the underlying reader to read bean properties from
attributes - list of attribute names that will be used to create the beans

BeanReader

protected BeanReader(java.lang.Class<?> beanClass,
                     TableReader reader,
                     boolean evaluateHeaderRow,
                     java.lang.String[] attributes)
Internal Constructor.

Parameters:
beanClass - the beanClass
reader - the underlying reader to read bean properties from
attributes - list of attribute names that will be used to create the beans
evaluateHeaderRow - whether header row will be delivered by reader
Method Detail

hasNext

public boolean hasNext()
Returns true when there are more beans to be returned.

Specified by:
hasNext in interface java.util.Iterator<java.lang.Object>
See Also:
Iterator.hasNext(), Iterator.hasNext()

next

public java.lang.Object next()
Returns the next bean from the table reader.

Specified by:
next in interface java.util.Iterator<java.lang.Object>
See Also:
Iterator.next(), Iterator.next(), convertToBean(Object[])

reset

public void reset()
Resets the reader.


close

public void close()
Closes the reader.


convertToBean

public java.lang.Object convertToBean(java.lang.Object[] columns)
Constructs new bean from values in array.

Parameters:
columns - attribute values
Returns:
new bean

remove

public void remove()
Method not supported.

Specified by:
remove in interface java.util.Iterator<java.lang.Object>
See Also:
Iterator.remove()

isEvaluateHeaderRow

public boolean isEvaluateHeaderRow()
Returns true if attribute names will be evaluated from header row.

Returns:
true if attribute names will be evaluated

getAttributes

public java.lang.String[] getAttributes()
Returns the attributes that will be used for each column index.

Returns:
the attributes array where attribute name stands at respective index.

setAttributes

protected void setAttributes(java.lang.String[] attributes)
Sets the attribute names to be set for each column.

Parameters:
attributes - attribute names to set

readHeaderRow

public void readHeaderRow()
Reads the next row from stream and sets the attribute names.


getAttributeName

protected java.lang.String getAttributeName(int columnIndex)
Returns the attribute name of specified column

Parameters:
columnIndex - index of column
Returns:
name or null if it was not set

getMethod

protected java.lang.reflect.Method getMethod(java.lang.String attribute)
Returns the correct setter method object for the given attribute. The method will be found by inspection of the JavaBean class.

Parameters:
attribute - attribute to be set
Returns:
setter method

isValidSetterMethod

protected boolean isValidSetterMethod(java.lang.reflect.Method method)
Returns true if method conforms to JavaBean style of a Setter.

Parameters:
method - method
Returns:
true if method is a setter.

getMethodName

protected java.lang.String getMethodName(java.lang.String attribute)
This implementation returns the name of setter method for the given attribute

Parameters:
attribute - attribute
Returns:
the name of the setter method for this attribute

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.

Copyright © 2008-2011 Ralph Schuster. All Rights Reserved.