001/* 002 * Copyright 2002-2018 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.framework.adapter; 018 019import java.io.Serializable; 020 021import org.aopalliance.intercept.MethodInterceptor; 022import org.aopalliance.intercept.MethodInvocation; 023 024import org.springframework.aop.AfterAdvice; 025import org.springframework.aop.AfterReturningAdvice; 026import org.springframework.util.Assert; 027 028/** 029 * Interceptor to wrap an {@link org.springframework.aop.AfterReturningAdvice}. 030 * Used internally by the AOP framework; application developers should not need 031 * to use this class directly. 032 * 033 * @author Rod Johnson 034 * @see MethodBeforeAdviceInterceptor 035 * @see ThrowsAdviceInterceptor 036 */ 037@SuppressWarnings("serial") 038public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice, Serializable { 039 040 private final AfterReturningAdvice advice; 041 042 043 /** 044 * Create a new AfterReturningAdviceInterceptor for the given advice. 045 * @param advice the AfterReturningAdvice to wrap 046 */ 047 public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { 048 Assert.notNull(advice, "Advice must not be null"); 049 this.advice = advice; 050 } 051 052 053 @Override 054 public Object invoke(MethodInvocation mi) throws Throwable { 055 Object retVal = mi.proceed(); 056 this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis()); 057 return retVal; 058 } 059 060}