JSF-Spring

de.mindmatters.faces.spring.factory
Class ApplicationScope

java.lang.Object
  extended by de.mindmatters.faces.spring.factory.ApplicationScope
All Implemented Interfaces:
Scope

public final class ApplicationScope
extends java.lang.Object
implements Scope

Alternative singleton Scope implementation. This Scope relies on a ServletContext and a PortletContext repectively and therefore will work with Servlet and Portlet environments.

Author:
Andreas Kuhrwahl

Field Summary
protected  org.apache.commons.logging.Log logger
          For logging.
 
Constructor Summary
ApplicationScope(java.lang.Object context)
          Creates a scope relying on a ServletContext or a PortletContext respectively (depends on the type of context).
 
Method Summary
 void clear()
          Clears the scope.
 java.lang.Object get(java.lang.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.
 java.lang.String getConversationId()
          Return the conversation id for the current underlying scope, if any.
 void registerDestructionCallback(java.lang.String name, java.lang.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).
 java.lang.Object remove(java.lang.String name)
          Remove the object with the given name from the underlying scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.commons.logging.Log logger
For logging.

Constructor Detail

ApplicationScope

public ApplicationScope(java.lang.Object context)
Creates a scope relying on a ServletContext or a PortletContext respectively (depends on the type of context).

Parameters:
context - The ServletContext or the PortletContext respectively
Method Detail

get

public java.lang.Object get(java.lang.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.

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

remove

public java.lang.Object remove(java.lang.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.

Specified by:
remove in interface Scope
Parameters:
name - the name of the object to remove
Returns:
the removed object, if any

registerDestructionCallback

public void registerDestructionCallback(java.lang.String name,
                                        java.lang.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.

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

getConversationId

public java.lang.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.

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

clear

public void clear()
Clears the scope.


JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG