com.univocity.parsers.common.processor.core
Class AbstractBeanConversionProcessor<T>

java.lang.Object
  extended by com.univocity.parsers.common.DefaultConversionProcessor
      extended by com.univocity.parsers.common.processor.core.AbstractBeanConversionProcessor<T>
Type Parameters:
T - the annotated class type.
All Implemented Interfaces:
ConversionProcessor
Direct Known Subclasses:
AbstractBeanProcessor, BeanWriterProcessor

public abstract class AbstractBeanConversionProcessor<T>
extends DefaultConversionProcessor

The base class for Processor and RowWriterProcessor implementations that support java beans annotated with the annotations provided in com.univocity.parsers.annotations.

Author:
uniVocity Software Pty Ltd - parsers@univocity.com
See Also:
Processor, RowWriterProcessor

Field Summary
protected  boolean initialized
           
protected  Set<FieldMapping> parsedFields
           
 
Constructor Summary
AbstractBeanConversionProcessor(Class<T> beanType)
          Initializes the BeanConversionProcessor with the annotated bean class
 
Method Summary
 T createBean(String[] row, Context context)
          Converts a record with values extracted from the parser into a java bean instance.
 Class<T> getBeanClass()
          Returns the class of the annotated java bean instances that will be manipulated by this processor.
 void initialize()
          Identifies and extracts fields annotated with the Parsed annotation
 boolean isStrictHeaderValidationEnabled()
          Returns a flag indicating whether all headers declared in the annotated class must be present in the input.
protected  boolean processField(FieldMapping field)
          Determines whether or not an annotated field should be processed.
 Object[] reverseConversions(T bean, String[] headers, int[] indexesToWrite)
          Converts a java bean instance into a sequence of values for writing.
 void setStrictHeaderValidationEnabled(boolean strictHeaderValidationEnabled)
          Defines whether all headers declared in the annotated class must be present in the input.
 
Methods inherited from class com.univocity.parsers.common.DefaultConversionProcessor
applyConversions, convertAll, convertFields, convertIndexes, convertType, handleConversionError, reverseConversions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parsedFields

protected final Set<FieldMapping> parsedFields

initialized

protected boolean initialized
Constructor Detail

AbstractBeanConversionProcessor

public AbstractBeanConversionProcessor(Class<T> beanType)
Initializes the BeanConversionProcessor with the annotated bean class

Parameters:
beanType - the class annotated with one or more of the annotations provided in com.univocity.parsers.annotations.
Method Detail

isStrictHeaderValidationEnabled

public boolean isStrictHeaderValidationEnabled()
Returns a flag indicating whether all headers declared in the annotated class must be present in the input. If enabled, an exception will be thrown in case the input data does not contain all headers required.

Returns:
flag indicating whether strict validation of headers is enabled.

initialize

public final void initialize()
Identifies and extracts fields annotated with the Parsed annotation


setStrictHeaderValidationEnabled

public void setStrictHeaderValidationEnabled(boolean strictHeaderValidationEnabled)
Defines whether all headers declared in the annotated class must be present in the input. If enabled, an exception will be thrown in case the input data does not contain all headers required.

Parameters:
strictHeaderValidationEnabled - flag indicating whether strict validation of headers is enabled.

processField

protected boolean processField(FieldMapping field)
Determines whether or not an annotated field should be processed. Can be overridden by subclasses for fine grained control.

Parameters:
field - the field to be processed
Returns:
true if the given field should be processed, otherwise false.

createBean

public T createBean(String[] row,
                    Context context)
Converts a record with values extracted from the parser into a java bean instance.

Parameters:
row - The values extracted from the parser
context - The current state of the parsing process
Returns:
an instance of the java bean type defined in this class constructor.

reverseConversions

public final Object[] reverseConversions(T bean,
                                         String[] headers,
                                         int[] indexesToWrite)
Converts a java bean instance into a sequence of values for writing.

Parameters:
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...)
Returns:
a row of objects containing the values extracted from the java bean

getBeanClass

public Class<T> getBeanClass()
Returns the class of the annotated java bean instances that will be manipulated by this processor.

Returns:
the class of the annotated java bean instances that will be manipulated by this processor.


Copyright © 2016 uniVocity Software Pty Ltd. All rights reserved.