org.ceryle.util
Class MessageHandlerImpl

java.lang.Object
  extended by org.ceryle.util.MessageHandlerImpl
All Implemented Interfaces:
MessageHandler, MessageWriter, ErrorHandler

public class MessageHandlerImpl
extends Object
implements MessageHandler, MessageWriter, ErrorHandler

Implements MessageHandler, a messaging API. This class receives messaging events, also implementing and extending the SAX ErrorHandler interface. This also incorporates an application idle checker, which returns true on isIdle() following the delay set by the idle handler. It is the occurrence of message events or a call to active() that delays going into an idle state.

There are seven types of message handling, with resulting action based on which method is called:

method type state description
localizenormal returns localized version of message.
status normal writes localized message to status (UI if available, message if not).
log normal writes timestamped, localized message to log file.
message normal writes localized message to designated output.
notice normal writes localized notice to designated output.
warning error writes localized warning message to designated output and performs a system exit if the warning count exceeds maxWarnings.
error error writes localized error message to designated output and performs a system exit if the error count exceeds maxErrors.
fatal error writes localized error message to stderr and performs a system exit.

Note that status messages do not change the MessageHandler status.

The first parameter id may be a MessageId or MsgId reference from either of the localized ListResourceBundles Msg or Messages, or if not recognized as such, will be treated simply as a message String.

