org.springframework.conversation.scope
Class ConversationScope

java.lang.Object
  extended by org.springframework.conversation.scope.ConversationScope
All Implemented Interfaces:
Scope
Direct Known Subclasses:
WebAwareConversationScope

public class ConversationScope
extends Object
implements Scope

The default implementation of a conversation scope most likely being exposed as "conversation" scope. It uses the ConversationManager to get access to the current conversation being used as the container for storing and retrieving attributes and beans.

Since:
3.1
Author:
Micha Kiener

Field Summary
static String CURRENT_CONVERSATION_ATTRIBUTE_NAME
          The name of the current conversation object, made available through resolveContextualObject(String).
 
Constructor Summary
ConversationScope()
           
 
Method Summary
 Object get(String name, ObjectFactory<?> objectFactory)
          Return the object with the given name from the underlying scope, creating it if not found in the underlying storage mechanism.
 String getConversationId()
          Will return null if there is no current conversation.
 ConversationManager getConversationManager()
           
 void registerDestructionCallback(String name, Runnable callback)
          Registering a destruction callback is only possible, if supported by the underlying ConversationRepository.
 Object remove(String name)
          Remove the object with the given name from the underlying scope.
 Object resolveContextualObject(String key)
          Supports the following contextual objects: "currentConversation", returns the current Conversation
 void setConversationManager(ConversationManager conversationManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_CONVERSATION_ATTRIBUTE_NAME

public static final String CURRENT_CONVERSATION_ATTRIBUTE_NAME
The name of the current conversation object, made available through resolveContextualObject(String).

See Also:
Constant Field Values
Constructor Detail

ConversationScope

public ConversationScope()
Method Detail

get

public Object get(String name,
                  ObjectFactory<?> objectFactory)
Description copied from interface: Scope
Return the object with the given name from the underlying scope, creating it if not found in the underlying storage mechanism.

This is the central operation of a Scope, and the only operation that is absolutely required.

Specified by:
get in interface Scope
Parameters:
name - the name of the object to retrieve
objectFactory - the ObjectFactory to use to create the scoped object if it is not present in the underlying storage mechanism
Returns:
the desired object (never null)

getConversationId

public String getConversationId()
Will return null if there is no current conversation. It will not implicitly start a new one, if no current conversation object in place.

Specified by:
getConversationId in interface Scope
Returns:
the conversation ID, or null if there is no conversation ID for the current scope

registerDestructionCallback

public void registerDestructionCallback(String name,
                                        Runnable callback)
Registering a destruction callback is only possible, if supported by the underlying ConversationRepository.

Specified by:
registerDestructionCallback in interface Scope
Parameters:
name - the name of the object to execute the destruction callback for
callback - the destruction callback to be executed. Note that the passed-in Runnable will never throw an exception, so it can safely be executed without an enclosing try-catch block. Furthermore, the Runnable will usually be serializable, provided that its target object is serializable as well.
See Also:
DisposableBean, AbstractBeanDefinition.getDestroyMethodName(), DestructionAwareBeanPostProcessor

remove

public Object remove(String name)
Description copied from interface: Scope
Remove the object with the given name from the underlying scope.

Returns null if no object was found; otherwise returns the removed Object.

Note that an implementation should also remove a registered destruction callback for the specified object, if any. It does, however, not need to execute a registered destruction callback in this case, since the object will be destroyed by the caller (if appropriate).

Note: This is an optional operation. Implementations may throw UnsupportedOperationException if they do not support explicitly removing an object.

Specified by:
remove in interface Scope
Parameters:
name - the name of the object to remove
Returns:
the removed object, or null if no object was present
See Also:
Scope.registerDestructionCallback(java.lang.String, java.lang.Runnable)

resolveContextualObject

public Object resolveContextualObject(String key)
Supports the following contextual objects:

Specified by:
resolveContextualObject in interface Scope
Parameters:
key - the contextual key
Returns:
the corresponding object, or null if none found
See Also:
Scope.resolveContextualObject(String)

setConversationManager

public void setConversationManager(ConversationManager conversationManager)

getConversationManager

public ConversationManager getConversationManager()