Package csv.util
Class BeanWriter<T>
java.lang.Object
csv.util.BeanWriter<T>
- Type Parameters:
T- Type of bean to be written
Writes beans to an underlying table writer.
The attributes written are either determined by inspection of first bean to be written
or by explicitely setting them through special methods.
- Author:
- ralph
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds a getter method to the methods being used for retrieveing column values.protected voidAdds a getter method to the methods being used for retrieveing column values.voidclose()Closes the underlying writer.Object[]convertToColumns(T bean) Converts the given bean to an object array.protected voidcreateAttributeList(Class<T> clazz) Creates the attribute list by introspection.protected voidcreateAttributeList(Class<T> clazz, String[] attributes) Creates the attribute list from given list.protected voidcreateAttributeList(Class<T> clazz, List<String> attributes) Creates the attribute list from given list.protected ObjectgetAttribute(int index, T bean) Returns the value for given bean at given column index.protected ObjectgetAttribute(Method method, T bean) Returns the attribute value for given bean.protected ObjectgetAttribute(String attribute, T bean) Returns the attribute value for given bean.protected StringReturns the attribute name derived from method nameReturns the current writer.protected booleanisValidGetterMethod(Method method) Returns true if method conforms to JavaBean style of a Getter.booleanReturns true when a header row with attribute names shall be written.protected voidsetWriteHeaderRow(boolean writeHeaderRow) Sets whether a header row with attribute names shall be written.protected voidsetWriter(TableWriter writer) Sets the writer.voidWrites the bean to the underlying table writer.intwriteBeans(Object[] arr) Copies the beans from the collection to this bean writer.intwriteBeans(Collection<? extends T> collection) Copies the beans from the collection to this bean writer.intwriteBeans(Iterator<? extends T> i) Copies the beans from the collection to this bean writer.protected voidWrites the header row to the underlying table writer.
-
Constructor Details
-
BeanWriter
Constructor.- Parameters:
writer- the underlying writerwriteHeaderRow- whether a header row with attribute names shall be written
-
-
Method Details
-
isWriteHeaderRow
public boolean isWriteHeaderRow()Returns true when a header row with attribute names shall be written.- Returns:
- the writeHeaderRow
-
setWriteHeaderRow
protected void setWriteHeaderRow(boolean writeHeaderRow) Sets whether a header row with attribute names shall be written.- Parameters:
writeHeaderRow- true if header row shall be written.
-
writeBean
Writes the bean to the underlying table writer.- Parameters:
bean- the bean to be written- Throws:
IOException- if bean cannot be written- See Also:
-
close
public void close()Closes the underlying writer. -
getWriter
Returns the current writer.- Returns:
- the writer
-
setWriter
Sets the writer.- Parameters:
writer- the writer
-
convertToColumns
Converts the given bean to an object array.- Parameters:
bean- bean to be converted- Returns:
- object array with attribute values
-
getAttribute
Returns the value for given bean at given column index.- Parameters:
index- column indexbean- bean object- Returns:
- value in column
-
getAttribute
Returns the attribute value for given bean.- Parameters:
attribute- name of attributebean- bean object- Returns:
- value of attribute
-
getAttribute
Returns the attribute value for given bean.- Parameters:
method- method that will deliver the valuebean- bean object- Returns:
- value of attribute
-
createAttributeList
Creates the attribute list from given list. All JavaBean getter methods will be taken over.- Parameters:
clazz- Class to introspectattributes- list of attributes
-
createAttributeList
Creates the attribute list from given list. All JavaBean getter methods will be taken over.- Parameters:
clazz- Class to introspectattributes- list of attributes
-
createAttributeList
Creates the attribute list by introspection. All JavaBean getter methods will be taken over.- Parameters:
clazz- Class to introspect
-
addGetter
Adds a getter method to the methods being used for retrieveing column values. The metthod must have a return type and no arguments.- Parameters:
clazz- Class to introspectattribute- name of attribute
-
isValidGetterMethod
Returns true if method conforms to JavaBean style of a Getter.- Parameters:
method- method- Returns:
- true if method is a getter.
-
addGetter
Adds a getter method to the methods being used for retrieveing column values. The metthod must have a return type and no arguments.- Parameters:
attributeName- name of attributemethod- method name.
-
writeHeaderRow
protected void writeHeaderRow()Writes the header row to the underlying table writer. -
getAttributeName
Returns the attribute name derived from method name- Parameters:
m- method- Returns:
- attribute name
-
writeBeans
Copies the beans from the collection to this bean writer.- Parameters:
collection- collection that contains JavaBeans- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
writeBeans
Copies the beans from the collection to this bean writer.- Parameters:
i- iterator that delivers JavaBeans- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-
writeBeans
Copies the beans from the collection to this bean writer.- Parameters:
arr- array with beans- Returns:
- number of rows written
- Throws:
IOException- when there is a problem with the writer.
-