openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1438245 - in /openwebbeans/trunk: webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/ webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/ webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ webb...
Date Thu, 24 Jan 2013 22:45:33 GMT
Author: arne
Date: Thu Jan 24 22:45:33 2013
New Revision: 1438245

URL: http://svn.apache.org/viewvc?rev=1438245&view=rev
Log:
OWB-770: Extracted ObserverMethodsBuilder

Added:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
      - copied, changed from r1438232, openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java
Modified:
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
    openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.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/config/BeansDeployer.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/TestContext.java

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java?rev=1438245&r1=1438244&r2=1438245&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/component/EjbBeanBuilder.java
Thu Jan 24 22:45:33 2013
@@ -26,10 +26,8 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.ObserverMethod;
 
 import org.apache.webbeans.component.BeanAttributesImpl;
-import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.creation.AbstractInjectionTargetBeanBuilder;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.ejb.common.util.EjbValidator;
@@ -49,18 +47,6 @@ public abstract class EjbBeanBuilder<T, 
         super(webBeansContext, annotatedType, beanAttributes);
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.webbeans.component.creation.AbstractInjectedTargetBeanCreator#defineObserverMethods()
-     */
-    @Override
-    public Set<ObserverMethod<?>> defineObserverMethods(InjectionTargetBean<T>
bean)
-    {
-        Set<ObserverMethod<?>> observerMethods = super.defineObserverMethods(bean);
-        EjbValidator.validateObserverMethods((BaseEjbBean<?>) bean, observerMethods);
-        
-        return observerMethods;
-    }
-
     @Override
     protected InjectionTarget<T> buildInjectionTarget(AnnotatedType<T> annotatedType,
                                                       Set<InjectionPoint> points,

Modified: openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java?rev=1438245&r1=1438244&r2=1438245&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
(original)
+++ openwebbeans/trunk/webbeans-ejb/src/main/java/org/apache/webbeans/ejb/common/util/EjbUtility.java
Thu Jan 24 22:45:33 2013
@@ -36,9 +36,11 @@ import javax.enterprise.inject.spi.Proce
 import javax.enterprise.inject.spi.Producer;
 
 import org.apache.webbeans.component.BeanAttributesImpl;
+import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.component.ProducerFieldBean;
 import org.apache.webbeans.component.ProducerMethodBean;
 import org.apache.webbeans.component.creation.BeanAttributesBuilder;
+import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.ejb.common.component.BaseEjbBean;
@@ -94,7 +96,8 @@ public final class EjbUtility
         Set<ProducerMethodBean<?>> producerMethodBeans = ejbBeanCreator.defineProducerMethods(ejbBean);
       
         checkProducerMethods(producerMethodBeans, ejbBean);
         Set<ProducerFieldBean<?>> producerFieldBeans = ejbBeanCreator.defineProducerFields(ejbBean);
          
-        Set<ObserverMethod<?>> observerMethods = ejbBeanCreator.defineObserverMethods(ejbBean);
       
+        Set<ObserverMethod<?>> observerMethods = new ObserverMethodsBuilder<T,
InjectionTargetBean<T>>(webBeansContext, ejbBean.getAnnotatedType()).defineObserverMethods(ejbBean);
+        EjbValidator.validateObserverMethods(ejbBean, observerMethods);
         
         //Fires ProcessInjectionTarget
         ProcessInjectionTargetImpl<T> processInjectionTargetEvent =

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=1438245&r1=1438244&r2=1438245&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
Thu Jan 24 22:45:33 2013
@@ -20,7 +20,6 @@ package org.apache.webbeans.component.cr
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
@@ -31,19 +30,15 @@ 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;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.ObserverMethod;
 import javax.inject.Inject;
 import javax.inject.Named;
 
@@ -64,7 +59,6 @@ import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
 
-
 /**
  * Abstract implementation of {@link AbstractBeanBuilder}.
  * 
@@ -107,83 +101,6 @@ public abstract class AbstractInjectionT
     /**
      * {@inheritDoc}
      */
-    public Set<ObserverMethod<?>> defineObserverMethods(InjectionTargetBean<T>
bean)
-    {   
-        Set<ObserverMethod<?>> definedObservers = new HashSet<ObserverMethod<?>>();
-        Set<AnnotatedMethod<? super T>> annotatedMethods = annotatedType.getMethods();
   
-        for (AnnotatedMethod<? super T> annotatedMethod : annotatedMethods)
-        {
-            AnnotatedMethod<T> annt = (AnnotatedMethod<T>)annotatedMethod;
-            List<AnnotatedParameter<T>> parameters = annt.getParameters();
-            boolean found = false;
-            for(AnnotatedParameter<T> parameter : parameters)
-            {
-                if(parameter.isAnnotationPresent(Observes.class))
-                {
-                    found = true;
-                    break;
-                }
-            }
-            
-            if(found)
-            {
-                checkObserverMethodConditions((AnnotatedMethod<T>) annotatedMethod,
annotatedMethod.getDeclaringType().getJavaClass());
-                if (bean.getScope().equals(Dependent.class))
-                {
-                    //Check Reception
-                     AnnotationUtil.getAnnotatedMethodFirstParameterWithAnnotation(annotatedMethod,
Observes.class);
-                    
-                     Observes observes = AnnotationUtil.getAnnotatedMethodFirstParameterAnnotation(annotatedMethod,
Observes.class);
-                     Reception reception = observes.notifyObserver();
-                     if(reception.equals(Reception.IF_EXISTS))
-                     {
-                         throw new WebBeansConfigurationException("Dependent Bean : " + annotatedType.getJavaClass()
+ " can not define observer method with @Receiver = IF_EXIST");
-                     }
-                }
-                
-                //Looking for ObserverMethod
-                ObserverMethod<?> definedObserver = webBeansContext.getBeanManagerImpl().getNotificationManager().getObservableMethodForAnnotatedMethod(annotatedMethod,
bean);
-                if(definedObserver != null)
-                {
-                    definedObservers.add(definedObserver);
-                }
-            }
-        }
-        
-        return definedObservers;
-    }
-
-    private void checkObserverMethodConditions(AnnotatedMethod<T> annotatedMethod,
Class<?> clazz)
-    {
-        Asserts.assertNotNull(annotatedMethod, "annotatedMethod parameter can not be null");
-        Asserts.nullCheckForClass(clazz);
-        
-        Method candidateObserverMethod = annotatedMethod.getJavaMember();
-        
-        if (AnnotationUtil.hasAnnotatedMethodMultipleParameterAnnotation(annotatedMethod,
Observes.class))
-        {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : " + clazz.getName()
-                                                     + " can not define two parameters with
annotated @Observes");
-        }
-
-        if (annotatedMethod.isAnnotationPresent(Produces.class) 
-                || annotatedMethod.isAnnotationPresent(Inject.class))
-        {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : " + clazz.getName()
-                                                     + " can not annotated with annotation
in the list {@Produces, @Initializer, @Destructor}");
-
-        }
-
-        if (AnnotationUtil.hasAnnotatedMethodParameterAnnotation(annotatedMethod, Disposes.class))
-        {
-            throw new WebBeansConfigurationException("Observer method : " + candidateObserverMethod.getName()
+ " in class : "
-                                                     + clazz.getName() + " can not annotated
with annotation @Disposes");
-        }                
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public Set<ProducerFieldBean<?>> defineProducerFields(InjectionTargetBean<T>
bean)
     {
         Set<ProducerFieldBean<?>> producerBeans = new HashSet<ProducerFieldBean<?>>();

Copied: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java
(from r1438232, 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/ObserverMethodsBuilder.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/ObserverMethodsBuilder.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractInjectionTargetBeanBuilder.java&r1=1438232&r2=1438245&rev=1438245&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/ObserverMethodsBuilder.java
Thu Jan 24 22:45:33 2013
@@ -18,52 +18,27 @@
  */
 package org.apache.webbeans.component.creation;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-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;
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.Specializes;
-import javax.enterprise.inject.spi.AnnotatedField;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.inject.Inject;
-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.ProducerMethodBean;
-import org.apache.webbeans.component.ResourceBean;
-import org.apache.webbeans.component.ResourceProvider;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
-import org.apache.webbeans.portable.InjectionTargetImpl;
-import org.apache.webbeans.portable.ProducerFieldProducer;
-import org.apache.webbeans.portable.ProviderBasedProxyProducer;
-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.WebBeansUtil;
-
 
 /**
  * Abstract implementation of {@link AbstractBeanBuilder}.
@@ -72,36 +47,22 @@ import org.apache.webbeans.util.WebBeans
  *
  * @param <T> bean class type
  */
-public abstract class AbstractInjectionTargetBeanBuilder<T, I extends InjectionTargetBean<T>>
+public class ObserverMethodsBuilder<T, I extends InjectionTargetBean<T>>
 {    
     
     protected final WebBeansContext webBeansContext;
     protected final AnnotatedType<T> annotatedType;
-    protected final BeanAttributesImpl<T> beanAttributes;
-    private boolean enabled = true;
 
     /**
      * Creates a new instance.
      * 
      */
-    public AbstractInjectionTargetBeanBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType, BeanAttributesImpl<T> beanAttributes)
+    public ObserverMethodsBuilder(WebBeansContext webBeansContext, AnnotatedType<T>
annotatedType)
     {
         Asserts.assertNotNull(webBeansContext, "webBeansContext may not be null");
         Asserts.assertNotNull(annotatedType, "annotated type may not be null");
-        Asserts.assertNotNull(beanAttributes, "beanAttributes may not be null");
         this.webBeansContext = webBeansContext;
         this.annotatedType = annotatedType;
-        this.beanAttributes = beanAttributes;
-    }
-
-    protected AnnotatedType<? super T> getSuperAnnotated()
-    {
-        Class<? super T> superclass = annotatedType.getJavaClass().getSuperclass();
-        if (superclass == null)
-        {
-            return null;
-        }
-        return webBeansContext.getAnnotatedElementFactory().getAnnotatedType(superclass);
     }
 
     /**
@@ -180,249 +141,4 @@ public abstract class AbstractInjectionT
                                                      + clazz.getName() + " can not annotated
with annotation @Disposes");
         }                
     }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Set<ProducerFieldBean<?>> defineProducerFields(InjectionTargetBean<T>
bean)
-    {
-        Set<ProducerFieldBean<?>> producerBeans = new HashSet<ProducerFieldBean<?>>();
-        Set<AnnotatedField<? super T>> annotatedFields = annotatedType.getFields();
       
-        for(AnnotatedField<? super T> annotatedField: annotatedFields)
-        {
-            if(annotatedField.isAnnotationPresent(Produces.class) && annotatedField.getDeclaringType().equals(annotatedType))
-            {
-                Type genericType = annotatedField.getBaseType();
-                
-                if(ClassUtil.isTypeVariable(genericType))
-                {
-                    throw new WebBeansConfigurationException("Producer annotated field :
" + annotatedField + " can not be Wildcard type or Type variable");
-                }
-                if(ClassUtil.isParametrizedType(genericType))
-                {
-                    if(!ClassUtil.checkParametrizedType((ParameterizedType)genericType))
-                    {
-                        throw new WebBeansConfigurationException("Producer annotated field
: " + annotatedField + " can not be Wildcard type or Type variable");
-                    }
-                }
-                
-                Annotation[] anns = AnnotationUtil.asArray(annotatedField.getAnnotations());
-                Field field = annotatedField.getJavaMember();
-                
-                //Producer field for resource
-                Annotation resourceAnnotation = AnnotationUtil.hasOwbInjectableResource(anns);
               
-                //Producer field for resource
-                if(resourceAnnotation != null)
-                {                    
-                    //Check for valid resource annotation
-                    //WebBeansUtil.checkForValidResources(annotatedField.getDeclaringType().getJavaClass(),
field.getType(), field.getName(), anns);
-                    if(!Modifier.isStatic(field.getModifiers()))
-                    {
-                        ResourceReference<T, Annotation> resourceRef = new ResourceReference<T,
Annotation>(annotatedType.getJavaClass(), field.getName(),
-                                                                                        
                   (Class<T>)field.getType(), resourceAnnotation);
-                        
-                        //Can not define EL name
-                        if(annotatedField.isAnnotationPresent(Named.class))
-                        {
-                            throw new WebBeansConfigurationException("Resource producer annotated
field : " + annotatedField + " can not define EL name");
-                        }
-                        
-                        BeanAttributesImpl<T> beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
-                        ResourceBeanBuilder<T, Annotation> resourceBeanCreator
-                            = new ResourceBeanBuilder<T, Annotation>(bean, resourceRef,
annotatedField, beanAttributes);
-                        ResourceBean<T, Annotation> resourceBean = resourceBeanCreator.getBean();
-                        ResourceProvider<T> resourceProvider = new ResourceProvider<T>(resourceBean.getReference(),
webBeansContext);
-                        resourceBean.setProducer(new ProviderBasedProxyProducer<T>(webBeansContext,
resourceBean.getReturnType(), resourceProvider));
-
-
-                        resourceBean.setProducerField(field);
-                        
-                        producerBeans.add(resourceBean);                                
           
-                    }
-                }
-                else
-                {
-                    BeanAttributesImpl<T> beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedField<T>)annotatedField).build();
-                    ProducerFieldBeanBuilder<T, ProducerFieldBean<T>> producerFieldBeanCreator
-                        = new ProducerFieldBeanBuilder<T, ProducerFieldBean<T>>(bean,
annotatedField, beanAttributes);
-                    ProducerFieldBean<T> producerFieldBean = producerFieldBeanCreator.getBean();
-                    webBeansContext.getDeploymentValidationService().validateProxyable(producerFieldBean);
-                    producerFieldBean.setProducer(new ProducerFieldProducer(bean, annotatedField,
producerFieldBean.getInjectionPoints()));
-                    producerFieldBean.setProducerField(field);
-
-                    webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
producerFieldBean, anns);
-                    WebBeansUtil.checkProducerGenericType(producerFieldBean, annotatedField.getJavaMember());
-                    
-                    producerBeans.add(producerFieldBean);
-                }
-            }
-        }
-        
-        return producerBeans;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Set<ProducerMethodBean<?>> defineProducerMethods(InjectionTargetBean<T>
bean)
-    {
-        Set<ProducerMethodBean<?>> producerBeans = new HashSet<ProducerMethodBean<?>>();
-        Set<AnnotatedMethod<? super T>> annotatedMethods = annotatedType.getMethods();
-        
-        for(AnnotatedMethod<? super T> annotatedMethod: annotatedMethods)
-        {
-            if(annotatedMethod.isAnnotationPresent(Produces.class) && annotatedMethod.getDeclaringType().equals(annotatedType))
-            {
-                checkProducerMethodForDeployment(annotatedMethod);
-                boolean specialize = false;
-                if(annotatedMethod.isAnnotationPresent(Specializes.class))
-                {
-                    if (annotatedMethod.isStatic())
-                    {
-                        throw new WebBeansConfigurationException("Specializing annotated
producer method : " + annotatedMethod + " can not be static");
-                    }
-                    
-                    specialize = true;
-                }
-                
-                BeanAttributesImpl<T> beanAttributes = BeanAttributesBuilder.forContext(webBeansContext).newBeanAttibutes((AnnotatedMethod<T>)annotatedMethod).build();
-                ProducerMethodBeanBuilder<T> producerMethodBeanCreator = new ProducerMethodBeanBuilder<T>(bean,
annotatedMethod, beanAttributes);
-                
-                ProducerMethodBean<T> producerMethodBean = producerMethodBeanCreator.getBean();
-                
-                webBeansContext.getDeploymentValidationService().validateProxyable(producerMethodBean);
-
-                if(specialize)
-                {
-                    producerMethodBeanCreator.configureProducerSpecialization(producerMethodBean,
(AnnotatedMethod<T>) annotatedMethod);
-                }
-                ProducerMethodProducerBuilder producerBuilder = new ProducerMethodProducerBuilder(producerMethodBean);
-                producerMethodBean.setProducer(producerBuilder.build(annotatedMethod));
-                producerMethodBean.setCreatorMethod(annotatedMethod.getJavaMember());
-                
-                webBeansContext.getWebBeansUtil().setBeanEnableFlagForProducerBean(bean,
-                        producerMethodBean,
-                        AnnotationUtil.asArray(annotatedMethod.getAnnotations()));
-                WebBeansUtil.checkProducerGenericType(producerMethodBean, annotatedMethod.getJavaMember());
-                producerBeans.add(producerMethodBean);
-                
-            }
-            
-        }
-        
-        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");
-        }
-    }
-
-    protected InjectionTarget<T> buildInjectionTarget(AnnotatedType<T> annotatedType,
-                                                      Set<InjectionPoint> points,
-                                                      WebBeansContext webBeansContext,
-                                                      List<AnnotatedMethod<?>>
postConstructMethods,
-                                                      List<AnnotatedMethod<?>>
preDestroyMethods)
-    {
-        InjectionTargetImpl<T> injectionTarget = new InjectionTargetImpl<T>(annotatedType,
points, webBeansContext, postConstructMethods, preDestroyMethods);
-
-        return injectionTarget;
-    }
-
-    protected abstract I createBean(Class<T> beanClass, boolean enabled);
-
-    protected final I createBean(Class<T> beanClass)
-    {
-        I bean =  createBean(beanClass, enabled);
-
-        //X TODO hack to set the InjectionTarget
-        InjectionTarget<T> injectionTarget
-                = buildInjectionTarget(bean.getAnnotatedType(), bean.getInjectionPoints(),
webBeansContext, getPostConstructMethods(), getPreDestroyMethods());
-        bean.setProducer(injectionTarget);
-
-        return bean;
-    }
-
-    protected List<AnnotatedMethod<?>> getPostConstructMethods()
-    {
-        List<AnnotatedMethod<?>> postConstructMethods = new ArrayList<AnnotatedMethod<?>>();
-        collectPostConstructMethods(annotatedType.getJavaClass(), postConstructMethods);
-        return postConstructMethods;
-    }
-
-    private void collectPostConstructMethods(Class<?> type, List<AnnotatedMethod<?>>
postConstructMethods)
-    {
-        if (type == null)
-        {
-            return;
-        }
-        collectPostConstructMethods(type.getSuperclass(), postConstructMethods);
-        for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
-        {
-            if (annotatedMethod.getJavaMember().getDeclaringClass() == type
-                && annotatedMethod.isAnnotationPresent(PostConstruct.class)
-                && annotatedMethod.getParameters().isEmpty())
-            {
-                postConstructMethods.add(annotatedMethod);
-            }
-        }
-    }
-
-    protected List<AnnotatedMethod<?>> getPreDestroyMethods()
-    {
-        List<AnnotatedMethod<?>> preDestroyMethods = new ArrayList<AnnotatedMethod<?>>();
-        collectPreDestroyMethods(annotatedType.getJavaClass(), preDestroyMethods);
-        return preDestroyMethods;
-    }
-
-    private void collectPreDestroyMethods(Class<?> type, List<AnnotatedMethod<?>>
preDestroyMethods)
-    {
-        if (type == null)
-        {
-            return;
-        }
-        collectPreDestroyMethods(type.getSuperclass(), preDestroyMethods);
-        for (AnnotatedMethod<?> annotatedMethod: annotatedType.getMethods())
-        {
-            if (annotatedMethod.getJavaMember().getDeclaringClass() == type
-                && annotatedMethod.isAnnotationPresent(PreDestroy.class)
-                && annotatedMethod.getParameters().isEmpty())
-            {
-                preDestroyMethods.add(annotatedMethod);
-            }
-        }
-    }
-
-    public boolean isEnabled()
-    {
-        return enabled;
-    }
-
-    public void defineEnabled()
-    {
-        enabled = webBeansContext.getWebBeansUtil().isBeanEnabled(annotatedType, annotatedType.getJavaClass(),
beanAttributes.getStereotypes());
-    }
-    
-    public I getBean()
-    {
-        I bean = createBean(annotatedType.getJavaClass());
-        for (InjectionPoint injectionPoint: webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
annotatedType))
-        {
-            bean.addInjectionPoint(injectionPoint);
-        }
-        return bean;
-    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1438245&r1=1438244&r2=1438245&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Thu Jan 24 22:45:33 2013
@@ -64,6 +64,7 @@ import org.apache.webbeans.component.cre
 import org.apache.webbeans.component.creation.CdiInterceptorBeanBuilder;
 import org.apache.webbeans.component.creation.DecoratorBeanBuilder;
 import org.apache.webbeans.component.creation.ManagedBeanBuilder;
+import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectableBeanManager;
 import org.apache.webbeans.container.InjectionResolver;
@@ -895,7 +896,7 @@ public class BeansDeployer
                 Set<ObserverMethod<?>> observerMethods = new HashSet<ObserverMethod<?>>();
                 if(managedBeanCreator.isEnabled())
                 {
-                    observerMethods = managedBeanCreator.defineObserverMethods(bean);
+                    observerMethods = new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
bean.getAnnotatedType()).defineObserverMethods(bean);
                 }
                 Set<ProducerMethodBean<?>> producerMethods = managedBeanCreator.defineProducerMethods(bean);
                 Set<ProducerFieldBean<?>> producerFields = managedBeanCreator.defineProducerFields(bean);

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=1438245&r1=1438244&r2=1438245&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
Thu Jan 24 22:45:33 2013
@@ -96,6 +96,7 @@ import org.apache.webbeans.component.Web
 import org.apache.webbeans.component.creation.BeanAttributesBuilder;
 import org.apache.webbeans.component.creation.ExtensionBeanBuilder;
 import org.apache.webbeans.component.creation.ManagedBeanBuilder;
+import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.component.creation.ProducerMethodProducerBuilder;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -475,7 +476,7 @@ public final class WebBeansUtil
         Asserts.nullCheckForClass(clazz);
         ExtensionBeanBuilder<T> extensionBeanCreator = new ExtensionBeanBuilder<T>(webBeansContext,
clazz);
         ExtensionBean<T> bean = extensionBeanCreator.getBean();
-        extensionBeanCreator.defineObserverMethods(bean);
+        new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
bean.getAnnotatedType()).defineObserverMethods(bean);
         return bean;
     }
 
@@ -1600,7 +1601,7 @@ public final class WebBeansUtil
         ManagedBean<T> managedBean = managedBeanCreator.getBean();
         managedBeanCreator.defineProducerMethods(managedBean);
         managedBeanCreator.defineProducerFields(managedBean);
-        managedBeanCreator.defineObserverMethods(managedBean);
+        new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
 
         if (managedBean instanceof InjectionTargetBean)
         {
@@ -1730,7 +1731,7 @@ public final class WebBeansUtil
         ManagedBean<T> managedBean = managedBeanCreator.getBean();
         managedBeanCreator.defineProducerMethods(managedBean);
         managedBeanCreator.defineProducerFields(managedBean);
-        managedBeanCreator.defineObserverMethods(managedBean);
+        new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
managedBean.getAnnotatedType()).defineObserverMethods(managedBean);
 
         if (managedBean instanceof InjectionTargetBean)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=1438245&r1=1438244&r2=1438245&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
Thu Jan 24 22:45:33 2013
@@ -20,7 +20,6 @@ package org.apache.webbeans.test;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -32,7 +31,6 @@ import javax.annotation.PreDestroy;
 import javax.decorator.Decorator;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.context.spi.Context;
-import javax.enterprise.inject.Typed;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
@@ -44,7 +42,6 @@ import org.apache.webbeans.component.Bea
 import org.apache.webbeans.component.CdiInterceptorBean;
 import org.apache.webbeans.component.DecoratorBean;
 import org.apache.webbeans.component.InjectionTargetBean;
-import org.apache.webbeans.component.AbstractProducerBean;
 import org.apache.webbeans.component.ManagedBean;
 import org.apache.webbeans.component.ProducerFieldBean;
 import org.apache.webbeans.component.ProducerMethodBean;
@@ -53,6 +50,7 @@ import org.apache.webbeans.component.cre
 import org.apache.webbeans.component.creation.CdiInterceptorBeanBuilder;
 import org.apache.webbeans.component.creation.DecoratorBeanBuilder;
 import org.apache.webbeans.component.creation.ManagedBeanBuilder;
+import org.apache.webbeans.component.creation.ObserverMethodsBuilder;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.DependentContext;
@@ -69,7 +67,6 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.decorator.clean.LargeTransactionDecorator;
 import org.apache.webbeans.test.component.decorator.clean.ServiceDecorator;
 import org.apache.webbeans.test.component.intercept.webbeans.ActionInterceptor;
-import org.apache.webbeans.test.component.intercept.webbeans.SecureAndTransactionalInterceptor;
 import org.apache.webbeans.test.component.intercept.webbeans.TransactionalInterceptor2;
 import org.apache.webbeans.test.containertests.ComponentResolutionByTypeTest;
 import org.apache.webbeans.test.mock.MockManager;
@@ -80,7 +77,6 @@ import org.apache.webbeans.test.sterotyp
 import org.apache.webbeans.test.sterotype.StereoWithSessionScope;
 import org.apache.webbeans.test.sterotype.StereoWithSessionScope2;
 import org.apache.webbeans.util.AnnotationUtil;
-import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.xml.WebBeansXMLConfigurator;
 
 /**
@@ -552,111 +548,8 @@ public abstract class TestContext implem
             manager.addBean(producerField);
         }
 
-        managedBeanCreator.defineObserverMethods(component);
+        new ObserverMethodsBuilder<T, InjectionTargetBean<T>>(webBeansContext,
component.getAnnotatedType()).defineObserverMethods(component);
 
         return component;
     }
-    
-    /**
-     * Configures the web bean api types.
-     * 
-     * @param <T> generic class type
-     * @param bean configuring web beans component
-     * @param clazz bean implementation class
-     */
-    private static <T> void defineApiTypes(AbstractOwbBean<T> bean, Class<T>
clazz)
-    {
-        //Looking for bean types
-        Typed beanTypes = clazz.getAnnotation(Typed.class);
-        if(beanTypes != null)
-        {
-            defineUserDefinedBeanTypes(bean, null, beanTypes);            
-        }
-        else
-        {
-            defineNormalApiTypes(bean, clazz);
-        }
-        removeIgnoredInterfaces(bean);
-    }
-
-    private static <T> void removeIgnoredInterfaces(AbstractOwbBean<T> bean)
-    {
-        Set<String> ignoredInterfaces = bean.getWebBeansContext().getOpenWebBeansConfiguration().getIgnoredInterfaces();
-        for (Iterator<Type> i = bean.getTypes().iterator(); i.hasNext(); )
-        {
-            Type t = i.next();
-            if (t instanceof Class && ignoredInterfaces.contains(((Class<?>)
t).getName()))
-            {
-                i.remove();
-            }
-        }
-    }
-    
-    private static <T> void defineUserDefinedBeanTypes(AbstractOwbBean<T> bean,
Type producerGenericReturnType, Typed beanTypes)
-    {
-        if(producerGenericReturnType != null)
-        {
-            defineNormalProducerMethodApi((AbstractProducerBean<T>)bean, producerGenericReturnType);
-        }
-        else
-        {
-            defineNormalApiTypes(bean, bean.getReturnType());
-        }
-        
-        //@Type values
-        Class<?>[] types = beanTypes.value();        
-        
-        //Normal api types
-        Set<Type> apiTypes = bean.getTypes();
-        //New api types
-        Set<Type> newTypes = new HashSet<Type>();
-        for(Class<?> type : types)
-        {
-            Type foundType = null;
-            
-            for(Type apiType : apiTypes)
-            {
-                if(ClassUtil.getClazz(apiType) == type)
-                {
-                    foundType = apiType;
-                    break;
-                }
-            }
-            
-            if(foundType == null)
-            {
-                throw new WebBeansConfigurationException("@Type values must be in bean api
types : " + bean.getTypes());
-            }
-            
-            newTypes.add(foundType);
-        }
-        
-        apiTypes.clear();
-        apiTypes.addAll(newTypes);
-        
-        apiTypes.add(Object.class);
-    }
-
-    private static <T> void defineNormalApiTypes(AbstractOwbBean<T> bean, Class<T>
clazz)
-    {
-        bean.getTypes().add(Object.class);
-        ClassUtil.setTypeHierarchy(bean.getTypes(), clazz);           
-    }
-
-    private static <T> void defineNormalProducerMethodApi(AbstractProducerBean<T>
producerBean, Type type)
-    {
-        Set<Type> types = producerBean.getTypes();
-        types.add(Object.class);
-        
-        Class<?> clazz  = ClassUtil.getClazz(type);
-        
-        if (clazz != null && (clazz.isPrimitive() || clazz.isArray()))
-        {
-            types.add(clazz);
-        }
-        else
-        {
-            ClassUtil.setTypeHierarchy(producerBean.getTypes(), type);
-        }                    
-    }
 }



Mime
View raw message