olg.csv.bean
Class BeanWriter<E>

Package class diagram package BeanWriter
java.lang.Object
  extended by olg.csv.bean.BeanWriter<E>
Type Parameters:
E - object this writer deals with.
All Implemented Interfaces:
Closeable

public class BeanWriter<E>
extends Object
implements Closeable

Class specialized in writing objects into a file Used a IWriter to write a list of Strings into a file Uses a list of PropertyFormatter to transform an E object into a list of Strings.

See Also:
IWriter, PropertyFormatter

Field Summary
private  IWriter baseWriter
          the writer.
private static org.slf4j.Logger LOGGER
          The class logger.
private  IRowProcessor<E> rowProcessor
          The row processor.
 
Constructor Summary
BeanWriter(File configFile, IWriter writer)
           
BeanWriter(File configFile, IWriter writer, boolean skipEmptyRow)
           
BeanWriter(IRowProcessor<E> rowProcessor, IWriter writer)
          Construct a BeanWriter with a rowProcessor and a writer.
 
Method Summary
 void close()
          
 void write(E element)
          Writes a bean on a dedicated output.
 void writeHeaders()
          Allows to write a header line to describe the fields.
 
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
The class logger.


baseWriter

private final IWriter baseWriter
the writer. Allows to write a list of Strings on a dedicated output.


rowProcessor

private final IRowProcessor<E> rowProcessor
The row processor.

Constructor Detail

BeanWriter

public BeanWriter(File configFile,
                  IWriter writer)
           throws LoadException
Parameters:
configFile - the file which describes how to load the field formatters used to transform an object into a list of Strings. XML Configuration must be a bean-writer or bean-row XML type, See bean-row.xsd file. Must be not null.
writer - Allows to write a list of Strings on a dedicated output. Must be not null.
Throws:
LoadException - if an error occurs during loading field formatters from file

BeanWriter

public BeanWriter(File configFile,
                  IWriter writer,
                  boolean skipEmptyRow)
           throws LoadException
Parameters:
configFile - the file which describe how to load the field formatters used to transform an object into a list of Strings. XML Configuration must be a bean-writer or bean-row XML type, See bean-row.xsd file. Must be not null.
writer - Allows to write a list of Strings on a dedicated output. Must be not null.
skipEmptyRow - if true avoids writing blank lines.
Throws:
LoadException - if an error occurs during loading field formatters from file.

BeanWriter

public BeanWriter(IRowProcessor<E> rowProcessor,
                  IWriter writer)
Construct a BeanWriter with a rowProcessor and a writer.

Parameters:
rowProcessor - the rowProcessor. If the rowProcessor products empty rows, blank lines are copied into the file.To avoid this case, use IgnoreNullWriter. Must be not null.
writer - the writer.
Method Detail

close

public void close()

Specified by:
close in interface Closeable

write

public void write(E element)
           throws PropertyException
Writes a bean on a dedicated output.

Throws PropertyException if error occurs during property extraction and formatting.

Throws WriterException if I/O error occurs during writing.

Parameters:
element - the bean to write. Must be not null.
Throws:
PropertyException

writeHeaders

public void writeHeaders()
Allows to write a header line to describe the fields.

if the configuration file from which this beanWriter is defined is the bean-writer element, try to take the declared name of the column otherwise use "column_"i where i is the column num.

if the configuration file from which this beanWriter is defined is the bean-row element, try to take the name of the declared column, otherwise use the name of the corresponding property.

throws WriterException if this method is called after objects had been wroten or I/O error occurs.



Copyright © 2014. All Rights Reserved.