T - Type of bean to be readpublic class BeanReader<T> extends Object implements Iterator<T>
Please notice that you need to explicitely pass the bean class to the constructor when you create a parameterized BeanReader inline:
// Error: Invalid usage BeanReader<TestBean> beanReader = new BeanReader<TestBean>(tableReader); // Correct usage BeanReader<TestBean> beanReader = new BeanReader<TestBean>(TestBean.class, tableReader);
You can omit the class argument in constructors when your BeanReader was explicitely defined as a class:
public class MyBeanReader extends BeanReader<TestBean> {
...
}
// Ok here
BeanReader<TestBean> = new MyBeanReader(tableReader);
The reason for this is the lack of class parameter inspection for in-line parameters at runtime.
| Modifier | Constructor and Description |
|---|---|
|
BeanReader(Class<T> beanClass,
TableReader reader)
Constructor.
|
protected |
BeanReader(Class<T> beanClass,
TableReader reader,
boolean evaluateHeaderRow,
String[] attributes)
Internal Constructor.
|
|
BeanReader(Class<T> beanClass,
TableReader reader,
String[] attributes)
Constructor.
|
|
BeanReader(TableReader reader)
Constructor.
|
|
BeanReader(TableReader reader,
String[] attributes)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the reader.
|
T |
convertToBean(Object[] columns)
Constructs new bean from values in array.
|
protected String |
getAttributeName(int columnIndex)
Returns the attribute name of specified column
|
String[] |
getAttributes()
Returns the attributes that will be used for each column index.
|
protected Method |
getMethod(String attribute)
Returns the correct setter method object for the given attribute.
|
protected String |
getMethodName(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(Method method)
Returns true if method conforms to JavaBean style of a Setter.
|
T |
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(String[] attributes)
Sets the attribute names to be set for each column.
|
public BeanReader(Class<T> beanClass, TableReader reader)
beanClass - class of bean - reflection does not guarantee to find out the correct class.reader - the underlying reader to read bean properties frompublic BeanReader(TableReader reader)
reader - the underlying reader to read bean properties frompublic BeanReader(TableReader reader, String[] attributes)
reader - the underlying reader to read bean properties fromattributes - list of attribute names that will be used to create the beanspublic BeanReader(Class<T> beanClass, TableReader reader, String[] attributes)
beanClass - class of bean - reflection does not guarantee to find out the correct class.reader - the underlying reader to read bean properties fromattributes - list of attribute names that will be used to create the beansprotected BeanReader(Class<T> beanClass, TableReader reader, boolean evaluateHeaderRow, String[] attributes)
beanClass - class of bean - reflection does not guarantee to find out the correct class.reader - the underlying reader to read bean properties fromattributes - list of attribute names that will be used to create the beansevaluateHeaderRow - whether header row will be delivered by readerpublic boolean hasNext()
hasNext in interface Iterator<T>Iterator.hasNext(),
Iterator.hasNext()public T next()
next in interface Iterator<T>Iterator.next(),
Iterator.next(),
convertToBean(Object[])public void reset()
public void close()
public T convertToBean(Object[] columns)
columns - attribute valuespublic void remove()
remove in interface Iterator<T>Iterator.remove()public boolean isEvaluateHeaderRow()
public String[] getAttributes()
protected void setAttributes(String[] attributes)
attributes - attribute names to setpublic void readHeaderRow()
protected String getAttributeName(int columnIndex)
columnIndex - index of columnprotected Method getMethod(String attribute)
attribute - attribute to be setprotected boolean isValidSetterMethod(Method method)
method - methodCopyright © 2014. All rights reserved.