Author: arne
Date: Sat Jan  5 20:49:07 2013
New Revision: 1429383

URL: http://svn.apache.org/viewvc?rev=1429383&view=rev
Log:
OWB-748: Fixed order of injection

Modified:
    
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractInjectionTargetBean.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.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/WebBeansAnnotatedTypeUtil.java

Modified: 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java?rev=1429383&r1=1429382&r2=1429383&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
 (original)
+++ 
openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/BaseEjbBean.java
 Sat Jan  5 20:49:07 2013
@@ -82,18 +82,6 @@ public abstract class BaseEjbBean<T> ext
     }
 
     /**
-     * Inject session bean injected fields. It is called from
-     * interceptor.
-     * @param instance bean instance
-     * @param creationalContext creational context instance
-     */
-    @SuppressWarnings("unchecked")
-    public void injectFieldInInterceptor(Object instance, CreationalContext<?> 
creationalContext)
-    {
-        super.injectFields((T)instance, 
(CreationalContext<T>)creationalContext);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override

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=1429383&r1=1429382&r2=1429383&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
 Sat Jan  5 20:49:07 2013
@@ -73,12 +73,6 @@ public abstract class AbstractInjectionT
     /** Injected methods of the bean */
     private Set<Method> injectedMethods = new HashSet<Method>();
     
-    /** Injected fields of the bean */
-    private Set<Field> injectedFromSuperFields = new HashSet<Field>();
-
-    /** Injected methods of the bean */
-    private Set<Method> injectedFromSuperMethods = new HashSet<Method>();
-    
     /**Annotated type for bean*/
     private AnnotatedType<T> annotatedType;
     
@@ -148,10 +142,7 @@ public abstract class AbstractInjectionT
                 //Therefore we inject dependencies of this instance
                 //Otherwise we loose injection
                 injectResources(instance, creationalContext);
-                injectSuperFields(instance, creationalContext);
-                injectSuperMethods(instance, creationalContext);
-                injectFields(instance, creationalContext);
-                injectMethods(instance, creationalContext);            
+                injectFieldsAndMethods(instance, creationalContext);
                 
                 //Dependent proxy
                 dependentProxy = result;
@@ -219,14 +210,7 @@ public abstract class AbstractInjectionT
         //Inject resources
         injectResources(instance, creationalContext);
         
-        injectSuperFields(instance, creationalContext);
-        injectSuperMethods(instance, creationalContext);
-        
-        // Inject fields
-        injectFields(instance, creationalContext);
-
-        // Inject methods
-        injectMethods(instance, creationalContext);
+        injectFieldsAndMethods(instance, creationalContext);
         
         //Post construct
         postConstruct(instance, creationalContext);
@@ -310,16 +294,38 @@ public abstract class AbstractInjectionT
     }
 
     /**
-     * Injects fields of the bean after constructing.
+     * Injects fields and methods of the bean after constructing.
+     * First the fields and methods of the superclasses are injected, then the 
fields and methdos of this class
      * 
      * @param instance bean instance
      * @param creationalContext creational context
      */
