openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1436225 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/context/creational/ main/java/org/apache/webbeans/inject/ main/java/org/apache/webbeans/inject/instance/ main/java/o...
Date Mon, 21 Jan 2013 08:39:48 GMT
Author: arne
Date: Mon Jan 21 08:39:47 2013
New Revision: 1436225

URL: http://svn.apache.org/viewvc?rev=1436225&view=rev
Log:
OWB-344: Fixed handling of creational contexts for dependent objects

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.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/inject/AbstractInjectable.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java

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=1436225&r1=1436224&r2=1436225&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
Mon Jan 21 08:39:47 2013
@@ -172,6 +172,10 @@ public abstract class AbstractOwbBean<T>
                 injectionTarget.inject(instance, creationalContext);
                 injectionTarget.postConstruct(instance);
             }
+            if (getScope().equals(Dependent.class))
+            {
+                ((CreationalContextImpl<T>)creationalContext).addDependent(this, instance);
+            }
             return instance;
         }
         catch (Exception re)
@@ -205,6 +209,14 @@ public abstract class AbstractOwbBean<T>
      */
     public void destroy(T instance, CreationalContext<T> creationalContext)
     {
+        if (getScope().equals(Dependent.class)
+            && creationalContext instanceof CreationalContextImpl
+            && ((CreationalContextImpl<T>)creationalContext).containsDependent(this,
instance))
+        {
+            // we just have to call release, because release will destroy us since we are
@Dependent
+            creationalContext.release();
+            return;
+        }
         try
         {
             if (producer instanceof InjectionTarget)

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=1436225&r1=1436224&r2=1436225&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
Mon Jan 21 08:39:47 2013
@@ -129,7 +129,24 @@ public class CreationalContextImpl<T> im
         }
     }
 
-
+    public boolean containsDependent(Contextual<?> contextual, Object instance)
+    {
+        if (dependentObjects == null)
+        {
+            return false;
+        }
+        synchronized (this)
+        {
+            for (DependentCreationalContext<?> dependentCreationalContext: dependentObjects)
+            {
+                if (dependentCreationalContext.getContextual().equals(contextual) &&
dependentCreationalContext.getInstance() == instance)
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
 
     @SuppressWarnings("unchecked")
     public void removeAllDependents()
@@ -152,9 +169,8 @@ public class CreationalContextImpl<T> im
                     // we don't use an iterator because the destroyal might register a 
                     // fresh PreDestroy interceptor as dependent object...
                     DependentCreationalContext<T> dependent = (DependentCreationalContext<T>)
dependentObjects.get(0);
-                    dependent.getContextual().destroy((T) dependent.getInstance(), this);
-                    
                     dependentObjects.remove(0);
+                    dependent.getContextual().destroy((T) dependent.getInstance(), this);
                     maxRemoval--;
                 }
                     

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=1436225&r1=1436224&r2=1436225&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
Mon Jan 21 08:39:47 2013
@@ -134,12 +134,6 @@ public abstract class AbstractInjectable
                                                     "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))
-            {
-                creationalContext.addDependent(injectedBean, injected);
-            }
         } 
         finally
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java?rev=1436225&r1=1436224&r2=1436225&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/instance/InstanceImpl.java
Mon Jan 21 08:39:47 2013
@@ -37,7 +37,6 @@ import javax.enterprise.util.TypeLiteral
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.context.creational.CreationalContextImpl;
 import org.apache.webbeans.portable.InjectionPointProducer;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.InjectionExceptionUtil;
@@ -131,11 +130,6 @@ public class InstanceImpl<T> implements 
             }
 
             instance = (T) beanManager.getReference(bean, null, creationalContext);
