openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r934161 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ container/ context/ context/creational/ decorator/ event/ inject/ intercept/ portable/creation/ util/
Date Wed, 14 Apr 2010 19:56:22 GMT
Author: gerdogdu
Date: Wed Apr 14 19:56:22 2010
New Revision: 934161

URL: http://svn.apache.org/viewvc?rev=934161&view=rev
Log:
[OWB-352] Thread Safety Problem in our InterceptorHandlers, aka proxies

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.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/context/creational/DependentCreationalContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java Wed Apr 14 19:56:22 2010
@@ -33,7 +33,6 @@ import org.apache.webbeans.annotation.De
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.inheritance.BeanInheritedMetaData;
 import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.decorator.WebBeansDecorator;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.exception.WebBeansException;
@@ -145,16 +144,6 @@ public abstract class AbstractInjectionT
             }
         }
                         
-        //Push instance into creational context, this is necessary because
-        //Context objects look for instance in the interceptors. If we do not
-        //push instance into cretional context, circular exception occurs.
-        //Context instance first look into creational context object whether
-        //Or not it exist.
-        if(creationalContext instanceof CreationalContextImpl)
-        {
-            CreationalContextImpl<T> cc = (CreationalContextImpl<T>)creationalContext;
-            cc.push(instance);
-        }
         
         //If dependent proxy
         if(isDependentProxy)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java Wed Apr 14 19:56:22 2010
@@ -165,9 +165,9 @@ public abstract class AbstractOwbBean<T>
                     ((AbstractInjectionTargetBean<T>)this).afterConstructor(instance, creationalContext);
                 }
             }
-            
-            //Remove incmplete instance from creational Context
-            ((CreationalContextImpl)creationalContext).remove();
+                        
+            //Remove proxy instance
+            ((CreationalContextImpl)creationalContext).setProxyInstance(null);
             
         }
         catch (Exception re)
@@ -223,13 +223,19 @@ public abstract class AbstractOwbBean<T>
                 destroyInstance(instance,creationalContext);
             }
             
+            //Setting destroying instance
+            CreationalContextImpl.currentRemoveObject.set(instance);
+            
             //Destory dependent instances
             creationalContext.release();                
-                                    
+                                                
         }catch(Exception e)
         {
             logger.fatal(OWBLogConst.FATAL_0001, new Object[]{toString()});
             e.printStackTrace();
+        }finally
+        {
+            CreationalContextImpl.currentRemoveObject.remove();
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java Wed Apr 14 19:56:22 2010
@@ -17,11 +17,21 @@ import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
 
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.context.creational.DependentCreationalContext;
+import org.apache.webbeans.context.creational.DependentCreationalContext.DependentType;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.inject.AbstractInjectable;
 import org.apache.webbeans.inject.InjectableMethods;
 import org.apache.webbeans.util.WebBeansUtil;
 
@@ -149,14 +159,17 @@ public class ProducerMethodBean<T> exten
      * @param creationalContext creational context
      * @return producer method instance
      */
+    @SuppressWarnings("unchecked")
     protected T createDefaultInstance(CreationalContext<T> creationalContext)
     {
         T instance = null;
         Object parentInstance = null;
         CreationalContext<?> parentCreational = null;
         InjectableMethods<T> m = null;
+        List<DependentCreationalContext<Object>> oldDependents = AbstractInjectable.dependentInstanceOfProducerMethods.get();
         try
         {
+            AbstractInjectable.dependentInstanceOfProducerMethods.set(new ArrayList<DependentCreationalContext<Object>>());
             parentCreational = getManager().createCreationalContext(this.ownerComponent);
             
             if (!Modifier.isStatic(creatorMethod.getModifiers()))
@@ -167,6 +180,74 @@ public class ProducerMethodBean<T> exten
             m = new InjectableMethods<T>(creatorMethod, parentInstance, this, creationalContext);
             //Injection of parameters
             instance = m.doInjection();
+            
+            boolean isInjectionToAnotherBean = false;
+            Contextual<?> contextual = null; 
+            if(creationalContext instanceof CreationalContextImpl)
+            {
+                contextual =  ((CreationalContextImpl)creationalContext).getBean();
+                isInjectionToAnotherBean = contextual == this ? false : true;
+            }
+            
+            Object injectionTargetInstance = AbstractInjectable.instanceUnderInjection;
+            if(isInjectionToAnotherBean)
+            {
+                if(oldDependents == null && injectionTargetInstance != null)
+                {
+                    ((CreationalContextImpl)creationalContext).addDependent(injectionTargetInstance, this , instance);
+                }
+                else
+                {
+                    DependentCreationalContext<Object> dependentCreational = new DependentCreationalContext<Object>((Contextual<Object>)this);
+                    dependentCreational.setInstance(instance);
+                    dependentCreational.setDependentType(DependentType.BEAN);
+
+                    oldDependents.add(dependentCreational);                    
+                }                
+            }
+            else
+            {
+                List<DependentCreationalContext<Object>> dependents = AbstractInjectable.dependentInstanceOfProducerMethods.get();
+                if(dependents != null)
+                {
+                    for(DependentCreationalContext<Object> dependent : dependents)
+                    {
+                        ((CreationalContextImpl)creationalContext).addDependent(instance, dependent.getContextual() , dependent.getInstance());
+                    }
+                }
+            }
+            
+            //Adding dependents of producers
+            Map<Bean<?>, Object> dependents = m.getDependentBeanParameters();
+            if(dependents != null)
+            {
+                Set<Bean<?>> beans = dependents.keySet();
+                for(Bean<?> bean : beans)
+                {
+                    if(creationalContext instanceof CreationalContextImpl)
+                    {
+                        if(isInjectionToAnotherBean)
+                        {
+                            if(oldDependents == null && injectionTargetInstance != null)
+                            {
+                                ((CreationalContextImpl)creationalContext).addDependent(injectionTargetInstance, this , instance);
+                            }
+                            else
+                            {
+                                DependentCreationalContext<Object> dependentCreational = new DependentCreationalContext<Object>((Contextual<Object>)bean);
+                                dependentCreational.setInstance(dependents.get(bean));
+                                dependentCreational.setDependentType(DependentType.BEAN);
+                                oldDependents.add(dependentCreational);                                                            
+                            }
+                        }
+                        else
+                        {
+                            ((CreationalContextImpl)creationalContext).addDependent(instance, bean , dependents.get(bean));   
+                        }
+                    }
+                }
+            }
+            
 
         }
         finally
@@ -176,8 +257,14 @@ public class ProducerMethodBean<T> exten
                 destroyBean(getParent(), parentInstance, parentCreational);
             }
             
-            //Remove any dependent objects
-            m.destroyDependentInjectionPoints();
+            if(oldDependents != null)
+            {
+                AbstractInjectable.dependentInstanceOfProducerMethods.set(oldDependents);   
+            }
+            else
+            {
+                AbstractInjectable.dependentInstanceOfProducerMethods.remove();
+            }
         }
 
         return instance;