Following the initial id, each of the four message types is available with one to four additional passed parameters, plus several include exception tunnelling (for compliance with SAX's ErrorHandler). While there is considerable flexibility in available methods, the minimum pattern followed for all is similar to message():

    public String message( String id )
    public String message( String id, String arg1 )
    public String message( String id, String arg1, String arg2 )
    public String message( String id, String arg1, String arg2, String arg3 )
    public String message( String id, String arg1, String arg2, String arg3, String arg4 )
 

localize() is also available with as many as six parameters.

Almost all return the resultant localized String, though in most cases (except for localize()) in Ceryle this is not used. warning, error and fatalError write output to stderr or to a designated File errorfile.

Note on Log4J

Previous versions of Ceryle used its own Logger class for logging, which worked fine, but the ready availability of Log4J as part of the pool of included libraries made it seem almost silly not to use it, so in recent versions log messages are now sent to Log4J, whose configuration file is in $CERYLE_HOME/resource/log4j.properties. Here's the useful Log4J methods in Level order:

   // Log4J printing methods:
   public void debug( Object message );
   public void info( Object message );
   public void warn( Object message );
   public void error( Object message );
   public void fatal( Object message );
 
Log4J will already be configured and running prior to the MessageHandler starting. (is this a good thing? does it really matter?)

Note on ResourceBundles

The static localize() methods found in the Localizer class uses the org.ceryle.util.Msg ResourceBundle, which is considered a "core" set of messages, used by XML and XNode services.

The Utilities class uses the org.ceryle.util.Msg, and org.ceryle.util.Message ResourceBundles, checking the incoming message ID and then using the appropriate ResourceBundle. This is done by using a cheap trick: all message IDs in the MsgId class begin with an underscore character.

Since:
JDK1.3
Version:
$Id: MessageHandlerImpl.java,v 3.6 2007-06-15 15:47:45 altheim Exp $
Author:
Murray Altheim
See Also:
MessageHandler, Localizer

Field Summary
static String CERYLE_LOG_FILE
          The default filename for the Ceryle log file.
protected  int errors
          Count of errors received by this MessageHandler.
protected static String m_logFilename
          The log filename.
protected  int maxErrors
          Maximum error count before exit (abort).
protected  int maxWarnings
          Maximum warning count before exit (abort).
static boolean permitExit
          When true, permits the MessageHandler to force an application exit upon a fatal error.
protected  int warnings
          Count of warnings received by this MessageHandler.
 
Fields inherited from interface org.ceryle.util.MessageHandler
DEBUG, ERROR, FATAL, INFO, LOCALIZE, LOG, LOG_FEATURE_PFX, LOG_LEVEL, MESSAGE_VERBOSE, MSG_PROPERTY_PFX, NOTICE, OFF, OK, WARN
 
Constructor Summary
MessageHandlerImpl()
          Default constructor; initializes the idle handler and all warning and error counters using default values.
MessageHandlerImpl(Properties properties)
          Constructor with Properties properties.
MessageHandlerImpl(Properties properties, SafeQuit safequit)
          Constructor with an optional Properties properties and an optional implementer of the SafeQuit API.
 
Method Summary
 void active()
          Indicates any kind of application activity, called upon any kind of system message sent to the MessageHandler (except requests for localization).
 void closeErrorFile()
          Closes the error file filename, if open.
 String error(Exception exception)
          Tunnel an existing Exception.
 void error(SAXParseException exception)
          Tunnel an existing SAXParseException.
 String error(String id)
          Handle an exception provided an error message and no arguments.
 String error(String id, Exception exception)
          Handle an exception provided an error message and no arguments, and the tunneled Exception.
 String error(String id, String arg)
          Handle an exception provided an error message and one argument.
 String error(String id, String arg, Exception exception)
          Handle an exception provided an error message with one argument and the tunneled Exception.
 String error(String id, String arg1, String arg2)
          Handle an exception provided an error message and two arguments.
 String error(String id, String arg1, String arg2, Exception exception)
          Handle an exception provided an error message with two arguments and the tunneled Exception.
 String error(String id, String arg1, String arg2, String arg3)
          Handle an exception provided an error message and three arguments.
 void exit(int status, String exitMessage, Exception exception)
          Aborts all processes and terminates the currently running application.
 String fatalError(Error error)
          A method which handles a fatal error provided the actual java.lang.Error.
 String fatalError(Exception exception)
          A method which handles a fatal exception given the tunneled Exception.
 void fatalError(SAXParseException exception)
          A method which handles a fatal exception given a tunneled SAXParseException.
 String fatalError(String id)
          A method which handles a fatal exception given an error message String.
 String fatalError(String id, Exception exception)
          A method which handles a fatal exception given an error message String and the tunneled Exception.
 String fatalError(String id, String arg1)
          A method which handles a fatal exception given an error id, one argument.
 String fatalError(String id, String arg1, Exception exception)
          A method which handles a fatal exception given an error id, one argument, and the tunneled Exception.
 String fatalError(String id, String arg1, String arg2)
          A method which handles a fatal exception given an error id and two arguments.
 String fatalError(String id, String arg1, String arg2, Exception exception)
          A method which handles a fatal exception given an error id, two arguments, and the tunneled Exception.
 void flush()
          Flushes the error file if open.
 Clock getClock()
          Returns the Clock object used by this MessageHandler for generating timestamps.
static Properties getDefaultProperties()
          Return the default Properties for the MessageHandler.
 long getElapsed(boolean active, boolean millis)
          Returns a long indicating the amount of time passed since the application session began.
 int getErrorCount()
          Returns the current number of errors registered with this MessageHandler.
 Enumeration getErrorList()
          Returns an Enumeration of the current error list.
 Idler getIdler()
          Returns the Idler object used by this MessageHandler for keeping track of idle state.
static org.apache.log4j.Level getLogLevel(int state)
          Converts the provided MessageHandler state value to a Log4J Level.
 Properties getProperties()
          Return the current MessageHandler Properties.
 int getSignalThreshold()
          Return the current signal threshold setting.
 int getStatus()
          Return the current MessageHandler status:
OK no activity LOG a log message has occurred.
 String getStatusText(int status)
          Returns a localized String indicating the provided message status.
 int getWarningCount()
          Returns the current number of warnings registered with this MessageHandler.
 Enumeration getWarningList()
          Returns an Enumeration of the current warning list.
 Writer getWriter()
          Returns the Writer used by for this MessageHandler.
 boolean isIdle()
          Returns the current idle state.
 String localize(String id)
          Return a localized message given a message id and no arguments.
 String localize(String id, String arg1)
          Return a localized message given a message id and one argument.
 String localize(String id, String arg1, String arg2)
          Return a localized message given a message id and two arguments.
 String localize(String id, String arg1, String arg2, String arg3)
          Return a localized message given a message id and three arguments.
 String localize(String id, String arg1, String arg2, String arg3, String arg4)
          Return a localized message given a message id and four arguments.
 String localize(String id, String arg1, String arg2, String arg3, String arg4, String arg5)
          Return a localized message given a message id and five arguments.
 String localize(String id, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6)
          Return a localized message given a message id and six arguments.
 String log(String message)
          Write the message to the log file, given the message and no arguments.
 String log(String timeStamp, String id)
          Write the message to the log file, given an optional time stamp, a message id and no arguments.
 String log(String timeStamp, String id, String arg1)
          Write the message to the log file, given an optional time stamp, a message id and one argument.
 String log(String timeStamp, String id, String arg1, String arg2)
          Write the message to the log file, given an optional time stamp, a message id and two arguments.
 String log(String timeStamp, String id, String arg1, String arg2, String arg3)
          Write the message to the log file, given an optional time stamp, a message id and three arguments.
 String log(String timeStamp, String id, String arg1, String arg2, String arg3, String arg4)
          Write the message to the log file, given an optional time stamp, a message id and four arguments.
 String message(String id)
          Display a non-fatal informational message given a message id and no arguments.
 String message(String id, String arg1)
          Display a non-fatal informational message given a message id and one argument.
 String message(String id, String arg1, String arg2)
          Display a non-fatal informational message given a message id and two arguments.
 String message(String id, String arg1, String arg2, String arg3)
          Display a non-fatal informational message given a message id and three arguments.
 String message(String id, String arg1, String arg2, String arg3, String arg4)
          Display a non-fatal informational message given a message id and four arguments.
 String notice(String id)
          Display a highlighted notice given a notice id and no arguments.
 String notice(String id, String arg1)
          Display a highlighted notice given a notice id and one argument.
 String notice(String id, String arg1, String arg2)
          Display a highlighted notice given a notice id and two arguments.
 String notice(String id, String arg1, String arg2, String arg3)
          Display a highlighted notice given a notice id and three arguments.
 String notice(String id, String arg1, String arg2, String arg3, String arg4)
          Display a highlighted notice given a notice id and four arguments.
 void openErrorFile(String filename)
          Opens error file filename for writing, defining the Writer writer.
 void printStackTrace(Throwable throwable)
          Prints the stack trace from the provided Exception to the error output.
 void registerListener(MessageWriter msgwriter)
          Registers the provided object wi as the receiver for MessageHandler messaging events.
 void registerProcessor(Object processor)
          Registers the provided Object processor with this MessageHandler, so that in the event of a fatal error this might be set to null.
 void reset()
          Clears all warning and error counters and containers.
 void setMaxErrors(int newMax)
          Sets the maximum error count before exit (abort).
 void setMaxWarnings(int newMax)
          Sets the maximum warning count before exit (abort).
 void setProperties(Properties properties)
          Set MessageHandler properties to the provided Properties.
 void setSafeQuit(SafeQuit safequit)
          Sets the recipient for safe quit confirmation and quit messages.
 void setSignalThreshold(int status)
          Set signalling to the int value status.
 void status(String id)
          Display a status message to the UI if available (as a message if not) given a message id and no arguments.
 void status(String id, String arg1)
          Display a status message to the UI if available (as a message if not) given a message id and one argument.
 void status(String id, String arg1, String arg2)
          Display a status message to the UI if available (as a message if not) given a message id and two arguments.
 void status(String id, String arg1, String arg2, String arg3)
          Display a status message to the UI if available (as a message if not) given a message id and three arguments.
 void status(String id, String arg1, String arg2, String arg3, String arg4)
          Display a status message to the UI if available (as a message if not) given a message id and four arguments.
 String warning(Exception exception)
          Tunnel an existing Exception.
 void warning(SAXParseException exception)
          Tunnel an existing SAXParseException.
 String warning(String id)
          Display a non-fatal warning given an error message and no arguments.
 String warning(String id, String arg1)
          Display a non-fatal warning given an error id and one argument.
 String warning(String id, String arg1, String arg2)
          Display a non-fatal warning given an error id and two arguments.
 String warning(String id, String arg1, String arg2, String arg3)
          Display a non-fatal warning given an error id and three arguments.
 String writeMessage(int status, String message)
          Write the contents of the message to a message display with any indication of message type provided by the status parameter, whose values are one of the status values from MessageHandler.
 void writeMessage(String message)
          Writes the error message using the defined Writer.
 void writeStatus(String message)
          Display an informational message given a message String, using the defined Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

permitExit

public static boolean permitExit
When true, permits the MessageHandler to force an application exit upon a fatal error. The default is true.


CERYLE_LOG_FILE

public static final String CERYLE_LOG_FILE
The default filename for the Ceryle log file. The value is "ceryle.log".

See Also:
Constant Field Values

m_logFilename

protected static String m_logFilename
The log filename. If null, use default. This must be set prior to Logger instantiation.


errors

protected int errors
Count of errors received by this MessageHandler.


maxErrors

protected int maxErrors
Maximum error count before exit (abort). Allowed values 0-1000; default is 100.


warnings

protected int warnings
Count of warnings received by this MessageHandler.


maxWarnings

protected int maxWarnings
Maximum warning count before exit (abort). Allowed values 0-1000; default is 300.

Constructor Detail

MessageHandlerImpl

public MessageHandlerImpl()
Default constructor; initializes the idle handler and all warning and error counters using default values.


MessageHandlerImpl

public MessageHandlerImpl(Properties properties)
Constructor with Properties properties. Initializes the idle handler and all warning and error counters.


MessageHandlerImpl

public MessageHandlerImpl(Properties properties,
                          SafeQuit safequit)
Constructor with an optional Properties properties and an optional implementer of the SafeQuit API. Initializes the idle handler and all warning and error counters. If the Properties parameter is null, properties can be later set using setProperties(Properties).

Method Detail

getDefaultProperties

public static Properties getDefaultProperties()
Return the default Properties for the MessageHandler. This flags the verbose property as false. This can be overridden for logs setting a System property whose identifier matches the MessageHandler.LOG_LEVEL property.


setProperties

public void setProperties(Properties properties)
Set MessageHandler properties to the provided Properties. This method is called automatically if a non-null Properties object is provided upon instantiation of the class; otherwise it must be called manually (generally, upon receipt of the Properties read by the PropertyManager from a properties or preferences file).


getProperties

public Properties getProperties()
Return the current MessageHandler Properties.


setSafeQuit

public void setSafeQuit(SafeQuit safequit)
Sets the recipient for safe quit confirmation and quit messages.


getClock

public Clock getClock()
Returns the Clock object used by this MessageHandler for generating timestamps.

This is a MessageHandler API method.

Specified by:
getClock in interface MessageHandler

getIdler

public Idler getIdler()
Returns the Idler object used by this MessageHandler for keeping track of idle state.


getWriter

public Writer getWriter()
Returns the Writer used by for this MessageHandler.

Specified by:
getWriter in interface MessageHandler

registerProcessor

public void registerProcessor(Object processor)
Registers the provided Object processor with this MessageHandler, so that in the event of a fatal error this might be set to null.


registerListener

public void registerListener(MessageWriter msgwriter)
Registers the provided object wi as the receiver for MessageHandler messaging events.

This is a MessageHandler API method.

Specified by:
registerListener in interface MessageHandler

writeStatus

public void writeStatus(String message)
Display an informational message given a message String, using the defined Writer. If a MessageWriter has been externally registered, this method will never be called.

This is both a MessageWriter and MessageHandler API method.

Specified by:
writeStatus in interface MessageHandler
Specified by:
writeStatus in interface MessageWriter

writeMessage

public void writeMessage(String message)
Writes the error message using the defined Writer. If an MessageWriter has been externally registered, this method will never be called.

This is both a MessageWriter and MessageHandler API method.

Specified by:
writeMessage in interface MessageHandler
Specified by:
writeMessage in interface MessageWriter

writeMessage

public String writeMessage(int status,
                           String message)
Write the contents of the message to a message display with any indication of message type provided by the status parameter, whose values are one of the status values from MessageHandler.

This is both a MessageWriter and MessageHandler API method.

Specified by:
writeMessage in interface MessageHandler
Specified by:
writeMessage in interface MessageWriter
Returns:
the processed message, including any changes made.
See Also:
MessageHandler

active

public void active()
Indicates any kind of application activity, called upon any kind of system message sent to the MessageHandler (except requests for localization). This is blocked if the status of the message is less than the current signalling threshold.

Specified by:
active in interface MessageHandler

setSignalThreshold

public void setSignalThreshold(int status)
Set signalling to the int value status.

This is the level of message (i.e., MessageHandler status) that must be met to become an 'active' signal, indicated to the Idler as system activity. For example, setting the level to MessageHandler.WARN would require a warning or error message to be considered a signal.

Acceptable values are: MessageHandler.DEBUG, MessageHandler.LOG, MessageHandler.INFO, MessageHandler.NOTICE, MessageHandler.WARN, or MessageHandler.ERROR. Invalid values are ignored.


getSignalThreshold

public int getSignalThreshold()
Return the current signal threshold setting.


isIdle

public boolean isIdle()
Returns the current idle state. This always returns false if logging is inactive.


getElapsed

public long getElapsed(boolean active,
                       boolean millis)
Returns a long indicating the amount of time passed since the application session began. When the boolean active is true, the total includes only active (i.e., non-idle) time; when false, idle time is ignored. When the boolean millis is true, the value returned is in milliseconds; when false, in seconds.

If logging is not active, this always returns 0.


printStackTrace

public void printStackTrace(Throwable throwable)
Prints the stack trace from the provided Exception to the error output.

Specified by:
printStackTrace in interface MessageHandler

localize

public String localize(String id)
Return a localized message given a message id and no arguments. Note that the id can simply be a text message.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1)
Return a localized message given a message id and one argument.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1,
                       String arg2)
