openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r933259 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/injection/circular/beans/ test/java/org/apache/webbeans/newtests/injection/circular/tests/
Date Mon, 12 Apr 2010 14:52:42 GMT
Author: struberg
Date: Mon Apr 12 14:52:42 2010
New Revision: 933259

URL: http://svn.apache.org/viewvc?rev=933259&view=rev
Log:
OWB-351 for NormalScoped bean proxies, we need to create a new CreationalContext per Context

If we don't find a already used CreationalContext in the Context, we always create a new one.
NormalScoped beans must not use the CreationalContext of the beans they get injected into.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/tests/CircularInjectionTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java?rev=933259&r1=933258&r2=933259&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/ApplicationScopedBeanIntereptorHandler.java
Mon Apr 12 14:52:42 2010
@@ -21,6 +21,7 @@ package org.apache.webbeans.intercept;
 import javax.enterprise.context.spi.CreationalContext;
 
 import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 
 
 /**
@@ -42,7 +43,7 @@ public class ApplicationScopedBeanIntere
     /**
      * Creates a new handler.
      * @param bean bean
-     * @param creationalContext creaitonal context
+     * @param creationalContext creational context
      */
     public ApplicationScopedBeanIntereptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
@@ -52,11 +53,11 @@ public class ApplicationScopedBeanIntere
     /**
      * {@inheritDoc}
      */
