package com.Chang.manage;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.engine.BaseEngine;
import org.apache.tapestry.request.RequestContext;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ResEngine extends BaseEngine {
public static final String APPLICATION_CONTEXT_KEY = "appContext";
//private transient boolean killSession;
//private static final Log log = LogFactory.getLog(ResEngine.class);
public ResEngine() {
//log.info("Create a ResEngine Engine Instance.");
}
/**
* 通过Spring提供的WebApplicationContextUtils, 将ApplicationContext放置到Tapestry中。
*/
protected void setupForRequest(RequestContext context) {
super.setupForRequest(context);
//返回Global对象
Map global = (Map) getGlobal();
//先通过Global获得ApplicationContext,若为空,则用WebApplicationContextUtils装载
ApplicationContext ac = (ApplicationContext) global
.get(APPLICATION_CONTEXT_KEY);
if (ac == null) {
//用WebApplicationContextUtils装载ApplicationContext至TapeStry框架中
ac = WebApplicationContextUtils.getWebApplicationContext(context
.getServlet().getServletContext());
//保存至Global全局对象中
global.put(APPLICATION_CONTEXT_KEY, ac);
}
//log.info("now webapplication is initialized....................");
//获取客户端信息
//this.getClientInfo(context.getRequest());
}
/*
protected void cleanupAfterRequest(IRequestCycle cycle) {
super.cleanupAfterRequest(cycle);
// System.out.println("--------ResEngine--cleanupAfterRequest-----killSession----------"+killSession);
if (killSession) {
try {
HttpSession session = cycle.getRequestContext().getSession();
// System.out.println("--------ResEngine--cleanupAfterRequest-----session----------"+session);
if (session != null) {
session.invalidate();
}
} catch (IllegalStateException ex) {
}
}
}
*/
}