openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1435526 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ component/creation/ context/creational/ inject/ inject/instance/ intercept/ portable/
Date Sat, 19 Jan 2013 12:07:07 GMT
Author: arne
Date: Sat Jan 19 12:07:06 2013
New Revision: 1435526

URL: http://svn.apache.org/viewvc?rev=1435526&view=rev
Log:
OWB-344: Fixed lifecycle method-calls for dependent instances that where created via BeanManager#getReference

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/LifecycleMethodBuilder.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.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/intercept/WebBeansInterceptorConfig.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/InstanceProducer.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=1435526&r1=1435525&r2=1435526&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
Sat Jan 19 12:07:06 2013
@@ -164,10 +164,6 @@ public abstract class AbstractOwbBean<T>
                 injectionTarget.inject(instance, creationalContext);
                 injectionTarget.postConstruct(instance);
             }
-            if (getScope().equals(Dependent.class))
-            {
-                ((CreationalContextImpl<T>)creationalContext).addDependent(null, this,
instance);
-            }
             return instance;
         }
         catch (Exception re)
@@ -209,7 +205,7 @@ public abstract class AbstractOwbBean<T>
                 injectionTarget.preDestroy(instance);
             }
             producer.dispose(instance);
-            //Destory dependent instances
+            //Destroy dependent instances
             creationalContext.release();
         }
         catch(Exception e)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java?rev=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
Sat Jan 19 12:07:06 2013
@@ -27,10 +27,13 @@ import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.event.Observes;
 import javax.enterprise.event.Reception;
@@ -736,12 +739,52 @@ public abstract class AbstractInjectionT
 
     protected List<AnnotatedMethod<?>> getPostConstructMethods()
     {
-        return null;
+        List<AnnotatedMethod<?>> postConstructMethods = new ArrayList<AnnotatedMethod<?>>();
+        collectPostConstructMethods(getAnnotated().getJavaClass(), postConstructMethods);
+        return postConstructMethods;
+    }
+
+    private void collectPostConstructMethods(Class<?> type, List<AnnotatedMethod<?>>
postConstructMethods)
+    {
+        if (type == null)
+        {
+            return;
+        }
+        collectPostConstructMethods(type.getSuperclass(), postConstructMethods);
+        for (AnnotatedMethod<?> annotatedMethod: getAnnotated().getMethods())
+        {
+            if (annotatedMethod.getJavaMember().getDeclaringClass() == type
+                && annotatedMethod.isAnnotationPresent(PostConstruct.class)
+                && annotatedMethod.getParameters().isEmpty())
+            {
+                postConstructMethods.add(annotatedMethod);
+            }
+        }
     }
 
     protected List<AnnotatedMethod<?>> getPreDestroyMethods()
     {
-        return null;
+        List<AnnotatedMethod<?>> preDestroyMethods = new ArrayList<AnnotatedMethod<?>>();
+        collectPreDestroyMethods(getAnnotated().getJavaClass(), preDestroyMethods);
+        return preDestroyMethods;
+    }
+
+    private void collectPreDestroyMethods(Class<?> type, List<AnnotatedMethod<?>>
preDestroyMethods)
+    {
+        if (type == null)
+        {
+            return;
+        }
+        collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods);
+        for (AnnotatedMethod<?> annotatedMethod: getAnnotated().getMethods())
+        {
+            if (annotatedMethod.getJavaMember().getDeclaringClass() == type
+                && annotatedMethod.isAnnotationPresent(PreDestroy.class)
+                && annotatedMethod.getParameters().isEmpty())
+            {
+                preDestroyMethods.add(annotatedMethod);
+            }
+        }
     }
 
     public boolean isEnabled()

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java?rev=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/DecoratorBeanBuilder.java
Sat Jan 19 12:07:06 2013
@@ -119,54 +119,6 @@ public class DecoratorBeanBuilder<T> ext
         bean.setConstructor(constructor.getJavaMember());
     }
 
