|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.qfs.lib.util.MessageCollector
Very simple mechanism for collecting warning and error messages.
This class is intended for use in a parser or similar application where
many warnings and errors may arise during one run. Each message passed to
the MessageCollector is assigned a level of severity, WARNING
for warnings, ERROR
for errors and FATAL_ERROR
for fatal errors. After processing is finished,
the number of warnings, errors and fatal errors can be queried and the
collected messages are available via getMessages
.
Things get even more interesting when nested calls need to be handled,
e.g. when a parser needs to include files. To that end an instance
mechanism is implemented that associates a MessageCollector with
the current thread. For JDK 1.2 and above, ThreadLocal
is used for this, but for JDK 1.1 be sure to release
MessageCollector instances before a thread terminates, or they
will become uncollectable garbage.
Field Summary | |
static int |
ERROR
Level for errors. |
static int |
FATAL_ERROR
Level for fatal errors. |
static int |
NO_ERROR
Level for neither warnings nor errors. |
static int |
WARNING
Level for warnings. |
Constructor Summary | |
MessageCollector()
Create a new MessageCollector. |
Method Summary | |
void |
addMessage(int level,
java.lang.String message)
Add a message to the MessageCollector. |
int |
getErrorCount()
Get the number of errors that occured. |
int |
getFatalErrorCount()
Get the number of fatal errors that occured. |
java.lang.String |
getFirstError()
Get the firstError of the MessageCollector. |
java.lang.String |
getFirstFatalError()
Get the firstFatalError of the MessageCollector. |
java.lang.String |
getFirstWarning()
Get the firstWarning of the MessageCollector. |
java.lang.String |
getJoinedMessages()
Get the collected messages joined into a multi-line String. |
java.lang.String |
getLastError()
Get the lastError of the MessageCollector. |
java.lang.String |
getLastFatalError()
Get the lastFatalError of the MessageCollector. |
java.lang.String |
getLastWarning()
Get the lastWarning of the MessageCollector. |
java.lang.String[] |
getMessages()
Get the collected messages. |
int |
getWarningCount()
Get the number of warnings that occured. |
int |
getWorstCase()
Get the highest level of the collected messages. |
static MessageCollector |
instance()
Get the MessageCollector for the current thread, creating a new one if necessary. |
void |
logError(java.lang.String message)
Add a message at level ERROR. |
void |
logFatalError(java.lang.String message)
Add a message at level FATAL_ERROR. |
void |
logMessage(java.lang.String message)
Add a message at level NO_ERROR. |
void |
logWarning(java.lang.String message)
Add a message at level WARNING. |
static void |
release()
Destroy the MessageCollector for the current thread. |
void |
reset()
Reset the MessageCollector by clearing the collected messages and resetting the counts. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NO_ERROR
public static final int WARNING
public static final int ERROR
public static final int FATAL_ERROR
Constructor Detail |
public MessageCollector()
Method Detail |
public static MessageCollector instance()
public static void release()
public void addMessage(int level, java.lang.String message)
level
- The level of the message.message
- The message.public java.lang.String[] getMessages()
public java.lang.String getJoinedMessages()
public int getWarningCount()
public int getErrorCount()
public int getFatalErrorCount()
public int getWorstCase()
public final java.lang.String getFirstWarning()
public final java.lang.String getLastWarning()
public final java.lang.String getFirstError()
public final java.lang.String getLastError()
public final java.lang.String getFirstFatalError()
public final java.lang.String getLastFatalError()
public void reset()
public final void logMessage(java.lang.String message)
message
- The message to add.public final void logWarning(java.lang.String message)
message
- The message to add.public final void logError(java.lang.String message)
message
- The message to add.public final void logFatalError(java.lang.String message)
message
- The message to add.
|
qflib 0.99 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |