org.marc4j
Class ErrorHandler

java.lang.Object
  extended by org.marc4j.ErrorHandler

public class ErrorHandler
extends Object

Defines and describes errors encountered in the processing a given MARC record. Used in conjunction with the MarcPermissiveReader class.

Version:
$Revision: 1.8 $
Author:
Robert Haschart

Nested Class Summary
 class ErrorHandler.Error
           
 
Field Summary
static int ERROR_TYPO
          ERROR_TYPO indicates that an even less severe problem was found with the record, such as the record leader ends with characters other than "4500" or a field tag contains non-numeric characters the record contains a html-style entity reference such as & or "e; which was replaced with the unescaped version.
static int FATAL
          FATAL is the most severe error, it is usually set in conjunction with throwing an exception, generally no record is returned when a FATAL error occurs.
static int INFO
          INFO is used to pass information about the record translation process.
static int MAJOR_ERROR
          MAJOR_ERROR indicates that a serious problem existed with the record, such as a malformed directory or an invalid subfield tag, or an encoding error where missing data had to be inferred through some heuristic process.
static int MINOR_ERROR
          MINOR_ERROR indicates that a less serious problem existed with the record, such as a mismatch between the directory stated field sizes and the actual field sizes, or an encoding error where extraneous data had to be discarded to correctly interpret the data.
 
Constructor Summary
ErrorHandler()
           
 
Method Summary
 void addError(int severity, String message)
          Logs an error message using the stated severity level.
 void addError(String id, String field, String subfield, int severity, String message)
          Logs an error message using the stated severity level.
 List getErrors()
          Returns a list of all of the errors encountered in processing the current record.
 int getMaxSeverity()
          Returns the highest error severity level encountered in processing the current record.
 boolean hasErrors()
          Returns true if any errors (or warnings) were encountered in processing the current record.
 void reset()
          Resets the list of errors to empty.
 void setCurrentField(String curField)
          Sets the field tag to be stored for subsequent error messages that are logged
 void setCurrentSubfield(String curSubfield)
          Sets the subfield tag to be stored for subsequent error messages that are logged
 void setRecordID(String recordID)
          Sets the record ID to be stored for subsequent error messages that are logged If any previous messages are stored for the current record that don't have a stored record ID, set the value for those entries to this value also.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL

public static final int FATAL
FATAL is the most severe error, it is usually set in conjunction with throwing an exception, generally no record is returned when a FATAL error occurs. Although in some instances (a record with a field > 9999 bytes long) a record will be returned that can be used, but it cannot be written back out without causing an error.

See Also:
Constant Field Values

MAJOR_ERROR

public static final int MAJOR_ERROR
MAJOR_ERROR indicates that a serious problem existed with the record, such as a malformed directory or an invalid subfield tag, or an encoding error where missing data had to be inferred through some heuristic process. This indicates that although a record is returned, you cannot be sure that the record is not corrupted.

See Also:
Constant Field Values

MINOR_ERROR

public static final int MINOR_ERROR
MINOR_ERROR indicates that a less serious problem existed with the record, such as a mismatch between the directory stated field sizes and the actual field sizes, or an encoding error where extraneous data had to be discarded to correctly interpret the data.

See Also:
Constant Field Values

ERROR_TYPO

public static final int ERROR_TYPO
ERROR_TYPO indicates that an even less severe problem was found with the record, such as the record leader ends with characters other than "4500" or a field tag contains non-numeric characters the record contains a html-style entity reference such as & or "e; which was replaced with the unescaped version.

See Also:
Constant Field Values

INFO

public static final int INFO
INFO is used to pass information about the record translation process. It does not indicate an error. It usually will occur when a defaultEncoding value of "BESTGUESS" is passed in. INFO statements are generated to indicate which character encoding was determined to be the best fit for the data, and why.

See Also:
Constant Field Values
Constructor Detail

ErrorHandler

public ErrorHandler()
Method Detail

hasErrors

public boolean hasErrors()
Returns true if any errors (or warnings) were encountered in processing the current record. Note that if only INFO level messages are encountered for a given record, this method will return false.

Returns:
boolean - The highest error severity level encountered for the current record.

getMaxSeverity

public int getMaxSeverity()
Returns the highest error severity level encountered in processing the current record.

Returns:
int - The highest error severity level encountered for the current record.

getErrors

public List getErrors()
Returns a list of all of the errors encountered in processing the current record.

Returns:
List - A list of all of the errors encountered for the current record.

reset

public void reset()
Resets the list of errors to empty. This should be called at the beginning of processing of each record.


addError

public void addError(String id,
                     String field,
                     String subfield,
                     int severity,
                     String message)
Logs an error message using the stated severity level. Uses the values passed in id, field, and subfield to note the location of the error.

Parameters:
id - - the record ID of the record currently being processed
field - - the tag of the field currently being processed
subfield - - the subfield tag of the subfield currently being processed
severity - - An indication of the relative severity of the error that was encountered.
message - - A descriptive message about the error that was encountered.

addError

public void addError(int severity,
                     String message)
Logs an error message using the stated severity level. Uses the values stored in curRecordID, curField, and curSubfield to note the location of the error.

Parameters:
severity - - An indication of the relative severity of the error that was encountered.
message - - A descriptive message about the error that was encountered.

setRecordID

public void setRecordID(String recordID)
Sets the record ID to be stored for subsequent error messages that are logged If any previous messages are stored for the current record that don't have a stored record ID, set the value for those entries to this value also.

Parameters:
recordID - - the record ID of the record currently being processed

setCurrentField

public void setCurrentField(String curField)
Sets the field tag to be stored for subsequent error messages that are logged

Parameters:
curField - - the tag of the field currently being processed

setCurrentSubfield

public void setCurrentSubfield(String curSubfield)
Sets the subfield tag to be stored for subsequent error messages that are logged

Parameters:
curSubfield - - the subfield tag of the subfield currently being processed


Copyright © 2002-2006 Bas Peters. All Rights Reserved.