001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 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 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 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 */ 016package io.jboot.aop.jfinal; 017 018import com.jfinal.aop.Aop; 019import com.jfinal.config.Handlers; 020import com.jfinal.core.ActionHandler; 021import com.jfinal.handler.Handler; 022 023/** 024 * Jfinal Handlers 的代理类,方便为Handler插件的自动注入功能 025 */ 026public class JfinalHandlers { 027 028 private final Handlers handlers; 029 030 public JfinalHandlers(Handlers handlers) { 031 this.handlers = handlers; 032 } 033 034 public JfinalHandlers add(Handler handler) { 035 Aop.inject(handler); 036 handlers.add(handler); 037 return this; 038 } 039 040 public JfinalHandlers add(int index, Handler handler) { 041 Aop.inject(handler); 042 handlers.getHandlerList().add(index, handler); 043 return this; 044 } 045 046 public JfinalHandlers setActionHandler(ActionHandler actionHandler) { 047 Aop.inject(actionHandler); 048 handlers.setActionHandler(actionHandler); 049 return this; 050 } 051 052 public Handlers getHandlers() { 053 return handlers; 054 } 055}