ch.elca.el4j.services.exceptionhandler
Class AbstractExceptionHandlerInterceptor

java.lang.Object
  extended by ch.elca.el4j.services.exceptionhandler.AbstractExceptionHandlerInterceptor
All Implemented Interfaces:
org.aopalliance.aop.Advice, org.aopalliance.intercept.Interceptor, org.aopalliance.intercept.MethodInterceptor
Direct Known Subclasses:
ContextExceptionHandlerInterceptor, SafetyFacadeInterceptor

public abstract class AbstractExceptionHandlerInterceptor
extends Object
implements org.aopalliance.intercept.MethodInterceptor

This class provides functionality to handle exceptions centrally (with respect to a number of classes or the whole system).

Author:
Andreas Bur (ABU)
File-location:
AbstractExceptionHandlerInterceptor
Last check-in date:
2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) by swismer for revision 3873

Field Summary
protected static ThreadLocal s_retries
          Holds the number of retries.
 
Constructor Summary
AbstractExceptionHandlerInterceptor()
           
 
Method Summary
protected  Object doHandleException(Throwable t, org.aopalliance.intercept.MethodInvocation invocation, ExceptionConfiguration[] exceptionConfigurations)
          Handles the given exception that was thrown given method invocation using the provided exception configurations.
protected  Object doInvoke(org.aopalliance.intercept.MethodInvocation invocation)
          Performs the actual invocation of the MethodInvocation.prceed() method.
static int getRetries()
           
protected abstract  Object handleException(Throwable t, org.aopalliance.intercept.MethodInvocation invocation)
          Handles the given exception that was thrown in the given method invocation's execution.
protected  void handleInterfaceExceptions(org.aopalliance.intercept.MethodInvocation invocation, Throwable t)
          Handles exceptions that are listed in a method's signature.
 Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
          
 void setDefaultBehaviourConsume(boolean defaultBehaviourConsume)
          Sets the interceptor's exception handling default policy.
 void setForwardSignatureExceptions(boolean forwardSignatureException)
          Sets whether all exceptions have to be handled by this safety facade, even those which are listed in the signature.
 void setHandleRTSignatureExceptions(boolean handleRTSignatureExceptions)
          Sets whether runtime exceptions, that are listed in a method's signature, have to be handled.
protected static void setRetries(int retries)
          Sets the number of retries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_retries

protected static final ThreadLocal s_retries
Holds the number of retries.

Constructor Detail

AbstractExceptionHandlerInterceptor

public AbstractExceptionHandlerInterceptor()
Method Detail

getRetries

public static int getRetries()
Returns:
Returns the number of retries left, allowing AbstractRetryExceptionHandlers to determine whether they have to call their handling routines. -1 signals that no retires have been registered so far.

setRetries

protected static void setRetries(int retries)
Sets the number of retries. Each retry reinvokes the the interceptor chain as it would have been called by the client directly.

Parameters:
retries - The number of retries to set.

setHandleRTSignatureExceptions

public void setHandleRTSignatureExceptions(boolean handleRTSignatureExceptions)
Sets whether runtime exceptions, that are listed in a method's signature, have to be handled.

Parameters:
handleRTSignatureExceptions - true to handle unchecked exceptions by this exception handler, false to rethorw them.

setDefaultBehaviourConsume

public void setDefaultBehaviourConsume(boolean defaultBehaviourConsume)
Sets the interceptor's exception handling default policy. This affects exceptions that aren't handled by any exception handler only. Default is to consume them.

Parameters:
defaultBehaviourConsume - true to consume all exceptions that are not handled by an exception handler, false to forward all unhandled exceptions.

setForwardSignatureExceptions

public void setForwardSignatureExceptions(boolean forwardSignatureException)
Sets whether all exceptions have to be handled by this safety facade, even those which are listed in the signature.

Parameters:
forwardSignatureException - true forces to forward any exceptions listed in a method's interface (even unchecked exceptions, if they are in the signature). false handles all exceptions by an appropriate registered exception handler.
See Also:
setHandleRTSignatureExceptions(boolean)

invoke

public Object invoke(org.aopalliance.intercept.MethodInvocation invocation)
              throws Throwable

Specified by:
invoke in interface org.aopalliance.intercept.MethodInterceptor
Throws:
Throwable

doInvoke

protected Object doInvoke(org.aopalliance.intercept.MethodInvocation invocation)
                   throws RetryException,
                          Throwable
Performs the actual invocation of the MethodInvocation.prceed() method.

Parameters:
invocation - The MethodInvocation to call proceed() on.
Returns:
Returns the target's result;
Throws:
RetryException - Signals that the complete invocation has to be rerun.
Throwable - Any exception thrown by the original method's invocation or by one of the used exception handlers.

handleException

protected abstract Object handleException(Throwable t,
                                          org.aopalliance.intercept.MethodInvocation invocation)
                                   throws RetryException,
                                          Throwable
Handles the given exception that was thrown in the given method invocation's execution.

Parameters:
t - The exception to handle.
invocation - The method invocation that threw the exception.
Returns:
Returns an object which is treated as the original invocation's result.
Throws:
RetryException - Signals that the complete invocation has to be rerun.
Throwable - Any exception thrown by a exception handler.

handleInterfaceExceptions

protected void handleInterfaceExceptions(org.aopalliance.intercept.MethodInvocation invocation,
                                         Throwable t)
                                  throws Throwable
Handles exceptions that are listed in a method's signature.

Parameters:
invocation - The called method invocation.
t - The caught exception.
Throws:
Throwable - The given exception t if it has to be forwarded to the invoker.

doHandleException

protected Object doHandleException(Throwable t,
                                   org.aopalliance.intercept.MethodInvocation invocation,
                                   ExceptionConfiguration[] exceptionConfigurations)
                            throws RetryException,
                                   Throwable
Handles the given exception that was thrown given method invocation using the provided exception configurations.

Parameters:
t - The exception to handle.
invocation - The method invocation that threw the exception.
exceptionConfigurations - The exception handler configuration to use.
Returns:
Returns an object which is treated as the original invocation's result.
Throws:
RetryException - Signals that the complete invocation has to be rerun.
Throwable - Any exception thrown by a exception handler.


Copyright © 2005-2011 ELCA. All Rights Reserved.