001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.aop.aspectj; 018 019import java.io.Serializable; 020import java.lang.reflect.Method; 021 022import org.aopalliance.intercept.MethodInterceptor; 023import org.aopalliance.intercept.MethodInvocation; 024import org.aspectj.lang.ProceedingJoinPoint; 025import org.aspectj.weaver.tools.JoinPointMatch; 026 027import org.springframework.aop.ProxyMethodInvocation; 028 029/** 030 * Spring AOP around advice (MethodInterceptor) that wraps 031 * an AspectJ advice method. Exposes ProceedingJoinPoint. 032 * 033 * @author Rod Johnson 034 * @author Juergen Hoeller 035 * @since 2.0 036 */ 037@SuppressWarnings("serial") 038public class AspectJAroundAdvice extends AbstractAspectJAdvice implements MethodInterceptor, Serializable { 039 040 public AspectJAroundAdvice( 041 Method aspectJAroundAdviceMethod, AspectJExpressionPointcut pointcut, AspectInstanceFactory aif) { 042 043 super(aspectJAroundAdviceMethod, pointcut, aif); 044 } 045 046 047 @Override 048 public boolean isBeforeAdvice() { 049 return false; 050 } 051 052 @Override 053 public boolean isAfterAdvice() { 054 return false; 055 } 056 057 @Override 058 protected boolean supportsProceedingJoinPoint() { 059 return true; 060 } 061 062 @Override 063 public Object invoke(MethodInvocation mi) throws Throwable { 064 if (!(mi instanceof ProxyMethodInvocation)) { 065 throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); 066 } 067 ProxyMethodInvocation pmi = (ProxyMethodInvocation) mi; 068 ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi); 069 JoinPointMatch jpm = getJoinPointMatch(pmi); 070 return invokeAdviceMethod(pjp, jpm, null, null); 071 } 072 073 /** 074 * Return the ProceedingJoinPoint for the current invocation, 075 * instantiating it lazily if it hasn't been bound to the thread already. 076 * @param rmi the current Spring AOP ReflectiveMethodInvocation, 077 * which we'll use for attribute binding 078 * @return the ProceedingJoinPoint to make available to advice methods 079 */ 080 protected ProceedingJoinPoint lazyGetProceedingJoinPoint(ProxyMethodInvocation rmi) { 081 return new MethodInvocationProceedingJoinPoint(rmi); 082 } 083 084}