MethodBeforeAdviceInterceptor.java 1017 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package cn.noexception.container.aop.framework.adapter;

import cn.noexception.container.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * MethodBeforeAdviceInterceptor
 *   - 方法拦截器
 * @author 吕滔
 * @Date 2021/11/4 16:34
 */
public class MethodBeforeAdviceInterceptor implements MethodInterceptor {
    private MethodBeforeAdvice advice;

16 17
    public MethodBeforeAdviceInterceptor(){}

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
        this.advice = advice;
    }

    /**
     * 实现了 MethodInterceptor 接口,调用 advice 中的 before 方法,传入对应的参数信息。
     * @param invocation
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        this.advice.before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}