Search in sources :

Example 1 with Aop

use of com.blade.aop.annotation.Aop in project blade by biezhi.

the class AbstractMethodInterceptor method intercept.

/**
	 * 切面逻辑 obj 代理对象实例 method 源对象的方法名 args 传递给方法的实际入参 proxyMethod
	 * 与源对象中的method相对应的代理对象中的方法
	 */
public Object intercept(Object target, Method method, Object[] args, MethodProxy proxy) throws Throwable {
    // 执行源对象的method方法
    try {
        Aop aop = method.getDeclaringClass().getAnnotation(Aop.class);
        if (null != aop) {
            String methodPrefix = aop.methodPrefix();
            String methodName = method.getName();
            if (!"".equals(methodPrefix) && !methodName.startsWith(methodPrefix)) {
                return proxy.invokeSuper(target, args);
            }
        } else {
            return proxy.invokeSuper(target, args);
        }
        Invocaction invocaction = new Invocaction(target, args, proxy);
        before(invocaction);
        Object returnValue = doInvoke(invocaction);
        after(invocaction);
        return returnValue;
    } catch (Exception e) {
        throw e;
    }
}
Also used : Aop(com.blade.aop.annotation.Aop)

Example 2 with Aop

use of com.blade.aop.annotation.Aop in project blade by biezhi.

the class ProxyFactory method filter.

private static MethodInterceptor[] filter(Class<?> clazz) {
    if (null != aopInterceptors) {
        Aop aop = clazz.getAnnotation(Aop.class);
        if (null != aop) {
            Class<?> inteceptorType = aop.value();
            List<MethodInterceptor> methodInterceptors = new ArrayList<MethodInterceptor>();
            for (MethodInterceptor methodInterceptor : aopInterceptors) {
                if (inteceptorType.equals(methodInterceptor.getClass())) {
                    methodInterceptors.add(methodInterceptor);
                }
            }
            return methodInterceptors.toArray(new MethodInterceptor[methodInterceptors.size()]);
        }
    }
    return null;
}
Also used : Aop(com.blade.aop.annotation.Aop) MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) ArrayList(java.util.ArrayList)

Aggregations

Aop (com.blade.aop.annotation.Aop)2 ArrayList (java.util.ArrayList)1 MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)1