org.apache.wicket.session
Class HttpSessionStore

java.lang.Object
  extended by org.apache.wicket.session.HttpSessionStore
All Implemented Interfaces:
ISessionStore

public class HttpSessionStore
extends java.lang.Object
implements ISessionStore

Implementation of ISessionStore that works with web applications and provides some specific http servlet/ session related functionality.

Author:
jcompagner, Eelco Hillenius, Matej Knopp

Nested Class Summary
protected static class HttpSessionStore.SessionBindingListener
          Reacts on unbinding from the session by cleaning up the session related data.
 
Nested classes/interfaces inherited from interface org.apache.wicket.session.ISessionStore
ISessionStore.UnboundListener
 
Constructor Summary
HttpSessionStore()
          Construct.
 
Method Summary
 void bind(Request request, Session newSession)
          Adds the provided new session to this facade using the provided request.
 void destroy()
          Called when the WebApplication is destroyed.
 void flushSession(Request request, Session session)
          Flushes the session.
 java.io.Serializable getAttribute(Request request, java.lang.String name)
          Gets the attribute value with the given name
 java.util.List<java.lang.String> getAttributeNames(Request request)
           
protected  javax.servlet.http.HttpServletRequest getHttpServletRequest(Request request)
           
 java.lang.String getSessionId(Request request, boolean create)
          Get the session id for the provided request.
 java.util.Set<ISessionStore.UnboundListener> getUnboundListener()
           
 void invalidate(Request request)
          Invalidates the session.
 Session lookup(Request request)
          Retrieves the session for the provided request from this facade.
protected  void onBind(Request request, Session newSession)
          Template method that is called when a session is being bound to the session store.
protected  void onUnbind(java.lang.String sessionId)
          Template method that is called when the session is being detached from the store, which typically happens when the HttpSession was invalidated.
 void registerUnboundListener(ISessionStore.UnboundListener listener)
          Registers listener invoked when session is unbound.
 void removeAttribute(Request request, java.lang.String name)
          Removes the attribute with the given name.
 void setAttribute(Request request, java.lang.String name, java.io.Serializable value)
          Adds or replaces the attribute with the given name and value.
 void unregisterUnboundListener(ISessionStore.UnboundListener listener)
          Unregisters listener invoked when session is unbound.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpSessionStore

public HttpSessionStore()
Construct.

Method Detail

getHttpServletRequest

protected final javax.servlet.http.HttpServletRequest getHttpServletRequest(Request request)
Parameters:
request -
Returns:
The http servlet request

bind

public final void bind(Request request,
                       Session newSession)
Description copied from interface: ISessionStore
Adds the provided new session to this facade using the provided request.

Specified by:
bind in interface ISessionStore
Parameters:
request - The request that triggered making a new session
newSession - The new session
See Also:
ISessionStore.bind(Request, Session)

flushSession

public void flushSession(Request request,
                         Session session)
Description copied from interface: ISessionStore
Flushes the session. Flushing the session generally means setting the attribute with the value of the current session. Some servlet containers use the setAttribute() as a signal that the value is dirty and needs to be replicated. Essentially this call comes down to: String attr=getSessionAttributeName(); Session session=getAttribute(attr); setAttribute(attr, session); If the session is not yet bound it will be.

Specified by:
flushSession in interface ISessionStore
Parameters:
request - current request
session - session to be flushed

destroy

public void destroy()
Description copied from interface: ISessionStore
Called when the WebApplication is destroyed.

Specified by:
destroy in interface ISessionStore
See Also:
ISessionStore.destroy()

getSessionId

public java.lang.String getSessionId(Request request,
                                     boolean create)
Description copied from interface: ISessionStore
Get the session id for the provided request. If create is false and the creation of the actual session is deferred, this method should return null to reflect it doesn't have one.

