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.aopalliance.intercept.MethodInterceptor;
22: import org.aopalliance.intercept.MethodInvocation;
23: import org.aspectj.lang.ProceedingJoinPoint;
24: import org.aspectj.weaver.tools.JoinPointMatch;
25:
26: import org.springframework.aop.ProxyMethodInvocation;
27:
28: /**
29: * Spring AOP around advice (MethodInterceptor) that wraps
30: * an AspectJ advice method. Exposes ProceedingJoinPoint.
31: *
32: * @author Rod Johnson
33: * @author Juergen Hoeller
34: * @since 2.0
35: */
36: public class AspectJAroundAdvice extends AbstractAspectJAdvice
37: implements MethodInterceptor {
38:
39: public AspectJAroundAdvice(Method aspectJAroundAdviceMethod,
40: AspectJExpressionPointcut pointcut,
41: AspectInstanceFactory aif) {
42:
43: super (aspectJAroundAdviceMethod, pointcut, aif);
44: }
45:
46: public boolean isBeforeAdvice() {
47: return false;
48: }
49:
50: public boolean isAfterAdvice() {
51: return false;
52: }
53:
54: protected boolean supportsProceedingJoinPoint() {
55: return true;
56: }
57:
58: public Object invoke(MethodInvocation mi) throws Throwable {
59: if (!(mi instanceof ProxyMethodInvocation)) {
60: throw new IllegalStateException(
61: "MethodInvocation is not a Spring ProxyMethodInvocation: "
62: + mi);
63: }
64: ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
65: ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
66: JoinPointMatch jpm = getJoinPointMatch(pmi);
67: return invokeAdviceMethod(pjp, jpm, null, null);
68: }
69:
70: /**
71: * Return the ProceedingJoinPoint for the current invocation,
72: * instantiating it lazily if it hasn't been bound to the thread already.
73: * @param rmi the current Spring AOP ReflectiveMethodInvocation,
74: * which we'll use for attribute binding
75: * @return the ProceedingJoinPoint to make available to advice methods
76: */
77: protected ProceedingJoinPoint lazyGetProceedingJoinPoint(
78: ProxyMethodInvocation rmi) {
79: return new MethodInvocationProceedingJoinPoint(rmi);
80: }
81:
82: }
|