public abstract class UnmarshallingContext extends ParsingContext
Subclasses must implement setRecordValue(Object)
which is called
by nextRecord()
each time a new record is read from the RecordReader
.
The Java object used to represent a record is dependent on the RecordReader
implementation for the stream format.
MARSHALLING, UNMARSHALLING
Constructor and Description |
---|
UnmarshallingContext()
Constructs a new UnmarshallingContext.
|
Modifier and Type | Method and Description |
---|---|
String |
addFieldError(String fieldName,
String fieldText,
String rule,
Object... params)
Adds a field error to this record.
|
protected String |
addRecordError(ErrorContext errorContext,
String rule,
Object... params)
Adds a record level error to this record.
|
String |
addRecordError(String rule,
Object... params)
Adds a record level error to this record.
|
int |
getLineNumber()
Returns the last line number read from the input stream.
|
Locale |
getLocale()
Returns the locale to format error messages in.
|
MessageFactory |
getMessageFactory()
Returns the
MessageFactory for formatting error messages. |
char |
getMode()
Returns the parsing mode.
|
RecordContext |
getRecordContext(int index)
Returns the record context for a record read for the last unmarshalled bean object.
|
int |
getRecordCount()
Returns the number of record read for the last unmarshalled bean object.
|
RecordReader |
getRecordReader()
Returns the
RecordReader to read from. |
boolean |
hasFieldErrors()
Returns true if a field error was reported while parsing
this record.
|
boolean |
hasRecordErrors()
Returns true if a record level error was reported while parsing
this record.
|
boolean |
isEOF()
Returns whether the end of the stream was reached after
nextRecord() was called. |
BeanReaderException |
newMalformedRecordException(RecordIOException cause) |
BeanReaderException |
newUnsatisfiedGroupException(String groupName) |
BeanReaderException |
newUnsatisfiedRecordException(String recordName) |
void |
nextRecord()
Reads the next record from the input stream and calls
setRecordValue(Object) . |
void |
prepare(String componentName,
boolean isRecordGroup)
Prepares this context for unmarshalling a record (or group of records that
are combined to form a single bean object).
|
void |
recordCompleted()
Either this method (or
recordSkipped() ) must be invoked after a
record is unmarshalled, even if an error has occurred. |
protected ErrorContext |
recordException(String recordName,
String rule,
Object... params)
Handles a record level exception and returns a new
ErrorContext for
the exception. |
void |
recordSkipped()
This method should be invoked when a record is skipped.
|
void |
recordStarted(String recordName)
This method must be invoked before a record is unmarshalled.
|
BeanReaderException |
recordUnexpectedException(String recordName) |
BeanReaderException |
recordUnidentifiedException() |
void |
setFieldText(String fieldName,
String text)
Sets the raw field text for a named field.
|
void |
setLocale(Locale locale)
Sets the locale to format error messages in.
|
void |
setMessageFactory(MessageFactory messageFactory)
Sets the
MessageFactory for formatting error messages. |
void |
setRecordReader(RecordReader recordReader)
Sets the
RecordReader to read from. |
abstract void |
setRecordValue(Object value)
Sets the value of the record returned from the RecordReader
|
Object |
toRecordValue(List<String> list)
Converts a
List to a record value. |
Object |
toRecordValue(Node node)
Converts a
Node to a record value. |
Object |
toRecordValue(String[] array)
Converts a String[] to a record value.
|
void |
validate()
Validates all unmarshalled records and throws an exception if any record
is invalid.
|
clear, createHeap, getAdjustedFieldPosition, getLocal, getRelativeFieldIndex, isRepeating, popIteration, pushIteration, setLocal
public UnmarshallingContext()
public final char getMode()
ParsingContext
getMode
in class ParsingContext
ParsingContext.UNMARSHALLING
or ParsingContext.MARSHALLING
public abstract void setRecordValue(Object value)
value
- the record value read by a record readerRecordReader
public Object toRecordValue(String[] array)
array
- the String[] to convertpublic Object toRecordValue(List<String> list)
List
to a record value.list
- the List to convertpublic Object toRecordValue(Node node)
Node
to a record value.node
- the Node to convertpublic void prepare(String componentName, boolean isRecordGroup)
componentName
- the record or group name to be unmarshalledisRecordGroup
- true if the component is a group, false if it is a recordpublic final void recordStarted(String recordName)
recordName
- the name of the recordpublic final void recordCompleted()
recordSkipped()
) must be invoked after a
record is unmarshalled, even if an error has occurred.public final void recordSkipped()
public final void validate() throws InvalidRecordException
InvalidRecordException
- if one or more unmarshalled records were invalidpublic final int getRecordCount()
public final RecordContext getRecordContext(int index) throws IndexOutOfBoundsException
index
- the index of the recordRecordContext
IndexOutOfBoundsException
- if there is no record for the given indexpublic final void setFieldText(String fieldName, String text)
fieldName
- the name of the fieldtext
- the raw field textpublic final boolean hasFieldErrors()
public final boolean hasRecordErrors()
public String addFieldError(String fieldName, String fieldText, String rule, Object... params)
fieldName
- the name of the field in errorfieldText
- the invalid field textrule
- the name of the failed validation ruleparams
- an optional list of parameters for formatting the error messagepublic final String addRecordError(String rule, Object... params)
rule
- the name of the failed validation ruleparams
- an optional list of parameters for formatting the error messageprotected String addRecordError(ErrorContext errorContext, String rule, Object... params)
errorContext
- the error context to updaterule
- the name of the failed validation ruleparams
- an optional list of parameters for formatting the error messagepublic BeanReaderException newMalformedRecordException(RecordIOException cause)
public BeanReaderException newUnsatisfiedGroupException(String groupName)
public BeanReaderException newUnsatisfiedRecordException(String recordName)
public BeanReaderException recordUnexpectedException(String recordName)
public BeanReaderException recordUnidentifiedException()
protected ErrorContext recordException(String recordName, String rule, Object... params)
ErrorContext
for
the exception.recordName
- the name of the record that failedrule
- the record level rule that failed validationparams
- message parameters for formatting the error messageErrorContext
public final void nextRecord() throws BeanReaderException
setRecordValue(Object)
.BeanReaderException
- if the next node cannot be determinedpublic final int getLineNumber()
public final boolean isEOF()
nextRecord()
was called.public final RecordReader getRecordReader()
RecordReader
to read from.RecordReader
to read frompublic final void setRecordReader(RecordReader recordReader)
RecordReader
to read from.recordReader
- the RecordReader
to read frompublic MessageFactory getMessageFactory()
MessageFactory
for formatting error messages.MessageFactory
public void setMessageFactory(MessageFactory messageFactory)
MessageFactory
for formatting error messages.messageFactory
- the MessageFactory
public Locale getLocale()
Locale