openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelap...@apache.org
Subject svn commit: r1244260 - in /openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans: component/InjectionPointBean.java event/ObserverMethodImpl.java inject/AbstractInjectable.java inject/OWBInjector.java
Date Tue, 14 Feb 2012 22:59:59 GMT
Author: kelapure
Date: Tue Feb 14 22:59:58 2012
New Revision: 1244260

URL: http://svn.apache.org/viewvc?rev=1244260&view=rev
Log:
OWB-645   Fixed multiple errors in test. This is the real fix. 

Modified:
    openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
    openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java

Modified: openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java?rev=1244260&r1=1244259&r2=1244260&view=diff
==============================================================================
--- openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
(original)
+++ openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
Tue Feb 14 22:59:58 2012
@@ -18,25 +18,58 @@
  */
 package org.apache.webbeans.component;
 
+import java.util.Stack;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.annotation.DependentScopeLiteral;
 import org.apache.webbeans.config.WebBeansContext;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.InjectionPoint;
-
+import org.apache.webbeans.logger.WebBeansLogger;
 
 public class InjectionPointBean extends AbstractOwbBean<InjectionPoint>
 {
-    //X TODO refactor. public static variables are utterly ugly
-    public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>();
+
+    public static final WebBeansLogger logger = WebBeansLogger.getLogger(InjectionPointBean.class);
+
+    private static ThreadLocal<Stack<InjectionPoint>> localThreadlocalStack =
new ThreadLocal<Stack<InjectionPoint>>();
+    
+    public static Stack<InjectionPoint> getStackOfInjectionPoints()
+    {
+        Stack<InjectionPoint> stackIP = localThreadlocalStack.get();
+        if (null == stackIP) 
+        {
+            stackIP = new Stack<InjectionPoint>();
+        }
+        return stackIP;
+    }
+    
+    public static boolean setThreadLocal(InjectionPoint ip) 
+    {
+
+        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
+        stackIP.push(ip);
+        localThreadlocalStack.set(stackIP);
+        logger.debug("PUSHED IP on stack {0}", stackIP);
+        return true;
+        
+    }
+    
+    public static void unsetThreadLocal() 
+    {
+        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
+        InjectionPoint ip = stackIP.pop();
+        logger.debug("POPPED IP on stack {0}", ip);
+    }
 
     /**
      * Removes the ThreadLocal from the ThreadMap to prevent memory leaks.
      */
-    public static void removeThreadLocal()
+    public static void removeThreadLocal() 
     {
-        local.remove();
+
+        logger.debug("REMOVED ThreadLocal stack");
+        localThreadlocalStack.remove();
+        
     }
 
     public InjectionPointBean(WebBeansContext webBeansContext)
@@ -50,24 +83,20 @@ public class InjectionPointBean extends 
     }
 
     @Override