@@ -206,6 +293,7 @@ public class ProducerMethodBean<T> exten
      * 
      * @param instance bean instance
      */
+    @SuppressWarnings("unchecked")
     protected void disposeDefault(T instance, CreationalContext<T> creationalContext)
     {
         if (disposalMethod != null)
@@ -235,9 +323,22 @@ public class ProducerMethodBean<T> exten
                 {
                     destroyBean(getParent(), parentInstance, parentCreational);
                 }
+
+                //Destroy dependent parameters
+                Map<Bean<?>, Object> dependents = m.getDependentBeanParameters();
+                if(dependents != null)
+                {
+                    Set<Bean<?>> beans = dependents.keySet();
+                    for(Bean<?> bean : beans)
+                    {
+                        Bean<Object> beanTt = (Bean<Object>)bean;
+                        if(creationalContext instanceof CreationalContextImpl)
+                        {
+                            beanTt.destroy(dependents.get(beanTt), (CreationalContext<Object>)creationalContext);
+                        }
+                    }
+                }
                 
-                //Remove any dependent objects
-                m.destroyDependentInjectionPoints();
             }
         }
     }

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=934161&r1=934160&r2=934161&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 Wed Apr 14 19:56:22 2010
@@ -698,44 +698,20 @@ public class BeanManagerImpl implements 
             return null;
         }
         
-        //Owner bean creational context
-        CreationalContextImpl<?> ownerCreationalContextImpl = null;
-        if(!(ownerCreationalContext instanceof CreationalContextImpl))
-        {
-            ownerCreationalContextImpl = (CreationalContextImpl<?>)CreationalContextFactory.getInstance().wrappedCreationalContext(ownerCreationalContext, injectionPoint.getBean());
-        }
-        else
-        {
-            ownerCreationalContextImpl = (CreationalContextImpl<?>)ownerCreationalContext;
-        }
-
         //Find the injection point Bean
         Bean<Object> injectedBean = (Bean<Object>)injectionResolver.getInjectionPointBean(injectionPoint);
-        CreationalContextImpl<Object> injectedCreational = (CreationalContextImpl<Object>)createCreationalContext(injectedBean);
-        
         if(WebBeansUtil.isDependent(injectedBean))
         {        
-            // this must only be added for dependent beans, otherwise we register @NormalScoped beans as dependent!
-            injectedCreational.setOwnerCreational(ownerCreationalContextImpl);
-            
-            //Creating a new creational context for target bean instance
-            instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
-            
-            // add this dependent into bean dependent list
-            if (!WebBeansUtil.isStaticInjection(injectionPoint))
-            {
-                ownerCreationalContextImpl.addDependent(injectedBean, instance, injectedCreational);
-            }
+            //Using owner creational context
+            //Dependents use parent creational context
+            instance = getReference(injectedBean, injectionPoint.getType(), ownerCreationalContext);            
         }
         
         else
-        {   //Look for creational stack
-            instance = WebBeansUtil.getObjectFromCreationalContext(injectedBean, ownerCreationalContextImpl);
-            //No in stack, create new
-            if(instance == null)
-            {
-                instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
-            }
+        {   
+            //New creational context for normal scoped beans
+            CreationalContextImpl<Object> injectedCreational = (CreationalContextImpl<Object>)createCreationalContext(injectedBean);            
+            instance = getReference(injectedBean, injectionPoint.getType(), injectedCreational);
         }
 
         return instance;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContext.java Wed Apr 14 19:56:22 2010
@@ -31,7 +31,6 @@ import javax.enterprise.context.spi.Cont
 import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 
-import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.context.type.ContextTypes;
 import org.apache.webbeans.util.Asserts;
 
@@ -177,17 +176,8 @@ public abstract class AbstractContext im
             }
             
             else