Specified by:
getSessionId in interface ISessionStore
Parameters:
request - The request
create - Whether to create an actual session (typically an instance of HttpSession) when not already done so
Returns:
The session id for the provided request, possibly null if create is false and the creation of the actual session was deferred
See Also:
ISessionStore.getSessionId(org.apache.wicket.request.Request, boolean)

invalidate

public final void invalidate(Request request)
Description copied from interface: ISessionStore
Invalidates the session.

Specified by:
invalidate in interface ISessionStore
Parameters:
request - the current request
See Also:
ISessionStore.invalidate(Request)

lookup

public final Session lookup(Request request)
Description copied from interface: ISessionStore
Retrieves the session for the provided request from this facade.

This method should return null if it is not bound yet, so that Wicket can recognize that it should create a session and call ISessionStore.bind(Request, Session) right after that.

Specified by:
lookup in interface ISessionStore
Parameters:
request - The current request
Returns:
The session for the provided request or null if the session was not bound
See Also:
ISessionStore.lookup(org.apache.wicket.request.Request)

onBind

protected void onBind(Request request,
                      Session newSession)
Template method that is called when a session is being bound to the session store. It is called before the session object itself is added to this store (which is done by calling ISessionStore.setAttribute(Request, String, Serializable) with key Session.SESSION_ATTRIBUTE_NAME.

Parameters:
request - The request
newSession - The new session

onUnbind

protected void onUnbind(java.lang.String sessionId)
Template method that is called when the session is being detached from the store, which typically happens when the HttpSession was invalidated.

Parameters:
sessionId - The session id of the session that was invalidated.

getAttribute

public final java.io.Serializable getAttribute(Request request,
                                               java.lang.String name)
Description copied from interface: ISessionStore
Gets the attribute value with the given name

Specified by:
getAttribute in interface ISessionStore
Parameters:
request - the current request
name - The name of the attribute to store
Returns:
The value of the attribute
See Also:
ISessionStore.getAttribute(org.apache.wicket.request.Request, java.lang.String)

getAttributeNames

public final java.util.List<java.lang.String> getAttributeNames(Request request)
Specified by:
getAttributeNames in interface ISessionStore
Parameters:
request - the current request
Returns:
List of attributes for this session
See Also:
ISessionStore.getAttributeNames(org.apache.wicket.request.Request)

removeAttribute

public final void removeAttribute(Request request,
                                  java.lang.String name)
Description copied from interface: ISessionStore
Removes the attribute with the given name.

Specified by:
removeAttribute in interface ISessionStore
Parameters:
request - the current request
name - the name of the attribute to remove
See Also:
ISessionStore.removeAttribute(org.apache.wicket.request.Request, java.lang.String)

setAttribute

public final void setAttribute(Request request,
                               java.lang.String name,
                               java.io.Serializable value)
Description copied from interface: ISessionStore
Adds or replaces the attribute with the given name and value.

Specified by:
setAttribute in interface ISessionStore
Parameters:
request - the current request
name - the name of the attribute
value - the value of the attribute
See Also:
ISessionStore.setAttribute(org.apache.wicket.request.Request, java.lang.String, java.io.Serializable)

registerUnboundListener

public final void registerUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface: ISessionStore
Registers listener invoked when session is unbound.

Specified by:
registerUnboundListener in interface ISessionStore
See Also:
ISessionStore.registerUnboundListener(org.apache.wicket.session.ISessionStore.UnboundListener)

unregisterUnboundListener

public final void unregisterUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface: ISessionStore
Unregisters listener invoked when session is unbound.

Specified by:
unregisterUnboundListener in interface ISessionStore
See Also:
ISessionStore.unregisterUnboundListener(org.apache.wicket.session.ISessionStore.UnboundListener)

getUnboundListener

public final java.util.Set<ISessionStore.UnboundListener> getUnboundListener()
Specified by:
getUnboundListener in interface ISessionStore
Returns:
The list of registered unbound listeners
See Also:
ISessionStore.getUnboundListener()


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.