Return a localized message given a message id and two arguments.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1,
                       String arg2,
                       String arg3)
Return a localized message given a message id and three arguments.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1,
                       String arg2,
                       String arg3,
                       String arg4)
Return a localized message given a message id and four arguments.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1,
                       String arg2,
                       String arg3,
                       String arg4,
                       String arg5)
Return a localized message given a message id and five arguments.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
arg5 - argument substituting %5 in the message string.
Returns:
a localized version of the message.

localize

public String localize(String id,
                       String arg1,
                       String arg2,
                       String arg3,
                       String arg4,
                       String arg5,
                       String arg6)
Return a localized message given a message id and six arguments.

This is a MessageHandler API method.

Specified by:
localize in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
arg5 - argument substituting %5 in the message string.
arg6 - argument substituting %5 in the message string.
Returns:
a localized version of the message.

log

public String log(String message)
Write the message to the log file, given the message and no arguments. Note that as apart from most methods in this class, the message is not localized but simply passed to the handler. The log timestamp will be added. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
message - the message to be written to the log file.
Returns:
the original message.

log

public String log(String timeStamp,
                  String id)
Write the message to the log file, given an optional time stamp, a message id and no arguments. Note that the id can simply be a text message. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
timeStamp - the optional time stamp string to be added to the log.
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

