org.kuali.student.common.util
Class ExceptionMappingAdvice

java.lang.Object
  extended by org.kuali.student.common.util.ExceptionMappingAdvice
All Implemented Interfaces:
org.aopalliance.aop.Advice, AfterAdvice, ThrowsAdvice, Ordered

public class ExceptionMappingAdvice
extends Object
implements ThrowsAdvice, Ordered

Author:
Daniel Epstein

Use this Advice to map one exception to another for use when other advice eats your runtime exceptions outside of your code. This happens in Transactions when commit is not called until outside of your DAO layer.

Set the property "exceptionMapping" as a map that maps an exception class to your own exception class

Remember that aspect order is important and that this bean will always be order "500"

Example:
 <tx:annotation-driven transaction-manager="JtaTxManager" order="1000"/>
 lt;bean id="mapExceptionAdvisor"
 class="org.myfoo.ExceptionMappingAdvice">
 <property name="exceptionMapping">
        <map>
                <entry key="javax.persistence.EntityExistsException"
                        value="org.myfoo.exceptions.AlreadyExistsException" />
        </map>
 </property>
 lt;/bean>
 lt;aop:config>
 <aop:aspect id="dataAccessToBusinessException"
        ref="mapExceptionAdvisor">
        <aop:after-throwing
                pointcut="execution(* org.myfoo.service.*.*(..))"
                method="afterThrowing" throwing="ex" />
 </aop:aspect>
 lt;/aop:config>
 

Field Summary
private  Class<? extends Exception> defaultException
           
private  Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping
           
(package private)  Logger logger
           
private  int order
           
private static long serialVersionUID
           
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
ExceptionMappingAdvice()
           
 
Method Summary
 void afterThrowing(Exception ex)
          This method will use the real exception thrown and look up the exception that should be thrown
 Class<? extends Exception> getDefaultException()
           
 Map<Class<? extends Exception>,Class<? extends Exception>> getExceptionMapping()
           
 int getOrder()
           
 void setDefaultException(Class<? extends Exception> defaultException)
           
 void setExceptionMapping(Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping)
           
 void setOrder(int order)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

order

private int order

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

exceptionMapping

private Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping

defaultException

private Class<? extends Exception> defaultException

logger

final Logger logger
Constructor Detail

ExceptionMappingAdvice

public ExceptionMappingAdvice()
Method Detail

afterThrowing

public void afterThrowing(Exception ex)
                   throws Exception
This method will use the real exception thrown and look up the exception that should be thrown

Parameters:
ex -
Throws:
Exception

getOrder

public int getOrder()
Specified by:
getOrder in interface Ordered

setOrder

public void setOrder(int order)
Parameters:
order - the order to set

getExceptionMapping

public Map<Class<? extends Exception>,Class<? extends Exception>> getExceptionMapping()
Returns:
the exceptionMapping

setExceptionMapping

public void setExceptionMapping(Map<Class<? extends Exception>,Class<? extends Exception>> exceptionMapping)
Parameters:
exceptionMapping - the exceptionMapping to set

getDefaultException

public Class<? extends Exception> getDefaultException()
Returns:
the defaultException

setDefaultException

public void setDefaultException(Class<? extends Exception> defaultException)
Parameters:
defaultException - the defaultException to set


Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.