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: public Object invoke(MethodInvocation mi) throws Throwable {
55: if (!(mi instanceof ProxyMethodInvocation)) {
56: throw new IllegalStateException(
57: "MethodInvocation is not a Spring ProxyMethodInvocation: "
58: + mi);
59: }
60: ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
61: ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
62: JoinPointMatch jpm = getJoinPointMatch(pmi);
63: return invokeAdviceMethod(pjp, jpm, null, null);
64: }
65:
66: /**
67: * Return the ProceedingJoinPoint for the current invocation,
68: * instantiating it lazily if it hasn't been bound to the thread already.
69: * @param rmi the current Spring AOP ReflectiveMethodInvocation,
70: * which we'll use for attribute binding
71: * @return the ProceedingJoinPoint to make available to advice methods
72: */
73: protected ProceedingJoinPoint lazyGetProceedingJoinPoint(
74: ProxyMethodInvocation rmi) {
75: return new MethodInvocationProceedingJoinPoint(rmi);
76: }
77:
78: }
|