Package org.beanio.internal.parser
Class ErrorContext
- java.lang.Object
-
- org.beanio.internal.parser.ErrorContext
-
- All Implemented Interfaces:
java.lang.Cloneable,RecordContext
public class ErrorContext extends java.lang.Object implements RecordContext, java.lang.Cloneable
- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description ErrorContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFieldError(java.lang.String fieldName, java.lang.String message)Adds a field error message.voidaddRecordError(java.lang.String message)Adds a record level error message.voidclear()Clears this context;intgetFieldCount(java.lang.String fieldName)Returns the number of times the given field was present in the stream.java.util.Map<java.lang.String,java.util.Collection<java.lang.String>>getFieldErrors()Returns aMapof all field errors.java.util.Collection<java.lang.String>getFieldErrors(java.lang.String fieldName)Returns the field errors for a given field.java.lang.StringgetFieldText(java.lang.String fieldName)Returns the raw text of a field found in this record.java.lang.StringgetFieldText(java.lang.String fieldName, int index)Returns the raw text of a field found in this record.intgetLineNumber()Returns the line number of this record, or 0 if the stream does not use new lines to terminate records.java.util.Collection<java.lang.String>getRecordErrors()Returns a collection of record level error messages.intgetRecordLineNumber()Returns the starting line number of the last record read from the record reader.java.lang.StringgetRecordName()Returns the name of the last record read from the record reader, ornullif not known.java.lang.StringgetRecordText()Returns the raw text of the last record read from the record reader.booleanhasErrors()Returns whether this record has any record or field level errors.booleanhasFieldErrors()Returns whether there are one or more field level errors.booleanhasRecordErrors()Returns whether there are one or more record level errors.voidsetFieldText(java.lang.String fieldName, java.lang.String text, boolean repeating)Sets the raw field text for a named field.voidsetLineNumber(int lineNumber)Sets the starting line number of the last record read from the record reader.voidsetRecordName(java.lang.String recordName)Sets the name of the last record read from the record reader.voidsetRecordText(java.lang.String text)Sets the raw text of the last record read from the record reader.
-
-
-
Method Detail
-
clear
public void clear()
Clears this context;
-
getRecordText
public java.lang.String getRecordText()
Returns the raw text of the last record read from the record reader.- Specified by:
getRecordTextin interfaceRecordContext- Returns:
- the raw text of the last record read
-
setRecordText
public void setRecordText(java.lang.String text)
Sets the raw text of the last record read from the record reader.- Parameters:
text- the raw text of the last record read
-
getRecordLineNumber
public int getRecordLineNumber()
Returns the starting line number of the last record read from the record reader.- Specified by:
getRecordLineNumberin interfaceRecordContext- Returns:
- the line number of the last record
-
setLineNumber
public void setLineNumber(int lineNumber)
Sets the starting line number of the last record read from the record reader.- Parameters:
lineNumber- the line number of the last record
-
getRecordName
public java.lang.String getRecordName()
Returns the name of the last record read from the record reader, ornullif not known.- Specified by:
getRecordNamein interfaceRecordContext- Returns:
- the name of the record
-
setRecordName
public void setRecordName(java.lang.String recordName)
Sets the name of the last record read from the record reader.- Parameters:
recordName- the record name
-
addFieldError
public void addFieldError(java.lang.String fieldName, java.lang.String message)Adds a field error message.- Parameters:
fieldName- the name of the fieldmessage- the error message to add
-
addRecordError
public void addRecordError(java.lang.String message)
Adds a record level error message.- Parameters:
message- the error message to add
-
setFieldText
public void setFieldText(java.lang.String fieldName, java.lang.String text, boolean repeating)Sets the raw field text for a named field.- Parameters:
fieldName- the name of the fieldtext- the raw field textrepeating- whether the field repeats in the stream
-
hasErrors
public boolean hasErrors()
Description copied from interface:RecordContextReturns whether this record has any record or field level errors.- Specified by:
hasErrorsin interfaceRecordContext- Returns:
- true if this record has any errors, false otherwise
-
hasRecordErrors
public boolean hasRecordErrors()
Description copied from interface:RecordContextReturns whether there are one or more record level errors.- Specified by:
hasRecordErrorsin interfaceRecordContext- Returns:
- true if there are one or more record level error, false otherwise
-
getRecordErrors
public java.util.Collection<java.lang.String> getRecordErrors()
Description copied from interface:RecordContextReturns a collection of record level error messages.- Specified by:
getRecordErrorsin interfaceRecordContext- Returns:
- the
Collectionof record level error messages
-
getFieldCount
public int getFieldCount(java.lang.String fieldName)
Description copied from interface:RecordContextReturns the number of times the given field was present in the stream.- Specified by:
getFieldCountin interfaceRecordContext- Parameters:
fieldName- the name of the field- Returns:
- the number of times the field was present in the stream
-
getFieldText
public java.lang.String getFieldText(java.lang.String fieldName)
Description copied from interface:RecordContextReturns the raw text of a field found in this record. Field text may be null under the following circumstances:- A record level exception was thrown before a field was parsed
fieldNamewas not declared in the mapping file- The field was not present in the record
If the field repeats in the stream, this method returns the field text for the first occurrence of the field.
- Specified by:
getFieldTextin interfaceRecordContext- Parameters:
fieldName- the name of the field- Returns:
- the unparsed field text
-
getFieldText
public java.lang.String getFieldText(java.lang.String fieldName, int index)Description copied from interface:RecordContextReturns the raw text of a field found in this record. Field text may be null under the following circumstances:- A record level exception was thrown before a field was parsed
fieldNamewas not declared in the mapping file- The field was not present in the record
- Specified by:
getFieldTextin interfaceRecordContext- Parameters:
fieldName- the name of the field to get the text forindex- the index of the field (beginning at 0), for repeating fields- Returns:
- the unparsed field text
-
hasFieldErrors
public boolean hasFieldErrors()
Description copied from interface:RecordContextReturns whether there are one or more field level errors.- Specified by:
hasFieldErrorsin interfaceRecordContext- Returns:
trueif there are one or more field level errors, false otherwise
-
getFieldErrors
public java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> getFieldErrors()
Description copied from interface:RecordContextReturns aMapof all field errors. The name of the field is used for theMapkey, and the value is aCollectionof field error messages.- Specified by:
getFieldErrorsin interfaceRecordContext- Returns:
- a
Mapof all field errors
-
getFieldErrors
public java.util.Collection<java.lang.String> getFieldErrors(java.lang.String fieldName)
Description copied from interface:RecordContextReturns the field errors for a given field.- Specified by:
getFieldErrorsin interfaceRecordContext- Parameters:
fieldName- the name of the field- Returns:
- the
Collectionof field errors, or null if no errors were reported for the field
-
getLineNumber
public int getLineNumber()
Description copied from interface:RecordContextReturns the line number of this record, or 0 if the stream does not use new lines to terminate records.- Specified by:
getLineNumberin interfaceRecordContext- Returns:
- the line number of this record
-
-