log

public String log(String timeStamp,
                  String id,
                  String arg1)
Write the message to the log file, given an optional time stamp, a message id and one argument. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
timeStamp - the optional time stamp string to be added to the log.
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the message.

log

public String log(String timeStamp,
                  String id,
                  String arg1,
                  String arg2)
Write the message to the log file, given an optional time stamp, a message id and two arguments. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
timeStamp - the optional time stamp string to be added to the log.
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

log

public String log(String timeStamp,
                  String id,
                  String arg1,
                  String arg2,
                  String arg3)
Write the message to the log file, given an optional time stamp, a message id and three arguments. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
timeStamp - the optional time stamp string to be added to the log.
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the message.

log

public String log(String timeStamp,
                  String id,
                  String arg1,
                  String arg2,
                  String arg3,
                  String arg4)
Write the message to the log file, given an optional time stamp, a message id and four arguments. If the log file has not been established, nothing happens.

This is a MessageHandler API method.

Specified by:
log in interface MessageHandler
Parameters:
timeStamp - the optional time stamp string to be added to the log.
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
Returns:
a localized version of the message.

status

public void status(String id)
Display a status message to the UI if available (as a message if not) given a message id and no arguments. Note that the id can simply be a text message.

This is a MessageHandler API method.

Specified by:
status in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.

