01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
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: import org.springframework.util.ClassUtils;
24:
25: /**
26: * Spring AOP advice wrapping an AspectJ after-returning advice method.
27: *
28: * @author Rod Johnson
29: * @author Juergen Hoeller
30: * @since 2.0
31: */
32: public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
33: implements AfterReturningAdvice, AfterAdvice {
34:
35: public AspectJAfterReturningAdvice(
36: Method aspectJBeforeAdviceMethod,
37: AspectJExpressionPointcut pointcut,
38: AspectInstanceFactory aif) {
39:
40: super (aspectJBeforeAdviceMethod, pointcut, aif);
41: }
42:
43: public boolean isBeforeAdvice() {
44: return false;
45: }
46:
47: public boolean isAfterAdvice() {
48: return true;
49: }
50:
51: public void setReturningName(String name) {
52: setReturningNameNoCheck(name);
53: }
54:
55: public void afterReturning(Object returnValue, Method method,
56: Object[] args, Object target) throws Throwable {
57: if (shouldInvokeOnReturnValueOf(returnValue)) {
58: invokeAdviceMethod(getJoinPointMatch(), returnValue, null);
59: }
60: }
61:
62: /**
63: * Following AspectJ semantics, if a returning clause was specified, then the
64: * advice is only invoked if the returned value is an instance of the given
65: * returning type. If the returning type is Object, the advice is *always* invoked.
66: * @param returnValue the return value of the target method
67: * @return whether to invoke the advice method for the given return value
68: */
69: private boolean shouldInvokeOnReturnValueOf(Object returnValue) {
70: return ClassUtils.isAssignableValue(
71: getDiscoveredReturningType(), returnValue);
72: }
73:
74: }
|