Class AbstractMasterDetailProcessor<T extends Context>
- java.lang.Object
-
- com.univocity.parsers.common.DefaultConversionProcessor
-
- com.univocity.parsers.common.processor.core.AbstractObjectProcessor<T>
-
- com.univocity.parsers.common.processor.core.AbstractMasterDetailProcessor<T>
-
- All Implemented Interfaces:
ConversionProcessor
,Processor<T>
- Direct Known Subclasses:
AbstractMasterDetailListProcessor
,MasterDetailProcessor
public abstract class AbstractMasterDetailProcessor<T extends Context> extends AbstractObjectProcessor<T>
AProcessor
implementation for associating rows extracted from any implementation ofAbstractParser
intoMasterDetailRecord
instances.For each row processed, a call to
isMasterRecord(String[], Context)
will be made to identify whether or not it is a master row.The detail rows are automatically associated with the master record in an instance of
MasterDetailRecord
.When the master record is fully processed (i.e.
MasterDetailRecord
contains a master row and all associated detail rows), it is sent to the user for processing inmasterDetailRecordProcessed(MasterDetailRecord, Context)
.Note this class extends
AbstractObjectProcessor
and value conversions provided byConversion
instances are fully supported.
-
-
Field Summary
Fields Modifier and Type Field Description private AbstractObjectListProcessor
detailProcessor
private boolean
isMasterRowAboveDetail
private MasterDetailRecord
record
-
Fields inherited from class com.univocity.parsers.common.DefaultConversionProcessor
conversions
-
-
Constructor Summary
Constructors Constructor Description AbstractMasterDetailProcessor(AbstractObjectListProcessor detailProcessor)
Creates a MasterDetailProcessor assuming master records are positioned above its detail records in the input.AbstractMasterDetailProcessor(RowPlacement rowPlacement, AbstractObjectListProcessor detailProcessor)
Creates a MasterDetailProcessor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
isMasterRecord(java.lang.String[] row, T context)
Queries whether or not the given row is a master record.protected abstract void
masterDetailRecordProcessed(MasterDetailRecord record, T context)
Invoked by the processor after a master row and all associated detail rows have been processed.void
processEnded(T context)
This method will by invoked by the parser once, after the parsing process stopped and all resources were closed.private void
processRecord(java.lang.Object[] row, T context)
Associates individual rows to aMasterDetailRecord
and invokesAbstractMasterDetailProcessor#masterDetailRecordProcessed(MasterDetailRecord, T)
when it is fully populated.void
processStarted(T context)
This method will by invoked by the parser once, when it is ready to start processing the input.void
rowProcessed(java.lang.Object[] row, T context)
Invoked by the parser after all values of a valid record have been processed and any conversions have been executed.void
rowProcessed(java.lang.String[] row, T context)
Invoked by the parser after all values of a valid record have been processed.-
Methods inherited from class com.univocity.parsers.common.DefaultConversionProcessor
applyConversions, convertAll, convertFields, convertIndexes, convertType, handleConversionError, initializeConversions, reverseConversions, toDataProcessingException
-
-
-
-
Field Detail
-
detailProcessor
private final AbstractObjectListProcessor detailProcessor
-
record
private MasterDetailRecord record
-
isMasterRowAboveDetail
private final boolean isMasterRowAboveDetail
-
-
Constructor Detail
-
AbstractMasterDetailProcessor
public AbstractMasterDetailProcessor(RowPlacement rowPlacement, AbstractObjectListProcessor detailProcessor)
Creates a MasterDetailProcessor- Parameters:
rowPlacement
- indication whether the master records are placed in relation its detail records in the input.Master record (Totals) Master record (Totals) above detail records under detail records Totals | 100 Item | 60 Item | 60 Item | 40 Item | 40 Totals | 100
detailProcessor
- theObjectRowListProcessor
that processes detail rows.
-
AbstractMasterDetailProcessor
public AbstractMasterDetailProcessor(AbstractObjectListProcessor detailProcessor)
Creates a MasterDetailProcessor assuming master records are positioned above its detail records in the input.- Parameters:
detailProcessor
- theAbstractObjectListProcessor
that processes detail rows.
-
-
Method Detail
-
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 interfaceProcessor<T extends Context>
- Overrides:
processStarted
in classAbstractObjectProcessor<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(java.lang.String[] row, T context)
Invoked by the parser after all values of a valid record have been processed.This method will then try to identify whether the given record is a master record.
If it is, any conversions applied to the fields of the master record will be executed;
Otherwise, the parsed row will be delegated to the
detailProcessor
given in the constructor, and a detail record will be associated with the currentMasterDetailRecord
- Specified by:
rowProcessed
in interfaceProcessor<T extends Context>
- Overrides:
rowProcessed
in classAbstractObjectProcessor<T extends Context>
- Parameters:
row
- the data extracted by the parser for an individual record.context
- A contextual object with information and controls over the current state of the parsing process
-
rowProcessed
public final void rowProcessed(java.lang.Object[] row, T context)
Invoked by the parser after all values of a valid record have been processed and any conversions have been executed.- Specified by:
rowProcessed
in classAbstractObjectProcessor<T extends Context>
- Parameters:
row
- the data extracted by the parser for an individual record.context
- A contextual object with information and controls over the current state of the parsing process
-
processRecord
private void processRecord(java.lang.Object[] row, T context)
Associates individual rows to aMasterDetailRecord
and invokesAbstractMasterDetailProcessor#masterDetailRecordProcessed(MasterDetailRecord, T)
when it is fully populated.- Parameters:
row
- a record extracted from the parser that had all (if any) conversions executed and is ready to be sent to the user.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 interfaceProcessor<T extends Context>
- Overrides:
processEnded
in classAbstractObjectProcessor<T extends Context>
- Parameters:
context
- A contextual object with information and controls over the state of the parsing process
-
isMasterRecord
protected abstract boolean isMasterRecord(java.lang.String[] row, T context)
Queries whether or not the given row is a master record.- Parameters:
row
- the data extracted by the parser for an individual record.context
- A contextual object with information and controls over the current state of the parsing process- Returns:
- true if the row is a master record, false if it is a detail record.
-
masterDetailRecordProcessed
protected abstract void masterDetailRecordProcessed(MasterDetailRecord record, T context)
Invoked by the processor after a master row and all associated detail rows have been processed.- Parameters:
record
- The master detail recordscontext
- A contextual object with information and controls over the current state of the parsing process
-
-