public class Errors
extends java.lang.Object
#warning
, #error
, #fatal
) can be invoked only in the "error scope" which is
created by process(Producer)
or
processWithException(Producer)
methods. Filed error messages are present also in this
scope.
TODO do not use static thread local?Modifier and Type | Class and Description |
---|---|
static class |
Errors.ErrorMessage
Generic error message.
|
static class |
Errors.ErrorMessagesException
Error message exception.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<Errors> |
errors |
private java.util.ArrayList<Errors.ErrorMessage> |
issues |
private static java.util.logging.Logger |
LOGGER |
private java.util.Deque<java.lang.Integer> |
mark |
private int |
stack |
Modifier | Constructor and Description |
---|---|
private |
Errors() |
Modifier and Type | Method and Description |
---|---|
private java.util.List<Errors.ErrorMessage> |
_getErrorMessages(boolean afterMark) |
private void |
_mark() |
private void |
_reset() |
private void |
_unmark() |
static void |
error(java.lang.Object source,
java.lang.String message,
Severity severity)
Add an error to the list of messages.
|
static void |
error(java.lang.String message,
Severity severity)
Add an error to the list of messages.
|
static void |
fatal(java.lang.Object source,
java.lang.String message)
Add a fatal error to the list of messages.
|
static boolean |
fatalIssuesFound()
Check whether a fatal error is present in the list of all messages.
|
static java.util.List<Errors.ErrorMessage> |
getErrorMessages()
Get the list of all error messages.
|
static java.util.List<Errors.ErrorMessage> |
getErrorMessages(boolean afterMark)
Get the list of error messages.
|
private static Errors |
getInstance() |
static void |
hint(java.lang.Object source,
java.lang.String message)
Add a hint to the list of messages.
|
static boolean |
logErrors(boolean afterMark)
Log errors and return a status flag indicating whether a fatal issue has been found
in the error collection.
|
private static boolean |
logErrors(java.util.Collection<Errors.ErrorMessage> errors)
Log supplied errors and return a status flag indicating whether a fatal issue has been found
in the error collection.
|
static void |
mark()
Set a mark at a current position in the errors messages list.
|
private void |
postProcess(boolean throwException) |
private void |
preProcess() |
static <T> T |
process(java.util.concurrent.Callable<T> task)
Invoke given callable task and gather messages.
|
private static <T> T |
process(java.util.concurrent.Callable<T> task,
boolean throwException) |
static <T> T |
process(Producer<T> producer)
Invoke given producer task and gather errors.
|
private static <T> T |
process(Producer<T> task,
boolean throwException) |
static void |
process(java.lang.Runnable task)
Invoke given task and gather messages.
|
private static void |
processErrors(boolean throwException)
Log errors and throw an exception if there are any fatal issues detected and
the
throwException flag has been set to true . |
static <T> T |
processWithException(Producer<T> producer)
Invoke given producer task and gather messages.
|
static void |
processWithException(java.lang.Runnable task)
Invoke given task and gather messages.
|
static void |
reset()
Removes all issues that have been added since the last marked position as well as
removes the last mark.
|
static void |
unmark()
Remove a previously set mark, if any.
|
static void |
warning(java.lang.Object source,
java.lang.String message)
Add a warning to the list of messages.
|
private static final java.util.logging.Logger LOGGER
private static final java.lang.ThreadLocal<Errors> errors
private final java.util.ArrayList<Errors.ErrorMessage> issues
private java.util.Deque<java.lang.Integer> mark
private int stack
public static void error(java.lang.String message, Severity severity)
message
- message of the error.severity
- indicates severity of added error.public static void error(java.lang.Object source, java.lang.String message, Severity severity)
source
- source of the error.message
- message of the error.severity
- indicates severity of added error.public static void fatal(java.lang.Object source, java.lang.String message)
source
- source of the error.message
- message of the error.public static void warning(java.lang.Object source, java.lang.String message)
source
- source of the error.message
- message of the error.public static void hint(java.lang.Object source, java.lang.String message)
source
- source of the error.message
- message of the error.private static void processErrors(boolean throwException)
throwException
flag has been set to true
.throwException
- if set to true
, any fatal issues will cause a Errors.ErrorMessagesException
to be thrown.public static boolean logErrors(boolean afterMark)
The afterMark
flag indicates whether only those issues should be logged that were
added after a mark has been set
.
afterMark
- if true
, only issues added after a mark has been set are returned,
if false
all issues are returned.true
if there are any fatal issues present in the collection, false
otherwise.private static boolean logErrors(java.util.Collection<Errors.ErrorMessage> errors)
errors
- a collection of errors to be logged.true
if there are any fatal issues present in the collection, false
otherwise.public static boolean fatalIssuesFound()
true
if there are any fatal issues in this error context, false
otherwise.public static <T> T process(Producer<T> producer)
producer
- producer task to be invoked.public static <T> T process(java.util.concurrent.Callable<T> task) throws java.lang.Exception
task
- callable task to be invoked.java.lang.Exception
- exception thrown by the task.public static <T> T processWithException(Producer<T> producer)
exception
is thrown.producer
- producer task to be invoked.public static void process(java.lang.Runnable task)
task
- task to be invoked.public static void processWithException(java.lang.Runnable task)
exception
is thrown.task
- task to be invoked.private static <T> T process(Producer<T> task, boolean throwException)
private static <T> T process(java.util.concurrent.Callable<T> task, boolean throwException) throws java.lang.Exception
java.lang.Exception
private static Errors getInstance()
public static java.util.List<Errors.ErrorMessage> getErrorMessages()
public static java.util.List<Errors.ErrorMessage> getErrorMessages(boolean afterMark)
The afterMark
flag indicates whether only those issues should be returned that were
added after a mark has been set
.
afterMark
- if true
, only issues added after a mark has been set are returned,
if false
all issues are returned.public static void mark()
public static void unmark()
public static void reset()
private void _mark()
private void _unmark()
private void _reset()
private void preProcess()
private void postProcess(boolean throwException)
private java.util.List<Errors.ErrorMessage> _getErrorMessages(boolean afterMark)