org.directwebremoting
Interface ScriptSession

All Known Subinterfaces:
RealScriptSession
All Known Implementing Classes:
DefaultScriptSession

public interface ScriptSession

Script scope is like session scope except that it is managed using a Javascript variable. The operations on a Page are similar to (and derived from) the options on a Session, with some added simplification.

Author:
Joe Walker [joe at getahead dot ltd dot uk]
See Also:
HttpSession

Method Summary
 void addRunnable(java.lang.Runnable runnable)
          Add a Runnable to the waiting list for execution.
 void addScript(ScriptBuffer script)
          Add a script to the list waiting for remote execution.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the object bound with the specified name in this ScriptSession, or null if no object is bound under the name.
 java.util.Iterator<java.lang.String> getAttributeNames()
          Returns an Enumeration of String objects containing the names of all the objects bound to this ScriptSession.
 long getCreationTime()
          Returns the time when this ScriptSession was created, measured in milliseconds since midnight January 1, 1970 GMT.
 java.lang.String getHttpSessionId()
          If this ScriptSession's browser session also has a HttpSession then this method gives access to its id (typically corresponding to the JSESSIONID cookie).
 java.lang.String getId()
          Returns a string containing the unique identifier assigned to this ScriptSession.
 long getLastAccessedTime()
          Returns the last time the client sent a request associated with this ScriptSession, as the number of milliseconds since 1/1/1970 GMT, and marked by the time the container received the request.
 java.lang.String getPage()
          What page is this script session attached to? The page does not include server information, but does include everything from the host/port onwards, including the query parameters depending on the configured PageNormalizer, which by default removes them.
 void invalidate()
          Invalidates this ScriptSession then unbinds any objects bound to it.
 boolean isInvalidated()
          Checks to see if this ScriptSession has been invalidated.
 void removeAttribute(java.lang.String name)
          Removes the object bound with the specified name from this ScriptSession.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Binds an object to this ScriptSession, using the name specified.
 

Method Detail

getAttribute

java.lang.Object getAttribute(java.lang.String name)
Returns the object bound with the specified name in this ScriptSession, or null if no object is bound under the name.

Parameters:
name - a string specifying the name of the object
Returns:
the object with the specified name

setAttribute

void setAttribute(java.lang.String name,
                  java.lang.Object value)
Binds an object to this ScriptSession, using the name specified. If an object of the same name is already bound to the ScriptSession, the object is replaced.

After this method executes, and if the new object implements ScriptSessionBindingListener, the container calls ScriptSessionBindingListener.valueBound(org.directwebremoting.event.ScriptSessionBindingEvent).

If an object was already bound to this ScriptSession of this name that implements ScriptSessionBindingListener, its ScriptSessionBindingListener.valueUnbound(org.directwebremoting.event.ScriptSessionBindingEvent) method is called.

If the value passed in is null, this has the same effect as calling removeAttribute(java.lang.String).

Parameters:
name - the name to which the object is bound; cannot be null
value - the object to be bound

removeAttribute

void removeAttribute(java.lang.String name)
Removes the object bound with the specified name from this ScriptSession. If the ScriptSession does not have an object bound with the specified name, this method does nothing.

After this method executes, and if the object implements ScriptSessionBindingListener, the container calls ScriptSessionBindingListener.valueUnbound(org.directwebremoting.event.ScriptSessionBindingEvent).

Parameters:
name - the name of the object to remove from this ScriptSession

getAttributeNames

java.util.Iterator<java.lang.String> getAttributeNames()
Returns an Enumeration of String objects containing the names of all the objects bound to this ScriptSession.

Returns:
an Iterator of Strings, specifying the names of all the objects bound to this ScriptSession

invalidate

void invalidate()
Invalidates this ScriptSession then unbinds any objects bound to it.


isInvalidated

boolean isInvalidated()
Checks to see if this ScriptSession has been invalidated.

There is no similar method on HttpSession because it is assumed that you do not store HttpSessions from one request to another, so all sessions that you have access to will always be either valid, or you have just invalidated it yourself so you wont need to ask. This method makes up for the change that now ScriptSessions are accessible from outside the normal scope.

Returns:
true if the ScriptSession has been invalidated

addScript

void addScript(ScriptBuffer script)
Add a script to the list waiting for remote execution.

Parameters:
script - The script to execute

addRunnable

void addRunnable(java.lang.Runnable runnable)
Add a Runnable to the waiting list for execution. A new poll request will be triggered and the runnable will be executed at the beginning of it. The WebContext may be used to access request details from within the Runnable.

Parameters:
runnable -

getId

java.lang.String getId()
Returns a string containing the unique identifier assigned to this ScriptSession. The identifier is assigned by DWR.

Returns:
a string specifying the identifier assigned to this ScriptSession

getCreationTime

long getCreationTime()
Returns the time when this ScriptSession was created, measured in milliseconds since midnight January 1, 1970 GMT.

Returns:
when was this ScriptSession created, in milliseconds since 1/1/1970 GMT

getLastAccessedTime

long getLastAccessedTime()
Returns the last time the client sent a request associated with this ScriptSession, as the number of milliseconds since 1/1/1970 GMT, and marked by the time the container received the request.

Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time.

Returns:
when was this ScriptSession last accessed, in milliseconds since 1/1/1970 GMT

getPage

java.lang.String getPage()
What page is this script session attached to? The page does not include server information, but does include everything from the host/port onwards, including the query parameters depending on the configured PageNormalizer, which by default removes them.

Returns:
The page that this script session is viewing

getHttpSessionId

java.lang.String getHttpSessionId()
If this ScriptSession's browser session also has a HttpSession then this method gives access to its id (typically corresponding to the JSESSIONID cookie).

Returns:
the id from an active associated HttpSession if any, otherwise null

Copyright ยจ 2008