/**
 * Copyright (c) 2015-2018, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jboot.aop.interceptor;


import com.jfinal.aop.Interceptor;
import com.jfinal.aop.InterceptorManager;
import com.jfinal.core.Controller;
import io.jboot.utils.ClassKits;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * 兼容 JFinal Service 的拦截器
 */
public class JFinalBeforeInterceptor implements MethodInterceptor {

    InterceptorManager manger = InterceptorManager.me();

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {

        Class targetClass = methodInvocation.getThis().getClass();

        //过滤掉controller，因为controller由action去执行@Before相关注解了
        if (Controller.class.isAssignableFrom(targetClass)) {
            return methodInvocation.proceed();
        }

        targetClass = ClassKits.getUsefulClass(targetClass);
        Method method = methodInvocation.getMethod();

        Interceptor[] finalInters = manger.buildServiceMethodInterceptor(InterceptorManager.NULL_INTERS, targetClass, method);
        JFinalBeforeInvocation invocation = new JFinalBeforeInvocation(methodInvocation, finalInters, methodInvocation.getArguments());
        invocation.invoke();
        return invocation.getReturnValue();
    }

}

@@ -1060,65 +1060,8 @@
  %7B%0A%0A
-    InterceptorManager manger = InterceptorManager.me();%0A
 %0A   
@@ -1526,43 +1526,118 @@
     
-Interceptor%5B%5D finalInters = m
+//service%E5%B1%82%E7%9A%84%E6%89%80%E6%9C%89%E6%8B%A6%E6%88%AA%E5%99%A8%EF%BC%8C%E5%8C%85%E5%90%AB%E4%BA%86%E5%85%A8%E5%B1%80%E7%9A%84%E6%8B%A6%E6%88%AA%E5%99%A8 %E5%92%8C @Before %E7%9A%84%E6%8B%A6%E6%88%AA%E5%99%A8%0A        Interceptor%5B%5D serviceInterceptors = InterceptorM
 an
+a
 ger.
+me().
 buil
@@ -1809,17 +1809,25 @@
 on, 
-finalInte
+serviceIntercepto
 rs, 

optimize JFinalBeforeInterceptor