olg.csv.bean
Class RowBean<T>

Package class diagram package RowBean
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.


Field Summary
private  Class<T> clazz
          The class this RowBean instance deals with.
private static org.slf4j.Logger LOGGER
          class logger.
private  RowBeanProcessor<T> rowBeanProcessor
          the processor to load RowProcessor/BeanProcessor/file reader settings/file writer settings.
 
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.
private  List<T> fromReader(IReader fileReader, File in)
          Extracts a list from a reader.
private  IBeanProcessor<T> getBeanProcessor()
          Provides the Bean processor built from the annoted T class.
 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.
private  IRowProcessor<T> getRowProcessor()
          Provides the row processor built from the annoted T class.
 IWriter getWriter(File out)
          Returns a ODS or CSV writer with settings read from RowBean Annotation setted on T class.
private static boolean isCSVFile(File file)
          check if a file extension matchs text file extension(.csv,.txt,.dat).
private static boolean isODSFile(File file)
          check if a file extension matchs ODS file extension.
 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.
private  void toWriter(List<T> beans, IWriter fileWriter, File out)
          Copy a list of T on a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final org.slf4j.Logger LOGGER
class logger.


clazz

private Class<T> clazz
The class this RowBean instance deals with.


rowBeanProcessor

private RowBeanProcessor<T> rowBeanProcessor
the processor to load RowProcessor/BeanProcessor/file reader settings/file writer settings.

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

isCSVFile

private static boolean isCSVFile(File file)
check if a file extension matchs text file extension(.csv,.txt,.dat).

Parameters:
file - the file to check
Returns:
true if the file has a text file extension.

isODSFile

private static boolean isODSFile(File file)
check if a file extension matchs ODS file extension.

Parameters:
file - the file to check
Returns:
true if has ODS extension

getRowProcessor

private IRowProcessor<T> getRowProcessor()
                                  throws AnnotationProcessorException
Provides the row processor built from the annoted T class.

Returns:
the row processor.
Throws:
AnnotationProcessorException - if an error occurs during processor building.

getBeanProcessor

private IBeanProcessor<T> getBeanProcessor()
                                    throws AnnotationProcessorException
Provides the Bean processor built from the annoted T class.

Returns:
the bean processor.
Throws:
AnnotationProcessorException - if error occurs during annotation processing.

fromReader

private List<T> fromReader(IReader fileReader,
                           File in)
                    throws AnnotationProcessorException
Extracts a list from a reader.

Parameters:
fileReader - the reader
in - the file
Returns:
the list of T extracted from the file.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.

toWriter

private void toWriter(List<T> beans,
                      IWriter fileWriter,
                      File out)
               throws AnnotationProcessorException
Copy a list of T on a writer.

Parameters:
beans - the beans to copy.
fileWriter - the writer
out - the opened file.
Throws:
AnnotationProcessorException - if error occurs during the annotation reading on T class.


Copyright © 2014. All Rights Reserved.