status

public void status(String id,
                   String arg1)
Display a status message to the UI if available (as a message if not) given a message id and one argument.

This is a MessageHandler API method.

Specified by:
status in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.

status

public void status(String id,
                   String arg1,
                   String arg2)
Display a status message to the UI if available (as a message if not) given a message id and two arguments.

This is a MessageHandler API method.

Specified by:
status in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.

status

public void status(String id,
                   String arg1,
                   String arg2,
                   String arg3)
Display a status message to the UI if available (as a message if not) given a message id and three arguments.

This is a MessageHandler API method.

Specified by:
status in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.

status

public void status(String id,
                   String arg1,
                   String arg2,
                   String arg3,
                   String arg4)
Display a status message to the UI if available (as a message if not) given a message id and four arguments.

This is a MessageHandler API method.

Specified by:
status in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.

message

public String message(String id)
Display a non-fatal informational message given a message id and no arguments. Note that the id can simply be a text message.

This is a MessageHandler API method.

Specified by:
message in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

message

public String message(String id,
                      String arg1)
Display a non-fatal informational message given a message id and one argument.

This is a MessageHandler API method.

Specified by:
message in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the message.

message

public String message(String id,
                      String arg1,
                      String arg2)
Display a non-fatal informational message given a message id and two arguments.