-
-            if (isDependentBean && creationalContext instanceof CreationalContextImpl)
-            {
-                ((CreationalContextImpl<?>) creationalContext).addDependent(bean, instance);
-            }
         }
         finally
         {
@@ -245,7 +239,7 @@ public class InstanceImpl<T> implements 
         
         Annotation[] newQualifiers = getAdditionalQualifiers(qualifiers);
         
-        InstanceImpl<U> newInstance = new InstanceImpl(sub, injectionPoint, webBeansContext,
parentCreationalContext, newQualifiers);
+        InstanceImpl<U> newInstance = new InstanceImpl<U>(sub, injectionPoint,
webBeansContext, parentCreationalContext, newQualifiers);
                     
         return newInstance;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java?rev=1436225&r1=1436224&r2=1436225&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionPointProducer.java
Mon Jan 21 08:39:47 2013
@@ -65,7 +65,10 @@ public class InjectionPointProducer exte
     public static void unsetThreadLocal()
     {
         Stack<InjectionPoint> stackIP = getStackOfInjectionPoints();
-        stackIP.pop();
+        if (!stackIP.isEmpty())
+        {
+            stackIP.pop();
+        }
     }
     
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java?rev=1436225&r1=1436224&r2=1436225&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InjectionTargetImpl.java
Mon Jan 21 08:39:47 2013
@@ -195,13 +195,12 @@ public class InjectionTargetImpl<T> exte
             {
                 List<Decorator<?>> decorators = interceptorInfo.getDecorators();
                 Map<Decorator<?>, Object> instances = new HashMap<Decorator<?>,
Object>();
+                CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)creationalContext;
                 for (int i = decorators.size(); i > 0; i--)
                 {
                     Decorator<?> decorator = decorators.get(i - 1);
-                    CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)creationalContext;
                     creationalContextImpl.putDelegate(delegate);
                     Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
-                    creationalContextImpl.addDependent(decorator, decoratorInstance);
                     instances.put(decorator, decoratorInstance);
                     delegate = pf.createProxyInstance(proxyClass, instance, new DecoratorHandler(interceptorInfo,
instances, i - 1, instance));
                 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java?rev=1436225&r1=1436224&r2=1436225&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/ProducerMethodProducer.java
Mon Jan 21 08:39:47 2013
@@ -18,11 +18,8 @@
  */
 package org.apache.webbeans.portable;
 
-import java.lang.reflect.Modifier;
-import java.util.Map;
 import java.util.Set;
 
-import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.Bean;
@@ -63,9 +60,30 @@ public class ProducerMethodProducer<T, P
     @Override
     public T produce(CreationalContext<T> creationalContext)
     {
-        CreationalContextImpl<T> context = (CreationalContextImpl<T>)creationalContext;
-        P ownerInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner, owner.getBeanClass(),
creationalContext);
-        return new InjectableMethod<T>(producerMethod.getJavaMember(), ownerInstance,
this, context).doInjection();
+        P parentInstance = null;
+        CreationalContext<P> parentCreationalContext = null;
+        InjectableMethod<T> m = null;
+        try
+        {
+            parentCreationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(owner);
+
+            if (!producerMethod.isStatic())
+            {
+                parentInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner,
owner.getBeanClass(), parentCreationalContext);
+            }
+            
+            m = new InjectableMethod<T>(producerMethod.getJavaMember(), parentInstance,
this, (CreationalContextImpl<T>) parentCreationalContext);
+            
+            return m.doInjection();
+
+        }
+        finally
+        {
+            if (parentCreationalContext != null)
+            {
+                parentCreationalContext.release();
+            }
+        }
     }
 
     @Override
@@ -74,18 +92,18 @@ public class ProducerMethodProducer<T, P
         if (disposalMethod != null)
         {
             P parentInstance = null;
-            CreationalContext<P> parentCreational = null;
+            CreationalContext<P> parentCreationalContext = null;
             InjectableMethod<T> m = null;
             try
             {
-                parentCreational = webBeansContext.getBeanManagerImpl().createCreationalContext(owner);
+                parentCreationalContext = webBeansContext.getBeanManagerImpl().createCreationalContext(owner);
                 
-                if (!Modifier.isStatic(disposalMethod.getJavaMember().getModifiers()))
+                if (!disposalMethod.isStatic())
                 {
-                    parentInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner,
owner.getBeanClass(), parentCreational);
+                    parentInstance = (P)webBeansContext.getBeanManagerImpl().getReference(owner,
owner.getBeanClass(), parentCreationalContext);
                 }
 
-                m = new InjectableMethod<T>(disposalMethod.getJavaMember(), parentInstance,
this, (CreationalContextImpl<T>) parentCreational);
+                m = new InjectableMethod<T>(disposalMethod.getJavaMember(), parentInstance,
this, (CreationalContextImpl<T>) parentCreationalContext);
                 m.setDisposable(true);
                 m.setProducerMethodInstance(instance);
 
@@ -94,22 +112,7 @@ public class ProducerMethodProducer<T, P
             }
             finally
             {
-                if (owner.getScope().equals(Dependent.class))
-                {
-                    owner.destroy(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;
-                        beanTt.destroy(dependents.get(beanTt), (CreationalContext<Object>)
parentCreational);
-                    }
-                }
+                parentCreationalContext.release();
             }
         }
     }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java?rev=1436225&r1=1436224&r2=1436225&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeOnProducerFieldTest.java
Mon Jan 21 08:39:47 2013
@@ -37,11 +37,6 @@ public class AlternativeOnProducerFieldT
 {
    private static final String PACKAGE_NAME = AlternativeOnProducerFieldTest.class.getPackage().getName();

     
-    public AlternativeOnProducerFieldTest()
-    {
-        
-    }
-    
     @Test
     public void testProducerFieldAlternativeNotEnabled()
     {



Mime
View raw message