📄 applicationengine.java
字号:
package com.ejsun.entapps.presentation;
import java.io.IOException;
import javax.servlet.ServletException;
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.apache.tapestry.request.ResponseOutputStream;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.ejsun.entapps.presentation.pages.ApplicationBasePage;
import com.ejsun.entapps.service.GenericServiceException;
import com.ejsun.entapps.service.InstallService;
import com.ejsun.entapps.service.impl.SpringServiceLocator;
/**
* @author Quake Wang (reference Tapestry Vlib example)
* @since 2004-3-21
* @version $Revision: 1.1 $
*
**/
public class ApplicationEngine extends BaseEngine {
private final static Log log = LogFactory.getLog(ApplicationEngine.class);
private transient boolean killSession;
protected void setupForRequest(RequestContext context) {
super.setupForRequest(context);
Global global = (Global) getGlobal();
if (global.serviceLocator == null) {
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context.getServlet().getServletContext());
global.serviceLocator = new SpringServiceLocator(applicationContext);
((InstallService) global.getService("installService")).install();
}
}
protected void cleanupAfterRequest(IRequestCycle cycle) {
super.cleanupAfterRequest(cycle);
if (killSession) {
try {
HttpSession session = cycle.getRequestContext().getSession();
if (session != null) {
session.invalidate();
}
} catch (IllegalStateException ex) {
// Ignore.
}
}
}
public void logout() {
Visit visit = (Visit) getVisit();
if (visit != null) {
visit.setUser(null);
visit = null;
}
killSession = true;
}
protected void activateExceptionPage(IRequestCycle cycle, ResponseOutputStream output, Throwable cause)
throws ServletException {
if (cause.getCause() instanceof GenericServiceException && cycle.getPage() instanceof ApplicationBasePage) {
((ApplicationBasePage) cycle.getPage()).setErrorCode(cause.getCause().getMessage());
try {
super.renderResponse(cycle, output);
} catch (IOException ioe) {
log.error(ioe);
throw new ServletException(ioe.getMessage(), ioe);
}
} else {
super.activateExceptionPage(cycle, output, cause);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -