openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1465293 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: container/ context/creational/ event/ inject/ portable/
Date Sat, 06 Apr 2013 19:55:21 GMT
Author: arne
Date: Sat Apr  6 19:55:20 2013
New Revision: 1465293

URL: http://svn.apache.org/r1465293
Log:
OWB-766: Removed public static ThreadLocal

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Sat Apr  6 19:55:20 2013
@@ -543,7 +543,7 @@ public class BeanManagerImpl implements 
     /**
      * {@inheritDoc}
      */
-    public <T> CreationalContext<T> createCreationalContext(Contextual<T>
contextual)
+    public <T> CreationalContextImpl<T> createCreationalContext(Contextual<T>
contextual)
     {
         if (contextual instanceof SerializableBean)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextFactory.java
Sat Apr  6 19:55:20 2013
@@ -49,7 +49,7 @@ public final class CreationalContextFact
      * @param contextual contextual instance
      * @return new creational context for given contextual
      */
-    public CreationalContext<T> getCreationalContext(Contextual<T> contextual)
+    public CreationalContextImpl<T> getCreationalContext(Contextual<T> contextual)
     {        
         return new CreationalContextImpl<T>(contextual, webBeansContext);
     }        

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Sat Apr  6 19:55:20 2013
@@ -24,10 +24,12 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Stack;
 
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansException;
@@ -44,6 +46,11 @@ public class CreationalContextImpl<T> im
      * The delegate object to be injected into delegate injection points
      */
     private transient T delegate;
+    
+    /**
+     * The injection point object to be injected into injection points of type InjectionPoint
+     */
+    private transient Stack<InjectionPoint> injectionPoints;
 
     /**
      * Contextual bean dependent instances
@@ -92,6 +99,33 @@ public class CreationalContextImpl<T> im
         return oldValue;
     }
 
+    public InjectionPoint getInjectionPoint()
+    {
+        if (injectionPoints == null || injectionPoints.isEmpty())
+        {
+            return null;
+        }
+        return injectionPoints.peek();
+    }
+
+    public void putInjectionPoint(InjectionPoint injectionPoint)
+    {
+        if (injectionPoints == null)
+        {
+            injectionPoints = new Stack<InjectionPoint>();
+        }
+        injectionPoints.push(injectionPoint);
+    }
+
+    public InjectionPoint removeInjectionPoint()
+    {
+        if (injectionPoints == null || injectionPoints.isEmpty())
+        {
+            return null;
+        }
+        return injectionPoints.pop();
+    }
+
     /**
      * Save this incomplete instance.
      * 
@@ -200,7 +234,6 @@ public class CreationalContextImpl<T> im
         return contextual;
     }
 
-
     /**
      * Write Object. 
      */

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Sat Apr  6 19:55:20 2013
@@ -53,11 +53,11 @@ import org.apache.webbeans.component.Web
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.inject.impl.InjectionPointFactory;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
-import org.apache.webbeans.portable.EventProducer;
 import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.proxy.OwbNormalScopeProxy;
 import org.apache.webbeans.util.AnnotationUtil;
@@ -404,12 +404,11 @@ public class ObserverMethodImpl<T> imple
                         }
                     }
                     
+                    CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
                     if (isEventProviderInjection(point))
                     {
-                        EventProducer.local.set(point);
+                        creational.putInjectionPoint(point);
                     }
-                    
-                    CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                     Object instance = manager.getReference(injectedBean, null, creational);
                     if (injectionPointBeanLocalSetOnStack)
                     {
@@ -476,12 +475,12 @@ public class ObserverMethodImpl<T> imple
                     }
                 }                    
 
+                
+                CreationalContextImpl<Object> creational = manager.createCreationalContext(injectedBean);
                 if (isEventProviderInjection(point))
                 {
-                    EventProducer.local.set(point);
+                    creational.putInjectionPoint(point);
                 }
-                
-                CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                 Object instance = manager.getReference(injectedBean, null, creational);
                 
                 if (injectionPointBeanLocalSetOnStack)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Sat Apr  6 19:55:20 2013
@@ -39,7 +39,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
-import org.apache.webbeans.portable.EventProducer;
 import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.portable.InstanceProducer;
 import org.apache.webbeans.util.ClassUtil;
@@ -90,7 +89,7 @@ public abstract class AbstractInjectable
         
         else if(isEventProviderInjection(injectionPoint))
         {
-            EventProducer.local.set(injectionPoint);
+            creationalContext.putInjectionPoint(injectionPoint);
         }        
         
         boolean injectionPointBeanLocalSetOnStack = false;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java?rev=1465293&r1=1465292&r2=1465293&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/EventProducer.java
Sat Apr  6 19:55:20 2013
@@ -27,14 +27,13 @@ import javax.enterprise.event.Event;
 import javax.enterprise.inject.spi.InjectionPoint;
 
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.event.EventImpl;
 import org.apache.webbeans.exception.WebBeansException;
 
 public class EventProducer<T> extends AbstractProducer<Event<T>>
 {
 
-    //X TODO refactor. public static variables are utterly ugly
-    public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>();
     private WebBeansContext webBeansContext;
     
     public EventProducer(WebBeansContext webBeansContext)
@@ -49,8 +48,13 @@ public class EventProducer<T> extends Ab
     public Event<T> produce(CreationalContext<Event<T>> creationalContext)
     {
         Event<T> instance = null;
+        InjectionPoint injectionPoint = null;
+        //TODO What should we do here if creationalContext is not instanceof CreationalContextImpl?
+        if (creationalContext instanceof CreationalContextImpl)
+        {
+            injectionPoint = ((CreationalContextImpl<Event<T>>)creationalContext).getInjectionPoint();
+        }
 
-        InjectionPoint injectionPoint = local.get();
         Type eventType;
         
         if(injectionPoint != null)
@@ -79,8 +83,10 @@ public class EventProducer<T> extends Ab
             }           
             finally
             {
-                local.set(null);
-                local.remove();
+                if (creationalContext instanceof CreationalContextImpl)
+                {
+                    ((CreationalContextImpl<Event<T>>)creationalContext).removeInjectionPoint();
+                }
             }
             
         }



Mime
View raw message