com.jfinal.aop.Interceptor Java Examples
The following examples show how to use
com.jfinal.aop.Interceptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JbootAopInterceptor.java From jboot with Apache License 2.0 | 6 votes |
/** * 移除拦截器 * * @param interceptor */ public static void removeInterceptor(Interceptor interceptor) { if (interceptor == null) { throw new NullPointerException("interceptor is null"); } synchronized (JbootAopInterceptor.class) { int length = aopInterceptors.length; List<Interceptor> tempList = new LinkedList<>(); for (int i = 0; i < length; i++) { if (aopInterceptors[i] != interceptor) { tempList.add(aopInterceptors[i]); } } if (tempList.size() != length) { aopInterceptors = tempList.toArray(new Interceptor[]{}); } } }
Example #2
Source File: JbootAopInterceptor.java From jboot with Apache License 2.0 | 6 votes |
/** * 移除拦截器 * * @param clazz */ public static void removeInterceptor(Class<? extends Interceptor> clazz) { if (clazz == null) { throw new NullPointerException("interceptor class is null"); } synchronized (JbootAopInterceptor.class) { int length = aopInterceptors.length; List<Interceptor> tempList = new LinkedList<>(); for (int i = 0; i < length; i++) { if (aopInterceptors[i].getClass() != clazz) { tempList.add(aopInterceptors[i]); } } if (tempList.size() != length) { aopInterceptors = tempList.toArray(new Interceptor[]{}); } } }
Example #3
Source File: AddonInterceptorProcesser.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void invoke() { if (index < inters.length) { Interceptor interceptor = inters[index++]; try { interceptor.intercept(this); }finally { if (Jboot.isDevMode()){ System.out.println("addon interceptor intercepted : " + interceptor); } } } else if (index++ == inters.length) { invocation.invoke(); } }
Example #4
Source File: JbootAopInterceptor.java From jboot with Apache License 2.0 | 5 votes |
/** * 添加新的拦截器 * * @param interceptor * @param toIndex */ public static void addInterceptor(Interceptor interceptor, int toIndex) { if (interceptor == null) { throw new NullPointerException("interceptor is null"); } synchronized (JbootAopInterceptor.class) { int length = aopInterceptors.length; if (toIndex < 0) { toIndex = 0; } if (toIndex > length) { toIndex = length; } Interceptor[] temp = new Interceptor[length + 1]; System.arraycopy(aopInterceptors, 0, temp, 0, toIndex); temp[toIndex] = interceptor; if (toIndex < length) { System.arraycopy(aopInterceptors, toIndex, temp, toIndex + 1, length - toIndex); } aopInterceptors = temp; } }
Example #5
Source File: AddonInterceptorManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private static void initInterceptors() { synchronized (AddonInterceptorManager.class) { Interceptor[] temp = new Interceptor[interceptorClasses.size()]; int index = 0; Iterator<Class<? extends Interceptor>> iterator = interceptorClasses.iterator(); while (iterator.hasNext()) { temp[index++] = ClassUtil.newInstance(iterator.next()); } interceptors = temp; } }
Example #6
Source File: AddonInterceptorProcesser.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void intercept(Invocation invocation) { Interceptor[] interceptors = AddonInterceptorManager.getInterceptors(); if (interceptors == null || interceptors.length == 0) { invocation.invoke(); } else { new AddonInvocation(invocation, interceptors).invoke(); } }
Example #7
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void deleteInteceptors(AddonInfo addonInfo) { List<Class<? extends Interceptor>> interceptorClasses = addonInfo.getInterceptors(); if (interceptorClasses != null) { for (Class<? extends Interceptor> c : interceptorClasses) { AddonInterceptorManager.deleteInterceptor(c); } } }
Example #8
Source File: AddonManager.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void addInterceptors(AddonInfo addonInfo) { List<Class<? extends Interceptor>> interceptorClasses = addonInfo.getInterceptors(); if (interceptorClasses != null) { for (Class<? extends Interceptor> c : interceptorClasses) { AddonInterceptorManager.addInterceptor(c); } } }
Example #9
Source File: AddonInterceptorProcesser.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public AddonInvocation(Invocation invocation, Interceptor[] interceptors) { this.invocation = invocation; this.inters = interceptors; }
Example #10
Source File: AddonInterceptorManager.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public static Interceptor[] getInterceptors() { return interceptors; }
Example #11
Source File: JbootAopInvocation.java From jboot with Apache License 2.0 | 4 votes |
public JbootAopInvocation(Invocation originInvocation, Interceptor[] inters) { this.originInvocation = originInvocation; this.inters = inters; }
Example #12
Source File: AddonInterceptorManager.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public static void addInterceptor(Class<? extends Interceptor> c) { interceptorClasses.add(c); initInterceptors(); }
Example #13
Source File: AddonInterceptorManager.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public static void deleteInterceptor(Class<? extends Interceptor> c) { interceptorClasses.removeIf(aClass -> Objects.equals(c.getName(),aClass.getName())); initInterceptors(); }
Example #14
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public void addInterceptor(Class<? extends Interceptor> clazz) { if (interceptors == null) { interceptors = new ArrayList<>(); } interceptors.add(clazz); }
Example #15
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public List<Class<? extends Interceptor>> getInterceptors() { return interceptors; }
Example #16
Source File: AddonInfo.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public void setInterceptors(List<Class<? extends Interceptor>> interceptors) { this.interceptors = interceptors; }
Example #17
Source File: AddonClassLoader.java From jpress with GNU Lesser General Public License v3.0 | 4 votes |
public void load() { for (String className : classNameList) { try { Class loadedClass = loadClass(className); Bean bean = (Bean) loadedClass.getDeclaredAnnotation(Bean.class); if (bean != null) { initBeanMapping(loadedClass); } // controllers if (Controller.class.isAssignableFrom(loadedClass)) { addonInfo.addController(loadedClass); } // interceptors else if (Interceptor.class.isAssignableFrom(loadedClass)) { if (loadedClass.getAnnotation(GlobalInterceptor.class) != null) { addonInfo.addInterceptor(loadedClass); } } // handlers else if (Handler.class.isAssignableFrom(loadedClass)) { addonInfo.addHandler(loadedClass); } // models else if (JbootModel.class.isAssignableFrom(loadedClass)) { addonInfo.addModel(loadedClass); } // directives else if (Directive.class.isAssignableFrom(loadedClass)) { addonInfo.addDirective(loadedClass); } // wechatAddons else if (WechatAddon.class.isAssignableFrom(loadedClass)) { addonInfo.addWechatAddon(loadedClass); } // addonClass else if (Addon.class.isAssignableFrom(loadedClass)) { addonInfo.setAddonClass(loadedClass); } // upgraderClass else if (AddonUpgrader.class.isAssignableFrom(loadedClass)) { addonInfo.setUpgraderClass(loadedClass); } } catch (Exception ex) { LOG.error(ex.toString(), ex); } } }