You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2013/01/06 15:53:13 UTC

svn commit: r1429532 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/creation/AbstractInjecionTargetBeanCreator.java component/creation/ProducerMethodBeanCreator.java util/WebBeansAnnotatedTypeUtil.java

Author: arne
Date: Sun Jan  6 14:53:13 2013
New Revision: 1429532

URL: http://svn.apache.org/viewvc?rev=1429532&view=rev
Log:
OWB-745: moved WebBeansAnnotatedTypeUtil.configureProducerSpecialization to ProducerMethodBeanCreatorImpl

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanCreator.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java?rev=1429532&r1=1429531&r2=1429532&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjecionTargetBeanCreator.java Sun Jan  6 14:53:13 2013
@@ -57,6 +57,7 @@ import org.apache.webbeans.container.Inj
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.spi.api.ResourceReference;
 import org.apache.webbeans.util.AnnotationUtil;
+import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -429,7 +430,7 @@ public abstract class AbstractInjecionTa
         {
             if(annotatedMethod.isAnnotationPresent(Produces.class) && annotatedMethod.getDeclaringType().equals(getAnnotated()))
             {
-                WebBeansAnnotatedTypeUtil.checkProducerMethodForDeployment(annotatedMethod);
+                checkProducerMethodForDeployment(annotatedMethod);
                 boolean specialize = false;
                 if(annotatedMethod.isAnnotationPresent(Specializes.class))
                 {
@@ -447,7 +448,7 @@ public abstract class AbstractInjecionTa
                 
                 if(specialize)
                 {
-                    WebBeansAnnotatedTypeUtil.configureProducerSpecialization(producerMethodBean, (AnnotatedMethod<T>)annotatedMethod);
+                    producerMethodBeanCreator.configureProducerSpecialization((AnnotatedMethod<T>) annotatedMethod);
                 }
                 
                 if (ClassUtil.getClass(annotatedMethod.getBaseType()).isPrimitive())
@@ -488,7 +489,25 @@ public abstract class AbstractInjecionTa
         
         return producerBeans;
     }
-    
+
+    /**
+     * Check producer method is ok for deployment.
+     * 
+     * @param annotatedMethod producer method
+     */
+    private void checkProducerMethodForDeployment(AnnotatedMethod<? super T> annotatedMethod)
+    {
+        Asserts.assertNotNull(annotatedMethod, "annotatedMethod argument can not be null");
+
+        if (annotatedMethod.isAnnotationPresent(Inject.class) || 
+                annotatedMethod.isAnnotationPresent(Disposes.class) ||  
+                annotatedMethod.isAnnotationPresent(Observes.class))
+        {
+            throw new WebBeansConfigurationException("Producer annotated method : " + annotatedMethod + " can not be annotated with"
+                                                     + " @Initializer/@Destructor annotation or has a parameter annotated with @Disposes/@Observes");
+        }
+    }
+
     private <X> void addFieldInjectionPointMetaData(AnnotatedField<X> annotField)
     {
         InjectionPoint injectionPoint = webBeansContext.getInjectionPointFactory().getFieldInjectionPointData(getBean(), annotField);

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanCreator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanCreator.java?rev=1429532&r1=1429531&r2=1429532&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanCreator.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ProducerMethodBeanCreator.java Sun Jan  6 14:53:13 2013
@@ -18,10 +18,18 @@
  */
 package org.apache.webbeans.component.creation;
 
+import java.lang.reflect.Method;
+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 org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.ProducerMethodBean;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 
 public class ProducerMethodBeanCreator<T> extends AbstractProducerBeanCreator<T>
@@ -39,4 +47,44 @@ public class ProducerMethodBeanCreator<T
     {
         return (ProducerMethodBean<T>)super.getBean();
     }
+
+    public void configureProducerSpecialization(AnnotatedMethod<T> annotatedMethod)
+    {
+        List<AnnotatedParameter<T>> annotatedParameters = annotatedMethod.getParameters();
+        List<Class<?>> parameters = new ArrayList<Class<?>>();
+        for(AnnotatedParameter<T> annotatedParam : annotatedParameters)
+        {
+            parameters.add(ClassUtil.getClass(annotatedParam.getBaseType()));
+        }
+        
+        Method superMethod = ClassUtil.getClassMethodWithTypes(annotatedMethod.getDeclaringType().getJavaClass().getSuperclass(), 
+                annotatedMethod.getJavaMember().getName(), parameters);
+        if (superMethod == null)
+        {
+            throw new WebBeansConfigurationException("Anontated producer method specialization is failed : " + annotatedMethod.getJavaMember().getName()
+                                                     + " not found in super class : " + annotatedMethod.getDeclaringType().getJavaClass().getSuperclass().getName()
+                                                     + " for annotated method : " + annotatedMethod);
+        }
+        
+        if (!AnnotationUtil.hasAnnotation(superMethod.getAnnotations(), Produces.class))
+        {
+            throw new WebBeansConfigurationException("Anontated producer method specialization is failed : " + annotatedMethod.getJavaMember().getName()
+                                                     + " found in super class : " + annotatedMethod.getDeclaringType().getJavaClass().getSuperclass().getName()
+                                                     + " is not annotated with @Produces" + " for annotated method : " + annotatedMethod);
+        }
+
+        /* To avoid multiple invocations of setBeanName(), following code is delayed to
+         * configSpecializedProducerMethodBeans() when checkSpecializations.
+        Annotation[] anns = AnnotationUtil.getQualifierAnnotations(superMethod.getAnnotations());
+
+        for (Annotation ann : anns)
+        {
+            bean.addQualifier(ann);
+        }
+        
+        WebBeansUtil.configuredProducerSpecializedName(bean, annotatedMethod.getJavaMember(), superMethod);
+        */
+        
+        getBean().setSpecializedBean(true);        
+    }
 }

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=1429532&r1=1429531&r2=1429532&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 Sun Jan  6 14:53:13 2013
@@ -20,7 +20,6 @@ package org.apache.webbeans.util;
 
 import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.component.AbstractInjectionTargetBean;
-import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 
 import javax.enterprise.event.Observes;
@@ -31,69 +30,10 @@ import javax.enterprise.inject.spi.Annot
 import javax.inject.Inject;
 import java.lang.reflect.Method;
 import java.lang.reflect.TypeVariable;
-import java.util.ArrayList;
 import java.util.List;
 
 public final class WebBeansAnnotatedTypeUtil
-{
-    
-    /**
-     * Check producer method is ok for deployment.
-     * 
-     * @param annotatedMethod producer method
-     */
-    public static <X> void checkProducerMethodForDeployment(AnnotatedMethod<X> annotatedMethod)
-    {
-        Asserts.assertNotNull(annotatedMethod, "annotatedMethod argument can not be null");
-
-        if (annotatedMethod.isAnnotationPresent(Inject.class) || 
-                annotatedMethod.isAnnotationPresent(Disposes.class) ||  
-                annotatedMethod.isAnnotationPresent(Observes.class))
-        {
-            throw new WebBeansConfigurationException("Producer annotated method : " + annotatedMethod + " can not be annotated with"
-                                                     + " @Initializer/@Destructor annotation or has a parameter annotated with @Disposes/@Observes");
-        }
-    }
-    
-    public static <X> void configureProducerSpecialization(AbstractOwbBean<X> bean,AnnotatedMethod<X> annotatedMethod)
-    {
-        List<AnnotatedParameter<X>> annotatedParameters = annotatedMethod.getParameters();
-        List<Class<?>> parameters = new ArrayList<Class<?>>();
-        for(AnnotatedParameter<X> annotatedParam : annotatedParameters)
-        {
-            parameters.add(ClassUtil.getClass(annotatedParam.getBaseType()));
-        }
-        
-        Method superMethod = ClassUtil.getClassMethodWithTypes(annotatedMethod.getDeclaringType().getJavaClass().getSuperclass(), 
-                annotatedMethod.getJavaMember().getName(), parameters);
-        if (superMethod == null)
-        {
-            throw new WebBeansConfigurationException("Anontated producer method specialization is failed : " + annotatedMethod.getJavaMember().getName()
-                                                     + " not found in super class : " + annotatedMethod.getDeclaringType().getJavaClass().getSuperclass().getName()
-                                                     + " for annotated method : " + annotatedMethod);
-        }
-        
-        if (!AnnotationUtil.hasAnnotation(superMethod.getAnnotations(), Produces.class))
-        {
-            throw new WebBeansConfigurationException("Anontated producer method specialization is failed : " + annotatedMethod.getJavaMember().getName()
-                                                     + " found in super class : " + annotatedMethod.getDeclaringType().getJavaClass().getSuperclass().getName()
-                                                     + " is not annotated with @Produces" + " for annotated method : " + annotatedMethod);
-        }
-
-        /* To avoid multiple invocations of setBeanName(), following code is delayed to
-         * configSpecializedProducerMethodBeans() when checkSpecializations.
-        Annotation[] anns = AnnotationUtil.getQualifierAnnotations(superMethod.getAnnotations());
-
-        for (Annotation ann : anns)
-        {
-            bean.addQualifier(ann);
-        }
-        
-        WebBeansUtil.configuredProducerSpecializedName(bean, annotatedMethod.getJavaMember(), superMethod);
-        */
-        
-        bean.setSpecializedBean(true);        
-    }
+{    
     
     /**
      * add the definitions for a &#x0040;Initializer method.