openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsandt...@apache.org
Subject svn commit: r1654385 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/test/events/injectiontarget/
Date Fri, 23 Jan 2015 21:12:17 GMT
Author: rsandtner
Date: Fri Jan 23 21:12:16 2015
New Revision: 1654385

URL: http://svn.apache.org/r1654385
Log:
OWB-1033 fixed annotated for producers in ProcessBeanAttributes

added annotatedMethod for producerMethods and
annotatedField for producerFields

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessBeanAttributesTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java?rev=1654385&r1=1654384&r2=1654385&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerFieldBeansBuilder.java
Fri Jan 23 21:12:16 2015
@@ -29,7 +29,6 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.BeanAttributes;
 import javax.inject.Named;
 
-import org.apache.webbeans.component.BeanAttributesImpl;
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.ProducerFieldBean;
 import org.apache.webbeans.component.ResourceBean;
@@ -92,9 +91,7 @@ public class ProducerFieldBeansBuilder<T
                         throw new WebBeansConfigurationException("Resource producer annotated
field : " + annotatedField + " can not define EL name");
                     }
 
-                    final BeanAttributes<T> beanAttributes = webBeansContext.getWebBeansUtil().fireProcessBeanAttributes(
-                            annotatedType, annotatedField.getJavaMember().getType(),
-                            BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build());
+                    final BeanAttributes<T> beanAttributes = fireProcessBeanAttributes(annotatedField);
                     if (beanAttributes != null)
                     {
                         ResourceBeanBuilder<T, Annotation> resourceBeanCreator
@@ -106,7 +103,8 @@ public class ProducerFieldBeansBuilder<T
                 }
                 else
                 {
-                    BeanAttributesImpl<T> beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
+                    BeanAttributes<T> beanAttributes = fireProcessBeanAttributes(annotatedField);
+
                     ProducerFieldBeanBuilder<T, ProducerFieldBean<T>> producerFieldBeanCreator
                         = new ProducerFieldBeanBuilder<T, ProducerFieldBean<T>>(bean,
annotatedField, beanAttributes);
                     ProducerFieldBean<T> producerFieldBean = producerFieldBeanCreator.getBean();
@@ -119,12 +117,20 @@ public class ProducerFieldBeansBuilder<T
 
                     webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
producerFieldBean, anns);
                     WebBeansUtil.checkProducerGenericType(producerFieldBean, annotatedField.getJavaMember());
-                    
+
                     producerBeans.add(producerFieldBean);
                 }
             }
         }
-        
+
         return producerBeans;
     }