This is a MessageHandler API method.

Specified by:
message in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

message

public String message(String id,
                      String arg1,
                      String arg2,
                      String arg3)
Display a non-fatal informational message given a message id and three arguments.

This is a MessageHandler API method.

Specified by:
message in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the message.

message

public String message(String id,
                      String arg1,
                      String arg2,
                      String arg3,
                      String arg4)
Display a non-fatal informational message given a message id and four arguments.

This is a MessageHandler API method.

Specified by:
message in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
Returns:
a localized version of the message.

notice

public String notice(String id)
Display a highlighted notice given a notice id and no arguments. Note that the id can simply be a text notice.

This is a MessageHandler API method.

Specified by:
notice in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the notice.

notice

public String notice(String id,
                     String arg1)
Display a highlighted notice given a notice id and one argument.

This is a MessageHandler API method.

Specified by:
notice in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the notice.

notice

public String notice(String id,
                     String arg1,
                     String arg2)
Display a highlighted notice given a notice id and two arguments.

This is a MessageHandler API method.

Specified by:
notice in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the notice.

notice

public String notice(String id,
                     String arg1,
                     String arg2,
                     String arg3)
Display a highlighted notice given a notice id and three arguments.

This is a MessageHandler API method.

Specified by:
notice in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the notice.

notice

public String notice(String id,
                     String arg1,
                     String arg2,
                     String arg3,
                     String arg4)
Display a highlighted notice given a notice id and four arguments.

