openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsandt...@apache.org
Subject svn commit: r1628178 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation: BaseProducerFactory.java ProducerMethodBeanBuilder.java
Date Mon, 29 Sep 2014 13:13:38 GMT
Author: rsandtner
Date: Mon Sep 29 13:13:37 2014
New Revision: 1628178

URL: http://svn.apache.org/r1628178
Log:
OWB-1014 validate injection of bean metadata in producers

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java?rev=1628178&r1=1628177&r2=1628178&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BaseProducerFactory.java
Mon Sep 29 13:13:37 2014
@@ -23,6 +23,7 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.GenericsUtil;
 
 import javax.enterprise.event.Observes;
@@ -205,11 +206,18 @@ public abstract class BaseProducerFactor
 
         for (AnnotatedParameter param : annotatedMethod.getParameters())
         {
-            if (param.getBaseType().equals(InjectionPoint.class))
+            Type type = param.getBaseType();
+            if (type.equals(InjectionPoint.class))
             {
+
                 throw new DefinitionException("Error in definining disposal method of annotated
method : " + annotatedMethod
                     + ". Disposal methods must not have an InjectionPoint.");
             }
+            else if (Bean.class.isAssignableFrom(ClassUtil.getClass(type)))
+            {
+                throw new DefinitionException("Error in defining disposal method of annoted
method: " + annotatedMethod +
+                        ". Disposal methods must not have a Bean parameter.");
+            }
         }
     }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java?rev=1628178&r1=1628177&r2=1628178&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanBuilder.java
Mon Sep 29 13:13:37 2014
@@ -19,13 +19,16 @@
 package org.apache.webbeans.component.creation;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanAttributes;
+import javax.enterprise.inject.spi.DefinitionException;
 
 import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.ProducerMethodBean;
@@ -87,4 +90,20 @@ public class ProducerMethodBeanBuilder<T
     {
         return createBean((Class<T>) annotatedMember.getJavaMember().getReturnType());
     }
+
+    @Override
+    public void validate() throws DefinitionException
+    {
+        super.validate();
+
+        for (AnnotatedParameter<?> parameter : annotatedMember.getParameters())
+        {
+            Type type = parameter.getBaseType();
+            if (Bean.class.equals(ClassUtil.getClass(type)) &&
+                !annotatedMember.getBaseType().equals(ClassUtil.getActualTypeArguments(type)[0]))
+            {
+                throw new DefinitionException("Type parameter of the injected bean must be
the same as the return type. Producer method: " + annotatedMember);
+            }
+        }
+    }
 }



Mime
View raw message