Search in sources :

Example 1 with RequestIocContext

use of org.nutz.mvc.ioc.RequestIocContext in project nutz by nutzam.

the class ModuleProcessor method process.

public void process(ActionContext ac) throws Throwable {
    RequestIocContext reqContext = null;
    try {
        if (null != moduleObj) {
            ac.setModule(moduleObj);
        } else {
            Ioc ioc = ac.getIoc();
            Object obj;
            /*
                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
            if (NutSessionListener.isSessionScopeEnable && ioc instanceof Ioc2) {
                reqContext = new RequestIocContext(ac.getRequest());
                HttpSession sess = Mvcs.getHttpSession(false);
                IocContext myContext = null;
                // 如果容器可以创建 Session ...
                if (null != sess) {
                    SessionIocContext sessionContext = new SessionIocContext(sess);
                    myContext = new ComboContext(reqContext, sessionContext);
                } else // 如果容器禁止了 Session ...
                {
                    myContext = reqContext;
                }
                Mvcs.setIocContext(myContext);
                obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
            } else
                /*
                 * 否则,则仅仅简单的从容器获取
                 */
                obj = ioc.get(moduleType, injectName);
            ac.setModule(obj);
        }
        ac.setMethod(method);
        // if (log.isDebugEnabled()) //打印实际执行的Method信息
        // log.debugf("Handle URL[%s] by Method[%s]",ac.getPath(),method);
        doNext(ac);
    } finally {
        if (reqContext != null)
            try {
                reqContext.depose();
            } catch (Throwable e) {
                if (log.isDebugEnabled())
                    log.debug("ReqContext depose fail?!", e);
            }
    }
}
Also used : ComboContext(org.nutz.ioc.impl.ComboContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext) IocContext(org.nutz.ioc.IocContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) HttpSession(javax.servlet.http.HttpSession) Ioc2(org.nutz.ioc.Ioc2) Ioc(org.nutz.ioc.Ioc) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext)

Aggregations

HttpSession (javax.servlet.http.HttpSession)1 Ioc (org.nutz.ioc.Ioc)1 Ioc2 (org.nutz.ioc.Ioc2)1 IocContext (org.nutz.ioc.IocContext)1 ComboContext (org.nutz.ioc.impl.ComboContext)1 RequestIocContext (org.nutz.mvc.ioc.RequestIocContext)1 SessionIocContext (org.nutz.mvc.ioc.SessionIocContext)1