This is a MessageHandler API method.

Specified by:
notice in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
arg4 - argument substituting %4 in the message string.
Returns:
a localized version of the notice.

warning

public String warning(String id)
Display a non-fatal warning given an error message and no arguments.

This is a MessageHandler API method.

Specified by:
warning in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

warning

public String warning(Exception exception)
Tunnel an existing Exception. Displays a non-fatal warning.

This is a MessageHandler API method.

Specified by:
warning in interface MessageHandler
Parameters:
exception - the tunneled Exception.
Returns:
a localized version of the message.

warning

public void warning(SAXParseException exception)
Tunnel an existing SAXParseException. Displays a non-fatal warning. Note: no return value is provided (for compliance with SAX ErrorHandler).

Specified by:
warning in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.

warning

public String warning(String id,
                      String arg1)
Display a non-fatal warning given an error id and one argument.

This is a MessageHandler API method.

Specified by:
warning in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the message.

warning

public String warning(String id,
                      String arg1,
                      String arg2)
Display a non-fatal warning given an error id and two arguments.

This is a MessageHandler API method.

Specified by:
warning in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

warning

public String warning(String id,
                      String arg1,
                      String arg2,
                      String arg3)
Display a non-fatal warning given an error id and three arguments.

This is a MessageHandler API method.

Specified by:
warning in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the message.

error

public String error(String id)
Handle an exception provided an error message and no arguments. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

error

public String error(Exception exception)
Tunnel an existing Exception. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
exception - the tunneled Exception.
Returns:
a localized version of the message.

error

public void error(SAXParseException exception)
Tunnel an existing SAXParseException. This error may be recoverable with error handling code in specific contexts. Note: no return value is provided (for compliance with SAX ErrorHandler).

Specified by:
error in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.

error

public String error(String id,
                    Exception exception)
Handle an exception provided an error message and no arguments, and the tunneled Exception. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
exception - the tunneled Exception.
Returns:
a localized version of the message.

error

public String error(String id,
                    String arg)
Handle an exception provided an error message and one argument. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg - argument substituting %1 in the message string.
Returns:
a localized version of the message.

error

public String error(String id,
                    String arg,
                    Exception exception)
Handle an exception provided an error message with one argument and the tunneled Exception. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg - argument substituting %1 in the message string.
exception - the tunneled Exception.
Returns:
a localized version of the message.

error

public String error(String id,
                    String arg1,
                    String arg2)
Handle an exception provided an error message and two arguments. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

error

public String error(String id,
                    String arg1,
                    String arg2,
                    String arg3)
Handle an exception provided an error message and three arguments. This error may be recoverable with error handling code in specific contexts.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
arg3 - argument substituting %3 in the message string.
Returns:
a localized version of the message.

error

public String error(String id,
                    String arg1,
                    String arg2,
                    Exception exception)
Handle an exception provided an error message with two arguments and the tunneled Exception. This error may be recoverable with error handling code in specific contexts.

This is a MessageHandler API method.

Specified by:
error in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
exception - the tunneled Exception.
Returns:
a localized version of the message.

fatalError

public String fatalError(Exception exception)
A method which handles a fatal exception given the tunneled Exception.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
exception - the tunneled Exception.
Returns:
a localized version of the message.

fatalError

public void fatalError(SAXParseException exception)
A method which handles a fatal exception given a tunneled SAXParseException. Note: no return value is provided (for compliance with SAX ErrorHandler).

Specified by:
fatalError in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.

fatalError

public String fatalError(Error error)
A method which handles a fatal error provided the actual java.lang.Error.

Specified by:
fatalError in interface MessageHandler
Parameters:
error - the Error thrown.
Returns:
the error message.

fatalError

public String fatalError(String id)
A method which handles a fatal exception given an error message String.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
Returns:
a localized version of the message.

fatalError

public String fatalError(String id,
                         Exception exception)
A method which handles a fatal exception given an error message String and the tunneled Exception.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
exception - the tunneled Exception.
Returns:
a localized version of the message.

