You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2007/12/04 18:18:50 UTC
svn commit: r601007 -
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java
Author: skitching
Date: Tue Dec 4 09:18:49 2007
New Revision: 601007
URL: http://svn.apache.org/viewvc?rev=601007&view=rev
Log:
Simplified invocation of ConversationAware interface. Rather than run it as a BeanPostProcessor, just call it after getBean() is called.
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java?rev=601007&r1=601006&r2=601007&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/AbstractSpringOrchestraScope.java Tue Dec 4 09:18:49 2007
@@ -37,8 +37,6 @@
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.Scope;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -64,7 +62,6 @@
private final Log log = LogFactory.getLog(AbstractSpringOrchestraScope.class);
private static final String POST_PROCESSOR_BEAN_NAME = AbstractSpringOrchestraScope.class.getName() + "_BeanPostProcessor";
- private BeanFactory beanFactory;
private ConfigurableApplicationContext applicationContext;
private Advice[] advices;
private boolean autoProxy = true;
@@ -219,30 +216,6 @@
*/
protected Object getProxy(String beanName, ObjectFactory objectFactory)
{
- // TODO: consider proxy scope
- //
- // Q: can proxies be added to the session or even app scope? It would seem
- // so, as they always do a lookup each time. In that case, bean lookup
- // to find the proxy will be much faster, and the lookup from the proxy will
- // also be faster as it knows the Scope and the ConversationName. The only
- // drawback is that session.containsKey will always be true even when the
- // bean does not currently exist. And that app-variables that "shadow" the
- // real bean will not work. But that's pretty ugly anyway.
- //
- // And if is stored in app scope, then there is no need to cache it inside the
- // beandef..
- //
- // Or should the proxy then be stored in the spring "singleton" scope? Odd, as
- // we have no bean definition for it...
- //
- // Hmm..maybe that is the reason for the ugly scoping "rename" hack - so that
- // the proxy can have singleton scope even though the bean it references
- // does not.
- //
-
- // Check for a cached proxy under a key that is the name of ScopedBeanTargetSource.class.
- // The "proxy class" cannot be used as a key, because it really has no class of its own :-)
-
if (log.isDebugEnabled())
{
log.debug("getProxy called for bean " + beanName);
@@ -259,6 +232,7 @@
String conversationName = (String) beanDefinition.getAttribute(BeanDefinitionConversationNameAttrDecorator.CONVERSATION_NAME_ATTRIBUTE);
if (conversationName == null)
conversationName = beanName;
+ BeanFactory beanFactory = applicationContext.getBeanFactory();
proxy = _SpringUtils.newProxy(this, conversationName, beanName, objectFactory, beanFactory);
beanDefinition.setAttribute(ScopedBeanTargetSource.class.getName(), proxy);
}
@@ -362,6 +336,11 @@
}
conversation.setAttribute(beanName, value);
+
+ if (value instanceof ConversationAware)
+ {
+ ((ConversationAware) value).setConversation(conversation);
+ }
}
}
@@ -429,56 +408,8 @@
*/
public void setBeanFactory(BeanFactory beanFactory) throws BeansException
{
- ConfigurableBeanFactory cbf = (ConfigurableBeanFactory) beanFactory;
- if (!cbf.containsSingleton(POST_PROCESSOR_BEAN_NAME))
- {
- // TODO: this processor instance is implicitly bound to *this* scope instance, and
- // it calls the non-static getConversationNameForBean method on *this* instance, even
- // though the bean it is invoking may be handled by some other scope object. This
- // doesn't actually matter, as the getConversationForBean method is actually stateless,
- // but it is not elegant and should be fixed.
- BeanPostProcessor processor =
- new BeanPostProcessor()
- {
- public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
- {
- if (bean instanceof ConversationAware)
- {
- Conversation conversation = getConversationForBean(beanName);
-
- ((ConversationAware) bean).setConversation(conversation);
- }
-
- return bean;
- }
-
- public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
- {
- return bean;
- }
- };
-
- // Adding the bean to the singletons set causes it to be picked up by the standard
- // AbstractApplicationContext.RegisterBeanPostProcessors method; that calls
- // getBeanNamesForType(BeanPostProcessor.class, ...) which finds stuff in the
- // singleton map even when there is no actual BeanDefinition for it.
- //
- // We cannot call cbf.addBeanPostProcessor even if we want to, as the singleton
- // registration will be added again, making the processor run twice on each bean..
- cbf.registerSingleton(POST_PROCESSOR_BEAN_NAME, processor);
- }
-
- this.beanFactory = beanFactory;
- }
-
- /**
- * Return the BeanFactory that this scope object exists within.
- */
- protected BeanFactory getBeanFactory()
- {
- return beanFactory;
}
-
+
/**
* Get the conversation for the given beanName.
* Returns null if the conversation does not exist.
@@ -548,7 +479,8 @@
*/
protected String getExplicitConversationName(BeanDefinition beanDef)
{
- String attr = (String) beanDef.getAttribute(BeanDefinitionConversationNameAttrDecorator.CONVERSATION_NAME_ATTRIBUTE);
+ String attr = (String) beanDef.getAttribute(
+ BeanDefinitionConversationNameAttrDecorator.CONVERSATION_NAME_ATTRIBUTE);
return attr;
}