openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelap...@apache.org
Subject svn commit: r1244239 - 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:18:49 GMT
Author: kelapure
Date: Tue Feb 14 22:18:49 2012
New Revision: 1244239

URL: http://svn.apache.org/viewvc?rev=1244239&view=rev
Log:
OWB-645  Rolling back the  changes made earlier due to an error.  Fixing the code and will
check in again soon.

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=1244239&r1=1244238&r2=1244239&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:18:49 2012
@@ -18,57 +18,25 @@
  */
 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 org.apache.webbeans.logger.WebBeansLogger;
-
-public class InjectionPointBean extends AbstractOwbBean<InjectionPoint>
-{
 
-    public static final WebBeansLogger logger = WebBeansLogger.getLogger(InjectionPointBean.class);
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
 
-    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 void setThreadLocal(InjectionPoint ip) 
-    {
 
-        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
-        stackIP.push(ip);
-        localThreadlocalStack.set(stackIP);
-        logger.debug("PUSHED IP on stack {0}", stackIP);
-        
-    }
-    
-    public static void unsetThreadLocal() 
-    {
-        Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
-        InjectionPoint ip = stackIP.pop();
-        logger.debug("POPPED IP on stack {0}", ip);
-    }
+public class InjectionPointBean extends AbstractOwbBean<InjectionPoint>
+{
+    //X TODO refactor. public static variables are utterly ugly
+    public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>();
 
     /**
      * Removes the ThreadLocal from the ThreadMap to prevent memory leaks.
      */
-    public static void removeThreadLocal() 
+    public static void removeThreadLocal()
     {
-
-        logger.debug("REMOVED ThreadLocal stack");
-        localThreadlocalStack.remove();
-        
+        local.remove();
     }
 
     public InjectionPointBean(WebBeansContext webBeansContext)
@@ -82,20 +50,24 @@ public class InjectionPointBean extends 
     }
 
     @Override
-    protected InjectionPoint createInstance(CreationalContext<InjectionPoint> creationalContext)

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

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=1244239&r1=1244238&r2=1244239&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:18:49 2012
@@ -391,13 +391,12 @@ public class ObserverMethodImpl<T> imple
                     {
                         if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                         {
-                            InjectionPointBean.setThreadLocal(point);  
+                            InjectionPointBean.local.set(point);   
                         }
                     }                           
                     
                     CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                     Object instance = manager.getInstance(injectedBean, creational); 
-                    InjectionPointBean.unsetThreadLocal();
                     
                     param = new ObserverParams();
                     param.isBean = true;
@@ -454,13 +453,12 @@ public class ObserverMethodImpl<T> imple
                 {
                     if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(point.getType())))
                     {
-                        InjectionPointBean.setThreadLocal(point);
+                        InjectionPointBean.local.set(point);   
                     }
                 }                    
                 
                 CreationalContext<Object> creational = manager.createCreationalContext(injectedBean);
                 Object instance = manager.getInstance(injectedBean, creational); 
-                InjectionPointBean.unsetThreadLocal();
                                     
                 param = new ObserverParams();
                 param.isBean = true;

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=1244239&r1=1244238&r2=1244239&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:18:49 2012
@@ -40,7 +40,6 @@ import org.apache.webbeans.container.Bea
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.context.creational.DependentCreationalContext;
-import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -57,8 +56,6 @@ import org.apache.webbeans.util.WebBeans
  */
 public abstract class AbstractInjectable implements Injectable
 {
-    private final WebBeansLogger logger = WebBeansLogger.getLogger(AbstractInjectable.class);
-        
     /** Owner bean of the injection point*/
     protected OwbBean<?> injectionOwnerBean;
     
@@ -110,56 +107,49 @@ public abstract class AbstractInjectable
         {
             EventBean.local.set(injectionPoint);
         }        
-
-        try 
+        
+        //Injection for dependent instance InjectionPoint fields
+        boolean dependentProducer = false;
+        if(WebBeansUtil.isDependent(injectedBean))
         {
-            //Injection for dependent instance InjectionPoint fields
-            boolean dependentProducer = false;
-            if(WebBeansUtil.isDependent(injectedBean))
+            if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
             {
-                if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
-                {
-                    InjectionPointBean.setThreadLocal(injectionPoint);
-                }
-
-                if(!injectionPoint.isTransient())
+                InjectionPointBean.local.set(injectionPoint);   
+            }
+            
+            if(!injectionPoint.isTransient())
+            {
+                if(injectedBean instanceof AbstractProducerBean)
                 {
-                    if(injectedBean instanceof AbstractProducerBean)
+                    if(injectionOwnerBean.isPassivationCapable())
                     {
-                        if(injectionOwnerBean.isPassivationCapable())
-                        {
-                            dependentProducer = true;   
-                        }
+                        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);
 
-
-            // add this dependent into bean dependent list
-            if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+        /*X TODO see spec issue CDI-140 */
+        if(dependentProducer)
+        {
+            if(injected != null && !Serializable.class.isAssignableFrom(injected.getClass()))
             {
-                if(instanceUnderInjection.get() != null)
-                {
-                    ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
-                }
+                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");
             }
         }
+
         
-        finally {
-            InjectionPointBean.unsetThreadLocal();
+        // add this dependent into bean dependent list
+        if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+        {
+            if(instanceUnderInjection.get() != null)
+            {
+                ((CreationalContextImpl<?>) injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean,
injected);
+            }
         }
 
         return injected;

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=1244239&r1=1244238&r2=1244239&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:18:49 2012
@@ -44,7 +44,6 @@ import org.apache.webbeans.container.Bea
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansException;
-import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -61,8 +60,6 @@ public final class OWBInjector implement
     //Serial id
     private static final long serialVersionUID = 1L;
     
-    public static final WebBeansLogger logger = WebBeansLogger.getLogger(OWBInjector.class);
-    
     /**Creational context to hold dependent instances*/
     private CreationalContextImpl<?> ownerCreationalContext = null;
     
@@ -245,13 +242,12 @@ public final class OWBInjector implement
         {
             if(!InjectionPoint.class.isAssignableFrom(ClassUtil.getClass(injectionPoint.getType())))
             {
-                InjectionPointBean.setThreadLocal(injectionPoint);
+                InjectionPointBean.local.set(injectionPoint);   
             }
         }
         
         object = beanManager.getInjectableReference(injectionPoint, ownerCreationalContext);
-        InjectionPointBean.unsetThreadLocal();
-
+        
         return object;
     }
     



Mime
View raw message