public abstract class AbstractMasterDetailProcessor<T extends Context> extends AbstractObjectProcessor<T>
Processor
implementation for associating rows extracted from any implementation of AbstractParser
into MasterDetailRecord
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 in masterDetailRecordProcessed(MasterDetailRecord, Context)
.
Note this class extends AbstractObjectProcessor
and value conversions provided by Conversion
instances are fully supported.
MasterDetailRecord
,
RowPlacement
,
AbstractParser
,
ObjectRowListProcessor
,
Processor
conversions
Constructor and 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
|
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
isMasterRecord(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.
|
void |
processStarted(T context)
This method will by invoked by the parser once, when it is ready to start processing the input.
|
void |
rowProcessed(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(String[] row,
T context)
Invoked by the parser after all values of a valid record have been processed.
|
applyConversions, convertAll, convertFields, convertIndexes, convertType, handleConversionError, initializeConversions, reverseConversions, toDataProcessingException
public AbstractMasterDetailProcessor(RowPlacement rowPlacement, AbstractObjectListProcessor detailProcessor)
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
- the ObjectRowListProcessor
that processes detail rows.public AbstractMasterDetailProcessor(AbstractObjectListProcessor detailProcessor)
detailProcessor
- the AbstractObjectListProcessor
that processes detail rows.public void processStarted(T context)
Processor
processStarted
in interface Processor<T extends Context>
processStarted
in class AbstractObjectProcessor<T extends Context>
context
- A contextual object with information and controls over the current state of the parsing processpublic final void rowProcessed(String[] row, T context)
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 current MasterDetailRecord
rowProcessed
in interface Processor<T extends Context>
rowProcessed
in class AbstractObjectProcessor<T extends Context>
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 processpublic final void rowProcessed(Object[] row, T context)
rowProcessed
in class AbstractObjectProcessor<T extends Context>
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 processpublic void processEnded(T context)
Processor
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()
.
processEnded
in interface Processor<T extends Context>
processEnded
in class AbstractObjectProcessor<T extends Context>
context
- A contextual object with information and controls over the state of the parsing processprotected abstract boolean isMasterRecord(String[] row, T context)
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 processprotected abstract void masterDetailRecordProcessed(MasterDetailRecord record, T context)
record
- The master detail recordscontext
- A contextual object with information and controls over the current state of the parsing processCopyright © 2022 Univocity Software Pty Ltd. All rights reserved.