[webbeans-commits] Webbeans SVN: r3686 - in ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder: spi and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Sep 16 14:37:09 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-09-16 14:37:08 -0400 (Wed, 16 Sep 2009)
New Revision: 3686

Modified:
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderImpl.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/spi/ManagedBeanBuilder.java
Log:
Disposal beans should not be registered in the bean manager, and should be available in bean deployer environment before producer beans are created

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderImpl.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderImpl.java	2009-09-16 18:35:18 UTC (rev 3685)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderImpl.java	2009-09-16 18:37:08 UTC (rev 3686)
@@ -22,7 +22,9 @@
 package org.jboss.webbeans.bean.builder;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -68,26 +70,30 @@
  */
 public class BeanBuilderImpl<T> implements SimpleBeanBuilder<T>, EnterpriseBeanBuilder<T>, DecoratorBeanBuilder<T>, InternalObserverMethodBuilder<T>
 {
+   private final BeanManagerImpl beanManager;
+   
+   private final BeanDeployerEnvironment beanDeployerEnvironment;
+   
    private final AnnotatedType<T> type;
 
    private final EjbDescriptor<T> ejbDescriptor;
    
    private final boolean decorator;
 
+   private final boolean delayInitialization;
+
    private Bean<T> mainBean;
    
+   private Bean<T> newBean;
+   
+   private Set<Bean<?>> producers;
+   
    private Set<Bean<?>> beans;
    
    private Set<ObserverMethod<T, ?>> observerMethods;
    
-   private final BeanManagerImpl beanManager;
-   
-   private final BeanDeployerEnvironment beanDeployerEnvironment;
-   
    private final List<Throwable> definitionErrors = new ArrayList<Throwable>();
    
-   private final boolean delayInitialization;
-   
    private BeanBuilderImpl(BeanManager beanManager, BeanDeployerEnvironment beanDeployerEnvironment, AnnotatedType<T> type, EjbDescriptor<T> ejbDescriptor, boolean decorator, boolean delayInitialization)
    {
       if (beanManager != beanManager)
@@ -135,6 +141,19 @@
       return beans;
    }
 
+   public Bean<T> getNewBean()
+   {
+      return newBean;
+   }
+
+   public Set<Bean<?>> getProducerBeans()
+   {
+      if (producers == null)
+         return Collections.emptySet();
+      
+      return producers;
+   }
+
    private void createBeans()
    {
       if (decorator)
@@ -162,7 +181,7 @@
    
    private Set<Bean<?>> createSimpleBeans(WBClass<T> clazz)
    {
-      beans = new HashSet<Bean<?>>();
+      beans = new LinkedHashSet<Bean<?>>();
       ManagedBean<T> bean = ManagedBean.of(clazz, beanManager);
       mainBean = bean;
       
@@ -177,6 +196,8 @@
       NewManagedBean<T> newBean = NewManagedBean.of(clazz, beanManager);
       beanDeployerEnvironment.addBean(newBean);
       beans.add(newBean);
+      this.newBean = newBean;
+      
       if (!delayInitialization)
          newBean.initialize(beanDeployerEnvironment);
       
@@ -185,7 +206,7 @@
    
    private Set<Bean<?>> createEnterpriseBeans(InternalEjbDescriptor<T> ejbDescriptor)
    {
-      beans = new HashSet<Bean<?>>();
+      beans = new LinkedHashSet<Bean<?>>();
       SessionBean<T> bean = SessionBean.of(ejbDescriptor, beanManager);
       mainBean = bean;
       
@@ -199,6 +220,8 @@
       NewSessionBean<T> newBean = NewSessionBean.of(ejbDescriptor, beanManager);
       beanDeployerEnvironment.addBean(newBean);
       beans.add(newBean);
+      this.newBean = newBean;
+      
       if (!delayInitialization)
          newBean.initialize(beanDeployerEnvironment);
       
@@ -226,25 +249,32 @@
     */
    protected void createSubBeans(Set<Bean<?>> beans, AbstractClassBean<T> bean)
    {
-      createProducerMethods(beans, bean, bean.getAnnotatedItem());
+      //Register the disposal methods before the producer methods
+      createDisposalMethods(bean, bean.getAnnotatedItem());
+      
+      producers = createProducerMethods(beans, bean, bean.getAnnotatedItem());
       if (beanManager.isBeanEnabled(bean))
       {
          observerMethods = createObserverMethods(bean, bean.getAnnotatedItem());
       }
 
       createProducerFields(beans, bean, bean.getAnnotatedItem());
-      createDisposalMethods(beans, bean, bean.getAnnotatedItem());
    }
 
-   protected void createProducerMethods(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
+   protected Set<Bean<?>> createProducerMethods(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
    {
+      Set<Bean<?>> producers = null;
       for (WBMethod<?, ?> method : annotatedClass.getDeclaredWBAnnotatedMethods(Produces.class))
       {
+         if (producers == null)
+            producers = new HashSet<Bean<?>>();
+
          createProducerMethod(beans, declaringBean, method);         
       }
+      return producers;
    }
    
-   protected void createDisposalMethods(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
+   protected void createDisposalMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
    {
       for (WBMethod<?, ?> method : annotatedClass.getWBDeclaredMethodsWithAnnotatedParameters(Disposes.class))
       {
@@ -252,7 +282,6 @@
          beanDeployerEnvironment.addBean(disposalBean);
          //Do not delay initialization of decorator beans, they get initialized right away in the original impl
          disposalBean.initialize(beanDeployerEnvironment);
-         beans.add(disposalBean);
       }
    }
    
@@ -284,9 +313,11 @@
       
    public Set<ObserverMethod<T, ?>> createObserverMethods(RIBean<T> declaringBean, WBClass<T> annotatedClass)
    {
-      Set<ObserverMethod<T, ?>> methods = new HashSet<ObserverMethod<T, ?>>();
+      Set<ObserverMethod<T, ?>> methods = null;
       for (WBMethod<?, T> method : annotatedClass.getWBDeclaredMethodsWithAnnotatedParameters(Observes.class))
       {
+         if (methods == null)
+            methods = new HashSet<ObserverMethod<T, ?>>();
          methods.add(createObserverMethod(declaringBean, method));
       }
       return methods;

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/spi/ManagedBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/spi/ManagedBeanBuilder.java	2009-09-16 18:35:18 UTC (rev 3685)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/spi/ManagedBeanBuilder.java	2009-09-16 18:37:08 UTC (rev 3686)
@@ -34,5 +34,12 @@
 public interface ManagedBeanBuilder<T>
 {
    Set<Bean<?>> getBeans();
+   
+   Bean<T> getBean();
+   
+   Bean<T> getNewBean();
+   
+   Set<Bean<?>> getProducerBeans();
+   
    Set<ObserverMethod<T, ?>> getObserverMethods();
 }




More information about the weld-commits mailing list