org.apache.myfaces.orchestra.conversation.spring
Class AbstractSpringOrchestraScope

java.lang.Object
  extended by org.apache.myfaces.orchestra.conversation.spring.AbstractSpringOrchestraScope
All Implemented Interfaces:
ConversationFactory, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.config.Scope, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
SpringConversationScope, SpringViewControllerScope

public abstract class AbstractSpringOrchestraScope
extends java.lang.Object
implements ConversationFactory, org.springframework.beans.factory.config.Scope, org.springframework.beans.factory.BeanFactoryAware, org.springframework.context.ApplicationContextAware

Abstract basis class for all the Orchestra scopes.

A scope object has two quite different roles:

  1. It handles the lookup of beans in a scope, and creates them if needed
  2. It handles the creation of Conversation objects, using the spring properties configured on the scope object.

This base class handles item 1 above, and leaves item 2 to a subclass. The declaration of interface ConversationFactory needs to be on this class, however, as the createBean method needs to invoke it.


Constructor Summary
AbstractSpringOrchestraScope()
           
 
Method Summary
protected  void assertSameScope(java.lang.String beanName, Conversation conversation)
           
protected  java.lang.String buildBeanName(java.lang.String name)
          Strip off any Spring namespace (eg scopedTarget).
 java.lang.Object get(java.lang.String name, org.springframework.beans.factory.ObjectFactory objectFactory)
          This is invoked by Spring whenever someone calls getBean(name) on a bean-factory and the bean-definition for that bean has a scope attribute that maps to an instance of this class.
protected  java.lang.Object getBean(java.lang.String beanName, org.springframework.beans.factory.ObjectFactory objectFactory)
          See method get(name, objectFactory).
protected  Conversation getConversationForBean(java.lang.String beanName)
          Get the conversation for the given beanName.
 java.lang.String getConversationId()
          Return the conversation context id.
protected  java.lang.String getConversationNameForBean(java.lang.String beanName)
          Get the conversation name associated with the beanName.
protected  void notifyAccessConversation(Conversation conversation)
           
 void registerDestructionCallback(java.lang.String name, java.lang.Runnable runnable)
          Add the given runnable wrapped within an ConversationBindingListener to the conversation map.
 java.lang.Object remove(java.lang.String name)
           
 void setAdvices(org.aopalliance.aop.Advice[] advices)
          The advices (interceptors) which will be applied to the conversation scoped bean.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          Get an ApplicationContext injected by Spring.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
          Set the Conversation object to the bean if it implements the ConversationAware interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.myfaces.orchestra.conversation.ConversationFactory
createConversation
 

Constructor Detail

AbstractSpringOrchestraScope

public AbstractSpringOrchestraScope()
Method Detail

setAdvices

public void setAdvices(org.aopalliance.aop.Advice[] advices)
The advices (interceptors) which will be applied to the conversation scoped bean.


getConversationId

public java.lang.String getConversationId()
Return the conversation context id.

Note: This conversationId is something spring requires. It has nothing to do with the Orchestra conversation id.

Specified by:
getConversationId in interface org.springframework.beans.factory.config.Scope

get

public java.lang.Object get(java.lang.String name,
                            org.springframework.beans.factory.ObjectFactory objectFactory)
This is invoked by Spring whenever someone calls getBean(name) on a bean-factory and the bean-definition for that bean has a scope attribute that maps to an instance of this class.

First, the appropriate ConversationContext is retrieved.

Second, the appropriate Conversation is retrieved; if it does not yet exist then it is created and started. The conversation name is either specified on the bean-definition via a custom attribute, or defaults to the bean name.

Then if the bean already exists in the Conversation then it is returned. Otherwise a new instance is created, stored into the Conversation and returned.

When a bean is created, a proxy is actually created for it which has one or more AOP "advices" (ie method interceptors). The CurrentConversationAdvice class is always attached. Note that if the bean definition contains the aop:proxy tag (and most do) then the bean that spring creates is already a proxy, ie what is returned is a proxy of a proxy.

Specified by:
get in interface org.springframework.beans.factory.config.Scope

getBean

protected java.lang.Object getBean(java.lang.String beanName,
                                   org.springframework.beans.factory.ObjectFactory objectFactory)
See method get(name, objectFactory).


assertSameScope

protected void assertSameScope(java.lang.String beanName,
                               Conversation conversation)

notifyAccessConversation

protected void notifyAccessConversation(Conversation conversation)

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
                    throws org.springframework.beans.BeansException
Set the Conversation object to the bean if it implements the ConversationAware interface.

Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

getConversationForBean

protected Conversation getConversationForBean(java.lang.String beanName)
Get the conversation for the given beanName.


getConversationNameForBean

protected java.lang.String getConversationNameForBean(java.lang.String beanName)
Get the conversation name associated with the beanName.


buildBeanName

protected java.lang.String buildBeanName(java.lang.String name)
Strip off any Spring namespace (eg scopedTarget).

This method will simply strip off anything before the first dot.


remove

public java.lang.Object remove(java.lang.String name)
Specified by:
remove in interface org.springframework.beans.factory.config.Scope

registerDestructionCallback

public void registerDestructionCallback(java.lang.String name,
                                        java.lang.Runnable runnable)
Add the given runnable wrapped within an ConversationBindingListener to the conversation map.

This ensures it will be called during conversation destroy.

Specified by:
registerDestructionCallback in interface org.springframework.beans.factory.config.Scope

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
Get an ApplicationContext injected by Spring. See ApplicationContextAware interface.

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException


Copyright 2007 The Apache Software Foundation. All Rights Reserved.