com.ricebridge.csvman
Class BadLine

java.lang.Object
  extended bycom.ricebridge.csvman.BadLine

public class BadLine
extends Object

Description of a badly formatted data line.

This class describes a badly formatted data line. By default, CSV processing stops when a bad line is encountered and a CsvManagerException (CODE_bad_line) is thrown. The CsvManagerException.getBadLine method returns a BadLine object describing the problem.

When CsvManager.setRunInbackground is true, the bad lines are collected and can be obtained using the CsvManager.getBadLines method.

Each bad line has the following attributes:

Sometimes the original data line is not available and the previous line or an empty String is provided. For example, for an error at the start of loading, no lines have been read yet, but a single BadLine object is still generated for consistency of error handling.

If you implement LineListener, parsing errors in the CSV data are reported via LineListener.handleBadLine. You can also return your own BadLine objects from LineListener.handleLine if you encounter a semantic data error. BadLine objects are also created when LineProvider instances throw an Exception. This maintains the accuracy of the CsvManager statistics.

You may subclass BadLine in order to add your own additional error description information.

The Source Code of this Java class is available under a BSD-style license.

See Also:
LineListener, LineProvider

Field Summary
protected  String iErrorMsg
          A technical error message describing the problem with the original data line.
protected  int iErrorType
          The type of error, syntactic or semantic.
protected  Exception iException
          The Exception that caused the bad line, if any.
protected  long iLineNumber
          The line number of the bad data line, counting from 1.
protected  String iOriginalLine
          The original text of the data line.
static int SEMANTIC
          Indicate that the data line was semantically invalid and that the value of one or more data fields is incorrect.
static int SYNTAX
          Indicate that the data line was syntactically invalid and could not be parsed correctly as a CSV format line.
 
Constructor Summary
BadLine(long pLineNumber, String pOriginalLine, String pErrorMsg)
          Create a SEMANTIC error description of a bad data line.
BadLine(long pLineNumber, String pOriginalLine, String pErrorMsg, Exception pException)
          Create an SEMANTIC error description caused by a particular Exception.
BadLine(long pLineNumber, String pOriginalLine, String pErrorMsg, int pErrorType)
          Create an error description of type pErrorType (SYNTAX or SEMANTIC).
BadLine(long pLineNumber, String pOriginalLine, String pErrorMsg, int pErrorType, Exception pException)
          Create an error description of a bad data line.
 
Method Summary
protected  void appendErrorMsg(String pAppend)
          Append more text to the error message.
 String getErrorMsg()
          Get the error message describing the bad data line.
 int getErrorType()
          Get the type of error that occurred.
 Exception getException()
          Get the Exception that caused the bad line.
 long getLineNumber()
          Get the line number of the bad data line.
 String getOriginalLine()
          Get the text of the bad data line.
 String toString()
          A utility method useful for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SEMANTIC

public static final int SEMANTIC
Indicate that the data line was semantically invalid and that the value of one or more data fields is incorrect.

See Also:
Constant Field Values

SYNTAX

public static final int SYNTAX
Indicate that the data line was syntactically invalid and could not be parsed correctly as a CSV format line.

See Also:
Constant Field Values

iOriginalLine

protected String iOriginalLine
The original text of the data line.


iErrorMsg

protected String iErrorMsg
A technical error message describing the problem with the original data line.


iErrorType

protected int iErrorType
The type of error, syntactic or semantic.


iLineNumber

protected long iLineNumber
The line number of the bad data line, counting from 1.


iException

protected Exception iException
The Exception that caused the bad line, if any.

Constructor Detail

BadLine

public BadLine(long pLineNumber,
               String pOriginalLine,
               String pErrorMsg)
Create a SEMANTIC error description of a bad data line.

The LineListener.handleLine method can return a BadLine object if the data line is semantically invalid. Use this constructor to create the BadLine object to return. If there is no error, you should return null from the handleLine method.

Parameters:
pLineNumber - line number if the bad data line, available from handleLine parameters.
pOriginalLine - original text of the line in the CSV file, available from handleLine parameters.
pErrorMsg - your own description of the problem
See Also:
BadLine(long, String, String, int), BadLine(long, String, String, Exception), BadLine(long, String, String, int, Exception)

BadLine

public BadLine(long pLineNumber,
               String pOriginalLine,
               String pErrorMsg,
               int pErrorType)
Create an error description of type pErrorType (SYNTAX or SEMANTIC).

This constructor is used by CsvManager to create syntax error reports.

Parameters:
pLineNumber - line number if the bad data line, available from handleLine parameters.
pOriginalLine - original text of the line in the CSV file, available from handleLine parameters.
pErrorMsg - your own description of the problem
pErrorType - one of SYNTAX or SEMANTIC
See Also:
BadLine(long, String, String), BadLine(long, String, String, Exception), BadLine(long, String, String, int, Exception)

BadLine

public BadLine(long pLineNumber,
               String pOriginalLine,
               String pErrorMsg,
               Exception pException)
Create an SEMANTIC error description caused by a particular Exception.

Parameters:
pLineNumber - line number if the bad data line, available from handleLine parameters.
pOriginalLine - original text of the line in the CSV file, available from handleLine parameters.
pErrorMsg - your own description of the problem
pException - Exception that caused the bad line, optional
See Also:
BadLine(long, String, String), BadLine(long, String, String, int), BadLine(long, String, String, int, Exception)

BadLine

public BadLine(long pLineNumber,
               String pOriginalLine,
               String pErrorMsg,
               int pErrorType,
               Exception pException)
Create an error description of a bad data line.

Parameters:
pLineNumber - line number if the bad data line, available from handleLine parameters.
pOriginalLine - original text of the line in the CSV file, available from handleLine parameters.
pErrorMsg - your own description of the problem
pErrorType - one of SYNTAX or SEMANTIC
pException - Exception that caused the bad line, optional
See Also:
BadLine(long, String, String), BadLine(long, String, String, int), BadLine(long, String, String, Exception)
Method Detail

getLineNumber

public long getLineNumber()
Get the line number of the bad data line.

Line numbers always start at 1. If no line information is available, this method returns 0.


getOriginalLine

public String getOriginalLine()
Get the text of the bad data line.

If no line information is available, this method returns an empty string.


getErrorMsg

public String getErrorMsg()
Get the error message describing the bad data line.

This message is normally of a technical nature.


getErrorType

public int getErrorType()
Get the type of error that occurred.

The current error types are SEMANTIC, for invalid data values, and SYNTAX, for CSV data that cannot be parsed due to formatting errors.


getException

public Exception getException()
Get the Exception that caused the bad line.

WARNING: MAY BE NULL. There may not be a causing exception.


toString

public String toString()
A utility method useful for debugging.

returns a String in the format:

  [CSV:BadLine:1:error message text:SYNTAX|SEMANTIC:original data line text:exception msg]
  


appendErrorMsg

protected void appendErrorMsg(String pAppend)
Append more text to the error message.

Parameters:
pAppend - text to append


Copyright © 2003-2006 Ricebridge