org.barracudamvc.core.event
Class DefaultEventContext

java.lang.Object
  extended byorg.barracudamvc.core.event.DefaultEventContext
All Implemented Interfaces:
ControlEventContext, EventContext, StateMap, ViewEventContext

public class DefaultEventContext
extends Object
implements ViewEventContext

The context contains information about the event (event, queue, plus request and response info if appropriate). The context also implements StateMap, so you can use it to pass information between event handlers. The scope of the context is only for the duration of an event dispatch cycle (ie. from Http Request to Http Response)

Note that because DefaultEventContext implements ViewEventContext it can safely be cast to its two parent interfaces: EventContext and ControlEventContext. This is in fact what the DefaultEventDispatcher actually does to control access to the appropriate information (ie. a ControlEvent handler should get a reference to an ControlEventContext, NOT an ViewEventContext, since the control handlers shouldn't have access to the HttpServletResponse object.)


Field Summary
protected static org.apache.log4j.Logger logger
           
 
Fields inherited from interface org.barracudamvc.core.event.ViewEventContext
HTTP_SERVLET_RESPONSE
 
Fields inherited from interface org.barracudamvc.core.event.ControlEventContext
HTTP_SERVLET_REQUEST, SERVLET_CONFIG
 
Fields inherited from interface org.barracudamvc.core.event.EventContext
BASE_EVENT, DISPATCH_QUEUE, VIEW_CAPABILITIES
 
Constructor Summary
DefaultEventContext(DispatchQueue queue, ViewCapabilities vc, javax.servlet.ServletConfig config, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, HttpResponseEvent defaultResponseEvent)
          Public constructor.
 
Method Summary
 void clearState()
          clear all state information
 javax.servlet.ServletConfig getConfig()
          Get the associated ServletConfig structure
 BaseEvent getEvent()
          Get the underlying BaseEvent
 DispatchQueue getQueue()
          Get the underlying DispatchQueue
 javax.servlet.http.HttpServletRequest getRequest()
          Get the associated HttpServletRequest
 javax.servlet.http.HttpServletResponse getResponse()
          Get the associated HttpServletResponse
 Object getState(Object key)
          get a property in this StateMap
 Set getStateKeys()
          get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)
 Map getStateStore()
          get a copy of the underlying Map
 ViewCapabilities getViewCapabilities()
          Get the underlying ViewCapabilities
 void persistContext(ClientSideRedirectException re)
          The event context must be able to persist its state in the user's session.
 void putState(Object key, Object val)
          set a property in this StateMap
 Object removeState(Object key)
          remove a property in this StateMap
 void restoreContext(javax.servlet.http.HttpServletRequest req)
          The event context must also be able to restore state from the user's session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger
Constructor Detail

DefaultEventContext

public DefaultEventContext(DispatchQueue queue,
                           ViewCapabilities vc,
                           javax.servlet.ServletConfig config,
                           javax.servlet.http.HttpServletRequest req,
                           javax.servlet.http.HttpServletResponse resp,
                           HttpResponseEvent defaultResponseEvent)
Public constructor.

Parameters:
queue - the event dispatch queue
config - the servlet config structure
req - the HttpServletRequest
resp - the HttpServlet Response
defaultResponseEvent - the default response event to be used if none is generated by the control event handlers
Method Detail

getEvent

public BaseEvent getEvent()
Get the underlying BaseEvent

Specified by:
getEvent in interface EventContext
Returns:
the underlying BaseEvent

getQueue

public DispatchQueue getQueue()
Get the underlying DispatchQueue

Specified by:
getQueue in interface EventContext
Returns:
the underlying DispatchQueue

getViewCapabilities

public ViewCapabilities getViewCapabilities()
Get the underlying ViewCapabilities

Specified by:
getViewCapabilities in interface EventContext

getConfig

public javax.servlet.ServletConfig getConfig()
Get the associated ServletConfig structure

Specified by:
getConfig in interface ControlEventContext
Returns:
the associated ServletConfig structure

getRequest

public javax.servlet.http.HttpServletRequest getRequest()
Get the associated HttpServletRequest

Specified by:
getRequest in interface ControlEventContext
Returns:
the associated HttpServletRequest

getResponse

public javax.servlet.http.HttpServletResponse getResponse()
Get the associated HttpServletResponse

Specified by:
getResponse in interface ViewEventContext
Returns:
the associated HttpServletResponse

persistContext

public void persistContext(ClientSideRedirectException re)
The event context must be able to persist its state in the user's session. NOTE: this method is primarily intended for use by the EventDispatcher class when the system needs to persist context information over multiple request-response cycels (ie. to handle ClientSideRedirectExceptions). As such, developers using the event model in applications should never really need to call this method.

Specified by:
persistContext in interface EventContext
Parameters:
re - the client side redirect exception that is the reason for this call to persistContext

restoreContext

public void restoreContext(javax.servlet.http.HttpServletRequest req)
The event context must also be able to restore state from the user's session. Calling this method effectively removes the state from the session.


putState

public void putState(Object key,
                     Object val)
set a property in this StateMap

Specified by:
putState in interface StateMap
Parameters:
key - the state key object
val - the state value object

getState

public Object getState(Object key)
get a property in this StateMap

Specified by:
getState in interface StateMap
Parameters:
key - the state key object
Returns:
the value for the given key

removeState

public Object removeState(Object key)
remove a property in this StateMap

Specified by:
removeState in interface StateMap
Parameters:
key - the key object
Returns:
the object which was removed

getStateKeys

public Set getStateKeys()
get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)

Specified by:
getStateKeys in interface StateMap
Returns:
a Set of keys for this StateMap

getStateStore

public Map getStateStore()
get a copy of the underlying Map

Specified by:
getStateStore in interface StateMap
Returns:
a copy of the underlying state Map

clearState

public void clearState()
clear all state information

Specified by:
clearState in interface StateMap


Copyright © 2004 BarracudaMVC.org All Rights Reserved.