com.ricebridge.csvman
Interface FieldListener

All Known Implementing Classes:
FieldListenerSupport

public interface FieldListener

DEPRECATED — DO NOT USE.

This interface is included for backwards compatibility only and will be removed in CSV Manager 2.x

Implement this interface by extending FieldListenerSupport to receive each data field as it is loaded.

It is possible to handle each data field separately with this callback interface. Pass an instance of FieldListener to CsvManager.setFieldListener(com.ricebridge.csvman.FieldListener) and the CsvManager will call the addField(java.lang.String) method each time a data field is loaded. The String value of each data field is passed to the FieldListener using addField(java.lang.String). At the end of each data line, the endLine(java.lang.String, long) method is called. When a badly formatted line is encountered, the badLine(com.ricebridge.csvman.BadLine) method is called. Note that a LineListener object is always used as part of the CSV loading process, so LineListener.handleBadLine(com.ricebridge.csvman.BadLine) will also be called. During loading, FieldListener methods are always called before LineListener methods.

If you set CsvManager.setIgnoreBadLines(boolean) to true then loading of CSV data will continue past any badly formatted data lines. If this setting is false (the default), then loading is halted and a CsvManagerException (CODE_bad_line) is thrown after badLine is called.

To use a FieldListener, just use the CsvManager.load* methods in the usual manner. The FieldListener functionality is independent of the main loading functionality which uses LineListener.

An example of a FieldListener is provided by DebugFieldListener. This is a simple FieldListener implementation that prints out debugging information as each data field is parsed. You can use it to see exactly how far into your CSV file the parser gets before failing.

Important: You should implement this interface by extending the helper class FieldListenerSupport. This helper class adds fault tolerance and helps make your FieldListener implementation compatible with any future changes to the CSV Manager API.

Note: you may assume in your implementation that no parameters are null.

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

See Also:
FieldListenerSupport, CsvManager, CsvManagerException

Method Summary
 void addField(String pValue)
          Deprecated. Called each time a data field is loaded.
 void badLine(BadLine pBadLine)
          Deprecated. Called when a badly formatted data line is encountered.
 BadLine endLine(String pOriginalLine, long pLineNumber)
          Deprecated. Called each time the end of a data line is reached.
 void endLoad()
          Deprecated. Called just after loading of the CSV data ends.
 void startLoad()
          Deprecated. Called just before loading of the CSV data starts.
 

Method Detail

startLoad

public void startLoad()
Deprecated. 
Called just before loading of the CSV data starts.

You should use this method to initialise any data containers in your FieldListener.

This method is called before LineListener.startProcess().

See Also:
endLoad()

endLoad

public void endLoad()
Deprecated. 
Called just after loading of the CSV data ends.

You should use this method to release any resources used by your FieldListener.

This method is called before LineListener.endProcess().

See Also:
startLoad()

addField

public void addField(String pValue)
Deprecated. 
Called each time a data field is loaded. The String value of the data field is provided.

This method is called before LineListener.handleLine(java.lang.String[], int, long, java.lang.String).

Note: implement this method by implementing FieldListenerSupport.addFieldImpl(java.lang.String).

Parameters:
pValue - String value of data field

endLine

public BadLine endLine(String pOriginalLine,
                       long pLineNumber)
Deprecated. 
Called each time the end of a data line is reached.

If you encounter any errors in the data fields for the current line, use this method to report them by returning a BadLine object describing the error (If you also return a BadLine from a FieldListener from the same line, the error message from the BadLine returned here will be appended to the FieldListener BadLine error message. This is to ensure that only one BadLine object is created per bad line). If the data is valid, then return null to indicate that everything is OK.

Note: this method is called before LineListener.handleLine(java.lang.String[], int, long, java.lang.String).

Note: implement this method by implementing FieldListenerSupport.endLineImpl(java.lang.String, long).

Parameters:
pLineNumber - line number index, counting from 1
pOriginalLine - original line of data
Returns:
null if line is OK, BadLine object if line was bad in some way

badLine

public void badLine(BadLine pBadLine)
Deprecated. 
Called when a badly formatted data line is encountered.

This method is only called once if CsvManager.setIgnoreBadLines(boolean) is true. See LineListener.handleBadLine(com.ricebridge.csvman.BadLine) for more details about the pBadLine parameter. If you return a BadLine from endLine(java.lang.String, long), then it is not subsequently passed into this method. Only BadLines generated externally are passed into the FieldListener.

This method is called before LineListener.handleBadLine(com.ricebridge.csvman.BadLine).

Note: implement this method by implementing FieldListenerSupport.badLineImpl(com.ricebridge.csvman.BadLine).

Parameters:
pBadLine - BadLine object describing problem
See Also:
LineListener.handleBadLine(com.ricebridge.csvman.BadLine)


Copyright © 2003-2006 Ricebridge