-    protected Object getContextualInstance(OwbBean<Object> bean)
+    protected Object getContextualInstance(OwbBean<Object> bean, CreationalContextImpl<?>
creationalContext)
     {
         if (cachedInstance == null) 
         {
-            cachedInstance = super.getContextualInstance(bean);
+            cachedInstance = super.getContextualInstance(bean, creationalContext);
         }
         
         return cachedInstance;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java?rev=933259&r1=933258&r2=933259&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/DependentScopedBeanInterceptorHandler.java
Mon Apr 12 14:52:42 2010
@@ -67,10 +67,12 @@ public class DependentScopedBeanIntercep
     /**
      * {@inheritDoc}
      */
-    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack) throws Exception
+    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack,
+                                       CreationalContextImpl<?> cc)
+    throws Exception
     {
         InvocationContextImpl impl = new InvocationContextImpl(this.bean, this.actualInstance
,proceed, arguments, stack, InterceptorType.AROUND_INVOKE);
-        impl.setCreationalContext(creationalContext);
+        impl.setCreationalContext(cc);
         
         return impl.proceed();
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=933259&r1=933258&r2=933259&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
Mon Apr 12 14:52:42 2010
@@ -42,9 +42,6 @@ public class NormalScopedBeanInterceptor
     /**Serial id*/
     private static final long serialVersionUID = 1L;
     
-    /**Creational context*/
-    private transient CreationalContext<?> creationalContext;
-
     /**
      * Creates a new bean instance
      * @param bean bean 
@@ -53,7 +50,6 @@ public class NormalScopedBeanInterceptor
     public NormalScopedBeanInterceptorHandler(OwbBean<?> bean, CreationalContext<?>
creationalContext)
     {
         super(bean);
-        this.creationalContext = creationalContext;
     }
     
     /**
@@ -62,19 +58,36 @@ public class NormalScopedBeanInterceptor
     @Override
     public Object invoke(Object instance, Method method, Method proceed, Object[] arguments)
throws Exception
     {
+        CreationalContextImpl<?> creationalContext = null;
+        
+        //Context of the bean
+        Context webbeansContext = getBeanManager().getContext(bean.getScope());
+
+        if (webbeansContext instanceof AbstractContext)
+        {
+            creationalContext = (CreationalContextImpl<?>) ((AbstractContext)webbeansContext).getCreationalContext(bean);
+        }
+        if (creationalContext == null)
+        {
+            // if there was no CreationalContext set from external, we create a new one
+            creationalContext = (CreationalContextImpl<?>) CreationalContextFactory.getInstance().getCreationalContext(bean);
+        }
+        
         //Get instance from context
-        Object webbeansInstance = getContextualInstance((OwbBean<Object>) this.bean);
+        Object webbeansInstance = getContextualInstance((OwbBean<Object>) this.bean,
creationalContext);
         
         //Call super
-        return super.invoke(webbeansInstance, method, proceed, arguments, (CreationalContextImpl<?>)
this.creationalContext);
+        return super.invoke(webbeansInstance, method, proceed, arguments, creationalContext);
     }
         
     /**
      * {@inheritDoc}
      */
-    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack) throws Exception
+    protected Object callAroundInvokes(Method proceed, Object[] arguments, List<InterceptorData>
stack, CreationalContextImpl<?> creationalContext)
+    throws Exception
     {
-        InvocationContextImpl impl = new InvocationContextImpl(this.bean, getContextualInstance((OwbBean<Object>)
this.bean),
+        InvocationContextImpl impl = new InvocationContextImpl(this.bean, 
+                                                               getContextualInstance((OwbBean<Object>)
this.bean, creationalContext),
                                                                proceed, arguments, stack,
InterceptorType.AROUND_INVOKE);
         impl.setCreationalContext(creationalContext);
 
@@ -86,9 +99,10 @@ public class NormalScopedBeanInterceptor
     /**
      * Gets instance from context.
      * @param bean bean instance
+     * @param creationalContext
      * @return the underlying contextual instance, either cached or resolved from the context

      */
-    protected Object getContextualInstance(OwbBean<Object> bean)
+    protected Object getContextualInstance(OwbBean<Object> bean, CreationalContextImpl<?>
creationalContext)
     {
         Object webbeansInstance = null;
         
@@ -103,20 +117,6 @@ public class NormalScopedBeanInterceptor
             return webbeansInstance;
         }
         
-        if (webbeansContext instanceof AbstractContext)
-        {
-            CreationalContext<?> cc = ((AbstractContext)webbeansContext).getCreationalContext(bean);
-            if (cc != null)
-            {
-                creationalContext = cc;
-            }
-        }
-        if (creationalContext == null)
-        {
-            // if there was no CreationalContext set from external, we create a new one
-            creationalContext = CreationalContextFactory.getInstance().getCreationalContext(bean);
-        }
-        
         // finally, we create a new contextual instance
         webbeansInstance = webbeansContext.get((Contextual<Object>)this.bean, (CreationalContext<Object>)
creationalContext);
         

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java?rev=933259&r1=933258&r2=933259&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/beans/CircularDependenScopeBean.java
Mon Apr 12 14:52:42 2010
@@ -45,7 +45,9 @@ public class CircularDependenScopeBean i
     @PostConstruct
     public void postConstruct()
     {
-        app.hello();
+        // removed! This is not allowed in JSR-299 according to mbg because it causes a 
+        // cyclic reference in the creation of the beans! 
+        // app.hello();
         success = true;
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/tests/CircularInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/tests/CircularInjectionTest.java?rev=933259&r1=933258&r2=933259&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/tests/CircularInjectionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/circular/tests/CircularInjectionTest.java
Mon Apr 12 14:52:42 2010
@@ -50,12 +50,12 @@ public class CircularInjectionTest exten
         beanClasses.add(CircularDependenScopeBean.class);
         beanClasses.add(CircularApplicationScopedBean.class);
         
-        startContainer(beanClasses, beanXmls);        
+        startContainer(beanClasses, beanXmls);
         
         Set<Bean<?>> beans = getBeanManager().getBeans("org.apache.webbeans.newtests.injection.circular.beans.CircularApplicationScopedBean");
-        Assert.assertNotNull(beans);        
+        Assert.assertNotNull(beans);
         
-        Bean<CircularApplicationScopedBean> dependentBean = (Bean<CircularApplicationScopedBean>)beans.iterator().next();
       
+        Bean<CircularApplicationScopedBean> dependentBean = (Bean<CircularApplicationScopedBean>)beans.iterator().next();
         CreationalContext<CircularApplicationScopedBean> ctx = getBeanManager().createCreationalContext(dependentBean);
         
         Object reference = getBeanManager().getReference(dependentBean, CircularApplicationScopedBean.class,
ctx);
@@ -81,10 +81,10 @@ public class CircularInjectionTest exten
         beanClasses.add(CircularDependenScopeBean.class);
         beanClasses.add(CircularApplicationScopedBean.class);
         
-        startContainer(beanClasses, beanXmls);        
+        startContainer(beanClasses, beanXmls);
         
         Set<Bean<?>> beans = getBeanManager().getBeans("org.apache.webbeans.newtests.injection.circular.beans.CircularDependenScopeBean");
-        Assert.assertNotNull(beans);        
+        Assert.assertNotNull(beans);
         
         Bean<CircularDependenScopeBean> dependentBean = (Bean<CircularDependenScopeBean>)beans.iterator().next();
       
         CreationalContext<CircularDependenScopeBean> ctx = getBeanManager().createCreationalContext(dependentBean);



Mime
View raw message