au.gov.tas.dpiwe.mr.util
Class Messenger

java.lang.Object
  extended by au.gov.tas.dpiwe.mr.util.Messenger
Direct Known Subclasses:
Batch, BeanCache, DeploymentTool, MethodCall

public class Messenger
extends Object

A utility class used to print logging messages at various levels.

This class is a simple implementation using standard output as the console. It adds no time signature information to the messages before printing them.

Since:
Mr Architecture 1.0
Version:
1.0.2.4
Author:
Kade Hansson

Field Summary
protected  boolean console
          Set to true to echo messages on the standard output device.
protected  boolean error
          Set to true to echo messages on the standard error stream.
protected  Map exceptionMessageTable
          Lists the messages to be displayed for various exception types.
protected  boolean exceptionsToConsole
          Set to true to echo exception stack traces on the standard output device.
protected  boolean exceptionsToError
          Set to true to echo exception stack traces on the standard error stream.
static int Level_Debug
          The message level which displays debugging messages.
static int Level_Exception
          The message level which displays exception messages (unless tagged at zero or with a negative number.)
static int Level_None
          The message level which displays no messages (unless tagged at zero or with a negative number.)
static int Level_Normal
          The message level which displays normal command-level logging messages.
protected  int messageLevel
          Indicates the present message level.
 
Constructor Summary
Messenger()
           
 
Method Summary
 void debugEmptyMessage()
          Starts a new line after debugging messages.
 Object debugEmptyMessage(Object message)
          Starts a new line after debugging messages.
 Object debugMessage(Object message)
          Prints a debugging message related to an object, starting a new line afterward.
 Object debugMessage(Object message, MessageFormat format)
          Prints a debugging message related to an object, starting a new line afterward.
 Object debugMessage(String prefix, String suffix, Object message)
          Prints a debugging message related to an object, starting a new line afterward.
 Object debugMessageFirstPart(Object message)
          Prints a debugging message related to an object.
 Object debugMessageFirstPart(String prefix, String suffix, Object message)
          Prints a debugging message related to an object.
 Object debugMessageLastPart(Object message)
          Prints a debugging message related to an object, starting a new line afterward.
 Object debugMessageLastPart(String prefix, String suffix, Object message)
          Prints a debugging message related to an object, starting a new line afterward.
 Object debugMessagePart(Object message)
          Prints a debugging message related to an object.
 Object debugMessagePart(String prefix, String suffix, Object message)
          Prints a debugging message related to an object.
 void debugStackTrace(Throwable throwable)
          Prints a debugging stack trace.
 boolean debugStackTrace2(Throwable throwable)
          Prints a debugging stack trace.
 void emptyMessage()
          Starts a new line after command-level logging.
 void emptyMessage(int atLevel)
          Starts a new line after level tagged logging.
 Object emptyMessage(int atLevel, Object message)
          Starts a new line after level tagged logging.
 Object emptyMessage(Object message)
          Starts a new line after command-level logging.
 int getMessageLevel()
          Returns the level at which messages will be output.
