BeanIO 1.2.3

org.beanio.parser
Class Record

java.lang.Object
  extended by org.beanio.parser.Record
Direct Known Subclasses:
DelimitedRecord, XmlRecord

public class Record
extends Object

A Record holds state information about the last record read from an input stream. A single Record instance is used repeatedly while reading the input stream. Before each record is read, clear() is called to clear the state of the last record.

Since:
1.0
Author:
Kevin Seim

Constructor Summary
Record()
          Constructs a new Record.
 
Method Summary
 String addFieldError(String fieldName, String fieldText, String rule, Object... params)
          Adds a field error to this record.
protected  void addFieldErrorMessage(String fieldName, String message)
          Adds a field error message.
 String addRecordError(String rule, Object... params)
          Adds a record level error to this record.
protected  void addRecordErrorMessage(String message)
          Adds a record level error message.
 void clear()
          Clears the current state of the record before the next record is read.
 BeanReaderContext getContext()
          Returns the current state of the bean reader stored by this class.
 int getFieldOffset()
          Returns the index (or offset) of the current collection being parsed.
 List<Integer> getFieldOffsets()
          Returns the stack of field offsets.
 String getFieldText(String fieldName)
          Returns the unparsed text of a field from this record (if set).
 String getFieldText(String fieldName, int index)
          Returns the unparsed text of a field from this record (if set).
 Locale getLocale()
          Returns the locale used to format error messages.
 int getRecordLineNumber()
          Returns the starting line number of the last record read from the record reader.
 String getRecordName()
          Returns the name of the last record read from the record reader, or null if not known.
 String getRecordText()
          Returns the raw text of the last record read from the record reader.
 boolean hasFieldErrors()
          Returns true if a field error was reported while parsing this record.
 boolean hasFieldErrors(String fieldName)
          Returns true if a field error was reported for a specific field.
 boolean hasRecordErrors()
          Returns true if a record level error was reported while parsing this record.
 void popField()
          Pops the last field from the stack.
 void pushField()
          Pushes a field onto the stack.
 void setFieldOffset(int index)
          Sets the current index of the collection being parsed, from which all subsequent parsing will be offset.
 void setFieldText(String fieldName, String text)
          Sets the raw field text for a named field.
 void setLineNumber(int lineNumber)
          Sets the starting line number of the last record read from the record reader.
 void setLocale(Locale locale)
          Sets the locale used to format error messages.
 void setMessageContext(MessageFactory messageContext)
          Sets the MessageContext to use to format erorr messages.
 void setRecordName(String recordName)
          Sets the name of the last record read from the record reader.
 void setRecordText(String text)
          Sets the raw text of the last record read from the record reader.
 void setValue(Object value)
          Sets the value of the record as returned from the RecordReader
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Record

public Record()
Constructs a new Record.

Method Detail

clear

public void clear()
Clears the current state of the record before the next record is read.


setValue

public void setValue(Object value)
Sets the value of the record as returned from the RecordReader

Parameters:
value - the record value read by a record reader
See Also:
RecordReader

getContext

public BeanReaderContext getContext()
Returns the current state of the bean reader stored by this class.

Returns:
the current state of the reader

hasFieldErrors

public boolean hasFieldErrors()
Returns true if a field error was reported while parsing this record.

Returns:
true if a field error was reported

hasFieldErrors

public boolean hasFieldErrors(String fieldName)
Returns true if a field error was reported for a specific field.

Parameters:
fieldName - the name of the field to check
Returns:
true if an error was reported for the field

hasRecordErrors

public boolean hasRecordErrors()
Returns true if a record level error was reported while parsing this record.

Returns:
true if a record level error was reported

addFieldError

public String addFieldError(String fieldName,
                            String fieldText,
                            String rule,
                            Object... params)
Adds a field error to this record.

Parameters:
fieldName - the name of the field in error
fieldText - the invalid field text
rule - the name of the failed validation rule
params - an optional list of parameters for formatting the error message
Returns:
the formatted field error message

addRecordError

public String addRecordError(String rule,
                             Object... params)
Adds a record level error to this record.

Parameters:
rule - the name of the failed validation rule
params - an optional list of parameters for formatting the error message
Returns:
the formatted record error message

addFieldErrorMessage

protected void addFieldErrorMessage(String fieldName,
                                    String message)
Adds a field error message.

Parameters:
fieldName - the name of the field
message - the error message to add

addRecordErrorMessage

protected void addRecordErrorMessage(String message)
Adds a record level error message.

Parameters:
message - the error message to add

getRecordText

public String getRecordText()
Returns the raw text of the last record read from the record reader.

Returns:
the raw text of the last record read

setRecordText

public void setRecordText(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.

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 String getRecordName()
Returns the name of the last record read from the record reader, or null if not known.

Returns:
the name of the record

setRecordName

public void setRecordName(String recordName)
Sets the name of the last record read from the record reader.

Parameters:
recordName -

getLocale

public Locale getLocale()
Returns the locale used to format error messages.

Returns:
the locale used to format erorr messages

setLocale

public void setLocale(Locale locale)
Sets the locale used to format error messages.

Parameters:
locale -

setMessageContext

public void setMessageContext(MessageFactory messageContext)
Sets the MessageContext to use to format erorr messages.

Parameters:
messageContext - the MessageContext to use to format erorr messages

setFieldText

public void setFieldText(String fieldName,
                         String text)
Sets the raw field text for a named field.

Parameters:
fieldName - the name of the field
text - the raw field text

getFieldText

public String getFieldText(String fieldName)
Returns the unparsed text of a field from this record (if set).

If the field is a collection, this method returns the field text for the first occurrence of the field.

Parameters:
fieldName - the name of the field to get the text for
Returns:
the unparsed field text
See Also:
setFieldText(String, String)

getFieldText

public String getFieldText(String fieldName,
                           int index)
Returns the unparsed text of a field from this record (if set).

Parameters:
fieldName - the name of the field to get the text for
index - the index of the field, beginning at 0, for collection type fields
Returns:
the unparsed field text
See Also:
setFieldText(String, String)

pushField

public void pushField()
Pushes a field onto the stack.


setFieldOffset

public void setFieldOffset(int index)
Sets the current index of the collection being parsed, from which all subsequent parsing will be offset.

Parameters:
index - the current collection index

getFieldOffset

public int getFieldOffset()
Returns the index (or offset) of the current collection being parsed.

Returns:
the index of the current collection being parsed

popField

public void popField()
Pops the last field from the stack.


getFieldOffsets

public List<Integer> getFieldOffsets()
Returns the stack of field offsets. The most recently parsed field is at the beginning of the list.

Returns:
the field offset stack

toString

public String toString()
Overrides:
toString in class Object

BeanIO 1.2.3

Copyright © 2010-2012 Kevin Seim