2.17.2: 2011-06-17

net.sf.basedb.util.extensions
Class LoggingErrorHandlerFactory

java.lang.Object
  extended by net.sf.basedb.util.extensions.LoggingErrorHandlerFactory
All Implemented Interfaces:
ErrorHandler<Action>, ErrorHandlerFactory<Action>
Direct Known Subclasses:
RethrowErrorHandlerFactory

public class LoggingErrorHandlerFactory
extends Object
implements ErrorHandlerFactory<Action>, ErrorHandler<Action>

Exception handler factory implementation that logs error messages using the default logging mechanism. This factory is it's own error handler and the implementation is thread-safe (once the level has been set).

Since:
2.17
Author:
Nicklas
Last modified
$Date: 2010-11-15 13:32:35 +0100 (Mon, 15 Nov 2010) $

Field Summary
private  Level level
           
private static Logger log
           
private  boolean rememberLast
           
 
Constructor Summary
LoggingErrorHandlerFactory()
          Create a new error-level loggin error handler factory.
LoggingErrorHandlerFactory(String level)
          Create a new custom-level logging error handler factory.
 
Method Summary
 ErrorHandler<Action> getErrorHandler(InvokationContext<? extends Action> context)
          Get an error handler for the current context.
 void handleError(InvokationContext<? extends Action> context, Action action, String message, Throwable t)
          Handle an exception that has happened.
 void setLevel(String level)
          Set the level of the error handler.
 void setRememberLast(String remember)
          Set a flag indicating if errors should be remembered by the registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log

level

private Level level

rememberLast

private boolean rememberLast
Constructor Detail

LoggingErrorHandlerFactory

public LoggingErrorHandlerFactory()
Create a new error-level loggin error handler factory.


LoggingErrorHandlerFactory

public LoggingErrorHandlerFactory(String level)
Create a new custom-level logging error handler factory.

Method Detail

getErrorHandler

public ErrorHandler<Action> getErrorHandler(InvokationContext<? extends Action> context)
Description copied from interface: ErrorHandlerFactory
Get an error handler for the current context. This method is called once for each request/use of an extension point. Errors that happen when processing things related to this extension point will be directed to the error handler returned by this method. The factory may create a new or it may re-use the same error handler for each request. If the error handler is re-used it must be thread-safe.

Specified by:
getErrorHandler in interface ErrorHandlerFactory<Action>
Parameters:
context - The current invokation context which is an extension point context (the InvokationContext.getExtension() method is expected to return null)

handleError

public void handleError(InvokationContext<? extends Action> context,
                        Action action,
                        String message,
                        Throwable t)
Description copied from interface: ErrorHandler
Handle an exception that has happened. It is up to the error handler what should happen next. Typically, error should always be logged but the error handler may choose to re-throw the exception. If the exception isn't already a runtime exception it must be wrapped.

Note that there are three stages in the extension mechanism, which may cause some of the parameters to be null:

Specified by:
handleError in interface ErrorHandler<Action>
Parameters:
context - The extension context, which can be null
action - The action that was being rendered when the error happened, which can be null
message - An optional error message
t - The error

setLevel

public void setLevel(String level)
Set the level of the error handler.


setRememberLast

public void setRememberLast(String remember)
Set a flag indicating if errors should be remembered by the registry. The last error for an extension or extension point can be retreived by calling Registry.getLastExtensionError(String) and/or Registry.getLastExtensionPointError(String).

Parameters:
remember - A string that evaluates to a boolean

2.17.2: 2011-06-17