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.BeforeAdvice;
025import org.springframework.aop.MethodBeforeAdvice;
026import org.springframework.util.Assert;
027
028/**
029 * Interceptor to wrap am {@link org.springframework.aop.MethodBeforeAdvice}.
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 AfterReturningAdviceInterceptor
035 * @see ThrowsAdviceInterceptor
036 */
037@SuppressWarnings("serial")
038public class MethodBeforeAdviceInterceptor implements MethodInterceptor, BeforeAdvice, Serializable {
039
040        private final MethodBeforeAdvice advice;
041
042
043        /**
044         * Create a new MethodBeforeAdviceInterceptor for the given advice.
045         * @param advice the MethodBeforeAdvice to wrap
046         */
047        public MethodBeforeAdviceInterceptor(MethodBeforeAdvice 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                this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());
056                return mi.proceed();
057        }
058
059}