-    protected InjectionPoint createInstance(CreationalContext<InjectionPoint> creationalContext)
+    protected InjectionPoint createInstance(CreationalContext<InjectionPoint> creationalContext)

     {
-        try
-        {
-            return local.get();
-            
-        }
-        finally
-        {
-            local.set(null);
-            local.remove();
-        }
+
+        logger.debug("ENTRY createInstance {0}", creationalContext);
+        InjectionPoint ip = getStackOfInjectionPoints().peek();
+        logger.debug("RETURN {0}", ip);
+        return ip;
+
     }
 
     @Override
     protected void destroyInstance(InjectionPoint instance, CreationalContext<InjectionPoint>
creationalContext)
     {
-        local.remove();
+        removeThreadLocal();
     }
     
     /* (non-Javadoc)
@@ -78,6 +107,5 @@ public class InjectionPointBean extends 
     {
         return true;
     }
-    
-    
+        
 }

Modified: openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1244260&r1=1244259&r2=1244260&view=diff
==============================================================================
--- openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Tue Feb 14 22:59:58 2012
@@ -374,6 +374,8 @@ public class ObserverMethodImpl<T> imple
 
                 if (!observesAnnotation)
                 {
+                    boolean injectionPointBeanLocalSetOnStack = false;
+                    
                     //Get parameter annotations
                     Annotation[] bindingTypes = annotationManager.getQualifierAnnotations(annot);
                     
@@ -391,13 +393,18 @@ public class ObserverMethodImpl<T> imple
                     {
                         if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                         {
-                            InjectionPointBean.local.set(point);   
+                            injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                         }
                     }                           
                     
                     CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                     Object instance = manager.getInstance(injectedBean, creational); 
                     
+                    if (injectionPointBeanLocalSetOnStack)
+                    {
+                        InjectionPointBean.unsetThreadLocal();
+                    }
+                    
                     param = new ObserverParams();
                     param.isBean = true;
                     param.creational = creational;
@@ -436,6 +443,8 @@ public class ObserverMethodImpl<T> imple
             }
             else
             {
+                boolean injectionPointBeanLocalSetOnStack = false;
+                
                 //Get parameter annotations
                 Annotation[] bindingTypes =
                     annotationManager.getQualifierAnnotations(AnnotationUtil.
@@ -453,13 +462,18 @@ public class ObserverMethodImpl<T> imple
                 {
                     if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                     {
-                        InjectionPointBean.local.set(point);   
+                        injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(point);
                     }
                 }                    
                 
                 CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                 Object instance = manager.getInstance(injectedBean, creational); 
-                                    
+                
+                if (injectionPointBeanLocalSetOnStack)
+                {
+                	InjectionPointBean.unsetThreadLocal();
+                }
+                
                 param = new ObserverParams();
                 param.isBean = true;
                 param.creational = creational;

Modified: openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1244260&r1=1244259&r2=1244260&view=diff
==============================================================================
--- openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Tue Feb 14 22:59:58 2012
@@ -106,49 +106,61 @@ public abstract class AbstractInjectable
         else if(isEventProviderInjection(injectionPoint))
         {
             EventBean.local.set(injectionPoint);
-        }        
+        } 
         
-        //Injection for dependent instance InjectionPoint fields
-        boolean dependentProducer = false;
-        if(WebBeansUtil.isDependent(injectedBean))
+        boolean injectionPointBeanLocalSetOnStack = false;
+        
+        try 
         {
-            if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
+            //Injection for dependent instance InjectionPoint fields
+            boolean dependentProducer = false;
+            if(WebBeansUtil.isDependent(injectedBean))
             {
-                InjectionPointBean.local.set(injectionPoint);   
-            }
-            
-            if(!injectionPoint.isTransient())
-            {
-                if(injectedBean instanceof AbstractProducerBean)
+                if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
+                {
+                    injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint);
+                }
+
+                if(!injectionPoint.isTransient())
                 {
-                    if(injectionOwnerBean.isPassivationCapable())
+                    if(injectedBean instanceof AbstractProducerBean)
                     {
-                        dependentProducer = true;   
+                        if(injectionOwnerBean.isPassivationCapable())
+                        {
+                            dependentProducer = true;   
+                        }
                     }
                 }
+            }        
+
+            //Gets injectable reference for injected bean
+            injected = beanManager.getInjectableReference(injectionPoint, injectionOwnerCreationalContext);
+
+            /*X TODO see spec issue CDI-140 */
+            if(dependentProducer)
+            {
+                if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
+                {
+                    throw new IllegalProductException("If a producer method or field of scope
@Dependent returns an serializable object for injection " +
+                                                    "into an injection point "+ injectionPoint
+" that requires a passivation capable dependency");
+                }
             }
-        }        
-        
-        //Gets injectable reference for injected bean
-        injected = beanManager.getInjectableReference(injectionPoint, injectionOwnerCreationalContext);
 
-        /*X TODO see spec issue CDI-140 */
-        if(dependentProducer)
-        {
-            if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
+
+            // add this dependent into bean dependent list
+            if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
             {
-                throw new IllegalProductException("If a producer method or field of scope
@Dependent returns an serializable object for injection " +
-                                                  "into an injection point "+ injectionPoint
+" that requires a passivation capable dependency");
+                if(instanceUnderInjection.get() != null)
+                {
+                    ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
+                }
             }
         }
-
         
-        // add this dependent into bean dependent list
-        if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+        finally
         {
-            if(instanceUnderInjection.get() != null)
-            {
-                ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
+            if (injectionPointBeanLocalSetOnStack) {
+                InjectionPointBean.unsetThreadLocal();
             }
         }
 

Modified: openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
URL: http://svn.apache.org/viewvc/openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java?rev=1244260&r1=1244259&r2=1244260&view=diff
==============================================================================
--- openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
(original)
+++ openwebbeans/tags/openwebbeans-1.1.2/webbeans-impl/src/main/java/org/apache/webbeans/inject/OWBInjector.java
Tue Feb 14 22:59:58 2012
@@ -222,6 +222,7 @@ public final class OWBInjector implement
     private Object getInjectedObjectReference(InjectionPoint injectionPoint, BeanManagerImpl
beanManager)
     {
         Object object = null;
+        boolean injectionPointBeanLocalSetOnStack = false;
         
         //Injected contextual beam
         InjectionResolver injectionResolver = beanManager.getInjectionResolver();
@@ -242,12 +243,17 @@ public final class OWBInjector implement
         {
             if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
             {
-                InjectionPointBean.local.set(injectionPoint);   
+                injectionPointBeanLocalSetOnStack = InjectionPointBean.setThreadLocal(injectionPoint);
             }
         }
         
         object = beanManager.getInjectableReference(injectionPoint, ownerCreationalContext);
         
+        if (injectionPointBeanLocalSetOnStack )
+        {
+        	InjectionPointBean.unsetThreadLocal();
+        }
+        
         return object;
     }
     



Mime
View raw message