static boolean isTweenMessage(String tween)
          Returns true if tween contains what looks like a method call to this object which can take a prefix and a suffix.
 Object message(int atLevel, Object message)
          Prints a level tagged logging message related to an object, starting a new line afterward.
 Object message(int atLevel, Object message, MessageFormat format)
          Prints a level tagged logging message related to an object, starting a new line afterward.
 Object message(int atLevel, String prefix, String suffix, Object message)
          Prints a level tagged logging message related to an object, starting a new line afterward.
 Object message(Object message)
          Prints a command-level logging message related to an object, starting a new line afterward.
 Object message(Object message, MessageFormat format)
          Prints a command-level logging message related to an object, starting a new line afterward.
 Object message(String prefix, String suffix, Object message)
          Prints a command-level logging message related to an object, starting a new line afterward.
 Object messageFirstPart(int atLevel, Object message)
          Prints a level tagged logging message related to an object.
 Object messageFirstPart(int atLevel, String prefix, String suffix, Object message)
          Prints a level tagged logging message related to an object.
 Object messageFirstPart(Object message)
          Prints a command-level logging message related to an object.
 Object messageFirstPart(String prefix, String suffix, Object message)
          Prints a command-level logging message related to an object.
 Object messageLastPart(int atLevel, Object message)
          Prints a level tagged logging message related to an object, starting a new line afterward.
 Object messageLastPart(int atLevel, String prefix, String suffix, Object message)
          Prints a level tagged logging message related to an object, starting a new line afterward.
 Object messageLastPart(Object message)
          Prints a command-level logging message related to an object, starting a new line afterward.
 Object messageLastPart(String prefix, String suffix, Object message)
          Prints a command-level logging message related to an object, starting a new line afterward.
 Object messagePart(int atLevel, Object message)
          Prints a level tagged logging message related to an object.
 Object messagePart(int atLevel, Object message, MessageFormat format)
          Prints a level tagged logging message related to an object.
 Object messagePart(int atLevel, String prefix, String suffix, Object message)
          Prints a level tagged logging message related to an object.
 Object messagePart(Object message)
          Prints a command-level logging message related to an object.
 Object messagePart(Object message, MessageFormat format)
          Prints a command-level logging message related to an object.
 Object messagePart(String prefix, String suffix, Object message)
          Prints a command-level logging message related to an object.
 boolean prettyException(Throwable throwable)
          Prints a pretty exception message.
 void queryReport(Throwable throwable, String query)
          Reports a failed query.
 void setConsoleOutput(boolean console)
          Sets whether this messenger should direct messages to the standard output stream or GUI component.
 void setConsoleOutput(boolean console, boolean exceptionsToConsole)
          Sets whether this messenger should direct messages to the standard output stream or GUI component.
 void setErrorOutput(boolean error)
          Sets whether this messenger should direct messages to the standard error stream.
 void setErrorOutput(boolean error, boolean exceptionsToError)
          Sets whether this messenger should direct messages to the standard error stream.
 void setMessageLevel(int messageLevel)
          Sets the level at which messages should be output.
 void setOutput(boolean output)
          Sets whether this messenger should suppress all messages or produce messages on all outputs.
 void stackTrace(Throwable throwable)
          Prints a stack trace.
 boolean stackTrace2(Throwable throwable)
          Prints a stack trace.
 void success()
          Prints a success message.
 void success(int atLevel)
          Prints a success message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

console

protected boolean console
Set to true to echo messages on the standard output device.


error

protected boolean error
Set to true to echo messages on the standard error stream.


exceptionsToConsole

protected boolean exceptionsToConsole
Set to true to echo exception stack traces on the standard output device.


exceptionsToError

protected boolean exceptionsToError
Set to true to echo exception stack traces on the standard error stream.


messageLevel

protected int messageLevel
Indicates the present message level.


Level_None

public static final int Level_None
The message level which displays no messages (unless tagged at zero or with a negative number.)

See Also:
Constant Field Values

Level_Exception

public static final int Level_Exception
The message level which displays exception messages (unless tagged at zero or with a negative number.)

See Also:
Constant Field Values

Level_Normal

public static final int Level_Normal
The message level which displays normal command-level logging messages. Levels between Level_None and Level_Normal display only messages tagged between that level and Level_Normal (but not including Level_Normal.) This allows for terser logging modes.

See Also:
Constant Field Values

Level_Debug

public static final int Level_Debug
The message level which displays debugging messages. Levels between Level_Normal and Level_Debug are used to catch high-level debugging only. Levels beyond Level_Debug are to include low-level debugging.

See Also:
Constant Field Values

exceptionMessageTable

protected Map exceptionMessageTable
Lists the messages to be displayed for various exception types.

Constructor Detail

Messenger

public Messenger()
Method Detail

setOutput

public void setOutput(boolean output)
Sets whether this messenger should suppress all messages or produce messages on all outputs.