fatalError

public String fatalError(String id,
                         String arg1)
A method which handles a fatal exception given an error id, one argument.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
Returns:
a localized version of the message.

fatalError

public String fatalError(String id,
                         String arg1,
                         Exception exception)
A method which handles a fatal exception given an error id, one argument, and the tunneled Exception.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
exception - the tunneled Exception.
Returns:
a localized version of the message.

fatalError

public String fatalError(String id,
                         String arg1,
                         String arg2)
A method which handles a fatal exception given an error id and two arguments.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
Returns:
a localized version of the message.

fatalError

public String fatalError(String id,
                         String arg1,
                         String arg2,
                         Exception exception)
A method which handles a fatal exception given an error id, two arguments, and the tunneled Exception.

This is a MessageHandler API method.

Specified by:
fatalError in interface MessageHandler
Parameters:
id - the MsgId or MessageId within the ListResourceBundle MsgId or MessageId, respectively.
arg1 - argument substituting %1 in the message string.
arg2 - argument substituting %2 in the message string.
exception - the tunneled Exception.
Returns:
a localized version of the message.

getWarningList

public Enumeration getWarningList()
Returns an Enumeration of the current warning list.


getErrorList

public Enumeration getErrorList()
Returns an Enumeration of the current error list.


getWarningCount

public int getWarningCount()
Returns the current number of warnings registered with this MessageHandler.


getErrorCount

public int getErrorCount()
Returns the current number of errors registered with this MessageHandler.


setMaxWarnings

public void setMaxWarnings(int newMax)
Sets the maximum warning count before exit (abort). Allowed range 0-1000; values out of range are ignored.


setMaxErrors

public void setMaxErrors(int newMax)
Sets the maximum error count before exit (abort). For Draconian error handling, default is set to zero. Allowed values 0-1000; values out of range are ignored.


getStatusText

public String getStatusText(int status)
Returns a localized String indicating the provided message status. E.g., "ERROR", "WARNING", etc. For non-warning and error messages requests this will return an empty, otherwise undecorated String.

This is a MessageHandler API method.

Specified by:
getStatusText in interface MessageHandler

getStatus

public int getStatus()
Return the current MessageHandler status:
OK
no activity
LOG
a log message has occurred.
INFO
an informational message has occurred.
NOTICE
a highlighted notice has occurred.
WARN
a warning message has occurred.
ERROR
a (possibly) recoverable error has occurred.
FATAL
a fatal (abortive) error has occurred.

Note that the constants used for status are integers and can be compared using less-than and greater than operators.

Specified by:
getStatus in interface MessageHandler

getLogLevel

public static org.apache.log4j.Level getLogLevel(int state)
Converts the provided MessageHandler state value to a Log4J Level. If not explicitly noted, the "default" value of Level.INFO is returned if the MessageHandler state doesn't have an equivalent Log4J Level.
state returns... OK Level.ALL (i.e., all messages) LOCALIZE default DEBUG Level.DEBUG LOG default INFO Level.INFO NOTICE default WARN Level.WARN ERROR Level.ERROR FATAL Level.FATAL OFF Level.OFF (i.e., logging off)


reset

public void reset()
Clears all warning and error counters and containers.

Specified by:
reset in interface MessageHandler

exit

public void exit(int status,
                 String exitMessage,
                 Exception exception)
Aborts all processes and terminates the currently running application. A nonzero value for 'status' indicates an abnormal exit. Exit the program after closing any open files, removing temps, etc.

Parameters:
status - indicates an error condition when true.
exitMessage - final exit message
exception - the tunneled exception, used to print a stack trace

openErrorFile

public void openErrorFile(String filename)
Opens error file filename for writing, defining the Writer writer.


flush

public void flush()
           throws IOException
Flushes the error file if open.

Throws:
IOException

closeErrorFile

public void closeErrorFile()
Closes the error file filename, if open.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.