|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.univocity.parsers.common.processor.BeanProcessor<T>
T
- the annotated class type.public abstract class BeanProcessor<T>
A RowProcessor
implementation for converting rows extracted from any implementation of AbstractParser
into java objects.
The class type of the object must contain the annotations provided in com.univocity.parsers.annotations
.
For each row processed, a java bean instance of a given class will be created with its fields populated.
This instance will then be sent to the beanProcessed(Object, ParsingContext)
method, where the user can access it.
AbstractParser
,
RowProcessor
Constructor Summary | |
---|---|
BeanProcessor(Class<T> beanType)
Creates a processor for java beans of a given type. |
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. |
abstract void |
beanProcessed(T bean,
ParsingContext context)
Invoked by the processor after all values of a valid record have been processed and converted into a java object. |
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 |
processEnded(ParsingContext context)
This method will by invoked by the parser once, after the parsing process stopped and all resources were closed. |
void |
processStarted(ParsingContext context)
This method will by invoked by the parser once, when it is ready to start processing the input. |
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. |
void |
rowProcessed(String[] row,
ParsingContext context)
Converts a parsed row to a java object |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanProcessor(Class<T> beanType)
beanType
- the class with its attributes mapped to fields of records parsed by an AbstractParser
or written by an AbstractWriter
.Method Detail |
---|
public final void rowProcessed(String[] row, ParsingContext context)
rowProcessed
in interface RowProcessor
row
- the data extracted by the parser for an individual record. Note that:
CommonSettings.setSkipEmptyLines(boolean)
Format.setComment(char)
to '\0'context
- A contextual object with information and controls over the current state of the parsing processpublic abstract void beanProcessed(T bean, ParsingContext context)
bean
- java object created with the information extracted by the parser for an individual record.context
- A contextual object with information and controls over the current state of the parsing processpublic void processStarted(ParsingContext context)
processStarted
in interface RowProcessor
context
- A contextual object with information and controls over the current state of the parsing processpublic void processEnded(ParsingContext context)
It will always be called by the parser: in case of errors, if the end of the input us reached, or if the user stopped the process manually using ParsingContext.stop()
.
processEnded
in interface RowProcessor
context
- A contextual object with information and controls over the state of the parsing processprotected 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 |