Parameters:
output - true to direct messages to standard output or GUI component and standard error as well, false to suppress all messages.

setConsoleOutput

public void setConsoleOutput(boolean console)
Sets whether this messenger should direct messages to the standard output stream or GUI component.

Parameters:
error - true to direct messages to standard output or GUI component, false otherwise.

setConsoleOutput

public void setConsoleOutput(boolean console,
                             boolean exceptionsToConsole)
Sets whether this messenger should direct messages to the standard output stream or GUI component.

Parameters:
error - true to direct messages to standard output or GUI component, false otherwise.
exceptionsToConsole - true to direct stack traces to standard output or GUI component, false otherwise.

setErrorOutput

public void setErrorOutput(boolean error)
Sets whether this messenger should direct messages to the standard error stream.

Parameters:
error - true to direct messages to standard error, false otherwise.

setErrorOutput

public void setErrorOutput(boolean error,
                           boolean exceptionsToError)
Sets whether this messenger should direct messages to the standard error stream.

Parameters:
error - true to direct messages to standard error, false otherwise.
exceptionsToError - true to direct stack traces to standard error, false otherwise.

setMessageLevel

public void setMessageLevel(int messageLevel)
Sets the level at which messages should be output.

Parameters:
level - one of the constant values Level_None, Level_Normal or Level_Debug, or some other level constant defined by a subclass.

getMessageLevel

public int getMessageLevel()
Returns the level at which messages will be output.

Returns:
the current message level.

messageFirstPart

public Object messageFirstPart(int atLevel,
                               String prefix,
                               String suffix,
                               Object message)
Prints a level tagged logging message related to an object.

Parameters:
atLevel - the level at which this message is tagged. Prints a command-level logging message related to an object.
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messagePart

public Object messagePart(int atLevel,
                          String prefix,
                          String suffix,
                          Object message)
Prints a level tagged logging message related to an object.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messageLastPart

public Object messageLastPart(int atLevel,
                              String prefix,
                              String suffix,
                              Object message)
Prints a level tagged logging message related to an object, starting a new line afterward.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

message

public Object message(int atLevel,
                      String prefix,
                      String suffix,
                      Object message)
Prints a level tagged logging message related to an object, starting a new line afterward.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messageFirstPart

public Object messageFirstPart(int atLevel,
                               Object message)
Prints a level tagged logging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

messagePart

public Object messagePart(int atLevel,
                          Object message)
Prints a level tagged logging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

messagePart

public Object messagePart(int atLevel,
                          Object message,
                          MessageFormat format)
Prints a level tagged logging message related to an object.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
format - a context to display the subject.
Returns:
the subject of the message.

messageLastPart

public Object messageLastPart(int atLevel,
                              Object message)
Prints a level tagged logging message related to an object, starting a new line afterward.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
Returns:
the subject of the message.

message

public Object message(int atLevel,
                      Object message)
Prints a level tagged logging message related to an object, starting a new line afterward.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
Returns:
the subject of the message.

message

public Object message(int atLevel,
                      Object message,
                      MessageFormat format)
Prints a level tagged logging message related to an object, starting a new line afterward.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
format - a context to display the subject.
Returns:
the subject of the message.

emptyMessage

public Object emptyMessage(int atLevel,
                           Object message)
Starts a new line after level tagged logging.

Parameters:
atLevel - the level at which this message is tagged.
message - the subject of the message.
Returns:
the subject of the message.

emptyMessage

public void emptyMessage(int atLevel)
Starts a new line after level tagged logging.

Parameters:
atLevel - the level at which this message is tagged.

debugMessageFirstPart

public Object debugMessageFirstPart(String prefix,
                                    String suffix,
                                    Object message)
Prints a debugging message related to an object.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

debugMessagePart

public Object debugMessagePart(String prefix,
                               String suffix,
                               Object message)
Prints a debugging message related to an object.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

debugMessageLastPart

public Object debugMessageLastPart(String prefix,
                                   String suffix,
                                   Object message)
