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 Object
implements Processor<C>, ConversionProcessor
A
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.
- Author:
- Univocity Software Pty Ltd - parsers@univocity.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractMultiBeanProcessor(Class... beanTypes) Creates a processor for java beans of multiple types -
Method Summary
Modifier and TypeMethodDescriptionabstract voidbeanProcessed(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.voidconvertAll(Conversion... conversions) Applies a set ofConversionobjects over all elements of a recordconvertFields(Conversion... conversions) Applies a set ofConversionobjects over fields of a record by name.convertIndexes(Conversion... conversions) Applies a set ofConversionobjects over indexes of a record.voidconvertType(Class<?> type, Conversion... conversions) Applies a sequence of conversions over values of a given type.final Class[]<T> AbstractBeanProcessor<T, C> getProcessorOfType(Class<T> type) Returns theBeanProcessorresponsible for processing a given classvoidprocessEnded(C context) This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.voidprocessStarted(C context) This method will by invoked by the parser once, when it is ready to start processing the input.final voidrowProcessed(String[] row, C context) Invoked by the parser after all values of a valid record have been processed.
-
Constructor Details
-
AbstractMultiBeanProcessor
Creates a processor for java beans of multiple types- Parameters:
beanTypes- the classes with their attributes mapped to fields of records parsed by anAbstractParseror written by anAbstractWriter.
-
-
Method Details
-
getBeanClasses
-
getProcessorOfType
Returns theBeanProcessorresponsible 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
BeanProcessorthat handles java beans of the given class.
-
beanProcessed
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
Description copied from interface:ProcessorThis method will by invoked by the parser once, when it is ready to start processing the input.- Specified by:
processStartedin interfaceProcessor<C extends Context>- Parameters:
context- A contextual object with information and controls over the current state of the parsing process
-
rowProcessed
Description copied from interface:ProcessorInvoked by the parser after all values of a valid record have been processed.- Specified by:
rowProcessedin 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
Description copied from interface:ProcessorThis 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:
processEndedin interfaceProcessor<C extends Context>- Parameters:
context- A contextual object with information and controls over the state of the parsing process
-
convertIndexes
Description copied from interface:ConversionProcessorApplies a set ofConversionobjects 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:
convertIndexesin interfaceConversionProcessor- Parameters:
conversions- The sequence of conversions to be executed in a set of field indexes.- Returns:
- A
FieldSetfor indexes.
-
convertAll
Description copied from interface:ConversionProcessorApplies a set ofConversionobjects over all elements of a record- Specified by:
convertAllin interfaceConversionProcessor- Parameters:
conversions- The sequence of conversions to be executed in all elements of a record
-
convertFields
Description copied from interface:ConversionProcessorApplies a set ofConversionobjects 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:
convertFieldsin interfaceConversionProcessor- Parameters:
conversions- The sequence of conversions to be executed in a set of field indexes.- Returns:
- A
FieldSetfor field names.
-
convertType
Description copied from interface:ConversionProcessorApplies a sequence of conversions over values of a given type. Used for writing.- Specified by:
convertTypein 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.
-