-    public void injectFields(T instance, CreationalContext<T> 
creationalContext)
+    public void injectFieldsAndMethods(T instance, CreationalContext<T> 
creationalContext)
+    {
+        injectFieldsAndMethods(annotatedType.getJavaClass(), instance, 
creationalContext);
+    }
+    
+    private void injectFieldsAndMethods(Class<?> type, T instance, 
CreationalContext<T> creationalContext)
+    {
+        if (type == null || type.equals(Object.class))
+        {
+            return;
+        }
+        injectFieldsAndMethods(type.getSuperclass(), instance, 
creationalContext);
+        injectFields(type, instance, creationalContext);
+        injectMethods(type, instance, creationalContext);
+    }    
+    
+    private void injectFields(Class<?> type, T instance, CreationalContext<T> 
creationalContext)
     {
         Set<Field> fields = getInjectedFields();
         for (Field field : fields)
         {
+            if (!field.getDeclaringClass().equals(type))
+            {
+                // will be injected at another run
+                continue;
+            }
             if (field.getAnnotation(Delegate.class) == null)
             {
                 if(!field.getType().equals(InjectionPoint.class))
@@ -361,48 +367,22 @@ public abstract class AbstractInjectionT
         }
     }
 
-    public void injectSuperFields(T instance, CreationalContext<T> 
creationalContext)
-    {
-        Set<Field> fields = getInjectedFromSuperFields();
-        for (Field field : fields)
-        {
-            if (field.getAnnotation(Delegate.class) == null)
-            {
-                injectField(field, instance, creationalContext);
-            }
-        }                        
-    }
-    
-    public void injectSuperMethods(T instance, CreationalContext<T> 
creationalContext)
-    {
-        Set<Method> methods = getInjectedFromSuperMethods();
-
-        for (Method method : methods)
-        {
-            injectMethod(method, instance, creationalContext);
-        }        
-    }
-    
-    
     private void injectField(Field field, Object instance, 
CreationalContext<?> creationalContext)
     {
         InjectableField f = new InjectableField(field, instance, this, 
creationalContext);
         f.doInjection();        
     }
 
-    /**
-     * Injects all {@link javax.inject.Inject} methods of the bean instance.
-     * 
-     * @param instance bean instance
-     * @param creationalContext creational context instance
-     */
-    public void injectMethods(T instance, CreationalContext<T> 
creationalContext)
+    private void injectMethods(Class<?> type, T instance, CreationalContext<T> 
creationalContext)
     {
         Set<Method> methods = getInjectedMethods();
 
         for (Method method : methods)
         {
-            injectMethod(method, instance, creationalContext);
+            if (method.getDeclaringClass().equals(type))
+            {
+                injectMethod(method, instance, creationalContext);
+            }
         }
     }
     
@@ -484,27 +464,6 @@ public abstract class AbstractInjectionT
     }
     
     /**
-     * Gets injected from super fields.
-     * 
-     * @return injected fields
-     */
-    public Set<Field> getInjectedFromSuperFields()
-    {
-        return injectedFromSuperFields;
-    }
-
-    /**
-     * Add new injected field.
-     * 
-     * @param field new injected field
-     */
-    public void addInjectedFieldToSuper(Field field)
-    {
-        injectedFromSuperFields.add(field);
-    }
-    
-
-    /**
      * Gets injected methods.
      * 
      * @return injected methods
@@ -525,26 +484,6 @@ public abstract class AbstractInjectionT
     }
 
     /**
-     * Gets injected from super methods.
-     * 
-     * @return injected methods
-     */
-    public Set<Method> getInjectedFromSuperMethods()
-    {
-        return injectedFromSuperMethods;
-    }
-
-    /**
-     * Add new injected method.
-     * 
-     * @param method new injected method
-     */
-    public void addInjectedMethodToSuper(Method method)
-    {
-        injectedFromSuperMethods.add(method);
-    }
-    
-    /**
      * {@inheritDoc}
      */
     public List<InterceptorData> getInterceptorStack()

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1429383&r1=1429382&r2=1429383&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
 Sat Jan  5 20:49:07 2013
@@ -62,36 +62,12 @@ public interface InjectionTargetBean<T> 
     public void injectResources(T instance, CreationalContext<T> 
creationalContext);
     
     /**
-     * Inject fields of the bean instance.
+     * Inject fields and methods of the bean instance.
      * 
      * @param instance bean instance
      * @param creationalContext creational context
      */
-    public void injectFields(T instance, CreationalContext<T> 
creationalContext);
-    
-    /**
-     * Inject initializer methods of the bean instance.
-     * 
-     * @param instance bean instance
-     * @param creationalContext creational context
-     */
-    public void injectMethods(T instance, CreationalContext<T> 
creationalContext);
-    
-    /**
-     * Inject fields of the bean instance.
-     * 
-     * @param instance bean instance
-     * @param creationalContext creational context
-     */
-    public void injectSuperFields(T instance, CreationalContext<T> 
creationalContext);
-    
-    /**
-     * Inject initializer methods of the bean instance.
-     * 
-     * @param instance bean instance
-     * @param creationalContext creational context
-     */
-    public void injectSuperMethods(T instance, CreationalContext<T> 
creationalContext);
+    public void injectFieldsAndMethods(T instance, CreationalContext<T> 
creationalContext);
         
     /**
      * Gets all injected fields of bean.
@@ -106,18 +82,6 @@ public interface InjectionTargetBean<T> 
     public void addInjectedField(Field field);
     
     /**
-     * Gets injected fields from super class.
-     * @return injected fields from super class 
-     */
-    public Set<Field> getInjectedFromSuperFields();
-
-    /**
-     * Adds new super injected field.
-     * @param field add to super
-     */
-    public void addInjectedFieldToSuper(Field field);    
-    
-    /**
      * Gets injected methods.
      * @return injected(initializer) methods
      */
@@ -130,18 +94,6 @@ public interface InjectionTargetBean<T> 
     public void addInjectedMethod(Method method);
 
     /**
-     * Gets injected methods from super class.
-     * @return injected method from super class
-     */
-    public Set<Method> getInjectedFromSuperMethods();
-
-    /**
-     * Add injected method to super list.
-     * @param method injected method
-     */
-    public void addInjectedMethodToSuper(Method method);
-    
-    /**
      * Gets inherited meta data.
      * @return inherited meta data
      */

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java?rev=1429383&r1=1429382&r2=1429383&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/decorator/WebBeansDecorator.java
 Sat Jan  5 20:49:07 2013
@@ -393,7 +393,7 @@ public class WebBeansDecorator<T> extend
             // Set injected fields
             ManagedBean<T> delegate = (ManagedBean<T>) wrappedBean;
 
-            Set<Field> injectedFields = delegate.getInjectedFromSuperFields();
+            Set<Field> injectedFields = delegate.getInjectedFields();
             for (Field injectedField : injectedFields)
             {
                 boolean isDecorates = 
injectedField.isAnnotationPresent(Delegate.class);
@@ -404,24 +404,7 @@ public class WebBeansDecorator<T> extend
                 }
             }
             
