Package org.glassfish.jersey.internal
Class Errors
- java.lang.Object
-
- org.glassfish.jersey.internal.Errors
-
public class Errors extends java.lang.Object
Errors utility used to file processing messages (e.g. validation, provider, resource building errors, hint). Error filing methods (#warning
,#error
,#fatal
) can be invoked only in the "error scope" which is created byprocess(Producer)
orprocessWithException(Producer)
methods. Filed error messages are present also in this scope. TODO do not use static thread local?
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Errors.ErrorMessage
Generic error message.static class
Errors.ErrorMessagesException
Error message exception.
-
Constructor Summary
Constructors Modifier Constructor Description private
Errors()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 void
process(java.lang.Runnable task)
Invoke given task and gather messages.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)
private static void
processErrors(boolean throwException)
Log errors and throw an exception if there are any fatal issues detected and thethrowException
flag has been set totrue
.static void
processWithException(java.lang.Runnable task)
Invoke given task and gather messages.static <T> T
processWithException(Producer<T> producer)
Invoke given producer 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.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
errors
private static final java.lang.ThreadLocal<Errors> errors
-
issues
private final java.util.ArrayList<Errors.ErrorMessage> issues
-
mark
private java.util.Deque<java.lang.Integer> mark
-
stack
private int stack
-
-
Method Detail
-
error
public static void error(java.lang.String message, Severity severity)
Add an error to the list of messages.- Parameters:
message
- message of the error.severity
- indicates severity of added error.
-
error
public static void error(java.lang.Object source, java.lang.String message, Severity severity)
Add an error to the list of messages.- Parameters:
source
- source of the error.message
- message of the error.severity
- indicates severity of added error.
-
fatal
public static void fatal(java.lang.Object source, java.lang.String message)
Add a fatal error to the list of messages.- Parameters:
source
- source of the error.message
- message of the error.
-
warning
public static void warning(java.lang.Object source, java.lang.String message)
Add a warning to the list of messages.- Parameters:
source
- source of the error.message
- message of the error.
-
hint
public static void hint(java.lang.Object source, java.lang.String message)
Add a hint to the list of messages.- Parameters:
source
- source of the error.message
- message of the error.
-
processErrors
private static void processErrors(boolean throwException)
Log errors and throw an exception if there are any fatal issues detected and thethrowException
flag has been set totrue
.- Parameters:
throwException
- if set totrue
, any fatal issues will cause aErrors.ErrorMessagesException
to be thrown.
-
logErrors
public static boolean logErrors(boolean afterMark)
Log errors and return a status flag indicating whether a fatal issue has been found in the error collection.The
afterMark
flag indicates whether only those issues should be logged that were added after amark has been set
.- Parameters:
afterMark
- iftrue
, only issues added after a mark has been set are returned, iffalse
all issues are returned.- Returns:
true
if there are any fatal issues present in the collection,false
otherwise.
-
logErrors
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.- Parameters:
errors
- a collection of errors to be logged.- Returns:
true
if there are any fatal issues present in the collection,false
otherwise.
-
fatalIssuesFound
public static boolean fatalIssuesFound()
Check whether a fatal error is present in the list of all messages.- Returns:
true
if there are any fatal issues in this error context,false
otherwise.
-
process
public static <T> T process(Producer<T> producer)
Invoke given producer task and gather errors. After the task is complete all gathered errors are logged. No exception is thrown even if there is a fatal error present in the list of errors.- Parameters:
producer
- producer task to be invoked.- Returns:
- the result produced by the task.
-
process
public static <T> T process(java.util.concurrent.Callable<T> task) throws java.lang.Exception
Invoke given callable task and gather messages. After the task is complete all gathered errors are logged. Any exception thrown by the throwable is re-thrown.- Parameters:
task
- callable task to be invoked.- Returns:
- the result produced by the task.
- Throws:
java.lang.Exception
- exception thrown by the task.
-
processWithException
public static <T> T processWithException(Producer<T> producer)
Invoke given producer task and gather messages. After the task is complete all gathered errors are logged. If there is a fatal error present in the list of errors anexception
is thrown.- Parameters:
producer
- producer task to be invoked.- Returns:
- the result produced by the task.
-
process
public static void process(java.lang.Runnable task)
Invoke given task and gather messages. After the task is complete all gathered errors are logged. No exception is thrown even if there is a fatal error present in the list of errors.- Parameters:
task
- task to be invoked.
-
processWithException
public static void processWithException(java.lang.Runnable task)
Invoke given task and gather messages. After the task is complete all gathered errors are logged. If there is a fatal error present in the list of errors anexception
is thrown.- Parameters:
task
- task to be invoked.
-
process
private static <T> T process(Producer<T> task, boolean throwException)
-
process
private static <T> T process(java.util.concurrent.Callable<T> task, boolean throwException) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getInstance
private static Errors getInstance()
-
getErrorMessages
public static java.util.List<Errors.ErrorMessage> getErrorMessages()
Get the list of all error messages.- Returns:
- non-null error message list.
-
getErrorMessages
public static java.util.List<Errors.ErrorMessage> getErrorMessages(boolean afterMark)
Get the list of error messages.The
afterMark
flag indicates whether only those issues should be returned that were added after amark has been set
.- Parameters:
afterMark
- iftrue
, only issues added after a mark has been set are returned, iffalse
all issues are returned.- Returns:
- non-null error list.
-
mark
public static void mark()
Set a mark at a current position in the errors messages list.
-
unmark
public static void unmark()
Remove a previously set mark, if any.
-
reset
public static void reset()
Removes all issues that have been added since the last marked position as well as removes the last mark.
-
_mark
private void _mark()
-
_unmark
private void _unmark()
-
_reset
private void _reset()
-
preProcess
private void preProcess()
-
postProcess
private void postProcess(boolean throwException)
-
_getErrorMessages
private java.util.List<Errors.ErrorMessage> _getErrorMessages(boolean afterMark)
-
-