KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pets > PetshopEngine


1 package org.apache.tapestry.pets;
2
3 import java.util.Map JavaDoc;
4
5 import javax.servlet.http.HttpSession JavaDoc;
6
7 import org.apache.tapestry.IRequestCycle;
8 import org.apache.tapestry.engine.BaseEngine;
9 import org.apache.tapestry.request.RequestContext;
10 import org.springframework.context.ApplicationContext;
11 import org.springframework.web.context.support.WebApplicationContextUtils;
12
13 public class PetshopEngine extends BaseEngine {
14
15     private transient boolean killSession;
16
17     public static final String JavaDoc APPLICATION_CONTEXT_KEY = "appContext";
18
19     /**
20      * @see org.apache.tapestry.engine.AbstractEngine#setupForRequest(org.apache.tapestry.request.RequestContext)
21      */

22     protected void setupForRequest(RequestContext context) {
23         super.setupForRequest(context);
24
25         Map JavaDoc global = (Map JavaDoc) getGlobal();
26         ApplicationContext ac = (ApplicationContext) global
27                 .get(APPLICATION_CONTEXT_KEY);
28
29         ac = WebApplicationContextUtils.getWebApplicationContext(context
30                 .getServlet().getServletContext());
31         global.put(APPLICATION_CONTEXT_KEY, ac);
32
33     }
34
35     protected void cleanupAfterRequest(IRequestCycle cycle) {
36         if (killSession) {
37             try {
38                 HttpSession JavaDoc session = cycle.getRequestContext().getSession();
39                 if (session != null) {
40                     session.invalidate();
41                 }
42             } catch (IllegalStateException JavaDoc ex) {
43                 // Ignore.
44
}
45         }
46     }
47
48     public void logout() {
49         Visit visit = (Visit) getVisit();
50         if (visit != null) {
51             visit.setCustomer(null);
52             visit = null;
53         }
54         killSession = true;
55     }
56 }
Popular Tags