The Spring Framework

org.springframework.beans.factory.config
Interface Scope

All Known Implementing Classes:
AbstractRequestAttributesScope, RequestScope, SessionScope

public interface Scope

Strategy interface used by a ConfigurableBeanFactory, representing a target scope to hold beans in.

Provides the ability to get and put objects from whatever underlying storage mechanism, such as HTTP session or request. The name passed into this class's get and put methods will identify the target attribute in the scope.

Scope implementations are expected to be thread-safe. One Scope can be used with multiple bean factories, if desired.

An example of a possible underlying storage mechansim would be a session API such as the Servlet API's HttpSession interface.

Since:
2.0
Author:
Juergen Hoeller, Rob Harrop
See Also:
ConfigurableBeanFactory.registerScope(java.lang.String, org.springframework.beans.factory.config.Scope), ScopedProxyFactoryBean, CustomScopeConfigurer

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()
          Return the conversation id for the current underlying scope, if any.
 void registerDestructionCallback(String name, Runnable callback)
          Register a callback to be executed at destruction of the specified object (or at destruction of the entire scope, if the scope does not destroy individual objects but rather only terminate in its entirety).
 Object remove(String name)
          Remove the object with the given name from the underlying scope.
 

Method Detail

getConversationId

String getConversationId()
Return the conversation id for the current underlying scope, if any.

The exact value of the converation id is totally dependent on the underlying storage mechanism (of course). In the case of session scoped beans a good conversation id probably would be the session id; in the case of a JCache scope a good conversation id probably would be the name of the associated cache.

It is perfectly valid to return null in an implementation of this method if the underlying storage mechanism has no obvious good candidate for a conversation id.

Returns:
the conversation id, or null if there is no conversation id concept for this scope

get

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.

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

remove

Object remove(String name)
Remove the object with the given name from the underlying scope.

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

Parameters:
name - the name of the object to remove
Returns:
the removed object, if any

registerDestructionCallback

void registerDestructionCallback(String name,
                                 Runnable callback)
Register a callback to be executed at destruction of the specified object (or at destruction of the entire scope, if the scope does not destroy individual objects but rather only terminate in its entirety).

Implementations should do their best to execute the callback at the appropriate time. If such a callback is not supported by the underlying runtime environment, the callback must be ignored and a corresponding warning should be logged.

Parameters:
name - the name of the object to execute the destruction callback for
callback - the destruction callback to be executed

The Spring Framework

Copyright © 2002-2006 The Spring Framework.