-    @Override
-    protected List<AnnotatedMethod<?>> getPostConstructMethods()
-    {
-        List<AnnotatedMethod<?>> postConstructMethods = new ArrayList<AnnotatedMethod<?>>();
-        collectPostConstructMethods(getAnnotated().getJavaClass(), postConstructMethods);
-        return postConstructMethods;
-    }
-
-    private void collectPostConstructMethods(Class<?> type, List<AnnotatedMethod<?>>
postConstructMethods)
-    {
-        if (type == null)
-        {
-            return;
-        }
-        collectPostConstructMethods(type.getSuperclass(), postConstructMethods);
-        for (AnnotatedMethod<?> annotatedMethod: getAnnotated().getMethods())
-        {
-            if (annotatedMethod.getJavaMember().getDeclaringClass() == type && annotatedMethod.isAnnotationPresent(PostConstruct.class))
-            {
-                postConstructMethods.add(annotatedMethod);
-            }
-        }
-    }
-
-    @Override
-    protected List<AnnotatedMethod<?>> getPreDestroyMethods()
-    {
-        List<AnnotatedMethod<?>> preDestroyMethods = new ArrayList<AnnotatedMethod<?>>();
-        collectPreDestroyMethods(getAnnotated().getJavaClass(), preDestroyMethods);
-        return preDestroyMethods;
-    }
-
-    private void collectPreDestroyMethods(Class<?> type, List<AnnotatedMethod<?>>
preDestroyMethods)
-    {
-        if (type == null)
-        {
-            return;
-        }
-        collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods);
-        for (AnnotatedMethod<?> annotatedMethod: getAnnotated().getMethods())
-        {
-            if (annotatedMethod.getJavaMember().getDeclaringClass() == type && annotatedMethod.isAnnotationPresent(PreDestroy.class))
-            {
-                preDestroyMethods.add(annotatedMethod);
-            }
-        }
-    }
-
     /**
      * If this method returns <code>false</code> the {@link #getBean()} method
must not get called.
      *

Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/LifecycleMethodBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/LifecycleMethodBuilder.java?rev=1435526&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/LifecycleMethodBuilder.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/LifecycleMethodBuilder.java
Sat Jan 19 12:07:06 2013
@@ -0,0 +1,5 @@
+package org.apache.webbeans.component.creation;
+
+public class LifecycleMethodBuilder {
+
+}

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=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/context/creational/CreationalContextImpl.java
Sat Jan 19 12:07:06 2013
@@ -112,7 +112,7 @@ public class CreationalContextImpl<T> im
      * @param dependent dependent contextual
      * @param instance dependent instance
      */
