Package org.nutz.mvc.impl.processor

Source Code of org.nutz.mvc.impl.processor.ActionFiltersProcessor

package org.nutz.mvc.impl.processor;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.ActionInfo;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.ObjectInfo;
import org.nutz.mvc.View;

/**
*
* @author zozoh(zozohtnt@gmail.com)
* @author wendal(wendal1985@gmail.com)
*
*/
public class ActionFiltersProcessor extends AbstractProcessor {

  private ActionFilter[] filters = {};
 
  public void init(NutConfig config, ActionInfo ai) throws Throwable {
    ObjectInfo<? extends ActionFilter>[] filterInfos = ai.getFilterInfos();
    if (null != filterInfos) {
      filters = new ActionFilter[filterInfos.length];
      for (int i = 0; i < filters.length; i++) {
        filters[i] = evalObj(config, filterInfos[i]);
      }
    }
  }

  public void process(ActionContext ac) throws Throwable {
    View view;
    for (ActionFilter filter : filters) {
      view = filter.match(ac);
      if (null != view) {
        Object obj = ac.getError();
        if (null == obj)
          obj = ac.getMethodReturn();
        view.render(ac.getRequest(), ac.getResponse(), obj);
        return;
      }
    }
    doNext(ac);
  }

}
TOP

Related Classes of org.nutz.mvc.impl.processor.ActionFiltersProcessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.