openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1417338 - in /openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans: context/AbstractContext.java portable/creation/AbstractProducer.java portable/creation/InjectionTargetProducer.java
Date Wed, 05 Dec 2012 10:17:25 GMT
Author: struberg
Date: Wed Dec  5 10:17:24 2012
New Revision: 1417338

URL: http://svn.apache.org/viewvc?rev=1417338&view=rev
Log:
OWB-734 add quicks mode for getting the right CC

previously we only used the CC which got used for creating 
the _last_ contextual instance

Modified:
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/AbstractProducer.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=1417338&r1=1417337&r2=1417338&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
Wed Dec  5 10:17:24 2012
@@ -177,6 +177,12 @@ public abstract class AbstractContext im
     @SuppressWarnings("unchecked")
     public <T> CreationalContext<T> getCreationalContext(Contextual<T>
contextual)
     {
+        if (componentInstanceMap == null)
+        {
+            // this happens with @Dependent scoped beans
+            return null;
+        }
+
         BeanInstanceBag<?> bag = componentInstanceMap.get(contextual);
         if (bag != null)
         {

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/AbstractProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/AbstractProducer.java?rev=1417338&r1=1417337&r2=1417338&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/AbstractProducer.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/AbstractProducer.java
Wed Dec  5 10:17:24 2012
@@ -20,11 +20,14 @@ package org.apache.webbeans.portable.cre
 
 import java.util.Set;
 
+import javax.enterprise.context.spi.Context;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Producer;
 
 import org.apache.webbeans.component.OwbBean;
+import org.apache.webbeans.context.AbstractContext;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 
 /**
@@ -39,9 +42,6 @@ public abstract class AbstractProducer<T
     /**Bean instance*/
     protected OwbBean<T> bean;
 
-    /**Passing creational context*/
-    protected CreationalContext<T> creationalContext = null;
-    
     /**
      * Create a new producer with given bean.
      * 
@@ -72,11 +72,8 @@ public abstract class AbstractProducer<T
             creationalContext = bean.getWebBeansContext().getCreationalContextFactory().wrappedCreationalContext(creationalContext,
bean);
         }
         
-        //Save it
-        this.creationalContext = creationalContext;
-        
         //Create an instance of the bean
-        instance = bean.createNewInstance(this.creationalContext);
+        instance = bean.createNewInstance(creationalContext);
                 
         return instance; 
     }
@@ -86,10 +83,37 @@ public abstract class AbstractProducer<T
      */
     public void dispose(T instance)
     {
-        bean.destroyCreatedInstance(instance, creationalContext);
+        CreationalContext<T> cc= getCreationalContext();
+        bean.destroyCreatedInstance(instance, cc);
     }
 
     /**
+     * This is a quirks mode function :(
+     * The problem is that we also need the CC for detecting the
+     * interceptors for PreDestroy and PostConstruct methods for example.
+     * But sadly the CDI SPI doesn't pass the CC :/
+     *
+     * @return
+     */
+    protected CreationalContext<T> getCreationalContext()
+    {
+        CreationalContext<T> cc = null;
+        BeanManager bm = bean.getWebBeansContext().getBeanManagerImpl();
+        Context ctx = bm.getContext(bean.getScope());
+        if (ctx instanceof AbstractContext)
+        {
+            cc = ((AbstractContext) ctx).getCreationalContext(bean);
+        }
+
+        if (cc == null)
+        {
+            cc = bm.createCreationalContext(bean);
+        }
+        return cc;
+    }
+
+
+    /**
      * Returns actual bean instance.
      * 
      * @param <X> bean type info

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java?rev=1417338&r1=1417337&r2=1417338&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
Wed Dec  5 10:17:24 2012
@@ -119,7 +119,7 @@ public class InjectionTargetProducer<T> 
         InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);    
         if(!(bean instanceof EnterpriseBeanMarker))
         {
-            bean.postConstruct(instance, creationalContext);
+            bean.postConstruct(instance, getCreationalContext());
         }
     }
 
@@ -129,7 +129,7 @@ public class InjectionTargetProducer<T> 
     public void preDestroy(T instance)
     {
         InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);
-        bean.destroyCreatedInstance(instance, creationalContext);
+        bean.destroyCreatedInstance(instance, getCreationalContext());
     }
 
 }



Mime
View raw message