1 16 17 package org.springframework.aop.aspectj; 18 19 import java.lang.reflect.Method ; 20 21 import org.springframework.aop.AfterAdvice; 22 import org.springframework.aop.AfterReturningAdvice; 23 24 30 public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice implements AfterReturningAdvice, AfterAdvice { 31 32 public AspectJAfterReturningAdvice( 33 Method aspectJBeforeAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aif) { 34 35 super(aspectJBeforeAdviceMethod, pointcut, aif); 36 } 37 38 public boolean isBeforeAdvice() { 39 return false; 40 } 41 42 public boolean isAfterAdvice() { 43 return true; 44 } 45 46 public void setReturningName(String name) { 47 setReturningNameNoCheck(name); 48 } 49 50 public void afterReturning(Object returnValue, Method method, Object [] args, Object target) throws Throwable { 51 if (shouldInvokeOnReturnValueOf(returnValue)) { 52 invokeAdviceMethod(getJoinPointMatch(), returnValue, null); 53 } 54 } 55 56 61 private boolean shouldInvokeOnReturnValueOf(Object returnValue) { 62 Class returningType = getDiscoveredReturningType(); 63 if (returningType.equals(Object .class) || returningType.isPrimitive()) { 64 return true; 65 } 66 else { 67 return returningType.isAssignableFrom(returnValue.getClass()); 68 } 69 } 70 71 } 72 | Popular Tags |