org.spicefactory.cinnamon.service
Class RequestContext

java.lang.Object
  extended by org.spicefactory.cinnamon.service.RequestContext
Direct Known Subclasses:
HttpRequestContext

public abstract class RequestContext
extends Object

Abstract base class for request context implementations. In most scenarios Cinnamon will likely be used inside a web application and thus use HttpRequestContext as concrete implementation. But Cinnamon can also be used outside a Servlet container, i.e. for Unit/Integration Tests. For those cases custom subclasses of RequestContext can be created.

RequestContext instances will be associated with the thread of the request and can be retrieved with the static getCurrentContext method.

Author:
Jens Halm

Constructor Summary
protected RequestContext(CinnamonConfig config)
          Creates a new RequestContext.
 
Method Summary
protected abstract  Map<String,Object> createApplicationMap()
          Creates the application attribute Map for this request.
protected abstract  Map<String,String> createInitMap()
          Creates the initialization parameter Map for this request.
protected abstract  Map<String,String> createParameterMap()
          Creates the request parameter Map for this request.
protected abstract  Map<String,String[]> createParameterValuesMap()
          Creates the request parameter Map for this request.
protected abstract  Map<String,Object> createRequestMap()
          Creates the request attribute Map for this request.
protected abstract  Map<String,Object> createSessionMap()
          Creates the session attribute Map for this request.
 Map<String,Object> getApplicationMap()
          Returns the Map containing all application attributes.
 CinnamonConfig getCinnamonConfig()
          Return the CinnamonConfig instance associated with this request.
static RequestContext getCurrentContext()
          Returns the RequestContext for the current thread.
 Map<String,String> getInitMap()
          Returns the Map containing all initialization parameters.
 Map<String,String> getParameterMap()
          Returns the Map containing all request parameters.
 Map<String,String[]> getParameterValuesMap()
          Returns the Map containing all request parameters.
abstract  Object getRequest()
          Returns an environment-specific instance representing the current request.
 Map<String,Object> getRequestMap()
          Returns the Map containing all request attributes.
abstract  Object getResponse()
          Returns an environment-specific instance representing the current response.
 Map<String,Object> getSessionMap()
          Returns the Map containing all session attributes.
static void setCurrentContext(RequestContext newContext)
          Sets the RequestContext for the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestContext

protected RequestContext(CinnamonConfig config)
Creates a new RequestContext.

Parameters:
config - the CinnamonConfig instance in effect for this request
Method Detail

getCurrentContext

public static RequestContext getCurrentContext()
Returns the RequestContext for the current thread.

Returns:
the RequestContext for the current thread

setCurrentContext

public static void setCurrentContext(RequestContext newContext)
Sets the RequestContext for the current thread. Usually for internal use only. When deployed inside a ServletContainer the CinnamonServlet will create the RequestContext instance for each request.

Parameters:
newContext - the RequestContext that should be associated with the current thread

getCinnamonConfig

public CinnamonConfig getCinnamonConfig()
Return the CinnamonConfig instance associated with this request.

Returns:
the CinnamonConfig instance associated with this request

getRequestMap

public Map<String,Object> getRequestMap()
Returns the Map containing all request attributes. In a web application this Map will wrap the HttpServletRequest attributes.

Returns:
a Map containing all request attributes.

getSessionMap

public Map<String,Object> getSessionMap()
Returns the Map containing all session attributes. In a web application this Map will wrap the HttpSession attributes.

Returns:
a Map containing all session attributes.

getApplicationMap

public Map<String,Object> getApplicationMap()
Returns the Map containing all application attributes. In a web application this Map will wrap the ServletContext attributes.

Returns:
a Map containing all application attributes.

getInitMap

public Map<String,String> getInitMap()
Returns the Map containing all initialization parameters. In a web application this Map will wrap the ServletConfig initialization parameters.

Returns:
a Map containing all initialization parameters.

getParameterMap

public Map<String,String> getParameterMap()
Returns the Map containing all request parameters. In a web application this Map will wrap the HTTP request parameters. For multi-value parameters only the first value will be included.

Returns:
a Map containing all HTTP request parameters.

getParameterValuesMap

public Map<String,String[]> getParameterValuesMap()
Returns the Map containing all request parameters. In a web application this Map will wrap the HTTP request parameters. The values of this Map are String arrays to allow multiple values for each parameter.

Returns:
a Map containing all HTTP request parameters.

getRequest

public abstract Object getRequest()
Returns an environment-specific instance representing the current request. In a web application this will be an instance of HttpServletRequest.

Returns:
an environment-specific instance representing the current request

getResponse

public abstract Object getResponse()
Returns an environment-specific instance representing the current response. In a web application this will be an instance of HttpServletResponse.

Returns:
an environment-specific instance representing the current response

createRequestMap

protected abstract Map<String,Object> createRequestMap()
Creates the request attribute Map for this request.

Returns:
the request attribute Map for this request

createSessionMap

protected abstract Map<String,Object> createSessionMap()
Creates the session attribute Map for this request.

Returns:
the session attribute Map for this request

createApplicationMap

protected abstract Map<String,Object> createApplicationMap()
Creates the application attribute Map for this request.

Returns:
the application attribute Map for this request

createInitMap

protected abstract Map<String,String> createInitMap()
Creates the initialization parameter Map for this request.

Returns:
the initialization parameter Map for this request

createParameterMap

protected abstract Map<String,String> createParameterMap()
Creates the request parameter Map for this request. For multi-value parameters only the first value will be included.

Returns:
the request parameter Map for this request

createParameterValuesMap

protected abstract Map<String,String[]> createParameterValuesMap()
Creates the request parameter Map for this request. The values of this Map are String arrays to allow multiple values for each parameter.

Returns:
the request parameter Map for this request