+
+
+    private BeanAttributes<T> fireProcessBeanAttributes(AnnotatedField<? super T>
annotatedField)
+    {
+        return webBeansContext.getWebBeansUtil().fireProcessBeanAttributes(
+                annotatedField, annotatedField.getJavaMember().getType(),
+                BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build());
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java?rev=1654385&r1=1654384&r2=1654385&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeansBuilder.java
Fri Jan 23 21:12:16 2015
@@ -89,7 +89,7 @@ public class ProducerMethodBeansBuilder<
 
                 final AnnotatedMethod<T> method = (AnnotatedMethod<T>) annotatedMethod;
                 final BeanAttributes<T> beanAttributes = webBeansContext.getWebBeansUtil().fireProcessBeanAttributes(
-                        annotatedType, annotatedMethod.getJavaMember().getReturnType(),
+                        annotatedMethod, annotatedMethod.getJavaMember().getReturnType(),
                         BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes(method).build());
                 if (beanAttributes != null)
                 {

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=1654385&r1=1654384&r2=1654385&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
Fri Jan 23 21:12:16 2015
@@ -93,6 +93,7 @@ import javax.enterprise.inject.Intercept
 import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
 import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.AnnotatedMember;
@@ -1782,7 +1783,7 @@ public final class WebBeansUtil
         return false;
     }
 
-    public <T> BeanAttributes<T> fireProcessBeanAttributes(final AnnotatedType<T>
annotatedType, final Class<?> type, final BeanAttributes<T> ba)
+    public <T> BeanAttributes<T> fireProcessBeanAttributes(final Annotated annotatedType,
final Class<?> type, final BeanAttributes<T> ba)
     {
         // we don't use bm stack since it is actually quite useless
         final ProcessBeanAttributesImpl event = new GProcessBeanAttributes(type, annotatedType,
ba);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessBeanAttributesTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessBeanAttributesTest.java?rev=1654385&r1=1654384&r2=1654385&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessBeanAttributesTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/events/injectiontarget/ProcessBeanAttributesTest.java
Fri Jan 23 21:12:16 2015
@@ -24,6 +24,9 @@ import org.junit.Test;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessBeanAttributes;
 import javax.inject.Inject;
@@ -31,6 +34,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 public class ProcessBeanAttributesTest extends AbstractUnitTest
 {
@@ -46,12 +51,41 @@ public class ProcessBeanAttributesTest e
         assertEquals(1, processBeanAttributesExtension.producer.size());
     }
 
+    @Test
+    public void checkProducerMethod()
+    {
+        ProcessBeanAttributesExtension extension = new ProcessBeanAttributesExtension();
+        addExtension(extension);
+        startContainer(SomeOtherBean.class);
+
+        assertNotNull(extension.annotatedMethod);
+        assertTrue(extension.annotatedMethod instanceof AnnotatedMethod);
+        assertEquals("producer", ((AnnotatedMethod) extension.annotatedMethod).getJavaMember().getName());
+        assertEquals(String.class, ((AnnotatedMethod) extension.annotatedMethod).getJavaMember().getReturnType());
+    }
+
+    @Test
+    public void checkProducerField()
+    {
+        ProcessBeanAttributesExtension extension = new ProcessBeanAttributesExtension();
+        addExtension(extension);
+        startContainer(SomeOtherBean.class);
+
+        assertNotNull(extension.annotatedField);
+        assertTrue(extension.annotatedField instanceof AnnotatedField);
+        assertEquals("realMeaningOfLife", ((AnnotatedField) extension.annotatedField).getJavaMember().getName());
+        assertEquals(Integer.class, ((AnnotatedField) extension.annotatedField).getJavaMember().getType());
+
+    }
+
     public static class ProcessBeanAttributesExtension implements Extension
     {
         private Collection<ProcessBeanAttributes<?>> someBean = new ArrayList<ProcessBeanAttributes<?>>();
         private Collection<ProcessBeanAttributes<?>> someOtherBean = new ArrayList<ProcessBeanAttributes<?>>();
         private Collection<ProcessBeanAttributes<?>> producer = new ArrayList<ProcessBeanAttributes<?>>();
 
+        private Annotated annotatedMethod;
+        private Annotated annotatedField;
 
         public void someBean(@Observes ProcessBeanAttributes<SomeBean> pba)
         {
@@ -61,12 +95,18 @@ public class ProcessBeanAttributesTest e
         public void producer(@Observes ProcessBeanAttributes<String> pba)
         {
             producer.add(pba);
+            annotatedMethod = pba.getAnnotated();
         }
 
         public void otherBean(@Observes ProcessBeanAttributes<SomeOtherBean> pba)
         {
             someOtherBean.add(pba);
         }
+
+        public void fieldProducer(@Observes ProcessBeanAttributes<Integer> pba)
+        {
+            annotatedField = pba.getAnnotated();
+        }
     }
 
     @RequestScoped
@@ -83,8 +123,12 @@ public class ProcessBeanAttributesTest e
     @RequestScoped
     public static class SomeOtherBean
     {
+        @Produces
+        protected Integer realMeaningOfLife = 30;
+
         private int meaningOfLife = 42;
 
+
         public int getMeaningOfLife()
         {
             return meaningOfLife;



Mime
View raw message