Package org.apache.wicket.mock
Class MockSessionStore
- java.lang.Object
-
- org.apache.wicket.mock.MockSessionStore
-
- All Implemented Interfaces:
ISessionStore
public class MockSessionStore extends Object implements ISessionStore
Session store that holds one session.- Author:
- Matej Knopp
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.wicket.session.ISessionStore
ISessionStore.BindListener, ISessionStore.UnboundListener
-
-
Constructor Summary
Constructors Constructor Description MockSessionStore()
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Serializable
getAttribute(Request request, String name)
Gets the attribute value with the given nameList<String>
getAttributeNames(Request request)
Set<ISessionStore.BindListener>
getBindListeners()
String
getSessionId(Request request, boolean create)
Get the session id for the provided request.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.void
registerBindListener(ISessionStore.BindListener listener)
Registers listener invoked when session is bound.void
registerUnboundListener(ISessionStore.UnboundListener listener)
Registers listener invoked when session is unbound.void
removeAttribute(Request request, String name)
Removes the attribute with the given name.void
setAttribute(Request request, String name, Serializable value)
Adds or replaces the attribute with the given name and value.void
unregisterBindListener(ISessionStore.BindListener listener)
Unregisters listener invoked when session is bound.void
unregisterUnboundListener(ISessionStore.UnboundListener listener)
Unregisters listener invoked when session is unbound.
-
-
-
Constructor Detail
-
MockSessionStore
public MockSessionStore()
Construct.
-
-
Method Detail
-
bind
public 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 interfaceISessionStore
- Parameters:
request
- The request that triggered making a new sessionnewSession
- The new session
-
destroy
public void destroy()
Description copied from interface:ISessionStore
Called when the WebApplication is destroyed.- Specified by:
destroy
in interfaceISessionStore
-
getAttribute
public Serializable getAttribute(Request request, String name)
Description copied from interface:ISessionStore
Gets the attribute value with the given name- Specified by:
getAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- The name of the attribute to store- Returns:
- The value of the attribute
-
getAttributeNames
public List<String> getAttributeNames(Request request)
- Specified by:
getAttributeNames
in interfaceISessionStore
- Parameters:
request
- the current request- Returns:
- List of attributes for this session
-
getSessionId
public 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 interfaceISessionStore
- Parameters:
request
- The requestcreate
- Whether to create an actual session (typically an instance ofHttpSession
) 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
-
invalidate
public void invalidate(Request request)
Description copied from interface:ISessionStore
Invalidates the session.- Specified by:
invalidate
in interfaceISessionStore
- Parameters:
request
- the current request
-
lookup
public 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 interfaceISessionStore
- Parameters:
request
- The current request- Returns:
- The session for the provided request or null if the session was not bound
-
registerUnboundListener
public void registerUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface:ISessionStore
Registers listener invoked when session is unbound.- Specified by:
registerUnboundListener
in interfaceISessionStore
-
removeAttribute
public void removeAttribute(Request request, String name)
Description copied from interface:ISessionStore
Removes the attribute with the given name.- Specified by:
removeAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- the name of the attribute to remove
-
getUnboundListener
public final Set<ISessionStore.UnboundListener> getUnboundListener()
- Specified by:
getUnboundListener
in interfaceISessionStore
- Returns:
- The list of registered unbound listeners
-
setAttribute
public void setAttribute(Request request, String name, Serializable value)
Description copied from interface:ISessionStore
Adds or replaces the attribute with the given name and value.- Specified by:
setAttribute
in interfaceISessionStore
- Parameters:
request
- the current requestname
- the name of the attributevalue
- the value of the attribute
-
unregisterUnboundListener
public void unregisterUnboundListener(ISessionStore.UnboundListener listener)
Description copied from interface:ISessionStore
Unregisters listener invoked when session is unbound.- Specified by:
unregisterUnboundListener
in interfaceISessionStore
-
registerBindListener
public void registerBindListener(ISessionStore.BindListener listener)
Description copied from interface:ISessionStore
Registers listener invoked when session is bound.- Specified by:
registerBindListener
in interfaceISessionStore
-
unregisterBindListener
public void unregisterBindListener(ISessionStore.BindListener listener)
Description copied from interface:ISessionStore
Unregisters listener invoked when session is bound.- Specified by:
unregisterBindListener
in interfaceISessionStore
-
getBindListeners
public Set<ISessionStore.BindListener> getBindListeners()
- Specified by:
getBindListeners
in interfaceISessionStore
- Returns:
- The list of registered bind listeners
-
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 interfaceISessionStore
- Parameters:
request
- current requestsession
- session to be flushed
-
-