com.google.code.rees.scope.conversation
Class ConversationAdapter

java.lang.Object
  extended by com.google.code.rees.scope.conversation.ConversationAdapter
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
SpringConversationAdapter, StrutsConversationAdapter

public abstract class ConversationAdapter
extends Object
implements Serializable

This class is used to adapt/integrate the major components of the conversation management to control frameworks such as Struts2 and Spring MVC or any other framework.

By employing the adapter pattern, the conversation management aspects are separated from the details of the control framework and separated even from the underlying request and session mechanisms.

Makes use of ThreadLocal to make the current request's adapter available through the static call ConversationAdapter.getAdapter().

Author:
rees.byars
See Also:
Serialized Form

Field Summary
protected static ThreadLocal<ConversationAdapter> conversationAdapter
           
protected  ConversationPostProcessorWrapperFactory postProcessorFactory
           
protected  Collection<ConversationPostProcessorWrapper> postProcessors
           
protected  Map<String,String> viewContext
           
 
Constructor Summary
ConversationAdapter()
           
 
Method Summary
 void addPostProcessor(ConversationPostProcessor postProcessor, ConversationClassConfiguration conversationConfig, String conversationId)
          Add a ConversationPostProcessor that is guaranteed to be executed after action execution by a call to executePostProcessors()
abstract  ConversationContext beginConversation(String conversationName, long maxIdleTimeMillis)
          begins a new conversation, returning the context for the new conversation
static void cleanup()
          clean up this resource once processing is completed for the request, static to guarantee that it references current thread's instance
protected  void doCleanup()
          called by cleanup(), can be overridden to tweak
abstract  ConversationContext endConversation(String conversationName, String conversationId)
          Removes the conversation from the session, returning the context
 void executePostProcessors()
          Executes all ConversationPostProcessors that have been added using addPostProcessor(ConversationPostProcessor, ConversationClassConfiguration, String)
abstract  Object getAction()
          The controller instance, such as a Struts2 action class or a Spring MVC controller
abstract  String getActionId()
          A string identifying the current action.
static ConversationAdapter getAdapter()
          Get the ThreadLocal ConversationAdapter associated with the current request
abstract  ConversationContext getConversationContext(String conversationName, String conversationId)
          Returns a ConversationContext for the given name and ID
abstract  Map<String,String> getRequestContext()
          Returns a map containing, at a minimum, conversation name/id key/value pairs for the current request.
 Map<String,String> getViewContext()
          Returns a map that is used to place conversation name/id key/value pairs for placing in the view context (the view context being, for instance, a JSP).
static void setAdapter(ConversationAdapter adapter)
          Set the ThreadLocal ConversationAdapter for use with the current request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conversationAdapter

protected static ThreadLocal<ConversationAdapter> conversationAdapter

viewContext

protected Map<String,String> viewContext

postProcessorFactory

protected ConversationPostProcessorWrapperFactory postProcessorFactory

postProcessors

protected Collection<ConversationPostProcessorWrapper> postProcessors
Constructor Detail

ConversationAdapter

public ConversationAdapter()
Method Detail

getAction

public abstract Object getAction()
The controller instance, such as a Struts2 action class or a Spring MVC controller

Returns:

getActionId

public abstract String getActionId()
A string identifying the current action. The convention employed by the DefaultConversationArbitrator is the name of the controller method being executed.

Returns:

getRequestContext

public abstract Map<String,String> getRequestContext()
Returns a map containing, at a minimum, conversation name/id key/value pairs for the current request.

Returns:

beginConversation

public abstract ConversationContext beginConversation(String conversationName,
                                                      long maxIdleTimeMillis)
begins a new conversation, returning the context for the new conversation

Parameters:
conversationName -
maxIdleTimeMillis -
Returns:

getConversationContext

public abstract ConversationContext getConversationContext(String conversationName,
                                                           String conversationId)
Returns a ConversationContext for the given name and ID

Parameters:
conversationId -
Returns:

endConversation

public abstract ConversationContext endConversation(String conversationName,
                                                    String conversationId)
Removes the conversation from the session, returning the context


getViewContext

public Map<String,String> getViewContext()
Returns a map that is used to place conversation name/id key/value pairs for placing in the view context (the view context being, for instance, a JSP).

Returns:

addPostProcessor

public void addPostProcessor(ConversationPostProcessor postProcessor,
                             ConversationClassConfiguration conversationConfig,
                             String conversationId)
Add a ConversationPostProcessor that is guaranteed to be executed after action execution by a call to executePostProcessors()

Parameters:
postProcessor -
conversationConfig -
conversationId -

executePostProcessors

public void executePostProcessors()
Executes all ConversationPostProcessors that have been added using addPostProcessor(ConversationPostProcessor, ConversationClassConfiguration, String)


setAdapter

public static void setAdapter(ConversationAdapter adapter)
Set the ThreadLocal ConversationAdapter for use with the current request. Called in the constructor to force new instances into the ThreadLocal.

Parameters:
adapter -

getAdapter

public static ConversationAdapter getAdapter()
Get the ThreadLocal ConversationAdapter associated with the current request

Returns:

cleanup

public static void cleanup()
clean up this resource once processing is completed for the request, static to guarantee that it references current thread's instance


doCleanup

protected void doCleanup()
called by cleanup(), can be overridden to tweak



Copyright © 2012-2013. All Rights Reserved.