-            {
-                //Check for incomplete instance, putting for circular references
-                if(creationalContext instanceof CreationalContextImpl)
-                {
-                    CreationalContextImpl<?> cc = (CreationalContextImpl<?>)creationalContext;
-                    if(cc.get() != null)
-                    {
-                        instance = (T)cc.get();
-                    }
-                }
-                
+            {                
+                //No instance
                 if(instance == null)
                 {
                     instance = component.create(creationalContext);    

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=934161&r1=934160&r2=934161&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 Wed Apr 14 19:56:22 2010
@@ -34,26 +34,28 @@ import org.apache.webbeans.util.WebBeans
 /** {@inheritDoc} */
 public class CreationalContextImpl<T> implements CreationalContext<T>, Serializable
 {
-    private static final long serialVersionUID = -3416834742959340960L;
+    //Default serial id
+    private static final long serialVersionUID = 1L;
 
-    /**Actual bean instance*/
-    private transient volatile Object incompleteInstance = null;
-    
     /**Bean proxy*/
+    //This will be set to null after instance creations
     private volatile Object proxyInstance = null;
     
     /**Contextual bean dependent instances*/
-    private Map<Object, DependentCreationalContext<?>> dependentObjects = 
-        Collections.synchronizedMap(new WeakHashMap<Object, DependentCreationalContext<?>>());
+    //contextual instance --> dependents
+    private Map<Object, List<DependentCreationalContext<?>>> dependentObjects = 
+        Collections.synchronizedMap(new WeakHashMap<Object, List<DependentCreationalContext<?>>>());
      
-    /**Owner bean*/
+    /**Contextual bean*/
     private volatile Contextual<T> contextual = null;
-    
-    /**Owner creational context*/
-    private volatile CreationalContextImpl<?> ownerCreational = null;
-    
+        
     /**Ejb interceptors*/
-    private ConcurrentMap<Class<?>, EjbInterceptorContext> ejbInterceptors = new ConcurrentHashMap<Class<?>, EjbInterceptorContext>();
+    //contextual instance --> interceptors
+    private ConcurrentMap<Object, List<EjbInterceptorContext>> ejbInterceptors = 
+            new ConcurrentHashMap<Object, List<EjbInterceptorContext>>();
+    
+    /**When bean object is destroyed it is set*/
+    public static ThreadLocal<Object> currentRemoveObject = new ThreadLocal<Object>();
     
     /**
      * Package private
@@ -68,9 +70,24 @@ public class CreationalContextImpl<T> im
      * @param clazz interceptor class
      * @param instance interceptor instance
      */
-    public void addEjbInterceptor(Class<?> clazz, EjbInterceptorContext instance)
+    public void addEjbInterceptor(Object ownerInstance, EjbInterceptorContext instance)
     {
-        this.ejbInterceptors.putIfAbsent(clazz, instance);
+        Asserts.assertNotNull(ownerInstance,"Owner instance parameter can not be null");
+        Asserts.assertNotNull(instance,"Instance parameter can not be null");
+        
+        List<EjbInterceptorContext> list = this.ejbInterceptors.get(ownerInstance);
+        if(list == null)
+        {
+            list = new ArrayList<EjbInterceptorContext>();
+            List<EjbInterceptorContext> oldList = this.ejbInterceptors.putIfAbsent(ownerInstance, list);
+            if(oldList != null)
+            {
+                list = oldList;
+            }
+        }
+        
+        
+        list.add(instance);
     }
     
     /**
@@ -78,9 +95,23 @@ public class CreationalContextImpl<T> im
      * @param clazz interceptor class
      * @return interceptor instance
      */
-    public EjbInterceptorContext getEjbInterceptor(Class<?> clazz)
+    public EjbInterceptorContext getEjbInterceptor(Object ownerInstance,Class<?> clazz)
     {
-        return this.ejbInterceptors.get(clazz);
+        Asserts.assertNotNull(ownerInstance,"Owner instance can not be null");
+        
+        List<EjbInterceptorContext> ejbInterceptors = this.ejbInterceptors.get(ownerInstance);
+        if(ejbInterceptors != null)
+        {
+            for(EjbInterceptorContext ejbInterceptor : ejbInterceptors)
+            {
+                if(ejbInterceptor.getInterceptorClass() == clazz)
+                {
+                    return ejbInterceptor;
+                }
+            }            
+        }
+        
+        return null;
     }
     
     
@@ -91,11 +122,7 @@ public class CreationalContextImpl<T> im
      */
     public void push(T incompleteInstance)
     {
-        if(this.incompleteInstance != null)
-        {
-            this.incompleteInstance = incompleteInstance;   
-        }
-        
+        //No-action
     }
     
     /**
@@ -104,7 +131,7 @@ public class CreationalContextImpl<T> im
      */
     public void setProxyInstance(Object proxyInstance)
     {
-        if(this.proxyInstance != null)
+        if(this.proxyInstance == null)
         {
             this.proxyInstance = proxyInstance;   
         }
@@ -125,13 +152,16 @@ public class CreationalContextImpl<T> im
      * @param dependent dependent contextual
      * @param instance dependent instance
      */
-    public <K> void addDependent(Contextual<K> dependent, Object instance, CreationalContext<K> cc)
+    public <K> void addDependent(Object ownerInstance, Contextual<K> dependent, Object instance)
     {
+        Asserts.assertNotNull(dependent,"ownerInstance parameter cannot be null");
         Asserts.assertNotNull(dependent,"dependent parameter cannot be null");
+        Asserts.assertNotNull(dependent,"instance parameter cannot be null");
+        Asserts.assertNotNull(dependent,"cc parameter cannot be null");
         
         if(instance != null)
         {
-           DependentCreationalContext<K> dependentCreational = new DependentCreationalContext<K>(cc,dependent);
+           DependentCreationalContext<K> dependentCreational = new DependentCreationalContext<K>(dependent);
            if(dependent instanceof Interceptor)
            {
                dependentCreational.setDependentType(DependentType.INTERCEPTOR);
@@ -146,7 +176,14 @@ public class CreationalContextImpl<T> im
            }
            
            dependentCreational.setInstance(instance);
-           this.dependentObjects.put(instance, dependentCreational);   
+           List<DependentCreationalContext<?>> dependentList = this.dependentObjects.get(ownerInstance);
+           if(dependentList == null)
+           {
+               dependentList = new ArrayList<DependentCreationalContext<?>>();
+               this.dependentObjects.put(ownerInstance, dependentList);
+           }
+           
+           dependentList.add(dependentCreational);   
         }
     }
     
@@ -155,15 +192,20 @@ public class CreationalContextImpl<T> im
      * @param interceptor interceptor bean
      * @return bean interceptor instance
      */
-    public Object getDependentInterceptor(Contextual<?> interceptor)
+    public Object getDependentInterceptor(Object ownerInstance, Contextual<?> interceptor)
     {
-        List<DependentCreationalContext<?>> dcs = getDependentInterceptors();
-        for(DependentCreationalContext<?> dc : dcs)
+        Asserts.assertNotNull(interceptor,"Interceptor parameter can not be null");
+        
+        if(ownerInstance != null)
         {
-            if(dc.getContextual().equals(interceptor))
+            List<DependentCreationalContext<?>> dcs = getDependentInterceptors(ownerInstance);
+            for(DependentCreationalContext<?> dc : dcs)
             {
-                return dc.getInstance();
-            }
+                if(dc.getContextual().equals(interceptor))
+                {
+                    return dc.getInstance();
+                }
+            }            
         }
         
         return null;
@@ -176,6 +218,7 @@ public class CreationalContextImpl<T> im
      */
     public Object getDependentDecorator(Contextual<?> decorator)
     {
+        Asserts.assertNotNull(decorator, "Decorator parameter can not be null");
         List<DependentCreationalContext<?>> dcs = getDependentDecorators();
         for(DependentCreationalContext<?> dc : dcs)
         {
@@ -192,21 +235,25 @@ public class CreationalContextImpl<T> im
      * Gets list of dependent interceptors context.
      * @return list of dependent interceptors context
      */
-    private List<DependentCreationalContext<?>> getDependentInterceptors()
+    private List<DependentCreationalContext<?>> getDependentInterceptors(Object ownerInstance)
     {
         List<DependentCreationalContext<?>> list = new ArrayList<DependentCreationalContext<?>>();
-        Collection<DependentCreationalContext<?>> values = this.dependentObjects.values();
-        if(values != null && values.size() > 0)
+        
+        if(ownerInstance != null)
         {
-            Iterator<DependentCreationalContext<?>> it = values.iterator();
-            while(it.hasNext())
+            List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
+            if(values != null && values.size() > 0)
             {
-                DependentCreationalContext<?> dc = it.next();
-                if(dc.getDependentType().equals(DependentType.INTERCEPTOR))
+                Iterator<DependentCreationalContext<?>> it = values.iterator();
+                while(it.hasNext())
                 {
-                    list.add(dc);
+                    DependentCreationalContext<?> dc = it.next();
+                    if(dc.getDependentType().equals(DependentType.INTERCEPTOR))
+                    {
+                        list.add(dc);
+                    }
                 }
-            }
+            }            
         }
         
         return list;
@@ -219,7 +266,7 @@ public class CreationalContextImpl<T> im
     private List<DependentCreationalContext<?>> getDependentDecorators()
     {
         List<DependentCreationalContext<?>> list = new ArrayList<DependentCreationalContext<?>>();
-        Collection<DependentCreationalContext<?>> values = this.dependentObjects.values();
+        List<DependentCreationalContext<?>> values = new ArrayList<DependentCreationalContext<?>>();
         if(values != null && values.size() > 0)
         {
             Iterator<DependentCreationalContext<?>> it = values.iterator();
@@ -237,43 +284,30 @@ public class CreationalContextImpl<T> im
     }
     
     /**
-     * Returns incomplete instance.
-     * 
-     * @return incomplete instance
-     */
-    public Object get()
-    {
-        return this.incompleteInstance;
-    }
-    
-    
-    /**
-     * Removes from creational context.
-     */
-    public void  remove()
-    {
-        this.incompleteInstance = null;
-    }
-    
-    /**
      * Removes dependent objects.
      */
     @SuppressWarnings("unchecked")
-    public void  removeDependents()
+    public void  removeDependents(Object ownerInstance)
     {
-        Collection<?> values = this.dependentObjects.keySet();
-        Iterator<?> iterator = values.iterator();
-        
-        while(iterator.hasNext())
+        if(ownerInstance == null)
         {
-            T instance = (T)iterator.next();
-            DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)this.dependentObjects.get(instance);
-            dependent.getContextual().destroy(instance, dependent.getCreationalContext());
+            return;
         }
         
-        this.dependentObjects.clear();
+        List<DependentCreationalContext<?>> values = this.dependentObjects.get(ownerInstance);
+        if(values != null)
+        {
+            Iterator<?> iterator = values.iterator();        
+            while(iterator.hasNext())
+            {
+                DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)iterator.next();
+                dependent.getContextual().destroy((T)dependent.getInstance(), CreationalContextFactory.getInstance().getCreationalContext(dependent.getContextual()));
+            }
+
+            this.dependentObjects.remove(ownerInstance);                        
+        }
         
-        Collection<EjbInterceptorContext> interceptors = this.ejbInterceptors.values();
+        List<EjbInterceptorContext> interceptors = this.ejbInterceptors.get(ownerInstance);
         if(interceptors != null)
         {
             for(EjbInterceptorContext intereptor : interceptors)
@@ -282,7 +316,48 @@ public class CreationalContextImpl<T> im
             }
         }
         
+        this.ejbInterceptors.remove(ownerInstance);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public void removeAllDependents()
+    {
+        Collection<List<DependentCreationalContext<?>>> values = this.dependentObjects.values();
+        if(values != null)
+        {
+            for(List<DependentCreationalContext<?>> value : values)
+            {
+                if(values != null)
+                {
+                    Iterator<?> iterator = value.iterator();        
+                    while(iterator.hasNext())
+                    {
+                        DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)iterator.next();
+                        dependent.getContextual().destroy((T)dependent.getInstance(), CreationalContextFactory.getInstance().getCreationalContext(dependent.getContextual()));
+                    }                        
+                }                
+            }
+        }
+        
+        this.dependentObjects.clear();
+        
+        Collection<List<EjbInterceptorContext>> interceptorValues = this.ejbInterceptors.values();
+        if(interceptorValues != null)
+        {
+            for(List<EjbInterceptorContext> interceptors : interceptorValues)
+            {
+                if(interceptors != null)
+                {
+                    for(EjbInterceptorContext intereptor : interceptors)
+                    {
+                        intereptor.getInjectorInstance().destroy();
+                    }
+                }                
+            }
+        }
+        
         this.ejbInterceptors.clear();
+        
     }
     
     /**
@@ -291,8 +366,14 @@ public class CreationalContextImpl<T> im
     @Override
     public void release()
     {
-        removeDependents();
-        this.incompleteInstance = null;
+        if(currentRemoveObject.get() == null)
+        {
+            removeAllDependents();
+        }
+        else
+        {
+            removeDependents(currentRemoveObject.get());   
+        }
     }
     
     /**
@@ -306,36 +387,14 @@ public class CreationalContextImpl<T> im
 
 
     /**
-     * @return the ownerCreational
-     */
-    public CreationalContextImpl<?> getOwnerCreational()
-    {
-        return ownerCreational;
-    }
-
-
-    /**
-     * @param ownerCreational the ownerCreational to set
-     */
-    public void setOwnerCreational(CreationalContextImpl<?> ownerCreational)
-    {
-        if(this.ownerCreational != null)
-        {
-            this.ownerCreational = ownerCreational;   
-        }
-    }
-
-    /**
      * Write Object. 
      */
     private synchronized void writeObject(ObjectOutputStream s)
     throws IOException
     {
-        s.writeObject(proxyInstance);
-
         // we have to remap into a standard HashMap because WeakHashMap is not serializable
-        HashMap<Object, DependentCreationalContext<?>> depo
-                = new HashMap<Object, DependentCreationalContext<?>>(dependentObjects);
+        HashMap<Object, List<DependentCreationalContext<?>>> depo
+                = new HashMap<Object, List<DependentCreationalContext<?>>>(dependentObjects);
         s.writeObject(depo);
 
         String id = null;
@@ -347,7 +406,6 @@ public class CreationalContextImpl<T> im
         {
             s.writeObject(null);
         }
-        s.writeObject(ownerCreational);
         s.writeObject(ejbInterceptors);
     }
 
@@ -359,18 +417,16 @@ public class CreationalContextImpl<T> im
     private synchronized void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException
     {
-        proxyInstance = s.readObject();
-
-        HashMap<Object, DependentCreationalContext<?>> depo = (HashMap<Object, DependentCreationalContext<?>>)s.readObject();
-        dependentObjects = new WeakHashMap<Object, DependentCreationalContext<?>>(depo);
+        HashMap<Object, List<DependentCreationalContext<?>>> depo = (HashMap<Object, List<DependentCreationalContext<?>>>)s.readObject();
+        dependentObjects = new WeakHashMap<Object, List<DependentCreationalContext<?>>>(depo);
 
         String id = (String) s.readObject();
         if (id != null)
         {
             contextual = (Contextual<T>) BeanManagerImpl.getManager().getPassivationCapableBean(id);
         }
-        ownerCreational = (CreationalContextImpl<?>) s.readObject();
-        ejbInterceptors = (ConcurrentMap<Class<?>, EjbInterceptorContext>) s.readObject();
+                
+        ejbInterceptors = (ConcurrentMap<Object, List<EjbInterceptorContext>>) s.readObject();
     }
 
 }
\ No newline at end of file

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/DependentCreationalContext.java Wed Apr 14 19:56:22 2010
@@ -23,17 +23,14 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
 import javax.enterprise.context.spi.Contextual;
-import javax.enterprise.context.spi.CreationalContext;
 
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.util.WebBeansUtil;
 
-class DependentCreationalContext<S> implements Serializable
+public class DependentCreationalContext<S> implements Serializable
 {
     private static final long serialVersionUID = 1L;
 
-    private CreationalContext<S> creationalContext;
-    
     private Contextual<S> contextual;
     
     private DependentType dependentType;
@@ -65,10 +62,9 @@ class DependentCreationalContext<S> impl
         BEAN
     }
     
-    public DependentCreationalContext(CreationalContext<S> cc, Contextual<S> contextual)
+    public DependentCreationalContext(Contextual<S> contextual)
     {
         this.contextual = contextual;
-        this.creationalContext = cc;
     }
     
     
@@ -91,22 +87,6 @@ class DependentCreationalContext<S> impl
     }
 
     /**
-     * @return the creationalContext
-     */
-    public CreationalContext<S> getCreationalContext()
-    {
-        return creationalContext;
-    }
-
-    /**
-     * @param creationalContext the creationalContext to set
-     */
-    public void setCreationalContext(CreationalContext<S> creationalContext)
-    {
-        this.creationalContext = creationalContext;
-    }
-
-    /**
      * @return the contextual
      */
     public Contextual<S> getContextual()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/EjbInterceptorContext.java Wed Apr 14 19:56:22 2010
@@ -30,10 +30,33 @@ public class EjbInterceptorContext imple
     
     private OWBInjector injectorInstance;
     
+    private Class<?> interceptorClass;
+    
     public EjbInterceptorContext()
     {
         
     }
+    
+    
+
+    /**
+     * @return the interceptorClass
+     */
+    public Class<?> getInterceptorClass()
+    {
+        return interceptorClass;
+    }
+
+
+    /**
+     * @param interceptorClass the interceptorClass to set
+     */
+    public void setInterceptorClass(Class<?> interceptorClass)
+    {
+        this.interceptorClass = interceptorClass;
+    }
+
+
 
     /**
      * @return the interceptorInstance

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecoratorConfig.java Wed Apr 14 19:56:22 2010
@@ -102,7 +102,7 @@ public final class WebBeansDecoratorConf
                 
                 if (ownerCreationalContext != null)
                 {
-                    ownerCreationalContext.addDependent(decorator, decoratorInstance, creationalContext);
+                    ownerCreationalContext.addDependent(instance, decorator, decoratorInstance);
                 }                
             }
             

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Wed Apr 14 19:56:22 2010
@@ -411,10 +411,18 @@ public final class NotificationManager
             try
             {
                 TransactionPhase phase = observer.getTransactionPhase();
-                TransactionService transactionService = ServiceLoader.getService(TransactionService.class);
-                if(transactionService != null)
+                
+                if(phase != null && !phase.equals(TransactionPhase.IN_PROGRESS))
                 {
-                    transactionService.registerTransactionSynchronization(phase, observer, event);
+                    TransactionService transactionService = ServiceLoader.getService(TransactionService.class);
+                    if(transactionService != null)
+                    {
+                        transactionService.registerTransactionSynchronization(phase, observer, event);
+                    }
+                    else
+                    {
+                        observer.notify(event);
+                    }                    
                 }
                 else
                 {

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=934161&r1=934160&r2=934161&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 Wed Apr 14 19:56:22 2010
@@ -33,6 +33,8 @@ import org.apache.webbeans.component.Ins
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.container.BeanManagerImpl;
 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;
@@ -60,6 +62,11 @@ public abstract class AbstractInjectable
     
     /**Field, method or constructor injection*/
     protected Member injectionMember;
+    
+    public static ThreadLocal<Object> instanceUnderInjection = new ThreadLocal<Object>();
+    
+    public static ThreadLocal<List<DependentCreationalContext<Object>>> dependentInstanceOfProducerMethods = 
+        new ThreadLocal<List<DependentCreationalContext<Object>>>();
 
     /**
      * Creates a new injectable.
@@ -81,9 +88,11 @@ public abstract class AbstractInjectable
     public <T> Object inject(InjectionPoint injectionPoint)
     {
         logger.debug("Injected into bean : " + this.injectionOwnerBean.toString() + " with injection point : " + injectionPoint);
-        Object injected = null;
-        Bean<?> injectedBean = (Bean<?>)InjectionResolver.getInstance().getInjectionPointBean(injectionPoint);        
-        
+
+        Object injected = null;               
+
+        //Injected contextual beam
+        Bean<?> injectedBean = (Bean<?>)InjectionResolver.getInstance().getInjectionPointBean(injectionPoint);                
         if(isInstanceProviderInjection(injectionPoint))
         {
             InstanceBean.local.set(injectionPoint);
@@ -115,6 +124,7 @@ public abstract class AbstractInjectable
             }
         }        
         
+        //Gets injectable reference for injected bean
         injected = BeanManagerImpl.getManager().getInjectableReference(injectionPoint, this.injectionOwnerCreationalContext);
         
         if(dependentProducer)
@@ -122,11 +132,19 @@ public abstract class AbstractInjectable
             if(!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");
+                                                        "into an injection point "+ injectionPoint +" that requires a passivation capable dependency");
             }
         }
         
-
+        // add this dependent into bean dependent list
+        if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
+        {
+            if(instanceUnderInjection.get() != null)
+            {
+                ((CreationalContextImpl<?>)this.injectionOwnerCreationalContext).addDependent(instanceUnderInjection.get(),injectedBean, injected);   
+            }   
+        }
+            
         return injected;
     }
     

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/InjectableMethods.java Wed Apr 14 19:56:22 2010
@@ -15,8 +15,11 @@ package org.apache.webbeans.inject;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.spi.AnnotatedParameter;
@@ -28,6 +31,7 @@ import org.apache.webbeans.annotation.De
 import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.component.ProducerMethodBean;
 import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.exception.WebBeansException;
 
@@ -46,6 +50,7 @@ public class InjectableMethods<T> extend
     /**Used in dispose method, represents produces method parameter instance*/
     private Object producerMethodInstance = null;
     
+    private Map<Bean<?>,Object> dependentParameters = new HashMap<Bean<?>, Object>();
 
     /**
      * Constructs new instance.
@@ -74,7 +79,7 @@ public class InjectableMethods<T> extend
         for(int i=0;i<injectedPoints.size();i++)
         {
             for(InjectionPoint point : injectedPoints)
-            {
+            {                
                 AnnotatedParameter<?> parameter = (AnnotatedParameter<?>)point.getAnnotated();
                 if(parameter.getPosition() == i)
                 {
@@ -87,6 +92,7 @@ public class InjectableMethods<T> extend
                             Bean<?> injectionPointBean = manager.getBeans(InjectionPoint.class, new DefaultLiteral()).iterator().next();
                             Object reference = manager.getReference(injectionPointBean, InjectionPoint.class, manager.createCreationalContext(injectionPointBean));
                             
+                            this.dependentParameters.put(injectionPointBean, reference);
                             list.add(reference);
                             
                             injectionPoint = true;
@@ -102,7 +108,14 @@ public class InjectableMethods<T> extend
                         }
                         else
                         {
-                            list.add(inject(point));    
+                            Object instance = inject(point);
+                            Bean<?> injectedBean = (Bean<?>)InjectionResolver.getInstance().getInjectionPointBean(point);
+                            if(injectedBean.getScope() == Dependent.class)
+                            {
+                                this.dependentParameters.put(injectedBean, instance);
+                            }
+
+                            list.add(instance);    
                         }                        
                     }
                                         
@@ -130,10 +143,15 @@ public class InjectableMethods<T> extend
     /**
      * Destroy dependent objects of the bean.
      */
-    public void destroyDependentInjectionPoints()
+    public void destroyDependentInjectionPoints(Object ownerInstance)
     {
         CreationalContextImpl<?> ownerCreational = (CreationalContextImpl<?>) this.injectionOwnerCreationalContext;
-        ownerCreational.removeDependents();
+        ownerCreational.removeDependents(ownerInstance);
+    }
+    
+    public Map<Bean<?>,Object> getDependentBeanParameters()
+    {
+        return this.dependentParameters;
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorData.java Wed Apr 14 19:56:22 2010
@@ -164,7 +164,7 @@ public interface InterceptorData
      * Creates and returns a new interceptor instance.
      * @return creates a new interceptor instance
      */
-    public Object createNewInstance(CreationalContextImpl<?> ownerBean);
+    public Object createNewInstance(Object ownerInstance,CreationalContextImpl<?> ownerBean);
     
     /**
      * if this interceptor data is defined by interceptor,

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorDataImpl.java Wed Apr 14 19:56:22 2010
@@ -292,7 +292,7 @@ public class InterceptorDataImpl impleme
     
     @Override
     @SuppressWarnings("unchecked")
-    public Object createNewInstance(CreationalContextImpl<?> ownerCreationalContext)
+    public Object createNewInstance(Object ownerInstance,CreationalContextImpl<?> ownerCreationalContext)
     {
         //check for this InterceptorData is defined by interceptor class
         if(this.isDefinedWithWebBeansInterceptor && this.definedInInterceptorClass)
@@ -305,7 +305,7 @@ public class InterceptorDataImpl impleme
                 return this.decoratorInterceptor; 
             }
             
-            interceptor = ownerCreationalContext.getDependentInterceptor(this.webBeansInterceptor);
+            interceptor = ownerCreationalContext.getDependentInterceptor(ownerInstance,this.webBeansInterceptor);
             //There is no define interceptor, define and add it into dependent
             if(interceptor == null)
             {
@@ -317,7 +317,7 @@ public class InterceptorDataImpl impleme
                 
                 actualInterceptor.setInjections(interceptor, creationalContext);
 
-                ownerCreationalContext.addDependent((WebBeansInterceptor<Object>)this.webBeansInterceptor, interceptor, creationalContext);
+                ownerCreationalContext.addDependent(ownerInstance, (WebBeansInterceptor<Object>)this.webBeansInterceptor, interceptor);
             }
             
             return interceptor;
@@ -328,7 +328,7 @@ public class InterceptorDataImpl impleme
         //control for this InterceptorData is defined by interceptor class
         if(this.definedInInterceptorClass)
         {
-            ctx = ownerCreationalContext.getEjbInterceptor(this.interceptorClass);                
+            ctx = ownerCreationalContext.getEjbInterceptor(ownerInstance, this.interceptorClass);                
             if(ctx == null)
             {                    
                 interceptor = WebBeansUtil.newInstanceForced(this.interceptorClass);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InvocationContextImpl.java Wed Apr 14 19:56:22 2010
@@ -200,7 +200,7 @@ public class InvocationContextImpl imple
                 method.setAccessible(true);
             }
             
-            Object t = intc.createNewInstance((CreationalContextImpl<?>)this.creationalContext);
+            Object t = intc.createNewInstance(this.target,(CreationalContextImpl<?>)this.creationalContext);
             
             if (t == null)
             {
@@ -272,7 +272,7 @@ public class InvocationContextImpl imple
 
             currentMethod++;
 
-            Object t = intc.createNewInstance((CreationalContextImpl<?>)this.creationalContext);
+            Object t = intc.createNewInstance(this.target,(CreationalContextImpl<?>)this.creationalContext);
             
             //In bean class
             if (t == null)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/InjectionTargetProducer.java Wed Apr 14 19:56:22 2010
@@ -13,6 +13,7 @@
  */
 package org.apache.webbeans.portable.creation;
 
+import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.InjectionTarget;
 
@@ -20,6 +21,7 @@ import org.apache.webbeans.component.Ent
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.inject.AbstractInjectable;
 
 /**
  * InjectionTargetProducer implementation.
@@ -51,16 +53,45 @@ public class InjectionTargetProducer<T> 
             ctx = CreationalContextFactory.getInstance().wrappedCreationalContext(ctx, this.bean);
         }
         
-        InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);
-        
-        if(!(bean instanceof EnterpriseBeanMarker))
+        Object oldInstanceUnderInjection = AbstractInjectable.instanceUnderInjection.get();
+        boolean isInjectionToAnotherBean = false;
+        try
+        {
+            Contextual<?> contextual = null;
+            if(ctx instanceof CreationalContextImpl)
+            {
+                contextual = ((CreationalContextImpl)ctx).getBean();
+                isInjectionToAnotherBean = contextual == getBean(InjectionTargetBean.class) ? false : true;
+            }
+            
+            if(!isInjectionToAnotherBean)
+            {
+                AbstractInjectable.instanceUnderInjection.set(instance);   
+            }
+                        
+            InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class);
+            
+            if(!(bean instanceof EnterpriseBeanMarker))
+            {
+                bean.injectResources(instance, ctx);
+                bean.injectSuperFields(instance, ctx);
+                bean.injectSuperMethods(instance, ctx);
+                bean.injectFields(instance, ctx);
+                bean.injectMethods(instance, ctx);            
+            }                    
+        }
+        finally
         {
-            bean.injectResources(instance, ctx);
-            bean.injectSuperFields(instance, ctx);
-            bean.injectSuperMethods(instance, ctx);
-            bean.injectFields(instance, ctx);
-            bean.injectMethods(instance, ctx);            
-        }        
+            if(oldInstanceUnderInjection != null)
+            {
+                AbstractInjectable.instanceUnderInjection.set(oldInstanceUnderInjection);   
+            }
+            else
+            {
+                AbstractInjectable.instanceUnderInjection.remove();
+            }
+        }
+        
     }
     
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=934161&r1=934160&r2=934161&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Wed Apr 14 19:56:22 2010
@@ -126,7 +126,6 @@ import org.apache.webbeans.config.OWBLog
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.ExternalScope;
 import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.decorator.DecoratorUtil;
 import org.apache.webbeans.decorator.DecoratorsManager;
@@ -2563,28 +2562,7 @@ public final class WebBeansUtil
         {
             producer.setEnabled(parent.isEnabled());
         }
-    }
-    
-    public static Object getObjectFromCreationalContext(Bean<?> bean,CreationalContextImpl<?> cc)
-    {
-        if(cc == null)
-        {
-            throw new IllegalArgumentException("Creational context is null");
-        }
-        
-        final Contextual<?> existing = cc.getBean();
-        if(existing != null && existing.equals(bean))
-        {
-            return cc.getProxyInstance();
-        }
-
-        if(cc.getOwnerCreational() != null)
-        {
-            return getObjectFromCreationalContext(bean, cc.getOwnerCreational());
-        }
-        
-        return null;
-    }
+    }    
     
     public static boolean isExtensionEventType(Class<?> clazz)
     {



Mime
View raw message