-    public <K> void addDependent(Object ownerInstance, Contextual<K> dependent,
Object instance)
+    public <K> void addDependent(Contextual<K> dependent, Object instance)
     {
         Asserts.assertNotNull(dependent,"dependent parameter cannot be null");
 

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=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Sat Jan 19 12:07:06 2013
@@ -141,10 +141,7 @@ public abstract class AbstractInjectable
             // add this dependent into bean dependent list
             if (!WebBeansUtil.isStaticInjection(injectionPoint) && WebBeansUtil.isDependent(injectedBean))
             {
-                if(instanceUnderInjection.get() != null)
-                {
-                    creationalContext.addDependent(instanceUnderInjection.get(), injectedBean,
injected);
-                }
+                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=1435526&r1=1435525&r2=1435526&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
Sat Jan 19 12:07:06 2013
@@ -69,8 +69,6 @@ public class InstanceImpl<T> implements 
 
     private CreationalContext<?> parentCreationalContext;
 
-    private Object ownerInstance;
-
     /**
      * Creates new instance.
      * 
@@ -82,12 +80,11 @@ public class InstanceImpl<T> implements 
      * @param annotations qualifier annotations
      */
     public InstanceImpl(Type injectionClazz, InjectionPoint injectionPoint, WebBeansContext
webBeansContext,
-                 CreationalContext<?> creationalContext, Object ownerInstance, Annotation...
annotations)
+                 CreationalContext<?> creationalContext, Annotation... annotations)
     {
         this.injectionClazz = injectionClazz;
         this.injectionPoint = injectionPoint;
         this.parentCreationalContext = creationalContext;
-        this.ownerInstance = ownerInstance;
 
         for (Annotation ann : annotations)
         {
@@ -136,9 +133,9 @@ public class InstanceImpl<T> implements 
 
             instance = (T) beanManager.getReference(bean, null, creationalContext);
 
-            if (isDependentBean && ownerInstance != null && creationalContext
instanceof CreationalContextImpl)
+            if (isDependentBean && creationalContext instanceof CreationalContextImpl)
             {
-                ((CreationalContextImpl<?>) creationalContext).addDependent(ownerInstance,
bean, instance);
+                ((CreationalContextImpl<?>) creationalContext).addDependent(bean, instance);
             }
         }
         finally
@@ -198,9 +195,7 @@ public class InstanceImpl<T> implements 
     public Instance<T> select(Annotation... qualifiers)
     {
         Annotation[] newQualifiersArray = getAdditionalQualifiers(qualifiers);
-        InstanceImpl<T> newInstance = new InstanceImpl<T>(injectionClazz, injectionPoint,
-                                                          webBeansContext, parentCreationalContext,
-                                                          ownerInstance, newQualifiersArray);
+        InstanceImpl<T> newInstance = new InstanceImpl<T>(injectionClazz, injectionPoint,
webBeansContext, parentCreationalContext, newQualifiersArray);
 
         return newInstance;
     }
@@ -251,9 +246,7 @@ public class InstanceImpl<T> implements 
         
         Annotation[] newQualifiers = getAdditionalQualifiers(qualifiers);
         
-        InstanceImpl<U> newInstance = new InstanceImpl(sub, injectionPoint, webBeansContext,
-                                                       parentCreationalContext, ownerInstance,
-                                                       newQualifiers);
+        InstanceImpl<U> newInstance = new InstanceImpl(sub, injectionPoint, webBeansContext,
parentCreationalContext, newQualifiers);
                     
         return newInstance;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
Sat Jan 19 12:07:06 2013
@@ -144,7 +144,10 @@ public final class WebBeansInterceptorCo
 
                 injectionTarget.setInterceptorInfo(interceptorInfo, proxyClass, methodInterceptors,
postConstructInterceptors, preDestroyInterceptors);
             }
-
+            else // we have no interceptors so we have to define lifecycle methods
+            {
+                
+            }
         }
 
     }

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=1435526&r1=1435525&r2=1435526&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
Sat Jan 19 12:07:06 2013
@@ -202,7 +202,7 @@ public class InjectionTargetImpl<T> exte
                     CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>)creationalContext;
                     creationalContextImpl.putDelegate(delegate);
                     Object decoratorInstance = decorator.create((CreationalContext) creationalContext);
-                    creationalContextImpl.addDependent(instance, decorator, decoratorInstance);
+                    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/InstanceProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java?rev=1435526&r1=1435525&r2=1435526&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/InstanceProducer.java
Sat Jan 19 12:07:06 2013
@@ -75,7 +75,7 @@ public class InstanceProducer<T> extends
 
             Object ownerInstance = AbstractInjectable.instanceUnderInjection.get();
 
-            Instance<T> instance = new InstanceImpl<T>(type, injectionPoint,
webBeansContext, creationalContext, ownerInstance, qualifiers.toArray(new Annotation[qualifiers.size()]));
+            Instance<T> instance = new InstanceImpl<T>(type, injectionPoint,
webBeansContext, creationalContext, qualifiers.toArray(new Annotation[qualifiers.size()]));
             
             return instance;
         }



Mime
View raw message