if (log.isDebugEnabled())
{
log.debug("getRealBean called for bean " + beanName);
}
ConversationManager manager = ConversationManager.getInstance();
Conversation conversation;
// check if we have a conversation
synchronized(manager)
{
conversation = manager.getConversation(conversationName);
if (conversation == null)
{
// Start the conversation. This eventually results in a
// callback to the createConversation method on this class.
conversation = manager.startConversation(conversationName, this);
}
else
{
// sanity check: verify that two beans with the different scopes
// do not declare the same conversationName.
assertSameScope(beanName, conversation);
}
}
// get the conversation
notifyAccessConversation(conversation);
synchronized(conversation)
{
if (!conversation.hasAttribute(beanName))
{
Object value;
// Set the magic property that forces all proxies of this bean to be CGLIB proxies.
// It doesn't matter if we do this multiple times..
BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(beanName);
beanDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
try
{
// Create the new bean. Note that this will run the
// OrchestraAdvisorBeanPostProcessor processor, which
// will cause the returned object to actually be a proxy
// with the CurrentConversationAdvice (at least) attached to it.
value = objectFactory.getObject();
}
catch(org.springframework.aop.framework.AopConfigException e)
{
throw new IllegalStateException(
"Unable to create Orchestra proxy"
+ " for bean " + beanName, e);
}
conversation.setAttribute(beanName, value);
if (value instanceof ConversationAware)
{
((ConversationAware) value).setConversation(conversation);
}
}
}
// get the bean
return conversation.getAttribute(beanName);
}