org.directwebremoting.impl
Class DefaultServerContext

java.lang.Object
  extended by org.directwebremoting.impl.DefaultServerContext
All Implemented Interfaces:
ServerContext
Direct Known Subclasses:
DefaultWebContext

public class DefaultServerContext
extends java.lang.Object
implements ServerContext

The Default implementation of ServerContext

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

Constructor Summary
DefaultServerContext()
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.util.Collection<ScriptSession> getAllScriptSessions()
          Get a list of all the ScriptSessions known to this server at the given time.
 Container getContainer()
          Accessor for the IoC container.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 ScriptSession getScriptSessionById(java.lang.String sessionId)
          You can request access to a specific ScriptSession if you know it's ID.
 java.util.Collection<ScriptSession> getScriptSessionsByPage(java.lang.String url)
          Get a list of all ScriptSessions on a given page.
 javax.servlet.ServletConfig getServletConfig()
          Accessor for the servlet config.
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext to which this session belongs.
 java.lang.String getVersion()
          Fish the version number out of the dwr.properties file.
 void setContainer(Container container)
          Injection point for Container
 void setServletConfig(javax.servlet.ServletConfig servletConfig)
          Injection point for ServletConfig
 void setServletContext(javax.servlet.ServletContext servletContext)
          Injection point for ServletContext
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultServerContext

public DefaultServerContext()
Method Detail

getAllScriptSessions

public java.util.Collection<ScriptSession> getAllScriptSessions()
Description copied from interface: ServerContext
Get a list of all the ScriptSessions known to this server at the given time. Note that the list of known sessions is continually changing so it is possible that the list will be out of date by the time it is used. For this reason you should check that getScriptSession(String id) returns something non null.

Specified by:
getAllScriptSessions in interface ServerContext
Returns:
A collection of all the ScriptSessions.

getScriptSessionsByPage

public java.util.Collection<ScriptSession> getScriptSessionsByPage(java.lang.String url)
Description copied from interface: ServerContext
Get a list of all ScriptSessions on a given page. Note that the list of known sessions is continually changing so it is possible that the list will be out of date by the time it is used. For this reason you should check that getScriptSession(String id) returns something non null.

Specified by:
getScriptSessionsByPage in interface ServerContext
Parameters:
url - The URL including 'http://', up to (but not including) '?' or '#'
Returns:
A collection of all the ScriptSessions.

getScriptSessionById

public ScriptSession getScriptSessionById(java.lang.String sessionId)
Description copied from interface: ServerContext
You can request access to a specific ScriptSession if you know it's ID.

Take care with this method because it allows actions from one browser to affect another which could be a bad thing. It is certainly a VERY BAD idea to let session id's from one browser escape into another.

Consider that it is entirely possible that the ScriptSession may timeout while you are holding a reference to it.

Specified by:
getScriptSessionById in interface ServerContext
Parameters:
sessionId - The script session ID to lookup
Returns:
The ScriptSession for the given ID, or null if it does not exist

setContainer

public void setContainer(Container container)
Injection point for Container


getContainer

public Container getContainer()
Description copied from interface: ServerContext
Accessor for the IoC container.

Specified by:
getContainer in interface ServerContext
Returns:
The IoC container that created the interface implementations.

setServletConfig

public void setServletConfig(javax.servlet.ServletConfig servletConfig)
Injection point for ServletConfig


getServletConfig

public javax.servlet.ServletConfig getServletConfig()
Description copied from interface: ServerContext
Accessor for the servlet config.

Specified by:
getServletConfig in interface ServerContext
Returns:
Returns the config.

setServletContext

public void setServletContext(javax.servlet.ServletContext servletContext)
Injection point for ServletContext


getServletContext

public javax.servlet.ServletContext getServletContext()
Description copied from interface: ServerContext
Returns the ServletContext to which this session belongs.

Specified by:
getServletContext in interface ServerContext
Returns:
The servlet context information.

getVersion

public java.lang.String getVersion()
Description copied from interface: ServerContext
Fish the version number out of the dwr.properties file.

Specified by:
getVersion in interface ServerContext
Returns:
The current version number.

getContextPath

public java.lang.String getContextPath()
Description copied from interface: ServerContext
Returns the portion of the request URI that indicates the context of the request.

Annoyingly you can't get to this from the ServletContext until servlet 2.5 you need to cache the value from a recent HttpServletRequest.

The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.

WARNING: This method may return null if DWR has not received any requests. If this method is called from outside of DWR, as the servlet environment is starting up you should check for a null reply and try again later.

Specified by:
getContextPath in interface ServerContext
Returns:
The portion of the request URI that indicates the context or null if DWR has not received and requests so far

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

Copyright 2008