protected Object getBean(String beanName, ObjectFactory objectFactory)
{
String conversationName = getConversationNameForBean(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
{
assertSameScope(beanName, conversation);
}
}
// get the conversation
notifyAccessConversation(conversation);
synchronized(conversation)
{
if (!conversation.hasAttribute(beanName))
{
// create the bean (if not already done)
Object value = objectFactory.getObject();
ProxyFactory factory = new ProxyFactory(value);
factory.setProxyTargetClass(true);
factory.addAdvice(new CurrentConversationAdvice(conversation, beanName));
if (advices != null && advices.length > 0)
{
for (int i = 0; i < advices.length; i++)
{
factory.addAdvice(advices[i]);
}
}
value = factory.getProxy();
conversation.setAttribute(beanName, value);
}
}
// get the bean
return conversation.getAttribute(beanName);
}