[jboss-cvs] jboss-seam/src/main/org/jboss/seam/contexts ...
Gavin King
gavin.king at jboss.com
Mon Jan 8 12:28:19 EST 2007
User: gavin
Date: 07/01/08 12:28:19
Modified: src/main/org/jboss/seam/contexts Lifecycle.java
Log:
JBSEAM-693
Revision Changes Path
1.76 +44 -11 jboss-seam/src/main/org/jboss/seam/contexts/Lifecycle.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Lifecycle.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/contexts/Lifecycle.java,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -b -r1.75 -r1.76
--- Lifecycle.java 19 Dec 2006 23:12:22 -0000 1.75
+++ Lifecycle.java 8 Jan 2007 17:28:19 -0000 1.76
@@ -30,7 +30,7 @@
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.75 $
+ * @version $Revision: 1.76 $
*/
public class Lifecycle
{
@@ -183,16 +183,30 @@
{
log.debug("Session started");
- Context context = new WebApplicationContext(servletContext);
- Contexts.applicationContext.set(context);
+ //Normally called synchronously with a JSF request, but there are some
+ //special cases!
- Context tempSessionContext = new WebSessionContext( session );
+ boolean applicationContextActive = Contexts.isApplicationContextActive();
+ boolean eventContextActive = Contexts.isEventContextActive();
+ if ( !applicationContextActive )
+ {
+ Context tempApplicationContext = new WebApplicationContext(servletContext);
+ Contexts.applicationContext.set(tempApplicationContext);
+ }
+ Context tempEventContext = null;
+ if ( !eventContextActive )
+ {
+ tempEventContext = new MapContext(ScopeType.EVENT);
+ Contexts.applicationContext.set(tempEventContext);
+ }
+
+ Context tempSessionContext = new WebSessionContext(session);
Contexts.sessionContext.set(tempSessionContext);
//instantiate all session-scoped @Startup components
- for ( String name : context.getNames() )
+ for ( String name : Contexts.getApplicationContext().getNames() )
{
- Object object = context.get(name);
+ Object object = Contexts.getApplicationContext().get(name);
if ( object!=null && (object instanceof Component) )
{
Component component = (Component) object;
@@ -204,15 +218,33 @@
}
Contexts.sessionContext.set(null);
+ if ( !eventContextActive )
+ {
+ Contexts.destroy(tempEventContext);
+ Contexts.eventContext.set(null);
+ }
+ if ( !applicationContextActive )
+ {
Contexts.applicationContext.set(null);
}
+ }
+
public static void endSession(ServletContext servletContext, ContextAdaptor session)
{
log.debug("End of session, destroying contexts");
- Context tempAppContext = new WebApplicationContext(servletContext);
- Contexts.applicationContext.set(tempAppContext);
+ //This code assumes that sessions are only destroyed at the very end of a
+ //web request, after the request-bound context objects have been destroyed,
+ //or during session timeout, when there are no request-bound contexts.
+
+ if ( Contexts.isEventContextActive() || Contexts.isApplicationContextActive() )
+ {
+ throw new IllegalStateException("Please end the HttpSession via Seam.invalidateSession()");
+ }
+
+ Context tempApplicationContext = new WebApplicationContext(servletContext);
+ Contexts.applicationContext.set(tempApplicationContext);
//this is used just as a place to stick the ConversationManager
Context tempEventContext = new MapContext(ScopeType.EVENT);
@@ -220,7 +252,7 @@
//this is used (a) for destroying session-scoped components
//and is also used (b) by the ConversationManager
- Context tempSessionContext = new WebSessionContext( session );
+ Context tempSessionContext = new WebSessionContext(session);
Contexts.sessionContext.set(tempSessionContext);
Set<String> conversationIds = ConversationEntries.instance().getConversationIds();
@@ -230,6 +262,8 @@
destroyConversationContext(session, conversationId);
}
+ //we need some conversation-scope components for destroying
+ //the session context...
Context tempConversationContext = new MapContext(ScopeType.CONVERSATION);
Contexts.conversationContext.set(tempConversationContext);
@@ -243,7 +277,6 @@
Contexts.destroy(tempEventContext);
Contexts.eventContext.set(null);
- Contexts.conversationContext.set(null);
Contexts.applicationContext.set(null);
}
More information about the jboss-cvs-commits
mailing list