Class AbstractMultiBeanProcessor<C extends Context>
- java.lang.Object
-
- com.univocity.parsers.common.processor.core.AbstractMultiBeanProcessor<C>
-
- All Implemented Interfaces:
ConversionProcessor
,Processor<C>
- Direct Known Subclasses:
AbstractMultiBeanRowProcessor
,MultiBeanProcessor
public abstract class AbstractMultiBeanProcessor<C extends Context> extends java.lang.Object implements Processor<C>, ConversionProcessor
AProcessor
implementation for converting rows extracted from any implementation ofAbstractParser
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.- See Also:
AbstractParser
,Processor
,BeanProcessor
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractBeanProcessor<?,C>[]
beanProcessors
private java.util.Map<java.lang.Class,AbstractBeanProcessor>
processorMap
-
Constructor Summary
Constructors Constructor Description AbstractMultiBeanProcessor(java.lang.Class... beanTypes)
Creates a processor for java beans of multiple types
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
beanProcessed(java.lang.Class<?> beanType, java.lang.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 ofConversion
objects over all elements of a recordFieldSet<java.lang.String>
convertFields(Conversion... conversions)
Applies a set ofConversion
objects over fields of a record by name.FieldSet<java.lang.Integer>
convertIndexes(Conversion... conversions)
Applies a set ofConversion
objects over indexes of a record.void
convertType(java.lang.Class<?> type, Conversion... conversions)
Applies a sequence of conversions over values of a given type.java.lang.Class[]
getBeanClasses()
<T> AbstractBeanProcessor<T,C>
getProcessorOfType(java.lang.Class<T> type)
Returns theBeanProcessor
responsible for processing a given classvoid
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(java.lang.String[] row, C context)
Invoked by the parser after all values of a valid record have been processed.
-
-
-
Field Detail
-
beanProcessors
private final AbstractBeanProcessor<?,C extends Context>[] beanProcessors
-
processorMap
private final java.util.Map<java.lang.Class,AbstractBeanProcessor> processorMap
-
-
Constructor Detail
-
AbstractMultiBeanProcessor
public AbstractMultiBeanProcessor(java.lang.Class... beanTypes)
Creates a processor for java beans of multiple types- Parameters:
beanTypes
- the classes with their attributes mapped to fields of records parsed by anAbstractParser
or written by anAbstractWriter
.
-
-
Method Detail
-
getBeanClasses
public final java.lang.Class[] getBeanClasses()
-
getProcessorOfType
public <T> AbstractBeanProcessor<T,C> getProcessorOfType(java.lang.Class<T> type)
Returns theBeanProcessor
responsible for processing a given class- Type Parameters:
T
- the type of java bean being processed- Parameters:
type
- the type of java bean being processed- Returns:
- the
BeanProcessor
that handles java beans of the given class.
-
beanProcessed
public abstract void beanProcessed(java.lang.Class<?> beanType, java.lang.Object beanInstance, C context)
Invoked by the processor after all values of a valid record have been processed and converted into a java object.- Parameters:
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 process
-
processStarted
public void processStarted(C context)
Description copied from interface:Processor
This method will by invoked by the parser once, when it is ready to start processing the input.- Specified by:
processStarted
in interfaceProcessor<C extends Context>
- Parameters:
context
- A contextual object with information and controls over the current state of the parsing process
-
rowProcessed
public final void rowProcessed(java.lang.String[] row, C context)
Description copied from interface:Processor
Invoked by the parser after all values of a valid record have been processed.- Specified by:
rowProcessed
in interfaceProcessor<C extends Context>
- Parameters:
row
- the data extracted by the parser for an individual record. Note that:- it will never by null.
- it will never be empty unless explicitly configured using
CommonSettings.setSkipEmptyLines(boolean)
- it won't contain lines identified by the parser as comments. To disable comment processing set
Format.setComment(char)
to '\0'
context
- A contextual object with information and controls over the current state of the parsing process
-
processEnded
public void processEnded(C context)
Description copied from interface:Processor
This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.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()
.- Specified by:
processEnded
in interfaceProcessor<C extends Context>
- Parameters:
context
- A contextual object with information and controls over the state of the parsing process
-
convertIndexes
public FieldSet<java.lang.Integer> convertIndexes(Conversion... conversions)
Description copied from interface:ConversionProcessor
Applies a set ofConversion
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
- Specified by:
convertIndexes
in interfaceConversionProcessor
- Parameters:
conversions
- The sequence of conversions to be executed in a set of field indexes.- Returns:
- A
FieldSet
for indexes.
-
convertAll
public void convertAll(Conversion... conversions)
Description copied from interface:ConversionProcessor
Applies a set ofConversion
objects over all elements of a record- Specified by:
convertAll
in interfaceConversionProcessor
- Parameters:
conversions
- The sequence of conversions to be executed in all elements of a record
-
convertFields
public FieldSet<java.lang.String> convertFields(Conversion... conversions)
Description copied from interface:ConversionProcessor
Applies a set ofConversion
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"
- Specified by:
convertFields
in interfaceConversionProcessor
- Parameters:
conversions
- The sequence of conversions to be executed in a set of field indexes.- Returns:
- A
FieldSet
for field names.
-
convertType
public void convertType(java.lang.Class<?> type, Conversion... conversions)
Description copied from interface:ConversionProcessor
Applies a sequence of conversions over values of a given type. Used for writing.- Specified by:
convertType
in interfaceConversionProcessor
- Parameters:
type
- the type over which a sequence of conversions should be appliedconversions
- the sequence of conversions to apply over values of the given type.
-
-