1 56 57 package org.objectstyle.cayenne.conf; 58 59 import javax.servlet.ServletRequest ; 60 import javax.servlet.ServletRequestEvent ; 61 import javax.servlet.ServletRequestListener ; 62 import javax.servlet.http.HttpServletRequest ; 63 import javax.servlet.http.HttpSession ; 64 65 import org.objectstyle.cayenne.access.DataContext; 66 67 103 public class WebApplicationContextProvider extends WebApplicationListener implements 104 ServletRequestListener { 105 106 110 public void requestInitialized(ServletRequestEvent sre) { 111 112 ServletRequest req = sre.getServletRequest(); 113 if (req instanceof HttpServletRequest ) { 114 115 HttpSession session = ((HttpServletRequest ) req).getSession(); 116 DataContext dataContext = ServletUtil.getSessionContext(session); 117 118 DataContext.bindThreadDataContext(dataContext); 120 if (dataContext == null) { 121 throw new IllegalStateException ( 122 "DataContext is null for the session, cannot bind to thread."); 123 } 124 } 125 } 126 127 130 public void requestDestroyed(ServletRequestEvent sre) { 131 DataContext.bindThreadDataContext(null); 133 } 134 } | Popular Tags |