olg.csv.bean
Class RowBean<T>

java.lang.Object
  extended by olg.csv.bean.RowBean<T>
Type Parameters:
T - the bean to manage.

public final class RowBean<T>
extends Object

Main class to manage bean writing/reading based on Annotations setted on bean class.

Author:
Olivier Godineau

Constructor Summary
RowBean(Class<T> clazz)
          Constructor.
 
Method Summary
 List<T> fromFile(File in)
          Extracts a list from a file.
 List<T> fromFile(File in, CSVSettings csvSettings)
          Extracts a list from a CSV file opened with some CSV settings.
 List<T> fromFile(File in, ODSSettings odsSettings)
          Extracts a list from an ODS file opened with some ODS settings.
 IReader getReader(File in)
          Returns a ODS or CSV reader with settings read from RowBean Annotation setted on T class. throws IllegalArgumentException if file is null or or it's not possible to define a reader.
 IWriter getWriter(File out)
          Returns a ODS or CSV writer with settings read from RowBean Annotation setted on T class.
 void toFile(List<T> beans, File out)
          Copy in a new file a list of T.
 void toFile(List<T> beans, File out, CSVSettings csvSettings)
          Copy in a CSV file a list of T.
 void toFile(List<T> beans, File out, ODSSettings odsSettings)
          Copy in an ODS file a list of T.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RowBean

public RowBean(Class<T> clazz)
Constructor.

Parameters:
clazz - the class RowBean instance supports and deals with.
Method Detail

getReader

public IReader getReader(File in)
                  throws IOException,
                         AnnotationProcessorException
Returns a ODS or CSV reader with settings read from RowBean Annotation setted on T class. throws IllegalArgumentException if file is null or or it's not possible to define a reader.

Parameters:
in - the file. Must be an ODS or CSV file. ODS files must have .ods or.ODS extension. CSV files must have .csv,.CSV,.txt, .TXT, .dat or.DAT.
Returns:
the reader corresponding to the extension of the file.
Throws:
IOException - if an error occurs during the file opening.
AnnotationProcessorException - an error occurs on settings annotation reading at the rowBean annotation setted on the T class.

getWriter

public IWriter getWriter(File out)
                  throws AnnotationProcessorException,
                         IOException
Returns a ODS or CSV writer with settings read from RowBean Annotation setted on T class. Throws IllegalArgumentException if file is null or or it's not possible to define a writer.

Parameters:
out - the file. Must be an ODS or CSV file. ODS files must have .ods or.ODS extension. CSV files must have .csv,.CSV,.txt, .TXT, .dat or.DAT.
Returns:
the writer the row writer corresponding to the extension of the file.
Throws:
AnnotationProcessorException - error occurs on writing settings RowBean annotation
IOException - errors occurs on file opening

fromFile

public List<T> fromFile(File in,
                        CSVSettings csvSettings)
                 throws AnnotationProcessorException,
                        IOException
Extracts a list from a CSV file opened with some CSV settings. Use Annotations on T class to define how to read bean and how set the file reader.

Parameters:
in - the CSV file.
csvSettings - the settings the file will be opened with.
Returns:
the list of T extracted from the file.
Throws:
AnnotationProcessorException - if an error occurs during the annotation reading on T class.
IOException - if an error occurs during the file opening.

fromFile

public List<T> fromFile(File in,
                        ODSSettings odsSettings)
                 throws AnnotationProcessorException,
                        IOException
Extracts a list from an ODS file opened with some ODS settings. Use Annotations on T class to define how to read beans and how to set the file reader.

Parameters:
in - the ODS file.
odsSettings - the settings the file will be opened with.
Returns:
the list of T extracted from the file.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.
IOException - if an error occurs during the file opening.

fromFile

public List<T> fromFile(File in)
                 throws AnnotationProcessorException,
                        IOException
Extracts a list from a file. Use Annotations on T class to define how to read bean and how set the file reader. Throws IllegalArgumentException if file is null or or it's not possible to define a reader.

Parameters:
in - the file. Must be an ODS or CSV file. ODS files must have .ods or.ODS extension. CSV files must have .csv,.CSV,.txt, .TXT, .dat or.DAT. Use the reading settings read from RowBean Annotation setted on T class.
Returns:
the list of T extracted from the file.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.
IOException - if an error occurs during the file opening.

toFile

public void toFile(List<T> beans,
                   File out)
            throws AnnotationProcessorException,
                   IOException
Copy in a new file a list of T. Use the RowBean annotation setted on T class. Throws IllegalArgumentException if file is null or or it's not possible to define a writer.

Parameters:
beans - the list.
out - the file. Must be an ODS or CSV file. ODS files must have .ods or.ODS extension. CSV files must have .csv,.CSV,.txt, .TXT, .dat or.DAT. Use writing settings read from RowBean Annotation setted on T class.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

toFile

public void toFile(List<T> beans,
                   File out,
                   CSVSettings csvSettings)
            throws AnnotationProcessorException,
                   IOException
Copy in a CSV file a list of T. Use the RowBean annotation setted on T class.

Parameters:
beans - the beans to copy.
out - the file.
csvSettings - the settings the file is written with.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

toFile

public void toFile(List<T> beans,
                   File out,
                   ODSSettings odsSettings)
            throws AnnotationProcessorException,
                   IOException
Copy in an ODS file a list of T. Use the RowBean annotation setted on T class.

Parameters:
beans - the T beans to copy.
out - the file
odsSettings - the settings the file is written with.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason


Copyright © 2014. All rights reserved.