com.emarsys.ecommon.exceptions.handling
Class ExceptionScenario<E extends java.lang.Exception,T extends java.lang.Exception>

java.lang.Object
  extended by com.emarsys.ecommon.exceptions.handling.ExceptionScenario<E,T>
Type Parameters:
E - - the type of the Exception that may be thrown in this scenario
T - - the type of the Exception that may be rethrown in this scenario


public class ExceptionScenario<E extends java.lang.Exception,T extends java.lang.Exception>
extends java.lang.Object

An ExceptionScenario describes the context of a scenario where Exceptions may occur.

An ExceptionScenario is unique through its name and the classes specifying the type of the handled and (possibly) rethrown Exceptions which also correpond to the scenario's type parameters.

NOTE: the whole pluggable exception handling (PEH) module is highly experimental and still under heavy development, don't use it in production code unless you know what you're doing!

Author:
Michael "kULO" Kulovits


Field Summary
protected  java.lang.Class<E> handledExceptionClass
           
protected  java.lang.String name
           
static java.lang.String NAME_REGEX
           
protected  java.lang.Class<T> thrownExceptionClass
           
 
Constructor Summary
ExceptionScenario(java.lang.String name, java.lang.Class<E> handledExceptionClass, java.lang.Class<T> rethrownExceptionClass)
           
 
Method Summary
 boolean equals(java.lang.Object that)
           
 ExceptionScenario<E,T> generalize()
           
 java.lang.Class<E> getHandledExceptionClass()
           
static ExceptionScenario<?,?> getInstance(java.lang.reflect.AnnotatedElement elem)
          If a Method is passed a HandleExceptions annotation on it will be searched for, else if it's an instance of Class this will be done too and if not successfull than also delegates specified through HandleExceptionsFor will be searched.
static
<E extends java.lang.Exception,T extends java.lang.Exception>
ExceptionScenario<E,T>
getInstance(java.lang.String name, java.lang.Class<E> handledExceptionClass, java.lang.Class<T> rethrownExceptionClass)
           
static
<E extends java.lang.Exception>
ExceptionScenario<E,java.lang.Exception>
getInstanceWithHandledException(java.lang.String name, java.lang.Class<E> handledExceptionClass)
           
static
<T extends java.lang.Exception>
ExceptionScenario<java.lang.Exception,T>
getInstanceWithThrownException(java.lang.String name, java.lang.Class<T> rethrownExceptionClass)
           
 java.lang.String getName()
           
 java.lang.Class<T> getThrownExceptionClass()
           
 int hashCode()
           
 ExceptionScenario<E,T> internalize(java.lang.Object client)
           
 boolean isGeneralizable()
           
protected  void setName(java.lang.String name)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_REGEX

public static final java.lang.String NAME_REGEX
See Also:
Constant Field Values

name

protected java.lang.String name

handledExceptionClass

protected java.lang.Class<E extends java.lang.Exception> handledExceptionClass

thrownExceptionClass

protected java.lang.Class<T extends java.lang.Exception> thrownExceptionClass
Constructor Detail

ExceptionScenario

public ExceptionScenario(java.lang.String name,
                         java.lang.Class<E> handledExceptionClass,
                         java.lang.Class<T> rethrownExceptionClass)
Parameters:
name -
handledExceptionClass -
thrownExceptionClass -
Method Detail

getInstance

public static <E extends java.lang.Exception,T extends java.lang.Exception> ExceptionScenario<E,T> getInstance(java.lang.String name,
                                                                                                               java.lang.Class<E> handledExceptionClass,
                                                                                                               java.lang.Class<T> rethrownExceptionClass)
Type Parameters:
E -
T -
Parameters:
name -
handledExceptionClass -
rethrownExceptionClass -
Returns:

getInstanceWithHandledException

public static <E extends java.lang.Exception> ExceptionScenario<E,java.lang.Exception> getInstanceWithHandledException(java.lang.String name,
                                                                                                                       java.lang.Class<E> handledExceptionClass)
Type Parameters:
E -
Parameters:
name -
handledExceptionClass -
Returns:

getInstanceWithThrownException

public static <T extends java.lang.Exception> ExceptionScenario<java.lang.Exception,T> getInstanceWithThrownException(java.lang.String name,
                                                                                                                      java.lang.Class<T> rethrownExceptionClass)
Type Parameters:
T -
Parameters:
name -
rethrownExceptionClass -
Returns:

getInstance

public static ExceptionScenario<?,?> getInstance(java.lang.reflect.AnnotatedElement elem)
If a Method is passed a HandleExceptions annotation on it will be searched for, else if it's an instance of Class this will be done too and if not successfull than also delegates specified through HandleExceptionsFor will be searched.

Parameters:
o -
Returns:
an ExceptionScenario with the name, handled and thrown exception classes specified through an HandleExceptions or HandleExceptionsFor annotation on the passed AnnotatedElement or null if not present.

setName

protected void setName(java.lang.String name)

getHandledExceptionClass

public java.lang.Class<E> getHandledExceptionClass()
Returns:
the handledExceptionClass

getName

public java.lang.String getName()
Returns:
the name

getThrownExceptionClass

public java.lang.Class<T> getThrownExceptionClass()
Returns:
the thrownExceptionClass

isGeneralizable

public boolean isGeneralizable()
Returns:

generalize

public ExceptionScenario<E,T> generalize()
Returns:

internalize

public ExceptionScenario<E,T> internalize(java.lang.Object client)
Parameters:
client -
Returns:
a copy of the passed ExceptionScenario with its name prefixed with the passed instance's Class name.

equals

public boolean equals(java.lang.Object that)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2010 emarsys AG. All Rights Reserved.