blob: 26b86f4e2dbce219c1aba4b615fe0d85feb5e274 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.5.0_06) on Wed Jul 19 14:42:42 EDT 2006 -->
<TITLE>
WebApplicationContextProvider (Cayenne API Documentation - v.1.2)
</TITLE>
<META NAME="keywords" CONTENT="org.objectstyle.cayenne.conf.WebApplicationContextProvider class">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../objectstyle-javadoc.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="WebApplicationContextProvider (Cayenne API Documentation - v.1.2)";
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextFilter.html" title="class in org.objectstyle.cayenne.conf"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?org/objectstyle/cayenne/conf/WebApplicationContextProvider.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="WebApplicationContextProvider.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
org.objectstyle.cayenne.conf</FONT>
<BR>
Class WebApplicationContextProvider</H2>
<PRE>
java.lang.Object
<IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf">org.objectstyle.cayenne.conf.WebApplicationListener</A>
<IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>org.objectstyle.cayenne.conf.WebApplicationContextProvider</B>
</PRE>
<DL>
<DT><B>All Implemented Interfaces:</B> <DD>java.util.EventListener, javax.servlet.http.HttpSessionListener, javax.servlet.ServletContextListener, javax.servlet.ServletRequestListener</DD>
</DL>
<HR>
<B>Deprecated.</B>&nbsp;<I>since 1.2. This class is deprecated to reduce confusion due to multiple
redundant choices of web application configuration.
<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextFilter.html" title="class in org.objectstyle.cayenne.conf"><CODE>WebApplicationContextFilter</CODE></A> is the
official configuration choice for Cayenne, however you can still use a
custom listener similar to WebApplicationContextProvider if you want to.</I>
<P>
<DL>
<DT><PRE>public class <B>WebApplicationContextProvider</B><DT>extends <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf">WebApplicationListener</A><DT>implements javax.servlet.ServletRequestListener</DL>
</PRE>
<P>
WebApplicationContextProvider is a helper class integrating Cayenne with web
applications. It performs two related operations - (1) whenever an HttpSession is
started, it creates a new instance of DataContext and sets it as a session attribute;
(2) whenever a new request comes in for the session, it retrieves previously stored
session DataContext and binds it to the request worker thread for the duration of the
request. This way any class can get access to the correct instance of DataContext
without knowing anything about the servlet environment. This is useful for decoupling
the controller layer (Servlets, Struts, etc.) from a DAO layer, making public DAO API
independent from DataContext.
<p>
<b>Installation in the web container:</b> WebApplicationContextProvider should be
installed as a listener, similar to the WebApplicationListener). Per servlet
specification, listener is configured in <code>web.xml</code> deployment descriptor:
</p>
<pre>
&lt;listener&gt;
&lt;listener-class&gt;org.objectstyle.cayenne.conf.WebApplicationContextProvider&lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p>
<b>Accessing thread DataContext:</b> A DataContext bound to a worker thread can be
retrieved for the duration of the request processing by calling the static method
<A HREF="../../../../org/objectstyle/cayenne/access/DataContext.html#getThreadDataContext()"><CODE>DataContext.getThreadDataContext()</CODE></A>.
</p>
<p>
<p>
<b>Upgrading from <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf"><CODE>WebApplicationListener</CODE></A>:</b> WebApplicationContextProvider
supersedes WebApplicationListener. WebApplicationContextProvider relies on
ServletRequestListener API that is a part of Servlet Specification since version 2.4.
Therefore it requires a container that supports 2.4 spec, e.g. Tomcat 5.*
</p>
</p>
<P>
<P>
<DL>
<DT><B>Since:</B></DT>
<DD>1.1</DD>
<DT><B>Author:</B></DT>
<DD><a href="mailto:scott@smartblob.com">Scott McClure </a></DD>
</DL>
<HR>
<P>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextProvider.html#WebApplicationContextProvider()">WebApplicationContextProvider</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Deprecated.</B>&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextProvider.html#requestDestroyed(javax.servlet.ServletRequestEvent)">requestDestroyed</A></B>(javax.servlet.ServletRequestEvent&nbsp;sre)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Deprecated.</B>&nbsp;Removes the reference to the DataContext from the thread.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextProvider.html#requestInitialized(javax.servlet.ServletRequestEvent)">requestInitialized</A></B>(javax.servlet.ServletRequestEvent&nbsp;sre)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Deprecated.</B>&nbsp;Retrieves the DataContext bound earlier to the HttpSession, and binds it to the
current thread.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_org.objectstyle.cayenne.conf.WebApplicationListener"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class org.objectstyle.cayenne.conf.<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf">WebApplicationListener</A></B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#contextDestroyed(javax.servlet.ServletContextEvent)">contextDestroyed</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#contextInitialized(javax.servlet.ServletContextEvent)">contextInitialized</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#getConfiguration()">getConfiguration</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#newConfiguration(javax.servlet.ServletContext)">newConfiguration</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#sessionCreated(javax.servlet.http.HttpSessionEvent)">sessionCreated</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#sessionDestroyed(javax.servlet.http.HttpSessionEvent)">sessionDestroyed</A>, <A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html#setConfiguration(org.objectstyle.cayenne.conf.Configuration)">setConfiguration</A></CODE></TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="WebApplicationContextProvider()"><!-- --></A><H3>
WebApplicationContextProvider</H3>
<PRE>
public <B>WebApplicationContextProvider</B>()</PRE>
<DL>
<DD><B>Deprecated.</B>&nbsp;</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="requestInitialized(javax.servlet.ServletRequestEvent)"><!-- --></A><H3>
requestInitialized</H3>
<PRE>
public void <B>requestInitialized</B>(javax.servlet.ServletRequestEvent&nbsp;sre)</PRE>
<DL>
<DD><B>Deprecated.</B>&nbsp;<DD>Retrieves the DataContext bound earlier to the HttpSession, and binds it to the
current thread.
<P>
<DD><DL>
<DT><B>Specified by:</B><DD><CODE>requestInitialized</CODE> in interface <CODE>javax.servlet.ServletRequestListener</CODE></DL>
</DD>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="requestDestroyed(javax.servlet.ServletRequestEvent)"><!-- --></A><H3>
requestDestroyed</H3>
<PRE>
public void <B>requestDestroyed</B>(javax.servlet.ServletRequestEvent&nbsp;sre)</PRE>
<DL>
<DD><B>Deprecated.</B>&nbsp;<DD>Removes the reference to the DataContext from the thread.
<P>
<DD><DL>
<DT><B>Specified by:</B><DD><CODE>requestDestroyed</CODE> in interface <CODE>javax.servlet.ServletRequestListener</CODE></DL>
</DD>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationContextFilter.html" title="class in org.objectstyle.cayenne.conf"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../org/objectstyle/cayenne/conf/WebApplicationListener.html" title="class in org.objectstyle.cayenne.conf"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?org/objectstyle/cayenne/conf/WebApplicationContextProvider.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="WebApplicationContextProvider.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_summary">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;<A HREF="#constructor_detail">CONSTR</A>&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
<!--@SFLOGO@--> &nbsp; <i>Copyright &#169; 2001-2006 <a href=
"http://objectstyle.org" target="_top">ObjectStyle.org</a> All Rights Reserved.</i>
</BODY>
</HTML>