KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > aspectj > AspectJAroundAdvice


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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 implements MethodInterceptor {
37
38     public AspectJAroundAdvice(
39             Method JavaDoc aspectJAroundAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aif) {
40
41         super(aspectJAroundAdviceMethod, pointcut, aif);
42     }
43
44     public boolean isBeforeAdvice() {
45         return false;
46     }
47
48     public boolean isAfterAdvice() {
49         return false;
50     }
51
52
53     public Object JavaDoc invoke(MethodInvocation mi) throws Throwable JavaDoc {
54         if (!(mi instanceof ProxyMethodInvocation)) {
55             throw new IllegalStateException JavaDoc("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
56         }
57         ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi;
58         ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
59         JoinPointMatch jpm = getJoinPointMatch(pmi);
60         return invokeAdviceMethod(pjp, jpm, null, null);
61     }
62
63     /**
64      * Return the ProceedingJoinPoint for the current invocation,
65      * instantiating it lazily if it hasn't been bound to the thread already.
66      * @param rmi the current Spring AOP ReflectiveMethodInvocation,
67      * which we'll use for attribute binding
68      * @return the ProceedingJoinPoint to make available to advice methods
69      */

70     protected ProceedingJoinPoint lazyGetProceedingJoinPoint(ProxyMethodInvocation rmi) {
71         return new MethodInvocationProceedingJoinPoint(rmi);
72     }
73
74 }
75
Popular Tags