Prints a debugging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

debugMessage

public Object debugMessage(String prefix,
                           String suffix,
                           Object message)
Prints a debugging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

debugMessageFirstPart

public Object debugMessageFirstPart(Object message)
Prints a debugging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

debugMessagePart

public Object debugMessagePart(Object message)
Prints a debugging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

debugMessageLastPart

public Object debugMessageLastPart(Object message)
Prints a debugging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

debugMessage

public Object debugMessage(Object message)
Prints a debugging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

debugMessage

public Object debugMessage(Object message,
                           MessageFormat format)
Prints a debugging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
format - a context to display the subject.
Returns:
the subject of the message.

debugEmptyMessage

public Object debugEmptyMessage(Object message)
Starts a new line after debugging messages.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

debugEmptyMessage

public void debugEmptyMessage()
Starts a new line after debugging messages.


success

public void success(int atLevel)
Prints a success message.


prettyException

public boolean prettyException(Throwable throwable)
Prints a pretty exception message.

This call indirects via message().

Parameters:
throwable - the exception or error containing the stack trace.
Returns:
true if there is a pretty exception message and it was displayed, false otherwise.

stackTrace

public void stackTrace(Throwable throwable)
Prints a stack trace.

Parameters:
throwable - the exception or error containing the stack trace.

stackTrace2

public boolean stackTrace2(Throwable throwable)
Prints a stack trace.

Parameters:
throwable - the exception or error containing the stack trace.
Returns:
true if level is not none and exception was printed.

debugStackTrace

public void debugStackTrace(Throwable throwable)
Prints a debugging stack trace.

Parameters:
throwable - the exception or error containing the stack trace.

debugStackTrace2

public boolean debugStackTrace2(Throwable throwable)
Prints a debugging stack trace.

Parameters:
throwable - the exception or error containing the stack trace.
Returns:
true if debugging level is set and exception was printed.

queryReport

public void queryReport(Throwable throwable,
                        String query)
Reports a failed query.

Parameters:
throwable - the exception or error the query produced.
query - the query statement.

messageFirstPart

public Object messageFirstPart(String prefix,
                               String suffix,
                               Object message)
Prints a command-level logging message related to an object.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messagePart

public Object messagePart(String prefix,
                          String suffix,
                          Object message)
Prints a command-level logging message related to an object.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messageLastPart

public Object messageLastPart(String prefix,
                              String suffix,
                              Object message)
Prints a command-level logging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

message

public Object message(String prefix,
                      String suffix,
                      Object message)
Prints a command-level logging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
prefix - commentary prepended to the subject.
suffix - commentary appended to the subject.
Returns:
the subject of the message.

messageFirstPart

public Object messageFirstPart(Object message)
Prints a command-level logging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

messagePart

public Object messagePart(Object message)
Prints a command-level logging message related to an object.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

messagePart

public Object messagePart(Object message,
                          MessageFormat format)
Prints a command-level logging message related to an object.

Parameters:
message - the subject of the message.
format - a context to display the subject.
Returns:
the subject of the message.

messageLastPart

public Object messageLastPart(Object message)
Prints a command-level logging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

message

public Object message(Object message)
Prints a command-level logging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

message

public Object message(Object message,
                      MessageFormat format)
Prints a command-level logging message related to an object, starting a new line afterward.

Parameters:
message - the subject of the message.
format - a context to display the subject.
Returns:
the subject of the message.

emptyMessage

public Object emptyMessage(Object message)
Starts a new line after command-level logging.

Parameters:
message - the subject of the message.
Returns:
the subject of the message.

emptyMessage

public void emptyMessage()
Starts a new line after command-level logging.


success

public void success()
Prints a success message.


isTweenMessage

public static boolean isTweenMessage(String tween)
Returns true if tween contains what looks like a method call to this object which can take a prefix and a suffix.

Parameters:
tween - a fragment of Java code.
Returns:
true if tween is a method call taking a prefix and suffix, false otherwise (maybe.)