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.

See Also:
  • Field Details

  • Constructor Details

    • AbstractMultiBeanProcessor

      public AbstractMultiBeanProcessor(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 an AbstractParser or written by an AbstractWriter.
  • Method Details

    • getBeanClasses

      public final Class[] getBeanClasses()
    • getProcessorOfType

      public <T> AbstractBeanProcessor<T,C> getProcessorOfType(Class<T> type)
      Returns the BeanProcessor 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(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.
      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 interface Processor<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(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 interface Processor<C extends Context>
      Parameters:
      row - the data extracted by the parser for an individual record. Note that:
      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 interface Processor<C extends Context>
      Parameters:
      context - A contextual object with information and controls over the state of the parsing process
    • convertIndexes

      public FieldSet<Integer> convertIndexes(Conversion... conversions)
      Description copied from interface: ConversionProcessor
      Applies a set of 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
       

      Specified by:
      convertIndexes in interface ConversionProcessor
      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 of Conversion objects over all elements of a record
      Specified by:
      convertAll in interface ConversionProcessor
      Parameters:
      conversions - The sequence of conversions to be executed in all elements of a record
    • convertFields

      public FieldSet<String> convertFields(Conversion... conversions)
      Description copied from interface: ConversionProcessor
      Applies a set of 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"
       

      Specified by:
      convertFields in interface ConversionProcessor
      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(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 interface ConversionProcessor
      Parameters:
      type - the type over which a sequence of conversions should be applied
      conversions - the sequence of conversions to apply over values of the given type.