-            Set<Method> injectedMethods = 
delegate.getInjectedFromSuperMethods();
-            for (Method injectedMethod : injectedMethods)
-            {
-                injectMethod(injectedMethod, proxy, cretionalContext);
-            }        
-
-            injectedFields = delegate.getInjectedFields();
-            for (Field injectedField : injectedFields)
-            {
-                boolean isDecorates = 
injectedField.isAnnotationPresent(Delegate.class);
-
-                if (!isDecorates)
-                {
-                    injectField(injectedField, proxy, cretionalContext);
-                }
-            }
-            
-            injectedMethods = delegate.getInjectedMethods();
+            Set<Method> injectedMethods = delegate.getInjectedMethods();
             for (Method injectedMethod : injectedMethods)
             {
                 injectMethod(injectedMethod, proxy, cretionalContext);

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java?rev=1429383&r1=1429382&r2=1429383&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptorBean.java
 Sat Jan  5 20:49:07 2013
@@ -299,26 +299,14 @@ public class WebBeansInterceptorBean<T> 
         // Set injected fields
         ManagedBean<T> delegate = (ManagedBean<T>) delegateBean;
 
-        Set<Field> injectedFields = delegate.getInjectedFromSuperFields();
-        for (Field injectedField : injectedFields)
-        {
-            injectField(injectedField, proxy, creationalContext);
-        }
-
-        Set<Method> injectedMethods = delegate.getInjectedFromSuperMethods();
-        for (Method injectedMethod : injectedMethods)
-        {
-            injectMethod(injectedMethod, proxy, creationalContext);
-        }
-        
-        injectedFields = delegate.getInjectedFields();
+        Set<Field> injectedFields = delegate.getInjectedFields();
         for (Field injectedField : injectedFields)
         {
             injectField(injectedField, proxy, creationalContext);            
         }
         
 
-        injectedMethods = delegate.getInjectedMethods();
+        Set<Method> injectedMethods = delegate.getInjectedMethods();
         for (Method injectedMethod : injectedMethods)
         {
             injectMethod(injectedMethod, proxy, creationalContext);            

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=1429383&r1=1429382&r2=1429383&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
 Sat Jan  5 20:49:07 2013
@@ -90,10 +90,7 @@ public class InjectionTargetProducer<T> 
                 }
                 
                 bean.injectResources(instance, ctx);
-                bean.injectSuperFields(instance, ctx);
-                bean.injectSuperMethods(instance, ctx);
-                bean.injectFields(instance, ctx);
-                bean.injectMethods(instance, ctx);            
+                bean.injectFieldsAndMethods(instance, ctx);
             }                    
         }
         finally

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java?rev=1429383&r1=1429382&r2=1429383&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
 Sat Jan  5 20:49:07 2013
@@ -330,44 +330,13 @@ public final class WebBeansAnnotatedType
         }
     }
     
-    public <X> void defineInjectedFields(AbstractInjectionTargetBean<X> bean, 
AnnotatedType<X> annotatedType)
+    public <X> void defineInjectedFields(AbstractInjectionTargetBean<X> 
bean,AnnotatedType<X> annotatedType)
     {
-        // we start with the actual class and it will define the fields from 
the uppermost
-        // base class down to this very class
-        defineInjectedFields(bean, annotatedType, 
annotatedType.getJavaClass());
-    }
-
-    /**
-     * The &#064;Inject fields must be defined in a specific order. Fields in 
a Superclass must get defined
-     * before the fields in the Subclasses.
-     *
-     * @param bean which should get filled
-     * @param annotatedType to get the annotation information from
-     * @param targetClass the current class which should get introspected. 
Only fields from this very class will get defined.
-     */
-    private <X> void defineInjectedFields(AbstractInjectionTargetBean<X> bean, 
AnnotatedType<X> annotatedType, Class<?> targetClass)
-    {
-        if (targetClass.equals(Object.class))
-        {
-            return;
-        }
-
-        // we first recurse to the top level superclass
-        Class<?> superclass = targetClass.getSuperclass();
-        defineInjectedFields(bean, annotatedType, superclass);
-
-        // and start our field definition in the uppermost non-Object class :)
-
         AnnotationManager annotationManager = 
bean.getWebBeansContext().getAnnotationManager();
 
         Set<AnnotatedField<? super X>> annotatedFields = 
annotatedType.getFields();   
         for(AnnotatedField<? super X> annotatedField: annotatedFields)
         {
-            if 
(!targetClass.equals(annotatedField.getJavaMember().getDeclaringClass()))
-            {
-                // only scan fields of the current targetClass
-                continue;
-            }
             
if(Modifier.isPublic(annotatedField.getJavaMember().getModifiers()) && 
!annotatedField.isStatic())
             {
                 
if(webBeansContext.getBeanManagerImpl().isNormalScope(bean.getScope()))


Reply via email to