com.univocity.parsers.common.processor.core
Class AbstractProcessorSwitch<T extends Context>

java.lang.Object
  extended by com.univocity.parsers.common.processor.core.AbstractProcessorSwitch<T>
All Implemented Interfaces:
ColumnOrderDependent, Processor<T>
Direct Known Subclasses:
AbstractInputValueSwitch, RowProcessorSwitch

public abstract class AbstractProcessorSwitch<T extends Context>
extends Object
implements Processor<T>, ColumnOrderDependent

A special Processor implementation that combines and allows switching among different Processors. Each Processor will have its own Context. Concrete implementations of this class are expected to implement the switchRowProcessor(String[], Context) method and analyze the input row to determine whether or not the current Processor implementation must be changed to handle a special circumstance (determined by the concrete implementation) such as a different row format. When the processor is switched, the processorSwitched(Processor, Processor) will be called, and must be overridden, to notify the change to the user.


Constructor Summary
AbstractProcessorSwitch()
           
 
Method Summary
 String[] getHeaders()
          Returns the headers in use by the current row processor implementation, which can vary among row processors.
 int[] getIndexes()
          Returns the indexes in use by the current row processor implementation, which can vary among row processors.
 boolean preventColumnReordering()
          Returns a flag indicating whether or not columns should be reordered by the parser
 void processEnded(T context)
          This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.
 void processorSwitched(Processor<T> from, Processor<T> to)
          Notifies a change of Processor implementation.
 void processStarted(T context)
          This method will by invoked by the parser once, when it is ready to start processing the input.
 void rowProcessed(String[] row, T context)
          Invoked by the parser after all values of a valid record have been processed.
 void rowProcessorSwitched(RowProcessor from, RowProcessor to)
          Notifies a change of RowProcessor implementation.
protected abstract  Processor<T> switchRowProcessor(String[] row, T context)
          Analyzes the input to determine whether or not the row processor implementation must be changed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProcessorSwitch

public AbstractProcessorSwitch()
Method Detail

switchRowProcessor

protected abstract Processor<T> switchRowProcessor(String[] row,
                                                   T context)
Analyzes the input to determine whether or not the row processor implementation must be changed

Parameters:
row - a row parsed from the input
context - the current parsing context (not associated with the current row processor used by this class)
Returns:
the row processor implementation to use. If it is not the same as the one used by the previous row, the returned row processor will be used, and the processorSwitched(Processor, Processor) method will be called.

getHeaders

public String[] getHeaders()
Returns the headers in use by the current row processor implementation, which can vary among row processors. If null, the headers parsed by the input, or defined in CommonSettings.getHeaders() will be returned.

Returns:
the current sequence of headers to use.

getIndexes

public int[] getIndexes()
Returns the indexes in use by the current row processor implementation, which can vary among row processors. If null all columns of a given record will be considered.

Returns:
the current sequence of indexes to use.

processorSwitched

public void processorSwitched(Processor<T> from,
                              Processor<T> to)
Notifies a change of Processor implementation. Users are expected to override this method to receive the notification.

Parameters:
from - the processor previously in use
to - the new processor to use to continue processing the input.

rowProcessorSwitched

public void rowProcessorSwitched(RowProcessor from,
                                 RowProcessor to)
Notifies a change of RowProcessor implementation. Users are expected to override this method to receive the notification.

Parameters:
from - the row processor previously in use
to - the new row processor to use to continue processing the input.

processStarted

public void processStarted(T 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<T 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,
                               T 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<T 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(T 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<T extends Context>
Parameters:
context - A contextual object with information and controls over the state of the parsing process

preventColumnReordering

public boolean preventColumnReordering()
Description copied from interface: ColumnOrderDependent
Returns a flag indicating whether or not columns should be reordered by the parser

Specified by:
preventColumnReordering in interface ColumnOrderDependent
Returns:
a flag indicating whether or not columns should be reordered by the parser


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