public abstract class AbstractMultiBeanProcessor<C extends Context> extends Object implements Processor<C>, ConversionProcessor
Processor
implementation for converting rows extracted from any implementation of AbstractParser
into java objects.
The class types passed to the constructor of this class must contain the annotations provided in com.univocity.parsers.annotations
.
For each row processed, one or more java bean instances of any given class will be created with their fields populated.
Each individual instance will then be sent to the beanProcessed(Class, Object, Context)
method, where the user can access the
beans parsed for each row.
AbstractParser
,
Processor
,
BeanProcessor
Constructor and Description |
---|
AbstractMultiBeanProcessor(Class... beanTypes)
Creates a processor for java beans of multiple types
|
Modifier and Type | Method and Description |
---|---|
abstract void |
beanProcessed(Class<?> beanType,
Object beanInstance,
C 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. |
void |
convertType(Class<?> type,
Conversion... conversions)
Applies a sequence of conversions over values of a given type.
|
Class[] |
getBeanClasses() |
<T> AbstractBeanProcessor<T,C> |
getProcessorOfType(Class<T> type)
Returns the
BeanProcessor responsible for processing a given class |
void |
processEnded(C context)
This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
|
void |
processStarted(C context)
This method will by invoked by the parser once, when it is ready to start processing the input.
|
void |
rowProcessed(String[] row,
C context)
Invoked by the parser after all values of a valid record have been processed.
|
public AbstractMultiBeanProcessor(Class... beanTypes)
beanTypes
- the classes with their attributes mapped to fields of records parsed by an AbstractParser
or written by an AbstractWriter
.public final Class[] getBeanClasses()
public <T> AbstractBeanProcessor<T,C> getProcessorOfType(Class<T> type)
BeanProcessor
responsible for processing a given classT
- the type of java bean being processedtype
- the type of java bean being processedBeanProcessor
that handles java beans of the given class.public abstract void beanProcessed(Class<?> beanType, Object beanInstance, C context)
beanType
- the type of the object created by the parser using the information collected for an individual record.beanInstance
- 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(C context)
Processor
processStarted
in interface Processor<C extends Context>
context
- A contextual object with information and controls over the current state of the parsing processpublic final void rowProcessed(String[] row, C context)
Processor
rowProcessed
in interface Processor<C extends Context>
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 void processEnded(C context)
Processor
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 Context.stop()
.
processEnded
in interface Processor<C extends Context>
context
- A contextual object with information and controls over the state of the parsing processpublic FieldSet<Integer> convertIndexes(Conversion... conversions)
ConversionProcessor
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
convertIndexes
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in a set of field indexes.FieldSet
for indexes.public void convertAll(Conversion... conversions)
ConversionProcessor
Conversion
objects over all elements of a recordconvertAll
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in all elements of a recordpublic FieldSet<String> convertFields(Conversion... conversions)
ConversionProcessor
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"
convertFields
in interface ConversionProcessor
conversions
- The sequence of conversions to be executed in a set of field indexes.FieldSet
for field names.public void convertType(Class<?> type, Conversion... conversions)
ConversionProcessor
convertType
in interface ConversionProcessor
type
- the type over which a sequence of conversions should be appliedconversions
- the sequence of conversions to apply over values of the given type.Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.