1 16 17 package org.springframework.aop.aspectj; 18 19 import java.lang.reflect.Method ; 20 21 import org.aopalliance.intercept.MethodInterceptor; 22 import org.aopalliance.intercept.MethodInvocation; 23 24 import org.springframework.aop.AfterAdvice; 25 26 32 public class AspectJAfterThrowingAdvice extends AbstractAspectJAdvice implements MethodInterceptor, AfterAdvice { 33 34 public AspectJAfterThrowingAdvice( 35 Method aspectJBeforeAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aif) { 36 37 super(aspectJBeforeAdviceMethod, pointcut, aif); 38 } 39 40 public boolean isBeforeAdvice() { 41 return false; 42 } 43 44 public boolean isAfterAdvice() { 45 return true; 46 } 47 48 public void setThrowingName(String name) { 49 setThrowingNameNoCheck(name); 50 } 51 52 public Object invoke(MethodInvocation mi) throws Throwable { 53 try { 54 return mi.proceed(); 55 } 56 catch (Throwable t) { 57 if (shouldInvokeOnThrowing(t)) { 58 invokeAdviceMethod(getJoinPointMatch(), null, t); 59 } 60 throw t; 61 } 62 } 63 64 68 private boolean shouldInvokeOnThrowing(Throwable t) { 69 Class throwingType = getDiscoveredThrowingType(); 70 return throwingType.isAssignableFrom(t.getClass()); 71 } 72 73 } 74 | Popular Tags |