org.wings.session
Class Session

java.lang.Object
  extended by org.wings.session.Session
All Implemented Interfaces:
Serializable, PropertyService
Direct Known Subclasses:
WingsSession

public class Session
extends Object
implements PropertyService, Serializable

This class represents a wingS session meaning an application user session instance. Please do not mix this with a servlet HttpSession!

A wings Session is a session instance hold by the global WingServlet servlet. It aggregates all per--user-session data (mainly the root SFrames and provides some information about the client like the browser getUserAgent(), the current character encoding getCharacterEncoding() or the used Locale getLocale().

Author:
Holger Engels
See Also:
Serialized Form

Field Summary
static String CHARACTER_ENCODING_PROPERTY
          The property name of the sessions character encoding
protected  EventListenerList listenerList
          Store here only weak references.
static String LOCALE_PROPERTY
          The property name of the locale
static String LOOK_AND_FEEL_PROPERTY
          The property name of the look&feel
protected  javax.servlet.http.HttpServletRequest servletRequest
           
protected  javax.servlet.http.HttpServletResponse servletResponse
           
 
Constructor Summary
Session()
           
 
Method Summary
 void addExitListener(SExitListener listener)
           
 void addFrame(SFrame frame)
          Describe addFrame method here.
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Describe addPropertyChangeListener method here.
 void addRequestListener(SRequestListener listener)
           
 boolean containsProperty(String key)
           
 String createUniqueId()
          Creates a session context unique ID, that can be used as an identifier, i.e.
protected  void destroy()
           
 void exit()
          Exit the current session and redirect to new application instance.
 void exit(String redirectAddress)
          Exit the current session and redirect to other URL.
protected  void finalize()
           
 CGManager getCGManager()
          The CG manager is responsible to provide the renderer implementation (aka.
 String getCharacterEncoding()
          The current character encoding used for the communication with the clients userAgent.
 SComponent getComponentByName(SContainer container, String name)
          Search in the given SContainer for the SComponent with the given name.
 SComponent getComponentByName(String name)
           
 LowLevelEventDispatcher getDispatcher()
          The low level event dispatcher is responsible for taking an HTTP request, parse it contents and delegate the so called low level events to the registered LowLevelEventListeners (i.e.
 DragAndDropManager getDragAndDropManager()
           
 String getExitAddress()
           
 SExitListener[] getExitListeners()
           
 ExternalizeManager getExternalizeManager()
          The Externalize manager is response to provide all Resource via HTTP to the client.
 Set<SFrame> getFrames()
          Describe frames method here.
 Locale getLocale()
          The Locale of the current session.
 boolean getLocaleFromHeader()
          Indicates if the wings session servlet should adopt the clients Locale provided by the browsers in the HTTP header.
 int getMaxContentLength()
          Get the maximum content length (file size) for a post request.
 MenuManager getMenuManager()
           
 Map getProperties()
          Describe getProperties method here.
 Object getProperty(String key)
          Gets the session property indicated by the specified key.
 Object getProperty(String key, Object def)
          Gets the session property indicated by the specified key.
 String getRedirectAddress()
           
 ReloadManager getReloadManager()
          The reload manager responsible for the component invalidation of the components contained in this wingS session.
 ResourceMapper getResourceMapper()
           
 SFrame getRootFrame()
          The root frame is the first shown frame.
 ScriptManager getScriptManager()
          The Script manager collects scripts
 javax.servlet.ServletContext getServletContext()
          The current servlet context provided by the underlying servlet container.
 javax.servlet.http.HttpServletRequest getServletRequest()
           
 javax.servlet.http.HttpServletResponse getServletResponse()
          The current HTTP servlet response which the framework will deliver after processing the current request.
 SessionStatistics getStatistics()
           
 Locale[] getSupportedLocales()
          Returns the locales, supported by this application.
 SToolTipManager getToolTipManager()
           
 Browser getUserAgent()
          Returns the current browser of the client detected by the User-Agent parameter of the initial HTTP request for this user session.
 boolean hasDragAndDropManager()
           
 void init(javax.servlet.http.HttpServletRequest request)
          Detect user agent (userAgent).
 void init(javax.servlet.ServletConfig servletConfig, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Detect user agent (userAgent).
protected  void initMaxContentLength()
           
protected  void initProps(javax.servlet.ServletConfig servletConfig)
          Copy the init parameters.
protected  void initProps(javax.servlet.ServletContext servletContext)
           
 void removeExitListener(SExitListener listener)
           
 void removeFrame(SFrame frame)
          Describe removeFrame method here.
 Object removeProperty(String key)
           
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Describe removePropertyChangeListener method here.
 void removeRequestListener(SRequestListener listener)
           
 void setCharacterEncoding(String characterEncoding)
          The current character encoding used for the communication with the clients userAgent.
 void setDndManager(DragAndDropManager dndManager)
           
 void setLocale(Locale locale)
          Sets the locale for this session.
 void setLocaleFromHeader(boolean adoptLocale)
          Indicates if the wings session servlet should adopt the clients Locale provided by the browsers in the HTTP header.
 void setMaxContentLength(int l)
          Set the maximum content length (file size) for a post request.
 Object setProperty(String key, Object value)
          Sets the session property indicated by the specified key.
 void setRedirectAddress(String redirectAddress)
           
 void setReloadManager(ReloadManager reloadManager)
          Override the current reload manager.
 void setResourceMapper(ResourceMapper resourceMapper)
           
 void setSupportedLocales(Locale[] locales)
          sets the locales, supported by this application.
 void setUserAgentFromRequest(javax.servlet.http.HttpServletRequest request)
          Describe setUserAgentFromRequest method here.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE_PROPERTY

public static final String LOCALE_PROPERTY
The property name of the locale

See Also:
Constant Field Values

CHARACTER_ENCODING_PROPERTY

public static final String CHARACTER_ENCODING_PROPERTY
The property name of the sessions character encoding

See Also:
Constant Field Values

LOOK_AND_FEEL_PROPERTY

public static final String LOOK_AND_FEEL_PROPERTY
The property name of the look&feel

See Also:
Constant Field Values

servletResponse

protected transient javax.servlet.http.HttpServletResponse servletResponse

servletRequest

protected transient javax.servlet.http.HttpServletRequest servletRequest

listenerList

protected final EventListenerList listenerList
Store here only weak references.

Constructor Detail

Session

public Session()
Method Detail

getStatistics

public final SessionStatistics getStatistics()

init

public void init(javax.servlet.ServletConfig servletConfig,
                 javax.servlet.http.HttpServletRequest request,
                 javax.servlet.http.HttpServletResponse response)
          throws javax.servlet.ServletException
Detect user agent (userAgent). Copy init parameters. Set max content length for uploads / requests. Install look and feel.

Parameters:
servletConfig - a ServletConfig value
request - a HttpServletRequest value
response -
Throws:
javax.servlet.ServletException - if an error occurs

init

public void init(javax.servlet.http.HttpServletRequest request)
          throws javax.servlet.ServletException
Detect user agent (userAgent). Copy init parameters. Set max content length for uploads / requests. Install look and feel.

Parameters:
request - a HttpServletRequest value
Throws:
javax.servlet.ServletException - if an error occurs

initMaxContentLength

protected void initMaxContentLength()

initProps

protected void initProps(javax.servlet.ServletConfig servletConfig)
Copy the init parameters.


initProps

protected void initProps(javax.servlet.ServletContext servletContext)

getServletRequest

public javax.servlet.http.HttpServletRequest getServletRequest()

getServletResponse

public javax.servlet.http.HttpServletResponse getServletResponse()
The current HTTP servlet response which the framework will deliver after processing the current request. This is a part of the Servlet architecture.

Returns:
The current servlet response about to send to the client

getServletContext

public javax.servlet.ServletContext getServletContext()
The current servlet context provided by the underlying servlet container. This value is retrieved from the initial servlet request for this session.

Returns:
The current servlet context provided by the underlying servlet container.

setReloadManager

public void setReloadManager(ReloadManager reloadManager)
Override the current reload manager.

Parameters:
reloadManager - You customized reload manager implementation.

getReloadManager

public ReloadManager getReloadManager()
The reload manager responsible for the component invalidation of the components contained in this wingS session. (Epoch counter)

Returns:
Lazily constructs DefaultReloadManager if no other reload manager has been set

getMenuManager

public MenuManager getMenuManager()

getExternalizeManager

public ExternalizeManager getExternalizeManager()
The Externalize manager is response to provide all Resource via HTTP to the client.

Returns:
The externalize manager responsible to externalize all sort of resources contained in this session.

getScriptManager

public ScriptManager getScriptManager()
The Script manager collects scripts

Returns:
The script manager responsible to script all sort of resources contained in this session.

getCGManager

public CGManager getCGManager()
The CG manager is responsible to provide the renderer implementation (aka. PLAF) for a given component class.

Returns:
The current CG manager

getToolTipManager

public SToolTipManager getToolTipManager()
Returns:
The tooltip manager object containing configuration values on the components tooltip behaviour

getUserAgent

public Browser getUserAgent()
Returns the current browser of the client detected by the User-Agent parameter of the initial HTTP request for this user session.

Returns:
A Browser object providing browser type, os type and other informations from the HTTP User-Agent string.

setUserAgentFromRequest

public void setUserAgentFromRequest(javax.servlet.http.HttpServletRequest request)
Describe setUserAgentFromRequest method here.

Parameters:
request - a HttpServletRequest value

getDispatcher

public LowLevelEventDispatcher getDispatcher()
The low level event dispatcher is responsible for taking an HTTP request, parse it contents and delegate the so called low level events to the registered LowLevelEventListeners (i.e. Buttons, etc.)

Returns:
The low level event dispatcher responsible for this session.

addFrame

public void addFrame(SFrame frame)
Describe addFrame method here.

Parameters:
frame - a SFrame value

removeFrame

public void removeFrame(SFrame frame)
Describe removeFrame method here.

Parameters:
frame - a SFrame value

getFrames

public Set<SFrame> getFrames()
Describe frames method here.

Returns:
a Set value

getRootFrame

public SFrame getRootFrame()
The root frame is the first shown frame.

Returns:
a SFrame value

getComponentByName

public SComponent getComponentByName(String name)

getComponentByName

public SComponent getComponentByName(SContainer container,
                                     String name)
Search in the given SContainer for the SComponent with the given name.

Parameters:
container - The SContainer where you want to search for the SComponent with the given name.
name - The Name of the SComponent
Returns:
the SComponent with the given name

getProperties

public final Map getProperties()
Describe getProperties method here.

Specified by:
getProperties in interface PropertyService
Returns:
a Map value

getProperty

public Object getProperty(String key)
Gets the session property indicated by the specified key.

Specified by:
getProperty in interface PropertyService
Parameters:
key - the name of the session property.
Returns:
the string value of the session property, or null if there is no property with that key.
See Also:
PropertyService.getProperties()

getProperty

public Object getProperty(String key,
                          Object def)
Gets the session property indicated by the specified key.

Specified by:
getProperty in interface PropertyService
Parameters:
key - the name of the session property.
def - a default value.
Returns:
the string value of the session property, or the default value if there is no property with that key.
See Also:
PropertyService.getProperties()

setProperty

public Object setProperty(String key,
                          Object value)
Sets the session property indicated by the specified key.

Specified by:
setProperty in interface PropertyService
Parameters:
key - the name of the session property.
value - the value of the session property.
Returns:
the previous value of the session property, or null if it did not have one.
See Also:
PropertyService.getProperty(java.lang.String), PropertyService.getProperty(java.lang.String, java.lang.Object)

containsProperty

public boolean containsProperty(String key)
Specified by:
containsProperty in interface PropertyService

removeProperty

public Object removeProperty(String key)
Specified by:
removeProperty in interface PropertyService

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Describe addPropertyChangeListener method here.

Parameters:
propertyName - a String value
listener - a PropertyChangeListener value

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Describe removePropertyChangeListener method here.

Parameters:
propertyName - a String value
listener - a PropertyChangeListener value

setLocale

public void setLocale(Locale locale)
               throws IllegalArgumentException
Sets the locale for this session. A property change event is fired, if the locale has actually changed.

Parameters:
locale - the locale to be associated with this session.
Throws:
IllegalArgumentException

getLocale

public Locale getLocale()
The Locale of the current session. This Locale reflects the Locale of the clients userAgent.

Returns:
a Locale value

setLocaleFromHeader

public final void setLocaleFromHeader(boolean adoptLocale)
Indicates if the wings session servlet should adopt the clients Locale provided by the browsers in the HTTP header.

Parameters:
adoptLocale - if true, try to determine, false ignore

getLocaleFromHeader

public final boolean getLocaleFromHeader()
Indicates if the wings session servlet should adopt the clients Locale provided by the browsers in the HTTP header.


setSupportedLocales

public final void setSupportedLocales(Locale[] locales)
sets the locales, supported by this application. If empty or null, all locales are supported.


getSupportedLocales

public final Locale[] getSupportedLocales()
Returns the locales, supported by this application. If empty or null, all locales are supported.


setCharacterEncoding

public void setCharacterEncoding(String characterEncoding)
The current character encoding used for the communication with the clients userAgent. If null then the current characterEncoding is determined by the current session Locale via the charset.properties map.

Parameters:
characterEncoding - The charcterEncoding which should be enforces for this session (i.e. "utf-8"), or null if it should be determined by the clients userAgent Locale.

getCharacterEncoding

public String getCharacterEncoding()
The current character encoding used for the communication with the clients userAgent. If null then the current characterEncoding is determined by the current session Locale via the charset.properties map.

Returns:
The characterEncoding set for this sesson or determined by the current Locale.

createUniqueId

public String createUniqueId()
Creates a session context unique ID, that can be used as an identifier, i.e. it is guaranteed to start with a letter

Returns:
a String value

getMaxContentLength

public final int getMaxContentLength()
Get the maximum content length (file size) for a post request.

Returns:
maximum size in kB (1024 Byte)
See Also:
MultipartRequest

setMaxContentLength

public final void setMaxContentLength(int l)
Set the maximum content length (file size) for a post request.

Parameters:
l - size in kB (1024 Byte)
See Also:
MultipartRequest

destroy

protected void destroy()

exit

public void exit(String redirectAddress)
Exit the current session and redirect to other URL.

This removes the session and its associated application from memory. The userAgent is redirected to the given URL. Note, that it is not even possible for the user to re-enter the application with the BACK-button, since all information is removed.

Always exit an application by calling an exit() method, especially, if it is an application that requires a login and thus handles sensitive information accessible through the session. Usually, you will call this on behalf of an event within an ActionListener.actionPerformed() like for a pressed 'EXIT'-Button.

Parameters:
redirectAddress - the address, the userAgent is redirected after removing this session. This must be a String containing the complete URL (no relative URL) to the place to be redirected. If 'null', nothing happens.

exit

public void exit()
Exit the current session and redirect to new application instance.

This removes the session and its associated application from memory. The userAgent is redirected to the same application with a fresh session. Note, that it is not even possible for the user to re-enter the old application with the BACK-button, since all information is removed.

Always exit an application by calling an exit() method, especially, if it is an application that requires an login and thus handles sensitive information accessible through the session. Usually, you will call this on behalf of an event within an ActionListener.actionPerformed() like for a pressed 'EXIT'-Button.


getExitAddress

public String getExitAddress()

getRedirectAddress

public String getRedirectAddress()

setRedirectAddress

public void setRedirectAddress(String redirectAddress)

addExitListener

public void addExitListener(SExitListener listener)

removeExitListener

public void removeExitListener(SExitListener listener)

getExitListeners

public SExitListener[] getExitListeners()

addRequestListener

public void addRequestListener(SRequestListener listener)

removeRequestListener

public void removeRequestListener(SRequestListener listener)

finalize

protected void finalize()
Overrides:
finalize in class Object

hasDragAndDropManager

public boolean hasDragAndDropManager()

getDragAndDropManager

public DragAndDropManager getDragAndDropManager()

setDndManager

public void setDndManager(DragAndDropManager dndManager)

getResourceMapper

public ResourceMapper getResourceMapper()

setResourceMapper

public void setResourceMapper(ResourceMapper resourceMapper)


wingS Swings ;-)