|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.univocity.parsers.common.processor.BeanWriterProcessor<T>
T
- the annotated class type.public class BeanWriterProcessor<T>
A RowWriterProcessor
implementation for converting annotated java objects into object arrays suitable for writing in any implementation of AbstractWriter
.
The class type of the object must contain the annotations provided in com.univocity.parsers.annotations
.
For any given java bean instance, this processor will read and convert annotated fields into an object array.
AbstractWriter
,
RowWriterProcessor
Constructor Summary | |
---|---|
BeanWriterProcessor(Class<T> beanType)
Initializes the BeanWriterProcessor with the annotated bean class |
Method Summary | |
---|---|
Object[] |
applyConversions(String[] row,
ParsingContext context)
Executes the sequences of conversions defined using ConversionProcessor.convertFields(Conversion...) , ConversionProcessor.convertIndexes(Conversion...) and ConversionProcessor.convertAll(Conversion...) , for every field in the given row. |
void |
convertAll(Conversion... conversions)
Applies a set of Conversion objects over all elements of a record |
FieldSet<String> |
convertFields(Conversion... conversions)
Applies a set of Conversion objects over fields of a record by name. |
FieldSet<Integer> |
convertIndexes(Conversion... conversions)
Applies a set of Conversion objects over indexes of a record. |
T |
createBean(String[] row,
ParsingContext context)
Converts a record with values extracted from the parser into a java bean instance. |
protected void |
initialize()
Identifies and extracts fields annotated with the Parsed annotation |
void |
reverseConversions(boolean executeInReverseOrder,
Object[] row,
String[] headers,
int[] indexesToWrite)
Executes the sequences of reverse conversions defined using ConversionProcessor.convertFields(Conversion...) , ConversionProcessor.convertIndexes(Conversion...) and ConversionProcessor.convertAll(Conversion...) , for every field in the given row. |
Object[] |
reverseConversions(T bean,
String[] headers,
int[] indexesToWrite)
Converts a java bean instance into a sequence of values for writing. |
Object[] |
write(T input,
String[] headers,
int[] indexesToWrite)
Converts the java bean instance into a sequence of values for writing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanWriterProcessor(Class<T> beanType)
beanType
- the class annotated with one or more of the annotations provided in com.univocity.parsers.annotations
.Method Detail |
---|
public Object[] write(T input, String[] headers, int[] indexesToWrite)
write
in interface RowWriterProcessor<T>
input
- an instance of the type defined in this class constructor.headers
- All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings.getHeaders()
indexesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
CsvWriter
,
FixedWidthWriter
,
CommonSettings
,
AbstractWriter
protected final void initialize()
Parsed
annotation
public final T createBean(String[] row, ParsingContext context)
row
- The values extracted from the parsercontext
- The current state of the parsing process
public final Object[] reverseConversions(T bean, String[] headers, int[] indexesToWrite)
bean
- an instance of the type defined in this class constructor.headers
- All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings.getHeaders()
indexesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
public final FieldSet<Integer> convertIndexes(Conversion... conversions)
Conversion
objects over indexes of a record.
The idiom to define which indexes should have these conversions applies is as follows:
processor.convertIndexes(Conversions.trim(), Conversions.toUpperCase()).add(2, 5); // applies trim and uppercase conversions to fields in indexes 2 and 5
conversions
- The sequence of conversions to be executed in a set of field indexes.
FieldSet
for indexes.public final void convertAll(Conversion... conversions)
Conversion
objects over all elements of a record
conversions
- The sequence of conversions to be executed in all elements of a recordpublic final FieldSet<String> convertFields(Conversion... conversions)
Conversion
objects over fields of a record by name.
The idiom to define which fields should have these conversions applied is as follows:
processor.convertFields(Conversions.trim(), Conversions.toUpperCase()).add("name", "position"); // applies trim and uppercase conversions to fields with headers "name" and "position"
conversions
- The sequence of conversions to be executed in a set of field indexes.
FieldSet
for field names.public final Object[] applyConversions(String[] row, ParsingContext context)
ConversionProcessor.convertFields(Conversion...)
, ConversionProcessor.convertIndexes(Conversion...)
and ConversionProcessor.convertAll(Conversion...)
, for every field in the given row.
Each field will be transformed using the Conversion.execute(Object)
method.
In general the conversions will process a String and convert it to some object value (such as booleans, dates, etc).
row
- the parsed record with its individual records as extracted from the original input.context
- the current state of the parsing process.
Fields that do not have any conversion defined will just be copied to the object array into their original positions.
public final void reverseConversions(boolean executeInReverseOrder, Object[] row, String[] headers, int[] indexesToWrite)
ConversionProcessor.convertFields(Conversion...)
, ConversionProcessor.convertIndexes(Conversion...)
and ConversionProcessor.convertAll(Conversion...)
, for every field in the given row.
Each field will be transformed using the Conversion.revert(Object)
method.
In general the conversions will process an Object (such as a Boolean, Date, etc), and convert it to a String representation.
executeInReverseOrder
- flag to indicate whether the conversion sequence should be executed in the reverse order of its declaration (used in BeanConversionProcessor.reverseConversions(T, java.lang.String[], int[])
) .row
- the row of objects that will be convertedheaders
- All field names used to produce records in a given destination. May be null if no headers have been defined in CommonSettings.getHeaders()
indexesToWrite
- The indexes of the headers that are actually being written. May be null if no fields have been selected using CommonSettings.selectFields(String...)
or CommonSettings.selectIndexes(Integer...)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |