[webbeans-commits] Webbeans SVN: r3713 - in ri/branches/kabir-builder: impl/src/main/java/org/jboss/webbeans/bean/builder and 3 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Sep 21 12:33:41 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-09-21 12:33:40 -0400 (Mon, 21 Sep 2009)
New Revision: 3713

Added:
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingDecorator.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/RIBeanBuilder.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java
Modified:
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractReceiverBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewManagedBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderFactoryImpl.java
   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/ee/EEResourceProducerField.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
   ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
Log:
Immutable beans and builder. Core tests pass

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -23,10 +23,8 @@
 
 import javax.decorator.Decorates;
 import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Alternative;
 import javax.enterprise.inject.Specializes;
 import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.stereotype.Stereotype;
 import javax.inject.Named;
 import javax.inject.Qualifier;
 
@@ -56,36 +54,45 @@
 public abstract class AbstractBean<T, E> extends RIBean<T>
 {
 
-   private static final Annotation ANY_LITERAL = new AnyLiteral();
-   private static final Annotation CURRENT_LITERAL = new DefaultLiteral();
+//   private static final Annotation ANY_LITERAL = new AnyLiteral();
+//   private static final Annotation CURRENT_LITERAL = new DefaultLiteral();
+//
+   private final boolean proxyable;
 
-   private boolean proxyable;
-
    // Logger
    private final Log log = Logging.getLog(AbstractBean.class);
+
    // The binding types
-   protected Set<Annotation> bindings;
+   private final Set<Annotation> bindings;
+   
    // The name
-   protected String name;
+   protected final String name;
+   
    // The scope type
-   protected Class<? extends Annotation> scopeType;
+   protected final Class<? extends Annotation> scopeType;
+   
    // The merged stereotypes
-   private MergedStereotypes<T, E> mergedStereotypes;
+   private final MergedStereotypes<T, E> mergedStereotypes;
+   
    // Is it a policy, either defined by stereotypes or directly?
-   private boolean policy;
+   private final boolean policy;
+   
    // The type
-   protected Class<T> type;
+   protected final Class<T> type;
+   
    // The API types
-   protected Set<Type> types;
+   protected final Set<Type> types;
+   
    // The injection points
-   private Set<WBInjectionPoint<?, ?>> injectionPoints;
-   private Set<WBInjectionPoint<?, ?>> delegateInjectionPoints;
+   private final Set<WBInjectionPoint<?, ?>> injectionPoints;
+   private final Set<WBInjectionPoint<?, ?>> delegateInjectionPoints;
+   
    // If the type a primitive?
-   private boolean primitive;
+   private final boolean primitive;
    // The Web Beans manager
-   protected BeanManagerImpl manager;
+   protected final BeanManagerImpl manager;
 
-   private boolean _serializable;
+   private final boolean serializable;
 
    private boolean initialized;
 
@@ -101,12 +108,33 @@
     * 
     * @param manager The Web Beans manager
     */
-   public AbstractBean(BeanManagerImpl manager)
+   public AbstractBean(BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, E> mergedStereotypes,
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean serializable,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
       super(manager);
       this.manager = manager;
       this.injectionPoints = new HashSet<WBInjectionPoint<?, ?>>();
       this.delegateInjectionPoints = new HashSet<WBInjectionPoint<?,?>>();
+      
+      this.name = name;
+      this.type = type;
+      this.types = types;
+      this.mergedStereotypes = mergedStereotypes;
+      this.scopeType = scopeType;
+      this.policy = policy;
+      this.primitive = Reflections.isPrimitive(type);
+      this.bindings = bindings;
+      this.serializable = serializable;
+      this.proxyable = proxyable;
+      
    }
 
    /**
@@ -115,27 +143,9 @@
    @Override
    public void initialize(BeanDeployerEnvironment environment)
    {
-      if (isSpecializing())
-      {
-         preSpecialize(environment);
-         specialize(environment);
-         postSpecialize();
-      }
-      initDefaultBindings();
-      initPrimitive();
-      log.trace("Building Web Bean bean metadata for #0", getType());
-      initName();
-      initScopeType();
-      initSerializable();
-      initProxyable();
       checkDelegateInjectionPoints();
    }
    
-   protected void initStereotypes()
-   {
-      mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager);
-   }
-
    protected void checkDelegateInjectionPoints()
    {
       if (this.delegateInjectionPoints.size() > 0)
@@ -166,90 +176,6 @@
       return delegateInjectionPoints;
    }
 
-   /**
-    * Initializes the API types
-    */
-   protected void initTypes()
-   {
-      types = getAnnotatedItem().getTypeClosure();
-   }
-
-   /**
-    * Initializes the binding types
-    */
-   protected void initBindings()
-   {
-      this.bindings = new HashSet<Annotation>();
-      this.bindings.addAll(getAnnotatedItem().getMetaAnnotations(Qualifier.class));
-      initDefaultBindings();
-      log.trace("Using binding types " + bindings + " specified by annotations");
-   }
-
-   protected void initDefaultBindings()
-   {
-      if (bindings.size() == 0)
-      {
-         log.trace("Adding default @Current binding type");
-         this.bindings.add(CURRENT_LITERAL);
-      }
-      this.bindings.add(ANY_LITERAL);
-   }
-
-   protected void initPolicy()
-   {
-      if (getAnnotatedItem().isAnnotationPresent(Alternative.class))
-      {
-         this.policy = true;
-      }
-      else
-      {
-         this.policy = getMergedStereotypes().isPolicy();
-      }
-   }
-
-   /**
-    * Initializes the name
-    */
-   protected void initName()
-   {
-      boolean beanNameDefaulted = false;
-      if (getAnnotatedItem().isAnnotationPresent(Named.class))
-      {
-         String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
-         if ("".equals(javaName))
-         {
-            log.trace("Using default name (specified by annotations)");
-            beanNameDefaulted = true;
-         }
-         else
-         {
-            if (log.isTraceEnabled())
-               log.trace("Using name " + javaName + " specified by annotations");
-            this.name = javaName;
-            return;
-         }
-      }
-
-      if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
-      {
-         this.name = getDefaultName();
-         return;
-      }
-   }
-
-   protected void initProxyable()
-   {
-      proxyable = getAnnotatedItem().isProxyable();
-   }
-
-   /**
-    * Initializes the primitive flag
-    */
-   protected void initPrimitive()
-   {
-      this.primitive = Reflections.isPrimitive(getType());
-   }
-
    private boolean checkInjectionPointsAreSerializable()
    {
       boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(this.getScope()).isPassivating();
@@ -269,60 +195,11 @@
    }
 
    /**
-    * Initializes the scope type
-    */
-   protected abstract void initScopeType();
-
-   protected boolean initScopeTypeFromStereotype()
-   {
-      Set<Annotation> possibleScopeTypes = getMergedStereotypes().getPossibleScopeTypes();
-      if (possibleScopeTypes.size() == 1)
-      {
-         this.scopeType = possibleScopeTypes.iterator().next().annotationType();
-         if (log.isTraceEnabled())
-            log.trace("Scope " + scopeType + " specified by stereotype");
-         return true;
-      }
-      else if (possibleScopeTypes.size() > 1)
-      {
-         throw new DefinitionException("All stereotypes must specify the same scope OR a scope must be specified on " + getAnnotatedItem());
-      }
-      else
-      {
-         return false;
-      }
-   }
-
-   protected void postSpecialize()
-   {
-      if (getAnnotatedItem().isAnnotationPresent(Named.class) && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
-      {
-         throw new DefinitionException("Cannot put name on specializing and specialized class " + getAnnotatedItem());
-      }
-      this.bindings.addAll(getSpecializedBean().getQualifiers());
-      if (isSpecializing() && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
-      {
-         this.name = getSpecializedBean().getName();
-      }
-      manager.getSpecializedBeans().put(getSpecializedBean(), this);
-   }
-
-   protected void preSpecialize(BeanDeployerEnvironment environment)
-   {
-
-   }
-
-   protected void specialize(BeanDeployerEnvironment environment)
-   {
-
-   }
-
-   /**
     * Returns the annotated time the bean represents
     * 
     * @return The annotated item
     */
-   protected abstract WBAnnotated<T, E> getAnnotatedItem();
+   public abstract WBAnnotated<T, E> getAnnotatedItem();
 
    /**
     * Gets the binding types
@@ -448,13 +325,13 @@
    {
       // TODO WTF - why are we not caching the serializability of injection
       // points!
-      return _serializable && checkInjectionPointsAreSerializable();
+      return serializable && checkInjectionPointsAreSerializable();
    }
 
-   protected void initSerializable()
-   {
-      _serializable = Reflections.isSerializable(type);
-   }
+//   protected void initSerializable()
+//   {
+//      _serializable = Reflections.isSerializable(type);
+//   }
 
    /**
     * Gets a string representation

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -21,33 +21,26 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
-import javassist.util.proxy.ProxyFactory;
 import javassist.util.proxy.ProxyObject;
 
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.NormalScope;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Decorator;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Scope;
 
 import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.DefinitionException;
 import org.jboss.webbeans.bean.proxy.DecoratorProxyMethodHandler;
-import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.injection.FieldInjectionPoint;
 import org.jboss.webbeans.injection.MethodInjectionPoint;
 import org.jboss.webbeans.introspector.WBClass;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.util.Beans;
-import org.jboss.webbeans.util.Proxies;
 import org.jboss.webbeans.util.Strings;
 
 /**
@@ -62,22 +55,26 @@
 {
    // Logger
    private static final LogProvider log = Logging.getLogProvider(AbstractClassBean.class);
+   
    // The item representation
-   protected WBClass<T> annotatedItem;
+   protected final WBClass<T> annotatedItem;
+
    // The injectable fields
-   private Set<FieldInjectionPoint<?, ?>> injectableFields;
+   private final Set<FieldInjectionPoint<?, ?>> injectableFields;
+   
    // The initializer methods
-   private Set<MethodInjectionPoint<?, ?>> initializerMethods;
-   private Set<String> dependencies;
+   private final Set<MethodInjectionPoint<?, ?>> initializerMethods;
    
-   private List<Decorator<?>> decorators;
+   private final Set<String> dependencies;
    
+   private final List<Decorator<?>> decorators;
+   
    private final String id;
-   private Class<T> proxyClassForDecorators;
+   private final Class<T> proxyClassForDecorators;
    
    private final ThreadLocal<Integer> decoratorStackPosition;
-   private WBMethod<?, ?> postConstruct;
-   private WBMethod<?, ?> preDestroy;
+   private final WBMethod<?, ?> postConstruct;
+   private final WBMethod<?, ?> preDestroy;
 
    /**
     * Constructor
@@ -85,9 +82,23 @@
     * @param type The type
     * @param manager The Web Beans manager
     */
-   protected AbstractClassBean(WBClass<T> type, BeanManagerImpl manager)
+   protected AbstractClassBean(WBClass<T> type, 
+         BeanManagerImpl manager,
+         String name,
+         Set<Type> types,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean serializable,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy)
    {
-      super(manager);
+      super(manager, name, type.getJavaClass(), types, mergedStereotypes, scopeType, policy, serializable, proxyable, bindings);
       this.annotatedItem = type;
       this.id = createId(getClass().getSimpleName() + "-" + type.getName());
       this.decoratorStackPosition = new ThreadLocal<Integer>()
@@ -100,23 +111,16 @@
          }
          
       };
-      initStereotypes();
-      initPolicy();
-   }
+      this.dependencies = dependencies;
+      this.proxyClassForDecorators = proxyClassForDecorators;
+      this.decorators = decorators;
+      this.postConstruct = postConstruct;
+      this.preDestroy = preDestroy;
+      this.injectableFields = initInjectableFields();
+      this.initializerMethods = initInitializerMethods();
 
-   /**
-    * Initializes the bean and its metadata
-    */
-   @Override
-   public void initialize(BeanDeployerEnvironment environment)
-   {
-      initInitializerMethods();
-      initInjectableFields();
-      super.initialize(environment);
       checkBeanImplementation();
-      initDecorators();
       checkType();
-      initProxyClassForDecoratedBean();
    }
    
    protected void checkType()
@@ -124,30 +128,11 @@
       
    }
    
-   protected void initDecorators()
-   {
-      this.decorators = getManager().resolveDecorators(getTypes(), getQualifiers());
-   }
-   
    public boolean hasDecorators()
    {
       return this.decorators != null && this.decorators.size() > 0;
    }
    
-   protected void initProxyClassForDecoratedBean()
-   {
-      if (hasDecorators())
-      {
-         Set<Type> types = new LinkedHashSet<Type>(getTypes());
-         ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
-   
-         @SuppressWarnings("unchecked")
-         Class<T> proxyClass = proxyFactory.createClass();
-   
-         this.proxyClassForDecorators = proxyClass;
-      }
-   }
-   
    protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint)
    {
       List<SerializableBeanInstance<DecoratorImpl<Object>, Object>> decoratorInstances = new ArrayList<SerializableBeanInstance<DecoratorImpl<Object>,Object>>();
@@ -163,7 +148,6 @@
             {
                decoratorStackPosition.set(++i);
                
-               @SuppressWarnings("unchecked")
                DecoratorImpl<Object> decoratorBean = (DecoratorImpl<Object>) decorator;
                
                Object decoratorInstance = getManager().getReference(ip, decorator, creationalContext);
@@ -211,87 +195,30 @@
    
 
    /**
-    * Initializes the bean type
-    */
-   protected void initType()
-   {
-      log.trace("Bean type specified in Java");
-      this.type = getAnnotatedItem().getJavaClass();
-      this.dependencies = new HashSet<String>();
-      for (Class<?> clazz = type.getSuperclass(); clazz != Object.class; clazz = clazz.getSuperclass())
-      {
-         dependencies.add(clazz.getName());
-      }
-   }
-
-   /**
     * Initializes the injection points
     */
-   protected void initInjectableFields()
+   protected Set<FieldInjectionPoint<?, ?>> initInjectableFields()
    {
-      injectableFields = new HashSet<FieldInjectionPoint<?, ?>>(Beans.getFieldInjectionPoints(this, annotatedItem));
+      Set<FieldInjectionPoint<?, ?>> injectableFields = new HashSet<FieldInjectionPoint<?, ?>>(Beans.getFieldInjectionPoints(this, annotatedItem));
       addInjectionPoints(injectableFields);
+      return injectableFields;
    }
 
    /**
     * Initializes the initializer methods
     */
-   protected void initInitializerMethods()
+   protected Set<MethodInjectionPoint<?, ?>> initInitializerMethods()
    {
-      initializerMethods = Beans.getInitializerMethods(this, getAnnotatedItem());
+      Set<MethodInjectionPoint<?, ?>> initializerMethods = Beans.getInitializerMethods(this, getAnnotatedItem());
       addInjectionPoints(Beans.getParameterInjectionPoints(this, initializerMethods));
+      return initializerMethods;
    }
 
-   @Override
-   protected void initScopeType()
-   {
-      for (WBClass<?> clazz = getAnnotatedItem(); clazz != null; clazz = clazz.getWBSuperclass())
-      {
-         Set<Annotation> scopeTypes = new HashSet<Annotation>();
-         scopeTypes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class));
-         scopeTypes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class));
-         if (scopeTypes.size() == 1)
-         {
-            if (getAnnotatedItem().isAnnotationPresent(scopeTypes.iterator().next().annotationType()))
-            {
-               this.scopeType = scopeTypes.iterator().next().annotationType();
-               log.trace("Scope " + scopeType + " specified by annotation");
-            }
-            break;
-         }
-         else if (scopeTypes.size() > 1)
-         {
-            throw new DefinitionException("At most one scope may be specified on " + getAnnotatedItem());
-         }
-      }
-
-      if (this.scopeType == null)
-      {
-         initScopeTypeFromStereotype();
-      }
-
-      if (this.scopeType == null)
-      {
-         this.scopeType = Dependent.class;
-         log.trace("Using default @Dependent scope");
-      }
-   }
-
    /**
     * Validates the bean implementation
     */
    protected void checkBeanImplementation() {}
 
-   @Override
-   protected void preSpecialize(BeanDeployerEnvironment environment)
-   {
-      super.preSpecialize(environment);
-      if (getAnnotatedItem().getWBSuperclass() == null || getAnnotatedItem().getWBSuperclass().getJavaClass().equals(Object.class))
-      {
-         throw new DefinitionException("Specializing bean must extend another bean " + toString());
-      }
-   }
-
    /**
     * Gets the annotated item
     * 
@@ -391,22 +318,6 @@
    }
 
    /**
-    * Initializes the post-construct method
-    */
-   protected void initPostConstruct()
-   {
-      this.postConstruct = Beans.getPostConstruct(getAnnotatedItem());
-   }
-
-   /**
-    * Initializes the pre-destroy method
-    */
-   protected void initPreDestroy()
-   {
-      this.preDestroy = Beans.getPreDestroy(getAnnotatedItem());
-   }
-
-   /**
     * Returns the post-construct method
     * 
     * @return The post-construct method

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -25,18 +25,14 @@
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
 import java.lang.reflect.WildcardType;
-import java.util.HashSet;
 import java.util.Set;
 
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.NormalScope;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.IllegalProductException;
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.Producer;
 import javax.inject.Inject;
-import javax.inject.Scope;
 
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.DefinitionException;
@@ -44,6 +40,7 @@
 import org.jboss.webbeans.introspector.WBMember;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Names;
@@ -67,13 +64,22 @@
     * @param declaringBean The declaring bean
     * @param manager The Web Beans manager
     */
-   public AbstractProducerBean(AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public AbstractProducerBean(AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, S> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(declaringBean, manager);
+      super(declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, false, proxyable, bindings);
    }
 
    @Override
-   protected abstract WBMember<T, ?, S> getAnnotatedItem();
+   public abstract WBMember<T, ?, S> getAnnotatedItem();
 
    @Override
    // Overriden to provide the class of the bean that declares the producer method/field
@@ -82,47 +88,47 @@
       return getDeclaringBean().getBeanClass();
    }
 
-   /**
-    * Initializes the API types
-    */
-   @Override
-   protected void initTypes()
-   {
-      if (getType().isArray() || getType().isPrimitive())
-      {
-         Set<Type> types = new HashSet<Type>();
-         types = new HashSet<Type>();
-         types.add(getType());
-         types.add(Object.class);
-         super.types = types;
-      }
-      else if (getType().isInterface())
-      {
-         Set<Type> types = new HashSet<Type>();
-         types.add(Object.class);
-         types.addAll(getAnnotatedItem().getTypeClosure());
-         super.types = types;
-      }
-      else
-      {
-         super.initTypes();
-      }
-   }
+//   /**
+//    * Initializes the API types
+//    */
+//   @Override
+//   protected void initTypes()
+//   {
+//      if (getType().isArray() || getType().isPrimitive())
+//      {
+//         Set<Type> types = new HashSet<Type>();
+//         types = new HashSet<Type>();
+//         types.add(getType());
+//         types.add(Object.class);
+//         super.types = types;
+//      }
+//      else if (getType().isInterface())
+//      {
+//         Set<Type> types = new HashSet<Type>();
+//         types.add(Object.class);
+//         types.addAll(getAnnotatedItem().getTypeClosure());
+//         super.types = types;
+//      }
+//      else
+//      {
+//         super.initTypes();
+//      }
+//   }
 
-   /**
-    * Initializes the type
-    */
-   protected void initType()
-   {
-      try
-      {
-         this.type = getAnnotatedItem().getJavaClass();
-      }
-      catch (ClassCastException e)
-      {
-         throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getJavaClass() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
-      }
-   }
+//   /**
+//    * Initializes the type
+//    */
+//   protected void initType()
+//   {
+//      try
+//      {
+//         this.type = getAnnotatedItem().getJavaClass();
+//      }
+//      catch (ClassCastException e)
+//      {
+//         throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getJavaClass() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
+//      }
+//   }
 
    /**
     * Gets the declared bean type
@@ -228,39 +234,39 @@
       }
    }
 
-   @Override
-   protected void initScopeType()
-   {
-      Set<Annotation> scopeAnnotations = new HashSet<Annotation>();
-      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(Scope.class));
-      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(NormalScope.class));
-      if (scopeAnnotations.size() > 1)
-      {
-         throw new DefinitionException("At most one scope may be specified");
-      }
-      if (scopeAnnotations.size() == 1)
-      {
-         this.scopeType = scopeAnnotations.iterator().next().annotationType();
-         log.trace("Scope " + scopeType + " specified by annotation");
-         return;
-      }
+//   @Override
+//   protected void initScopeType()
+//   {
+//      Set<Annotation> scopeAnnotations = new HashSet<Annotation>();
+//      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(Scope.class));
+//      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(NormalScope.class));
+//      if (scopeAnnotations.size() > 1)
+//      {
+//         throw new DefinitionException("At most one scope may be specified");
+//      }
+//      if (scopeAnnotations.size() == 1)
+//      {
+//         this.scopeType = scopeAnnotations.iterator().next().annotationType();
+//         log.trace("Scope " + scopeType + " specified by annotation");
+//         return;
+//      }
+//
+//      initScopeTypeFromStereotype();
+//
+//      if (this.scopeType == null)
+//      {
+//         this.scopeType = Dependent.class;
+//         log.trace("Using default @Dependent scope");
+//      }
+//   }
+//   
+//   @Override
+//   protected void initSerializable()
+//   {
+//      // No-op
+//   }
 
-      initScopeTypeFromStereotype();
-
-      if (this.scopeType == null)
-      {
-         this.scopeType = Dependent.class;
-         log.trace("Using default @Dependent scope");
-      }
-   }
-   
    @Override
-   protected void initSerializable()
-   {
-      // No-op
-   }
-
-   @Override
    public boolean isSerializable()
    {
       return true;

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractReceiverBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractReceiverBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractReceiverBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -16,7 +16,10 @@
  */
 package org.jboss.webbeans.bean;
 
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.Alternative;
@@ -26,6 +29,7 @@
 import org.jboss.webbeans.context.WBCreationalContext;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 
 /**
  * @author pmuir
@@ -36,12 +40,23 @@
 
    private static final LogProvider log = Logging.getLogProvider(AbstractReceiverBean.class);
    
-   private AbstractClassBean<?> declaringBean;
-   private boolean policy;
+   private final AbstractClassBean<?> declaringBean;
+   
 
-   public AbstractReceiverBean(AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+
+   public AbstractReceiverBean(AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, S> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean serializable,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(manager);
+      super(manager, name, type, types, mergedStereotypes, scopeType, policy, serializable, proxyable, bindings);
       this.declaringBean = declaringBean;
    }
    
@@ -90,31 +105,4 @@
    {
       return declaringBean;
    }
-   
-   /* (non-Javadoc)
-    * @see org.jboss.webbeans.bean.AbstractBean#isPolicy()
-    */
-   @Override
-   public boolean isAlternative()
-   {
-      return policy;
-   }
-   
-   @Override
-   protected void initPolicy()
-   {
-      if (getDeclaringBean().isAlternative())
-      {
-         this.policy = true;
-      }
-      else if (getAnnotatedItem().isAnnotationPresent(Alternative.class))
-      {
-         this.policy = true;
-      }
-      else if (getMergedStereotypes().isPolicy())
-      {
-         this.policy = true;
-      }
-   }
-
 }

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -33,6 +33,8 @@
 import org.jboss.webbeans.injection.MethodInjectionPoint;
 import org.jboss.webbeans.injection.WBInjectionPoint;
 import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 
 public class DecoratorImpl<T> extends ManagedBean<T> implements Decorator<T>
 {
@@ -71,9 +73,21 @@
     * @param manager the current manager
     * @return a Bean
     */
-   public static <T> DecoratorImpl<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   public static <T> DecoratorImpl<T> of(WBClass<T> clazz, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      return new DecoratorImpl<T>(clazz, manager);
+      return new DecoratorImpl<T>(clazz, manager, name, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies, 
+            postConstruct, preDestroy, specializedBean);
    }
 
    private WBInjectionPoint<?, ?> delegateInjectionPoint;
@@ -82,9 +96,21 @@
    private Set<Type> delegateTypes;
    private Set<Type> decoratedTypes;
 
-   protected DecoratorImpl(WBClass<T> type, BeanManagerImpl manager)
+   protected DecoratorImpl(WBClass<T> type, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      super(type, manager);
+      super(type, manager, name, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies, null, null, 
+            postConstruct, preDestroy, specializedBean);
    }
 
    @Override
@@ -209,12 +235,6 @@
       return delegateTypes;
    }
    
-   @Override
-   protected void initDecorators()
-   {
-      // No-op, decorators can't have decorators
-   }
-   
    /* (non-Javadoc)
     * @see org.jboss.webbeans.bean.SimpleBean#toString()
     */

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -34,6 +34,8 @@
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.injection.MethodInjectionPoint;
 import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
+import org.jboss.webbeans.util.Reflections;
 
 public class DisposalMethod<T> extends AbstractReceiverBean<T, Method>
 {
@@ -41,16 +43,23 @@
    protected MethodInjectionPoint<T, ?> disposalMethodInjectionPoint;
    private final String id;
 
-   protected DisposalMethod(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
+   protected DisposalMethod(BeanManagerImpl manager, 
+         String name,
+         WBMethod<T, ?> disposalMethod, 
+         AbstractClassBean<?> declaringBean,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Method> mergedStereotypes, 
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(declaringBean, manager);
+      super(declaringBean, manager, name, type, types, mergedStereotypes, null, policy, Reflections.isSerializable(type), proxyable, bindings);
       this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
       this.id = createId("DisposalMethod-" + declaringBean.getName() + "-" + disposalMethod.getSignature().toString());
-      initBindings();
-      initType();
-      initTypes();
-      initStereotypes();
-      initPolicy();
+//      initBindings();
+//      initType();
+//      initTypes();
    }
    
    @Override
@@ -61,46 +70,28 @@
       checkDisposalMethod();
    }
 
-   @SuppressWarnings("unchecked")
-   protected void initType()
-   {
-      this.type = (Class<T>) disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).get(0).getJavaClass();
-   }
-
    @Override
    public WBMethod<T, ?> getAnnotatedItem()
    {
       return disposalMethodInjectionPoint;
    }
 
-   public static <T> DisposalMethod<T> of(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
+   public static <T> DisposalMethod<T> of(BeanManagerImpl manager, 
+         String name,
+         WBMethod<T, ?> disposalMethod, 
+         AbstractClassBean<?> declaringBean,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Method> mergedStereotypes, 
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      return new DisposalMethod<T>(manager, disposalMethod, declaringBean);
+      return new DisposalMethod<T>(manager, name, disposalMethod, declaringBean, type, types, mergedStereotypes, policy, proxyable, bindings);
    }
 
-   @Override
-   protected void initBindings()
-   {
-      // At least 1 parameter exists, already checked in constructor
-      this.bindings = new HashSet<Annotation>();
-      this.bindings.addAll(disposalMethodInjectionPoint.getWBParameters().get(0).getQualifiers());
-      initDefaultBindings();
-   }
 
-   /**
-    * Initializes the API types
-    */
    @Override
-   protected void initTypes()
-   {
-      Set<Type> types = new HashSet<Type>();
-      types = new HashSet<Type>();
-      types.addAll(disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).get(0).getTypeClosure());
-      types.add(Object.class);
-      super.types = types;
-   }
-
-   @Override
    public String getName()
    {
       return null;
@@ -244,11 +235,11 @@
       return null;
    }
    
-   @Override
-   protected void initScopeType()
-   {
-      // Disposal methods aren't scoped
-   }
+//   @Override
+//   protected void initScopeType()
+//   {
+//      // Disposal methods aren't scoped
+//   }
 
    public Set<Class<? extends Annotation>> getStereotypes()
    {

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -16,6 +16,8 @@
  */
 package org.jboss.webbeans.bean;
 
+import java.lang.annotation.Annotation;
+import java.util.List;
 import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
@@ -36,6 +38,7 @@
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Names;
@@ -54,13 +57,13 @@
    private static LogProvider log = Logging.getLogProvider(ManagedBean.class);
 
    // The constructor
-   private ConstructorInjectionPoint<T> constructor;
-   private Set<WBInjectionPoint<?, ?>> ejbInjectionPoints;
-   private Set<WBInjectionPoint<?, ?>> persistenceContextInjectionPoints;
-   private Set<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
-   private Set<WBInjectionPoint<?, ?>> resourceInjectionPoints;
+   private final ConstructorInjectionPoint<T> constructor;
+   private final Set<WBInjectionPoint<?, ?>> ejbInjectionPoints;
+   private final Set<WBInjectionPoint<?, ?>> persistenceContextInjectionPoints;
+   private final Set<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
+   private final Set<WBInjectionPoint<?, ?>> resourceInjectionPoints;
 
-   private ManagedBean<?> specializedBean;
+   private final  ManagedBean<?> specializedBean;
 
    
 
@@ -72,9 +75,23 @@
     * @param manager the current manager
     * @return A Web Bean
     */
-   public static <T> ManagedBean<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   public static <T> ManagedBean<T> of(WBClass<T> clazz, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      return new ManagedBean<T>(clazz, manager);
+      return new ManagedBean<T>(clazz, manager, name, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, specializedBean);
    }
 
    /**
@@ -83,12 +100,33 @@
     * @param type The type of the bean
     * @param manager The Web Beans manager
     */
-   protected ManagedBean(WBClass<T> type, BeanManagerImpl manager)
+   protected ManagedBean(WBClass<T> type, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      super(type, manager);
-      initType();
-      initTypes();
-      initBindings();
+      super(type, manager, name, type.getTypeClosure(), mergedStereotypes, scopeType, policy, Reflections.isSerializable(type.getJavaClass()), proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy);
+      this.specializedBean = specializedBean;
+      this.constructor = initConstructor();
+      this.ejbInjectionPoints = Beans.getEjbInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.persistenceContextInjectionPoints = Beans.getPersistenceContextInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.persistenceUnitInjectionPoints = Beans.getPersistenceUnitInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.resourceInjectionPoints = Beans.getResourceInjectionPoints(this, getAnnotatedItem(), manager);
+      
+      checkConstructor();
+
+
    }
 
    /**
@@ -182,22 +220,12 @@
    {
       if (!isInitialized())
       {
-         initConstructor();
-         checkConstructor();
          super.initialize(environment);
-         initPostConstruct();
-         initPreDestroy();
-         initEEInjectionPoints();
+//         initPostConstruct();
+//         initPreDestroy();
       }
    }
 
-   private void initEEInjectionPoints()
-   {
-      this.ejbInjectionPoints = Beans.getEjbInjectionPoints(this, getAnnotatedItem(), getManager());
-      this.persistenceContextInjectionPoints = Beans.getPersistenceContextInjectionPoints(this, getAnnotatedItem(), getManager());
-      this.persistenceUnitInjectionPoints = Beans.getPersistenceUnitInjectionPoints(this, getAnnotatedItem(), getManager());
-      this.resourceInjectionPoints = Beans.getResourceInjectionPoints(this, getAnnotatedItem(), manager);
-   }
 
    /**
     * Validates the type
@@ -273,43 +301,15 @@
       }
    }
 
-   @Override
-   protected void preSpecialize(BeanDeployerEnvironment environment)
-   {
-      super.preSpecialize(environment);
-      if (environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
-      {
-         throw new DefinitionException("Simple bean must specialize a simple bean");
-      }
-   }
-
-   @Override
-   protected void specialize(BeanDeployerEnvironment environment)
-   {
-      if (environment.getClassBean(getAnnotatedItem().getWBSuperclass()) == null)
-      {
-         throw new DefinitionException(toString() + " does not specialize a bean");
-      }
-      AbstractClassBean<?> specializedBean = environment.getClassBean(getAnnotatedItem().getWBSuperclass());
-      if (!(specializedBean instanceof ManagedBean))
-      {
-         throw new DefinitionException(toString() + " doesn't have a simple bean as a superclass " + specializedBean);
-      }
-      else
-      {
-         this.specializedBean = (ManagedBean<?>) specializedBean;
-      }
-   }
-
-
    /**
     * Initializes the constructor
     */
-   protected void initConstructor()
+   protected ConstructorInjectionPoint<T> initConstructor()
    {
-      this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
+      ConstructorInjectionPoint<T> ctor = Beans.getBeanConstructor(this, getAnnotatedItem());
       // TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
-      addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
+      addInjectionPoints(Beans.getParameterInjectionPoints(this, ctor));
+      return ctor;
    }
 
    /**

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewManagedBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewManagedBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewManagedBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -18,13 +18,17 @@
 
 import java.lang.annotation.Annotation;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.Decorator;
 
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.literal.NewLiteral;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 
 /**
  * Represents a @New simple bean
@@ -41,9 +45,23 @@
     * @param manager The Web Beans manager
     * @return a new NewSimpleBean instance
     */
-   public static <T> NewManagedBean<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   public static <T> NewManagedBean<T> of(WBClass<T> clazz, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      return new NewManagedBean<T>(clazz, manager);
+      return new NewManagedBean<T>(clazz, manager, name, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies, 
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, specializedBean);
    }
    
    private Set<Annotation> bindings;
@@ -54,9 +72,23 @@
     * @param type An annotated class
     * @param manager The Web Beans manager
     */
-   protected NewManagedBean(final WBClass<T> type, BeanManagerImpl manager)
+   protected NewManagedBean(final WBClass<T> type, 
+         BeanManagerImpl manager, 
+         String name,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         ManagedBean<?> specializedBean)
    {
-      super(type, manager);
+      super(type, manager, name, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, specializedBean);
       this.bindings = new HashSet<Annotation>();
       this.bindings.add(new NewLiteral()
       {

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -17,15 +17,20 @@
 package org.jboss.webbeans.bean;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.Decorator;
 
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.ejb.InternalEjbDescriptor;
 import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.literal.NewLiteral;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.resources.ClassTransformer;
 
 /**
@@ -43,10 +48,26 @@
     * @param manager The Web Beans manager
     * @return a new NewEnterpriseBean instance
     */
-   public static <T> NewSessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   public static <T> NewSessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, 
+         BeanManagerImpl manager, 
+         String name,
+         Set<Type> types,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         Class<T> proxyClass,
+         SessionBean<?> specializedBean)
    {
       WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
-      return new NewSessionBean<T>(type, ejbDescriptor, manager);
+      return new NewSessionBean<T>(type, ejbDescriptor, manager, name, types, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, proxyClass, specializedBean);
    }
    
    private Set<Annotation> bindings;
@@ -57,9 +78,26 @@
     * @param type An annotated class
     * @param manager The Web Beans manager
     */
-   protected NewSessionBean(final WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   protected NewSessionBean(final WBClass<T> type, 
+         InternalEjbDescriptor<T> ejbDescriptor, 
+         BeanManagerImpl manager, 
+         String name,
+         Set<Type> types,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         Class<T> proxyClass,
+         SessionBean<?> specializedBean)
    {
-      super(type, ejbDescriptor, manager);
+      super(type, ejbDescriptor, manager, name, types, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, proxyClass, specializedBean);
       this.bindings = new HashSet<Annotation>();
       this.bindings.add(new NewLiteral()
       {

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerField.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -18,6 +18,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.Type;
 import java.util.Collections;
 import java.util.Set;
 
@@ -26,6 +27,7 @@
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.util.Names;
 
 /**
@@ -38,7 +40,7 @@
 public class ProducerField<T> extends AbstractProducerBean<T, Field>
 {
    // The underlying field
-   private WBField<T, ?> field;
+   private final WBField<T, ?> field;
    private final String id;
    
    /**
@@ -49,9 +51,19 @@
     * @param manager the current manager
     * @return A producer field
     */
-   public static <T> ProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public static <T> ProducerField<T> of(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      return new ProducerField<T>(field, declaringBean, manager);
+      return new ProducerField<T>(field, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
    }
 
    /**
@@ -61,16 +73,26 @@
     * @param declaringBean The declaring bean
     * @param manager The Web Beans manager
     */
-   protected ProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   protected ProducerField(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(declaringBean, manager);
+      super(declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
       this.field = field;
-      initType();
-      initTypes();
-      initBindings();
+//      initType();
+//      initTypes();
+//      initBindings();
       this.id = createId("ProducerField-" + declaringBean.getType().getName() + "-"+ field.getName());
-      initStereotypes();
-      initPolicy();
+//      initStereotypes();
+//      initPolicy();
    }
    
    @Override
@@ -104,7 +126,7 @@
     * @return The annotated item
     */
    @Override
-   protected WBField<T, ?> getAnnotatedItem()
+   public WBField<T, ?> getAnnotatedItem()
    {
       return field;
    }

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -34,6 +34,7 @@
 import org.jboss.webbeans.injection.ParameterInjectionPoint;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.introspector.WBParameter;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.util.Names;
 
 /**
@@ -48,9 +49,9 @@
    // The underlying method
    private MethodInjectionPoint<T, ?> method;
 
-   private DisposalMethod<?> disposalMethodBean;
+   private final DisposalMethod<?> disposalMethodBean;
 
-   private ProducerMethod<?> specializedBean;
+   private final ProducerMethod<?> specializedBean;
 
    private final String id;
 
@@ -62,21 +63,42 @@
     * @param manager the current manager
     * @return A producer Web Bean
     */
-   public static <T> ProducerMethod<T> of(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public static <T> ProducerMethod<T> of(WBMethod<T, ?> method, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Method> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         DisposalMethod<?> disposalMethodBean,
+         final ProducerMethod<?> specializedBean)
    {
-      return new ProducerMethod<T>(method, declaringBean, manager);
+      return new ProducerMethod<T>(method, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings, disposalMethodBean, specializedBean);
    }
 
-   protected ProducerMethod(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   protected ProducerMethod(WBMethod<T, ?> method, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Method> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         DisposalMethod<?> disposalMethodBean,
+         final ProducerMethod<?> specializedBean)
    {
-      super(declaringBean, manager);
+      super(declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
       this.method = MethodInjectionPoint.of(this, method);
-      initType();
-      initTypes();
-      initBindings();
+      this.disposalMethodBean = disposalMethodBean;
+      this.specializedBean = specializedBean;
       this.id = createId("ProducerMethod-" + declaringBean.getType().getName() + "-" + method.getSignature().toString());
-      initStereotypes();
-      initPolicy();
    }
 
    public T produce(CreationalContext<T> creationalContext)
@@ -103,7 +125,6 @@
          initProducerMethodInjectableParameters();
          super.initialize(environment);
          checkProducerMethod();
-         initDisposalMethod(environment);
       }
    }
 
@@ -158,24 +179,6 @@
       }
    }
 
-   /**
-    * Initializes the remove method
-    */
-   protected void initDisposalMethod(BeanDeployerEnvironment environment)
-   {
-      Set<DisposalMethod<?>> disposalBeans = environment.resolveDisposalBeans(getTypes(), getQualifiers(), getDeclaringBean());
-
-      if (disposalBeans.size() == 1)
-      {
-         this.disposalMethodBean = disposalBeans.iterator().next();
-      }
-      else if (disposalBeans.size() > 1)
-      {
-         // TODO List out found disposal methods
-         throw new DefinitionException("Cannot declare multiple disposal methods for this producer method. Producer method: " + this + ". Disposal methods: " + disposalBeans);
-      }
-   }
-
    public void destroy(T instance, CreationalContext<T> creationalContext)
    {
       try
@@ -260,26 +263,6 @@
    }
 
    @Override
-   protected void preSpecialize(BeanDeployerEnvironment environment)
-   {
-      if (getDeclaringBean().getAnnotatedItem().getWBSuperclass().getDeclaredWBMethod(getAnnotatedItem().getAnnotatedMethod()) == null)
-      {
-         throw new DefinitionException("Specialized producer method does not override a method on the direct superclass");
-      }
-   }
-
-   @Override
-   protected void specialize(BeanDeployerEnvironment environment)
-   {
-      WBMethod<?, ?> superClassMethod = getDeclaringBean().getAnnotatedItem().getWBSuperclass().getWBMethod(getAnnotatedItem().getAnnotatedMethod());
-      if (environment.getProducerMethod(superClassMethod) == null)
-      {
-         throw new IllegalStateException(toString() + " does not specialize a bean");
-      }
-      this.specializedBean = environment.getProducerMethod(superClassMethod);
-   }
-
-   @Override
    public String getId()
    {
       return id;

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -36,7 +36,6 @@
  */
 public abstract class RIBean<T> implements Bean<T> 
 {
-   
    private static final ConcurrentMap<String, AtomicInteger> ids = new ConcurrentHashMap<String, AtomicInteger>();
    
    private final BeanManagerImpl manager;

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -16,17 +16,14 @@
  */
 package org.jboss.webbeans.bean;
 
-import java.io.Serializable;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
-import javassist.util.proxy.ProxyFactory;
 import javassist.util.proxy.ProxyObject;
 
 import javax.decorator.Decorator;
@@ -44,16 +41,15 @@
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.ejb.InternalEjbDescriptor;
 import org.jboss.webbeans.ejb.api.SessionObjectReference;
-import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
 import org.jboss.webbeans.ejb.spi.EjbServices;
 import org.jboss.webbeans.injection.InjectionContextImpl;
 import org.jboss.webbeans.introspector.WBClass;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.log.Log;
 import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.resources.ClassTransformer;
 import org.jboss.webbeans.util.Beans;
-import org.jboss.webbeans.util.Proxies;
 
 /**
  * An enterprise bean representation
@@ -67,11 +63,11 @@
    private final Log log = Logging.getLog(SessionBean.class);
 
    // The EJB descriptor
-   private InternalEjbDescriptor<T> ejbDescriptor;
+   private final InternalEjbDescriptor<T> ejbDescriptor;
 
-   private Class<T> proxyClass;
+   private final Class<T> proxyClass;
 
-   private SessionBean<?> specializedBean;
+   private final SessionBean<?> specializedBean;
 
    /**
     * Creates a simple, annotation defined Enterprise Web Bean
@@ -81,10 +77,26 @@
     * @param manager the current manager
     * @return An Enterprise Web Bean
     */
-   public static <T> SessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   public static <T> SessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, 
+         BeanManagerImpl manager, 
+         String name,
+         Set<Type> types,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<javax.enterprise.inject.spi.Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         Class<T> proxyClass,
+         SessionBean<?> specializedBean)
    {
       WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
-      return new SessionBean<T>(type, ejbDescriptor, manager);
+      return new SessionBean<T>(type, ejbDescriptor, manager, name, types, mergedStereotypes, scopeType, policy, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy, proxyClass, specializedBean);
    }
 
    /**
@@ -93,13 +105,29 @@
     * @param type The type of the bean
     * @param manager The Web Beans manager
     */
-   protected SessionBean(WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   protected SessionBean(WBClass<T> type, 
+         InternalEjbDescriptor<T> ejbDescriptor, 
+         BeanManagerImpl manager, 
+         String name,
+         Set<Type> types,
+         MergedStereotypes<T, Class<T>> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings,
+         Set<String> dependencies,
+         Class<T> proxyClassForDecorators,
+         List<javax.enterprise.inject.spi.Decorator<?>> decorators,
+         WBMethod<?, ?> postConstruct,
+         WBMethod<?, ?> preDestroy,
+         Class<T> proxyClass,
+         SessionBean<?> specializedBean)
    {
-      super(type, manager);
-      initType();
+      super(type, manager, name, types, mergedStereotypes, scopeType, policy, false, proxyable, bindings, dependencies,
+            proxyClassForDecorators, decorators, postConstruct, preDestroy);
       this.ejbDescriptor = ejbDescriptor;
-      initTypes();
-      initBindings();
+      this.proxyClass = proxyClass;
+      this.specializedBean = specializedBean;
    }
 
    /**
@@ -111,7 +139,7 @@
       if (!isInitialized())
       {
          super.initialize(environment);
-         initProxyClass();
+//         initProxyClass();
          checkEJBTypeAllowed();
          checkConflictingRoles();
          checkObserverMethods();
@@ -119,32 +147,19 @@
       }
    }
 
-   @Override
-   protected void initTypes()
-   {
-      Set<Type> types = new HashSet<Type>();
-      types = new LinkedHashSet<Type>();
-      types.add(Object.class);
-      for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor : ejbDescriptor.getLocalBusinessInterfaces())
-      {
-         types.add(businessInterfaceDescriptor.getInterface());
-      }
-      super.types = types;
-   }
+//   protected void initProxyClass()
+//   {
+//      Set<Type> types = new LinkedHashSet<Type>(getTypes());
+//      types.add(EnterpriseBeanInstance.class);
+//      types.add(Serializable.class);
+//      ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
+//
+//      @SuppressWarnings("unchecked")
+//      Class<T> proxyClass = proxyFactory.createClass();
+//
+//      this.proxyClass = proxyClass;
+//   }
 
-   protected void initProxyClass()
-   {
-      Set<Type> types = new LinkedHashSet<Type>(getTypes());
-      types.add(EnterpriseBeanInstance.class);
-      types.add(Serializable.class);
-      ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
-
-      @SuppressWarnings("unchecked")
-      Class<T> proxyClass = proxyFactory.createClass();
-
-      this.proxyClass = proxyClass;
-   }
-
    /**
     * Validates for non-conflicting roles
     */
@@ -177,38 +192,6 @@
    }
 
    /**
-    * Validates specialization
-    */
-   @Override
-   protected void preSpecialize(BeanDeployerEnvironment environment)
-   {
-      super.preSpecialize(environment);
-      // We appear to check this twice?
-      if (!environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
-      {
-         throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
-      }
-   }
-
-   @Override
-   protected void specialize(BeanDeployerEnvironment environment)
-   {
-      if (environment.getClassBean(getAnnotatedItem().getWBSuperclass()) == null)
-      {
-         throw new IllegalStateException(toString() + " does not specialize a bean");
-      }
-      AbstractClassBean<?> specializedBean = environment.getClassBean(getAnnotatedItem().getWBSuperclass());
-      if (!(specializedBean instanceof SessionBean<?>))
-      {
-         throw new IllegalStateException(toString() + " doesn't have a session bean as a superclass " + specializedBean);
-      }
-      else
-      {
-         this.specializedBean = (SessionBean<?>) specializedBean; 
-      }
-   }
-
-   /**
     * Creates an instance of the bean
     * 
     * @return The instance
@@ -324,12 +307,6 @@
    }
    
    @Override
-   protected void initSerializable()
-   {
-      // No-op
-   }
-   
-   @Override
    public boolean isSerializable()
    {
       return true;

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,512 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.decorator.Decorates;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.Specializes;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.stereotype.Stereotype;
+import javax.inject.Named;
+import javax.inject.Qualifier;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.WBInjectionPoint;
+import org.jboss.webbeans.introspector.WBAnnotated;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.introspector.WBParameter;
+import org.jboss.webbeans.literal.AnyLiteral;
+import org.jboss.webbeans.literal.DefaultLiteral;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
+import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ * An abstract bean representation common for all beans
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T> the type of bean
+ * @param <E> the Class<?> of the bean type
+ */
+abstract class AbstractBeanBuilder<T, E> extends RIBeanBuilder<T>
+{
+
+   private static final Annotation ANY_LITERAL = new AnyLiteral();
+   private static final Annotation CURRENT_LITERAL = new DefaultLiteral();
+
+   private boolean proxyable;
+
+   // Logger
+   private final Log log = Logging.getLog(AbstractBeanBuilder.class);
+   // The binding types
+   protected Set<Annotation> bindings;
+   // The name
+   protected String name;
+   // The scope type
+   protected Class<? extends Annotation> scopeType;
+   // The merged stereotypes
+   private MergedStereotypes<T, E> mergedStereotypes;
+   // Is it a policy, either defined by stereotypes or directly?
+   private boolean policy;
+   // The type
+   protected Class<T> type;
+   // The API types
+   protected Set<Type> types;
+   // The injection points
+   private Set<WBInjectionPoint<?, ?>> injectionPoints;
+   private Set<WBInjectionPoint<?, ?>> delegateInjectionPoints;
+   // If the type a primitive?
+   private boolean primitive;
+   // The Web Beans manager
+   protected BeanManagerImpl manager;
+
+   private boolean _serializable;
+
+   private boolean initialized;
+
+   
+
+   protected boolean isInitialized()
+   {
+      return initialized;
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param manager The Web Beans manager
+    */
+   public AbstractBeanBuilder(BeanManagerImpl manager)
+   {
+      super(manager);
+      this.manager = manager;
+      this.injectionPoints = new HashSet<WBInjectionPoint<?, ?>>();
+      this.delegateInjectionPoints = new HashSet<WBInjectionPoint<?,?>>();
+   }
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (isSpecializing())
+      {
+         preSpecialize(environment);
+         specialize(environment);
+         postSpecialize();
+      }
+      initDefaultBindings();
+      initPrimitive();
+      log.trace("Building Web Bean bean metadata for #0", getType());
+      initName();
+      initScopeType();
+      initSerializable();
+      initProxyable();
+      checkDelegateInjectionPoints();
+   }
+   
+   protected void initStereotypes()
+   {
+      mergedStereotypes = new MergedStereotypes<T, E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class), manager);
+   }
+
+   protected void checkDelegateInjectionPoints()
+   {
+      if (this.delegateInjectionPoints.size() > 0)
+      {
+         throw new DefinitionException("Cannot place @Decorates at an injection point which is not on a Decorator " + this);
+      }
+   }
+   
+   protected void addInjectionPoint(WBInjectionPoint<?, ?> injectionPoint)
+   {
+      if (injectionPoint.isAnnotationPresent(Decorates.class))
+      {
+         this.delegateInjectionPoints.add(injectionPoint);
+      }
+      injectionPoints.add(injectionPoint);
+   }
+   
+   protected void addInjectionPoints(Iterable<? extends WBInjectionPoint<?, ?>> injectionPoints)
+   {
+      for (WBInjectionPoint<?, ?> injectionPoint : injectionPoints)
+      {
+         addInjectionPoint(injectionPoint);
+      }
+   }
+
+   protected Set<WBInjectionPoint<?, ?>> getDelegateInjectionPoints()
+   {
+      return delegateInjectionPoints;
+   }
+
+   /**
+    * Initializes the API types
+    */
+   protected void initTypes()
+   {
+      types = getAnnotatedItem().getTypeClosure();
+   }
+
+   /**
+    * Initializes the binding types
+    */
+   protected void initBindings()
+   {
+      this.bindings = new HashSet<Annotation>();
+      this.bindings.addAll(getAnnotatedItem().getMetaAnnotations(Qualifier.class));
+      initDefaultBindings();
+      log.trace("Using binding types " + bindings + " specified by annotations");
+   }
+
+   protected void initDefaultBindings()
+   {
+      if (bindings.size() == 0)
+      {
+         log.trace("Adding default @Current binding type");
+         this.bindings.add(CURRENT_LITERAL);
+      }
+      this.bindings.add(ANY_LITERAL);
+   }
+
+   protected void initPolicy()
+   {
+      if (getAnnotatedItem().isAnnotationPresent(Alternative.class))
+      {
+         this.policy = true;
+      }
+      else
+      {
+         this.policy = getMergedStereotypes().isPolicy();
+      }
+   }
+
+   /**
+    * Initializes the name
+    */
+   protected void initName()
+   {
+      boolean beanNameDefaulted = false;
+      if (getAnnotatedItem().isAnnotationPresent(Named.class))
+      {
+         String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
+         if ("".equals(javaName))
+         {
+            log.trace("Using default name (specified by annotations)");
+            beanNameDefaulted = true;
+         }
+         else
+         {
+            if (log.isTraceEnabled())
+               log.trace("Using name " + javaName + " specified by annotations");
+            this.name = javaName;
+            return;
+         }
+      }
+
+      if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
+      {
+         this.name = getDefaultName();
+         return;
+      }
+   }
+
+   protected void initProxyable()
+   {
+      proxyable = getAnnotatedItem().isProxyable();
+   }
+
+   /**
+    * Initializes the primitive flag
+    */
+   protected void initPrimitive()
+   {
+      this.primitive = Reflections.isPrimitive(getType());
+   }
+
+   private boolean checkInjectionPointsAreSerializable()
+   {
+      boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(this.getScope()).isPassivating();
+      for (WBInjectionPoint<?, ?> injectionPoint : getAnnotatedInjectionPoints())
+      {
+         Annotation[] bindings = injectionPoint.getMetaAnnotationsAsArray(Qualifier.class);
+         Bean<?> resolvedBean = manager.getBeans(injectionPoint.getJavaClass(), bindings).iterator().next();
+         if (passivating)
+         {
+            if (Dependent.class.equals(resolvedBean.getScope()) && !Reflections.isSerializable(resolvedBean.getBeanClass()) && (((injectionPoint instanceof WBField<?, ?>) && !((WBField<?, ?>) injectionPoint).isTransient()) || (injectionPoint instanceof WBParameter<?, ?>)))
+            {
+               return false;
+            }
+         }
+      }
+      return true;
+   }
+
+   /**
+    * Initializes the scope type
+    */
+   protected abstract void initScopeType();
+
+   protected boolean initScopeTypeFromStereotype()
+   {
+      Set<Annotation> possibleScopeTypes = getMergedStereotypes().getPossibleScopeTypes();
+      if (possibleScopeTypes.size() == 1)
+      {
+         this.scopeType = possibleScopeTypes.iterator().next().annotationType();
+         if (log.isTraceEnabled())
+            log.trace("Scope " + scopeType + " specified by stereotype");
+         return true;
+      }
+      else if (possibleScopeTypes.size() > 1)
+      {
+         throw new DefinitionException("All stereotypes must specify the same scope OR a scope must be specified on " + getAnnotatedItem());
+      }
+      else
+      {
+         return false;
+      }
+   }
+
+   protected void postSpecialize()
+   {
+      if (getAnnotatedItem().isAnnotationPresent(Named.class) && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
+      {
+         throw new DefinitionException("Cannot put name on specializing and specialized class " + getAnnotatedItem());
+      }
+      this.bindings.addAll(getSpecializedBean().getQualifiers());
+      if (isSpecializing() && getSpecializedBean().getAnnotatedItem().isAnnotationPresent(Named.class))
+      {
+         this.name = getSpecializedBean().getName();
+      }
+      
+      throw new RuntimeException("Next line commented");
+//      manager.getSpecializedBeans().put(getSpecializedBean(), this);
+   }
+
+   protected void preSpecialize(BeanDeployerEnvironment environment)
+   {
+
+   }
+
+   protected void specialize(BeanDeployerEnvironment environment)
+   {
+
+   }
+
+   /**
+    * Returns the annotated time the bean represents
+    * 
+    * @return The annotated item
+    */
+   protected abstract WBAnnotated<T, E> getAnnotatedItem();
+
+   /**
+    * Gets the binding types
+    * 
+    * @return The set of binding types
+    * 
+    * @see org.jboss.webbeans.bean.BaseBean#getQualifiers()
+    */
+   public Set<Annotation> getQualifiers()
+   {
+      return bindings;
+   }
+
+   /**
+    * Gets the default name of the bean
+    * 
+    * @return The default name
+    */
+   protected abstract String getDefaultName();
+
+   @Override
+   public abstract AbstractBean<?, ?> getSpecializedBean();
+
+   @Override
+   public Set<WBInjectionPoint<?, ?>> getAnnotatedInjectionPoints()
+   {
+      return injectionPoints;
+   }
+
+   /**
+    * Gets the merged stereotypes of the bean
+    * 
+    * @return The set of merged stereotypes
+    */
+   protected MergedStereotypes<T, E> getMergedStereotypes()
+   {
+      return mergedStereotypes;
+   }
+
+   /**
+    * Gets the name of the bean
+    * 
+    * @return The name
+    * 
+    * @see org.jboss.webbeans.bean.BaseBean#getName()
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Gets the scope type of the bean
+    * 
+    * @return The scope type
+    * 
+    * @see org.jboss.webbeans.bean.BaseBean#getScope()
+    */
+   public Class<? extends Annotation> getScope()
+   {
+      return scopeType;
+   }
+
+   /**
+    * Gets the type of the bean
+    * 
+    * @return The type
+    */
+   @Override
+   public Class<T> getType()
+   {
+      return type;
+   }
+
+   /**
+    * Gets the API types of the bean
+    * 
+    * @return The set of API types
+    * 
+    * @see org.jboss.webbeans.bean.BaseBean#getTypeClosure()
+    */
+   public Set<Type> getTypes()
+   {
+      return types;
+   }
+
+   /**
+    * Checks if this beans annotated item is assignable from another annotated
+    * item
+    * 
+    * @param annotatedItem The other annotation to check
+    * @return True if assignable, otherwise false
+    */
+   public boolean isAssignableFrom(WBAnnotated<?, ?> annotatedItem)
+   {
+      return this.getAnnotatedItem().isAssignableFrom(annotatedItem);
+   }
+
+   /**
+    * Indicates if bean is nullable
+    * 
+    * @return True if nullable, false otherwise
+    * 
+    * @see org.jboss.webbeans.bean.BaseBean#isNullable()
+    */
+   public boolean isNullable()
+   {
+      return !isPrimitive();
+   }
+
+   /**
+    * Indicates if bean type is a primitive
+    * 
+    * @return True if primitive, false otherwise
+    */
+   @Override
+   public boolean isPrimitive()
+   {
+      return primitive;
+   }
+
+   public boolean isSerializable()
+   {
+      // TODO WTF - why are we not caching the serializability of injection
+      // points!
+      return _serializable && checkInjectionPointsAreSerializable();
+   }
+
+   protected void initSerializable()
+   {
+      _serializable = Reflections.isSerializable(type);
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      return "AbstractBean " + getName();
+   }
+
+   @Override
+   public boolean isProxyable()
+   {
+      return proxyable;
+   }
+
+   public boolean isAlternative()
+   {
+      return policy;
+   }
+
+   @Override
+   public boolean isSpecializing()
+   {
+      return getAnnotatedItem().isAnnotationPresent(Specializes.class);
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return mergedStereotypes.getStereotypes();
+   }
+
+   @Override
+   public String getId()
+   {
+      return null;
+   }
+
+   public T create(CreationalContext<T> creationalContext)
+   {
+      throw new IllegalStateException("Should not call create() on builder " + this);
+   }
+
+   public void destroy(T instance, CreationalContext<T> creationalContext)
+   {
+      throw new IllegalStateException("Should not call destroy() on builder " + this);
+   }
+
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractClassBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,408 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import javassist.util.proxy.ProxyFactory;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.NormalScope;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Scope;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.FieldInjectionPoint;
+import org.jboss.webbeans.injection.MethodInjectionPoint;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.Proxies;
+import org.jboss.webbeans.util.Strings;
+
+/**
+ * An abstract bean representation common for class-based beans
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T>
+ * @param <E>
+ */
+abstract class AbstractClassBeanBuilder<T> extends AbstractBeanBuilder<T, Class<T>>
+{
+   // Logger
+   private static final LogProvider log = Logging.getLogProvider(AbstractClassBeanBuilder.class);
+   // The item representation
+   protected WBClass<T> annotatedItem;
+   // The injectable fields
+   private Set<FieldInjectionPoint<?, ?>> injectableFields;
+   // The initializer methods
+   private Set<MethodInjectionPoint<?, ?>> initializerMethods;
+   private Set<String> dependencies;
+   
+   private List<Decorator<?>> decorators;
+   
+   private final String id;
+   private Class<T> proxyClassForDecorators;
+   
+   private final ThreadLocal<Integer> decoratorStackPosition;
+   private WBMethod<?, ?> postConstruct;
+   private WBMethod<?, ?> preDestroy;
+
+   /**
+    * Constructor
+    * 
+    * @param type The type
+    * @param manager The Web Beans manager
+    */
+   protected AbstractClassBeanBuilder(WBClass<T> type, BeanManagerImpl manager)
+   {
+      super(manager);
+      this.annotatedItem = type;
+      this.id = createId(getClass().getSimpleName() + "-" + type.getName());
+      this.decoratorStackPosition = new ThreadLocal<Integer>()
+      {
+         
+         @Override
+         protected Integer initialValue()
+         {
+            return 0;
+         }
+         
+      };
+      initStereotypes();
+      initPolicy();
+   }
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      initInitializerMethods();
+      initInjectableFields();
+      super.initialize(environment);
+      checkBeanImplementation();
+      initDecorators();
+      checkType();
+      initProxyClassForDecoratedBean();
+   }
+   
+   protected void checkType()
+   {
+      
+   }
+   
+   protected void initDecorators()
+   {
+      this.decorators = getManager().resolveDecorators(getTypes(), getQualifiers());
+   }
+   
+   public boolean hasDecorators()
+   {
+      return this.decorators != null && this.decorators.size() > 0;
+   }
+   
+   protected void initProxyClassForDecoratedBean()
+   {
+      if (hasDecorators())
+      {
+         Set<Type> types = new LinkedHashSet<Type>(getTypes());
+         ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
+   
+         Class<T> proxyClass = proxyFactory.createClass();
+   
+         this.proxyClassForDecorators = proxyClass;
+      }
+   }
+   
+   protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint)
+   {
+      throw new RuntimeException("NYI");
+//      List<SerializableBeanInstance<DecoratorImpl<Object>, Object>> decoratorInstances = new ArrayList<SerializableBeanInstance<DecoratorImpl<Object>,Object>>();
+//      InjectionPoint ip = originalInjectionPoint;
+//      boolean outside = decoratorStackPosition.get().intValue() == 0;
+//      try
+//      {
+//         int i = decoratorStackPosition.get();
+//         while (i < decorators.size())
+//         {
+//            Decorator<?> decorator = decorators.get(i);
+//            if (decorator instanceof DecoratorImpl<?>)
+//            {
+//               decoratorStackPosition.set(++i);
+//               
+//               @SuppressWarnings("unchecked")
+//               DecoratorImpl<Object> decoratorBean = (DecoratorImpl<Object>) decorator;
+//               
+//               Object decoratorInstance = getManager().getReference(ip, decorator, creationalContext);
+//               decoratorInstances.add(new SerializableBeanInstance<DecoratorImpl<Object>, Object>(decoratorBean, decoratorInstance));
+//               ip = decoratorBean.getDelegateInjectionPoint();
+//            }
+//            else
+//            {
+//               throw new IllegalStateException("Cannot operate on non container provided decorator " + decorator);
+//            }
+//         }
+//      }
+//      finally
+//      {
+//         if (outside)
+//         {
+//            decoratorStackPosition.remove();
+//         }
+//      }
+//      try
+//      {
+//         T proxy = proxyClassForDecorators.newInstance();
+//         ((ProxyObject) proxy).setHandler(new DecoratorProxyMethodHandler(decoratorInstances, instance));
+//         return proxy;
+//      }
+//      catch (InstantiationException e)
+//      {
+//         throw new RuntimeException("Could not instantiate decorator proxy for " + toString(), e);
+//      }
+//      catch (IllegalAccessException e)
+//      {
+//         throw new RuntimeException("Could not access bean correctly when creating decorator proxy for " + toString(), e);
+//      }
+   }
+   
+   public List<Decorator<?>> getDecorators()
+   {
+      return Collections.unmodifiableList(decorators);
+   }
+   
+   public Class<T> getProxyClassForDecorators()
+   {
+      return proxyClassForDecorators;
+   }
+
+   public void setProxyClassForDecorators(Class<T> proxyClassForDecorators)
+   {
+      this.proxyClassForDecorators = proxyClassForDecorators;
+   }
+
+   public void dispose(T instance) 
+   {
+      // No-op for class beans
+   }
+   
+
+   /**
+    * Initializes the bean type
+    */
+   protected void initType()
+   {
+      log.trace("Bean type specified in Java");
+      this.type = getAnnotatedItem().getJavaClass();
+      this.dependencies = new HashSet<String>();
+      for (Class<?> clazz = type.getSuperclass(); clazz != Object.class; clazz = clazz.getSuperclass())
+      {
+         dependencies.add(clazz.getName());
+      }
+   }
+
+   /**
+    * Initializes the injection points
+    */
+   protected void initInjectableFields()
+   {
+      injectableFields = new HashSet<FieldInjectionPoint<?, ?>>(Beans.getFieldInjectionPoints(this, annotatedItem));
+      addInjectionPoints(injectableFields);
+   }
+
+   /**
+    * Initializes the initializer methods
+    */
+   protected void initInitializerMethods()
+   {
+      initializerMethods = Beans.getInitializerMethods(this, getAnnotatedItem());
+      addInjectionPoints(Beans.getParameterInjectionPoints(this, initializerMethods));
+   }
+
+   @Override
+   protected void initScopeType()
+   {
+      for (WBClass<?> clazz = getAnnotatedItem(); clazz != null; clazz = clazz.getWBSuperclass())
+      {
+         Set<Annotation> scopeTypes = new HashSet<Annotation>();
+         scopeTypes.addAll(clazz.getDeclaredMetaAnnotations(Scope.class));
+         scopeTypes.addAll(clazz.getDeclaredMetaAnnotations(NormalScope.class));
+         if (scopeTypes.size() == 1)
+         {
+            if (getAnnotatedItem().isAnnotationPresent(scopeTypes.iterator().next().annotationType()))
+            {
+               this.scopeType = scopeTypes.iterator().next().annotationType();
+               log.trace("Scope " + scopeType + " specified by annotation");
+            }
+            break;
+         }
+         else if (scopeTypes.size() > 1)
+         {
+            throw new DefinitionException("At most one scope may be specified on " + getAnnotatedItem());
+         }
+      }
+
+      if (this.scopeType == null)
+      {
+         initScopeTypeFromStereotype();
+      }
+
+      if (this.scopeType == null)
+      {
+         this.scopeType = Dependent.class;
+         log.trace("Using default @Dependent scope");
+      }
+   }
+
+   /**
+    * Validates the bean implementation
+    */
+   protected void checkBeanImplementation() {}
+
+   @Override
+   protected void preSpecialize(BeanDeployerEnvironment environment)
+   {
+      super.preSpecialize(environment);
+      if (getAnnotatedItem().getWBSuperclass() == null || getAnnotatedItem().getWBSuperclass().getJavaClass().equals(Object.class))
+      {
+         throw new DefinitionException("Specializing bean must extend another bean " + toString());
+      }
+   }
+
+   /**
+    * Gets the annotated item
+    * 
+    * @return The annotated item
+    */
+   @Override
+   public WBClass<T> getAnnotatedItem()
+   {
+      return annotatedItem;
+   }
+
+   /**
+    * Gets the default name
+    * 
+    * @return The default name
+    */
+   @Override
+   protected String getDefaultName()
+   {
+      String name = Strings.decapitalize(getAnnotatedItem().getSimpleName());
+      log.trace("Default name of " + type + " is " + name);
+      return name;
+   }
+
+   /**
+    * Gets the annotated methods
+    * 
+    * @return The set of annotated methods
+    */
+   public Set<? extends MethodInjectionPoint<?, ?>> getInitializerMethods()
+   {
+      return Collections.unmodifiableSet(initializerMethods);
+   }
+   
+   /**
+    * @return the injectableFields
+    */
+   public Set<FieldInjectionPoint<?, ?>> getInjectableFields()
+   {
+      return Collections.unmodifiableSet(injectableFields);
+   }
+   
+   // TODO maybe a better way to expose this?
+   public Set<String> getSuperclasses()
+   {
+      return dependencies;
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      return "AbstractClassBean " + getName();
+   }
+   
+   @Override
+   public String getId()
+   {
+      return id;
+   }
+
+   /**
+    * Initializes the post-construct method
+    */
+   protected void initPostConstruct()
+   {
+      this.postConstruct = Beans.getPostConstruct(getAnnotatedItem());
+   }
+
+   /**
+    * Initializes the pre-destroy method
+    */
+   protected void initPreDestroy()
+   {
+      this.preDestroy = Beans.getPreDestroy(getAnnotatedItem());
+   }
+
+   /**
+    * Returns the post-construct method
+    * 
+    * @return The post-construct method
+    */
+   public WBMethod<?, ?> getPostConstruct()
+   {
+      return postConstruct;
+   }
+
+   /**
+    * Returns the pre-destroy method
+    * 
+    * @return The pre-destroy method
+    */
+   public WBMethod<?, ?> getPreDestroy()
+   {
+      return preDestroy;
+   }
+
+   @Override
+   public AbstractBean<?, ?> getSpecializedBean()
+   {
+      return null;
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractProducerBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,302 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.NormalScope;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.IllegalProductException;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.Producer;
+import javax.inject.Inject;
+import javax.inject.Scope;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.introspector.WBMember;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.Names;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ * The implicit producer bean
+ * 
+ * @author Gavin King
+ * 
+ * @param <T>
+ * @param <S>
+ */
+abstract class AbstractProducerBeanBuilder<T, S extends Member> extends AbstractReceiverBeanBuilder<T, S> implements Producer<T>
+{
+   private static final LogProvider log = Logging.getLogProvider(AbstractProducerBeanBuilder.class);
+
+   /**
+    * Constructor
+    * 
+    * @param declaringBean The declaring bean
+    * @param manager The Web Beans manager
+    */
+   public AbstractProducerBeanBuilder(AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      super(declaringBean, manager);
+   }
+
+   @Override
+   public abstract WBMember<T, ?, S> getAnnotatedItem();
+
+   @Override
+   // Overriden to provide the class of the bean that declares the producer method/field
+   public Class<?> getBeanClass()
+   {
+      return getDeclaringBean().getBeanClass();
+   }
+
+   /**
+    * Initializes the API types
+    */
+   @Override
+   protected void initTypes()
+   {
+      if (getType().isArray() || getType().isPrimitive())
+      {
+         Set<Type> types = new HashSet<Type>();
+         types = new HashSet<Type>();
+         types.add(getType());
+         types.add(Object.class);
+         super.types = types;
+      }
+      else if (getType().isInterface())
+      {
+         Set<Type> types = new HashSet<Type>();
+         types.add(Object.class);
+         types.addAll(getAnnotatedItem().getTypeClosure());
+         super.types = types;
+      }
+      else
+      {
+         super.initTypes();
+      }
+   }
+
+   /**
+    * Initializes the type
+    */
+   protected void initType()
+   {
+      try
+      {
+         this.type = getAnnotatedItem().getJavaClass();
+      }
+      catch (ClassCastException e)
+      {
+         throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getJavaClass() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
+      }
+   }
+
+   /**
+    * Gets the declared bean type
+    * 
+    * @return The bean type
+    */
+   protected Type getDeclaredBeanType()
+   {
+      Type type = getClass();
+      if (type instanceof ParameterizedType)
+      {
+         ParameterizedType parameterizedType = (ParameterizedType) type;
+         if (parameterizedType.getActualTypeArguments().length == 1)
+         {
+            return parameterizedType.getActualTypeArguments()[0];
+         }
+      }
+      return null;
+   }
+
+   /**
+    * Validates the producer method
+    */
+   protected void checkProducerReturnType()
+   {
+      if (getAnnotatedItem().getBaseType() instanceof TypeVariable<?>)
+      {
+         throw new DefinitionException("Return type must be concrete " + getAnnotatedItem().getBaseType());
+      }
+      if (getAnnotatedItem().getBaseType() instanceof WildcardType)
+      {
+         throw new DefinitionException("Return type must be concrete " + getAnnotatedItem().getBaseType());
+      }
+      for (Type type : getAnnotatedItem().getActualTypeArguments())
+      {
+         if (!(type instanceof Class))
+         {
+            throw new DefinitionException("Producer type cannot be parameterized with type parameter or wildcard:\n" + this.getAnnotatedItem());
+         }
+      }
+   }
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      getDeclaringBean().initialize(environment);
+      super.initialize(environment);
+      checkProducerReturnType();
+   }
+
+   /**
+    * Validates the return value
+    * 
+    * @param instance The instance to validate
+    */
+   protected void checkReturnValue(T instance)
+   {
+      if (instance == null && !isDependent())
+      {
+         throw new IllegalProductException("Cannot return null from a non-dependent producer method");
+      }
+      else if (instance != null)
+      {
+         boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(getScope()).isPassivating();
+         if (passivating && !Reflections.isSerializable(instance.getClass()))
+         {
+            throw new IllegalProductException("Producers cannot declare passivating scope and return a non-serializable class");
+         }
+         InjectionPoint injectionPoint = manager.getCurrentInjectionPoint();
+         if (injectionPoint == null)
+         {
+            return;
+         }
+         if (!Reflections.isSerializable(instance.getClass()) && Beans.isPassivationCapableBean(injectionPoint.getBean()))
+         {
+            if (injectionPoint.getMember() instanceof Field)
+            {
+               if (!Reflections.isTransient(injectionPoint.getMember()) && instance != null && !Reflections.isSerializable(instance.getClass()))
+               {
+                  throw new IllegalProductException("Producers cannot produce non-serializable instances for injection into non-transient fields of passivating beans\n\nProducer: " + this.toString() + "\nInjection Point: " + injectionPoint.toString());
+               }
+            }
+            else if (injectionPoint.getMember() instanceof Method)
+            {
+               Method method = (Method) injectionPoint.getMember();
+               if (method.isAnnotationPresent(Inject.class))
+               {
+                  throw new IllegalProductException("Producers cannot produce non-serializable instances for injection into parameters of intializers of beans declaring passivating scope. Bean " + toString() + " being injected into " + injectionPoint.toString());
+               }
+               if (method.isAnnotationPresent(Produces.class))
+               {
+                  throw new IllegalProductException("Producers cannot produce non-serializable instances for injection into parameters of producer methods declaring passivating scope. Bean " + toString() + " being injected into " + injectionPoint.toString());
+               }
+            }
+            else if (injectionPoint.getMember() instanceof Constructor)
+            {
+               throw new IllegalProductException("Producers cannot produce non-serializable instances for injection into parameters of constructors of beans declaring passivating scope. Bean " + toString() + " being injected into " + injectionPoint.toString());
+            }
+         }
+      }
+   }
+
+   @Override
+   protected void initScopeType()
+   {
+      Set<Annotation> scopeAnnotations = new HashSet<Annotation>();
+      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(Scope.class));
+      scopeAnnotations.addAll(getAnnotatedItem().getMetaAnnotations(NormalScope.class));
+      if (scopeAnnotations.size() > 1)
+      {
+         throw new DefinitionException("At most one scope may be specified");
+      }
+      if (scopeAnnotations.size() == 1)
+      {
+         this.scopeType = scopeAnnotations.iterator().next().annotationType();
+         log.trace("Scope " + scopeType + " specified by annotation");
+         return;
+      }
+
+      initScopeTypeFromStereotype();
+
+      if (this.scopeType == null)
+      {
+         this.scopeType = Dependent.class;
+         log.trace("Using default @Dependent scope");
+      }
+   }
+   
+   @Override
+   protected void initSerializable()
+   {
+      // No-op
+   }
+
+   @Override
+   public boolean isSerializable()
+   {
+      return true;
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder buffer = new StringBuilder();
+      buffer.append("Annotated " + Names.scopeTypeToString(getScope()));
+      if (getName() == null)
+      {
+         buffer.append("unnamed producer bean");
+      }
+      else
+      {
+         buffer.append("simple producer bean '" + getName() + "'");
+      }
+      buffer.append(" [" + getBeanClass().getName() + "] for class type [" + getType().getName() + "] API types " + getTypes() + ", binding types " + getQualifiers());
+      return buffer.toString();
+   }
+
+   public void dispose(T instance)
+   {
+      throw new IllegalStateException("Should not call dispose() on builder " + this);
+   }
+
+   public T produce(CreationalContext<T> ctx)
+   {
+      throw new IllegalStateException("Should not call produce() on builder " + this);
+   }
+   
+}
\ No newline at end of file

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/AbstractReceiverBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.reflect.Member;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.Alternative;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.context.WBCreationalContext;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * @author pmuir
+ *
+ */
+abstract class AbstractReceiverBeanBuilder<T, S extends Member> extends AbstractBeanBuilder<T, S>
+{
+   private static final LogProvider log = Logging.getLogProvider(AbstractReceiverBeanBuilder.class);
+   
+   private AbstractClassBean<?> declaringBean;
+   private boolean policy;
+
+   public AbstractReceiverBeanBuilder(AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      super(manager);
+      this.declaringBean = declaringBean;
+   }
+   
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      super.initialize(environment);
+   }
+
+   /**
+    * Gets the receiver of the product
+    * 
+    * @return The receiver
+    */
+   protected Object getReceiver(CreationalContext<?> creationalContext)
+   {
+      // This is a bit dangerous, as it means that producer methods can end of
+      // executing on partially constructed instances. Also, it's not required
+      // by the spec...
+      if (getAnnotatedItem().isStatic())
+      {
+         return null;
+      }
+      else
+      {
+         if (creationalContext instanceof WBCreationalContext<?>)
+         {
+            WBCreationalContext<?> creationalContextImpl = (WBCreationalContext<?>) creationalContext;
+            if (creationalContextImpl.containsIncompleteInstance(getDeclaringBean()))
+            {
+               log.warn("Executing producer field or method " + getAnnotatedItem() + " on incomplete declaring bean " + getDeclaringBean() + " due to circular injection");
+               return creationalContextImpl.getIncompleteInstance(getDeclaringBean());
+            }
+         }
+         return manager.getReference(getDeclaringBean(), Object.class, creationalContext);
+      }
+   }
+   
+
+   /**
+    * Returns the declaring bean
+    * 
+    * @return The bean representation
+    */
+   public AbstractClassBean<?> getDeclaringBean()
+   {
+      return declaringBean;
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.webbeans.bean.AbstractBean#isPolicy()
+    */
+   @Override
+   public boolean isAlternative()
+   {
+      return policy;
+   }
+   
+   @Override
+   protected void initPolicy()
+   {
+      if (getDeclaringBean().isAlternative())
+      {
+         this.policy = true;
+      }
+      else if (getAnnotatedItem().isAnnotationPresent(Alternative.class))
+      {
+         this.policy = true;
+      }
+      else if (getMergedStereotypes().isPolicy())
+      {
+         this.policy = true;
+      }
+   }
+
+}

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderFactoryImpl.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderFactoryImpl.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderFactoryImpl.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -30,10 +30,12 @@
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanManager;
 
+import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.bean.builder.spi.DecoratorBeanBuilder;
 import org.jboss.webbeans.bean.builder.spi.EnterpriseBeanBuilder;
 import org.jboss.webbeans.bean.builder.spi.SimpleBeanBuilder;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.ejb.EjbDescriptors;
 import org.jboss.webbeans.ejb.spi.EjbDescriptor;
 
 /**
@@ -76,54 +78,56 @@
    
    public <T> SimpleBeanBuilder<T> getSimpleBeanBuilder(BeanManager beanManager, AnnotatedType<T> annotatedType)
    {
-      return getBeanBuilderImpl(beanManager, false, annotatedType, null, false);
+      return getBeanBuilderImpl(beanManager, annotatedType, null, false);
    }
 
    public <T> EnterpriseBeanBuilder<T> getEnterpriseBeanBuilder(BeanManager beanManager, EjbDescriptor<T> ejbDescriptor)
    {
-      return getBeanBuilderImpl(beanManager, false, null, ejbDescriptor, false);
+      return getBeanBuilderImpl(beanManager, null, ejbDescriptor, false);
    }
 
    public <T> DecoratorBeanBuilder<T> getDecoratorBeanBuilder(BeanManager beanManager, AnnotatedType<T> annotatedType)
    {
-      return getBeanBuilderImpl(beanManager, false, annotatedType, null, true);
+      return getBeanBuilderImpl(beanManager, annotatedType, null, true);
    }
 
-   public <T> SimpleBeanBuilder<T> getInternalSimpleBeanBuilder(BeanManager beanManager, AnnotatedType<T> annotatedType)
-   {
-      return getBeanBuilderImpl(beanManager, true, annotatedType, null, false);
-   }
-
-   public <T> EnterpriseBeanBuilder<T> getInternalEnterpriseBeanBuilder(BeanManager beanManager, EjbDescriptor<T> ejbDescriptor)
-   {
-      return getBeanBuilderImpl(beanManager, true, null, ejbDescriptor, false);
-   }
-
-   public <T> DecoratorBeanBuilder<T> getInternalDecoratorBeanBuilder(BeanManager beanManager, AnnotatedType<T> annotatedType)
-   {
-      return getBeanBuilderImpl(beanManager, true, annotatedType, null, false);
-   }
-
    public <T> InternalObserverMethodBuilder<T> getInternalObserverMethodBuilder(BeanManager beanManager, AnnotatedType<T> annotatedType)
    {
-      return getBeanBuilderImpl(beanManager, true, annotatedType, null, false);
+      return getBeanBuilderImpl(beanManager, annotatedType, null, false);
    }
 
-   private <T> BeanBuilderImpl<T> getBeanBuilderImpl(BeanManager beanManager, boolean delayInitialization, AnnotatedType<T> annotatedType, EjbDescriptor<T> ejbDescriptor, boolean decorator)
+   private <T> BeanBuilderImpl<T> getBeanBuilderImpl(BeanManager beanManager, AnnotatedType<T> annotatedType, EjbDescriptor<T> ejbDescriptor, boolean decorator)
    {
       lock.readLock().lock();
       try
       {
          WeakReference<BeanDeployerEnvironment> ref = beanDeployerEnvironments.get(beanManager);
-         if (ref == null)
-            throw new IllegalStateException("BeanManager not registered " + beanManager);
+         BeanDeployerEnvironment environment = null;
+         
+         if (ref != null)
+         {
+            environment = ref.get();
+         }
+         else
+         {
+            lock.readLock().unlock();
+            try
+            {
+               if (beanManager instanceof BeanManagerImpl == false)
+                  throw new IllegalStateException("BeanManager is not a BeanManagerImpl");
+               environment = new BeanDeployerEnvironment(new EjbDescriptors(), (BeanManagerImpl)beanManager);
+               registerBeanManager(beanManager, environment);
+            }
+            finally
+            {
+               lock.readLock().lock();
+            }
+         }         
    
-         BeanDeployerEnvironment environment = ref.get();
-   
          if (environment == null)
             throw new IllegalStateException("BeanManager registered but no longer valid " + beanManager);
          
-         return BeanBuilderImpl.initialiseBuilder(beanManager, environment, annotatedType, ejbDescriptor, decorator, delayInitialization);
+         return BeanBuilderImpl.initialiseBuilder(beanManager, environment, annotatedType, ejbDescriptor, decorator);
       }
       finally
       {

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-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/BeanBuilderImpl.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -52,11 +52,8 @@
 import org.jboss.webbeans.bean.builder.spi.DecoratorBeanBuilder;
 import org.jboss.webbeans.bean.builder.spi.EnterpriseBeanBuilder;
 import org.jboss.webbeans.bean.builder.spi.SimpleBeanBuilder;
-import org.jboss.webbeans.bean.ee.EEResourceProducerField;
-import org.jboss.webbeans.bean.ee.PersistenceContextProducerField;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.bootstrap.ProcessObserverMethodImpl;
-import org.jboss.webbeans.ejb.EJBApiAbstraction;
 import org.jboss.webbeans.ejb.InternalEjbDescriptor;
 import org.jboss.webbeans.ejb.spi.EjbDescriptor;
 import org.jboss.webbeans.event.ObserverFactory;
@@ -64,9 +61,7 @@
 import org.jboss.webbeans.introspector.WBClass;
 import org.jboss.webbeans.introspector.WBField;
 import org.jboss.webbeans.introspector.WBMethod;
-import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
 import org.jboss.webbeans.resources.ClassTransformer;
-import org.jboss.webbeans.ws.WSApiAbstraction;
 
 /**
  * 
@@ -85,8 +80,6 @@
    
    private final boolean decorator;
 
-   private final boolean delayInitialization;
-
    private Bean<T> mainBean;
    
    private Bean<T> newBean;
@@ -99,20 +92,19 @@
    
    private final List<Throwable> definitionErrors = new ArrayList<Throwable>();
    
-   private BeanBuilderImpl(BeanManager beanManager, BeanDeployerEnvironment beanDeployerEnvironment, AnnotatedType<T> type, EjbDescriptor<T> ejbDescriptor, boolean decorator, boolean delayInitialization)
+   private BeanBuilderImpl(BeanManager beanManager, BeanDeployerEnvironment beanDeployerEnvironment, AnnotatedType<T> type, EjbDescriptor<T> ejbDescriptor, boolean decorator)
    {
       if (beanManager != beanManager)
          throw new IllegalStateException("beanManager is not an instance of " + BeanManagerImpl.class.getName());
       this.beanManager = (BeanManagerImpl)beanManager;
       
       this.beanDeployerEnvironment = beanDeployerEnvironment;
-      this.delayInitialization = delayInitialization;
       this.decorator = decorator;
       this.type = type;
       this.ejbDescriptor = ejbDescriptor;
    }
    
-   static <T> BeanBuilderImpl<T> initialiseBuilder(BeanManager beanManager, BeanDeployerEnvironment beanDeployerEnvironment, AnnotatedType<T> type, EjbDescriptor<T> ejbDescriptor, boolean decorator, boolean delayInitialization)
+   static <T> BeanBuilderImpl<T> initialiseBuilder(BeanManager beanManager, BeanDeployerEnvironment beanDeployerEnvironment, AnnotatedType<T> type, EjbDescriptor<T> ejbDescriptor, boolean decorator)
    {
       if (type == null && ejbDescriptor == null)
          throw new IllegalArgumentException("Need a type or an ejbDescriptor");
@@ -125,7 +117,7 @@
       if (ejbDescriptor != null && decorator)
          throw new IllegalArgumentException("Cannot create a decorator from an ejb");
       
-      BeanBuilderImpl<T> builder = new BeanBuilderImpl<T>(beanManager, beanDeployerEnvironment, type, ejbDescriptor, decorator, delayInitialization);
+      BeanBuilderImpl<T> builder = new BeanBuilderImpl<T>(beanManager, beanDeployerEnvironment, type, ejbDescriptor, decorator);
       builder.createBeans();
       
       return builder;
@@ -186,61 +178,105 @@
    
    private Set<Bean<?>> createSimpleBeans(WBClass<T> clazz)
    {
+//      beans = new LinkedHashSet<Bean<?>>();
+//      ManagedBeanBuilder<T> mainBuilder = ManagedBeanBuilder.of(clazz, beanManager);
+//      
+//      mainBean = bean;
+//      
+//      beanDeployerEnvironment.addBean(bean);
+//      beans.add(bean);
+//      
+//      createSubBeans(beans, bean);
+//      
+//      NewManagedBean<T> newBean = NewManagedBean.of(clazz, beanManager);
+//      beanDeployerEnvironment.addBean(newBean);
+//      beans.add(newBean);
+//      this.newBean = newBean;
+//      
+//      if (!delayInitialization)
+//         newBean.initialize(beanDeployerEnvironment);
+//      
+//      return beans;
       beans = new LinkedHashSet<Bean<?>>();
-      ManagedBean<T> bean = ManagedBean.of(clazz, beanManager);
-      mainBean = bean;
-      
+
+      ManagedBeanBuilder<T> builder = ManagedBeanBuilder.of(clazz, beanManager);
+      builder.initialize(beanDeployerEnvironment);
+      ManagedBean<T> bean = builder.createBean();
+      this.mainBean = bean;
       beanDeployerEnvironment.addBean(bean);
-      beans.add(bean);
-      
-      if (!delayInitialization)
-         bean.initialize(beanDeployerEnvironment);
-      
+      beans.add(mainBean);
+            
       createSubBeans(beans, bean);
       
-      NewManagedBean<T> newBean = NewManagedBean.of(clazz, beanManager);
+      NewManagedBeanBuilder<T> newBeanBuilder = NewManagedBeanBuilder.of(clazz, beanManager);
+      newBeanBuilder.initialize(beanDeployerEnvironment);
+      NewManagedBean<T> newBean = newBeanBuilder.createBean();
+      this.newBean = newBean;
       beanDeployerEnvironment.addBean(newBean);
       beans.add(newBean);
-      this.newBean = newBean;
       
-      if (!delayInitialization)
-         newBean.initialize(beanDeployerEnvironment);
-      
       return beans;
+
    }
    
    private Set<Bean<?>> createEnterpriseBeans(InternalEjbDescriptor<T> ejbDescriptor)
    {
-      beans = new LinkedHashSet<Bean<?>>();
-      SessionBean<T> bean = SessionBean.of(ejbDescriptor, beanManager);
-      mainBean = bean;
+//      beans = new LinkedHashSet<Bean<?>>();
+//      SessionBean<T> bean = SessionBean.of(ejbDescriptor, beanManager);
+//      mainBean = bean;
+//      
+//      beanDeployerEnvironment.addBean(bean);
+//      beans.add(bean);
+//      if (!delayInitialization)
+//         bean.initialize(beanDeployerEnvironment);
+//      
+//      createSubBeans(beans, bean);
+//      
+//      NewSessionBean<T> newBean = NewSessionBean.of(ejbDescriptor, beanManager);
+//      beanDeployerEnvironment.addBean(newBean);
+//      beans.add(newBean);
+//      this.newBean = newBean;
+//      
+//      if (!delayInitialization)
+//         newBean.initialize(beanDeployerEnvironment);
+//      
+//      return beans;
       
-      beanDeployerEnvironment.addBean(bean);
-      beans.add(bean);
-      if (!delayInitialization)
-         bean.initialize(beanDeployerEnvironment);
-      
-      createSubBeans(beans, bean);
-      
-      NewSessionBean<T> newBean = NewSessionBean.of(ejbDescriptor, beanManager);
-      beanDeployerEnvironment.addBean(newBean);
-      beans.add(newBean);
-      this.newBean = newBean;
-      
-      if (!delayInitialization)
-         newBean.initialize(beanDeployerEnvironment);
-      
-      return beans;
+       beans = new LinkedHashSet<Bean<?>>();
+       
+       SessionBeanBuilder<T> builder = SessionBeanBuilder.of(ejbDescriptor, beanManager);
+       builder.initialize(beanDeployerEnvironment);
+       SessionBean<T> bean = builder.createBean();
+       beanDeployerEnvironment.addBean(bean);
+       beans.add(bean);
+       
+       createSubBeans(beans, bean);
+       
+       NewSessionBeanBuilder<T> newBeanBuilder = NewSessionBeanBuilder.of(ejbDescriptor, beanManager);
+       newBeanBuilder.initialize(beanDeployerEnvironment);
+       NewSessionBean<T> newBean = newBeanBuilder.createBean();
+       this.newBean = newBean;
+       beanDeployerEnvironment.addBean(newBean);
+       beans.add(newBean);
+
+       return beans;
    }
    
    private Bean<T> createDecorator(WBClass<T> annotatedClass)
    {
-      DecoratorImpl<T> bean = DecoratorImpl.of(annotatedClass, beanManager);
-      mainBean = bean;
+//      DecoratorImpl<T> bean = DecoratorImpl.of(annotatedClass, beanManager);
+//      mainBean = bean;
+//      
+//      beanDeployerEnvironment.addBean(bean);
+//      if (!delayInitialization)
+//         bean.initialize(beanDeployerEnvironment);
+//      
+//      return bean;
       
-      beanDeployerEnvironment.addBean(bean);
-      if (!delayInitialization)
-         bean.initialize(beanDeployerEnvironment);
+      DecoratorBuilder<T> builder = DecoratorBuilder.of(annotatedClass, beanManager);
+      builder.initialize(beanDeployerEnvironment);
+      DecoratorImpl<T> bean = builder.createBean();
+      this.mainBean = bean;
       
       return bean;
    }
@@ -283,20 +319,33 @@
    {
       for (WBMethod<?, ?> method : annotatedClass.getWBDeclaredMethodsWithAnnotatedParameters(Disposes.class))
       {
-         DisposalMethod<?> disposalBean = DisposalMethod.of(beanManager, method, declaringBean);
+//         DisposalMethod<?> disposalBean = DisposalMethod.of(beanManager, method, declaringBean);
+//         beanDeployerEnvironment.addBean(disposalBean);
+//         //Do not delay initialization of decorator beans, they get initialized right away in the original impl
+//         disposalBean.initialize(beanDeployerEnvironment);
+         
+         DisposalMethodBuilder<?> builder = DisposalMethodBuilder.of(beanManager, method, declaringBean);
+         //Do not delay initialization of decorator beans, they get initialized right away in the original impl
+         builder.initialize(beanDeployerEnvironment);
+         DisposalMethod<?> disposalBean = builder.createBean();
          beanDeployerEnvironment.addBean(disposalBean);
-         //Do not delay initialization of decorator beans, they get initialized right away in the original impl
-         disposalBean.initialize(beanDeployerEnvironment);
+
       }
    }
    
    protected <T> void createProducerMethod(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBMethod<T, ?> annotatedMethod)
    {
-      ProducerMethod<T> bean = ProducerMethod.of(annotatedMethod, declaringBean, beanManager);
+//      ProducerMethod<T> bean = ProducerMethod.of(annotatedMethod, declaringBean, beanManager);
+//      beanDeployerEnvironment.addBean(bean);
+//      beans.add(bean);
+//      if (!delayInitialization)
+//         bean.initialize(beanDeployerEnvironment);
+      
+      ProducerMethodBuilder<T> builder = ProducerMethodBuilder.of(annotatedMethod, declaringBean, beanManager);
+      builder.initialize(beanDeployerEnvironment);
+      ProducerMethod<T> bean = builder.createBean();
       beanDeployerEnvironment.addBean(bean);
       beans.add(bean);
-      if (!delayInitialization)
-         bean.initialize(beanDeployerEnvironment);
    }
    
    protected void createProducerFields(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
@@ -309,24 +358,29 @@
 
    protected <T> void createProducerField(Set<Bean<?>> beans, AbstractClassBean<?> declaringBean, WBField<T, ?> field)
    {
-      ProducerField<T> bean;
-      if (isPersistenceContextProducerField(field))
-      {
-         bean = PersistenceContextProducerField.of(field, declaringBean, beanManager);
-      }
-      else if (isEEResourceProducerField(field))
-      {
-         bean = EEResourceProducerField.of(field, declaringBean, beanManager);
-      }
-      else
-      {
-         bean = ProducerField.of(field, declaringBean, beanManager);
-      }
+//      ProducerField<T> bean;
+//      if (isPersistenceContextProducerField(field))
+//      {
+//         bean = PersistenceContextProducerField.of(field, declaringBean, beanManager);
+//      }
+//      else if (isEEResourceProducerField(field))
+//      {
+//         bean = EEResourceProducerField.of(field, declaringBean, beanManager);
+//      }
+//      else
+//      {
+//         bean = ProducerField.of(field, declaringBean, beanManager);
+//      }
+//      
+//      beanDeployerEnvironment.addBean(bean);
+//      beans.add(bean);
+//      if (!delayInitialization)
+//         bean.initialize(beanDeployerEnvironment);
       
-      beanDeployerEnvironment.addBean(bean);
+      ProducerFieldBuilder<T> builder = ProducerFieldBuilder.of(field, declaringBean, beanManager);
+      builder.initialize(beanDeployerEnvironment);
+      ProducerField<T> bean = builder.createBean();
       beans.add(bean);
-      if (!delayInitialization)
-         bean.initialize(beanDeployerEnvironment);
    }
       
    public Set<ObserverMethod<T, ?>> createObserverMethods(RIBean<T> declaringBean, WBClass<T> annotatedClass)
@@ -343,13 +397,21 @@
    
    protected <X, T> ObserverMethodImpl<X, T> createObserverMethod(RIBean<X> declaringBean, WBMethod<T, X> method)
    {
+//      ObserverMethodImpl<X, T> observer = ObserverFactory.create(method, declaringBean, beanManager);
+//      ProcessObserverMethod<?, ?> event = createProcessObserverMethodEvent(observer, method);
+//      beanManager.fireEvent(event);
+//      beanDeployerEnvironment.addObserver(observer);
+//      if (!delayInitialization)
+//         observer.initialize();
+//      return observer;
+      
       ObserverMethodImpl<X, T> observer = ObserverFactory.create(method, declaringBean, beanManager);
       ProcessObserverMethod<?, ?> event = createProcessObserverMethodEvent(observer, method);
       beanManager.fireEvent(event);
       beanDeployerEnvironment.addObserver(observer);
-      if (!delayInitialization)
-         observer.initialize();
+      observer.initialize();
       return observer;
+
    }
    
    private <X, T> ProcessObserverMethod<X, T> createProcessObserverMethodEvent(ObserverMethod<X, T> observer, AnnotatedMethod<X> method)
@@ -373,20 +435,4 @@
       
       return new InternalEjbDescriptor<T>(ejbDescriptor);
    }
-   
-   protected boolean isEEResourceProducerField(WBField<?, ?> field)
-   {
-      EJBApiAbstraction ejbApiAbstraction = beanManager.getServices().get(EJBApiAbstraction.class);
-      PersistenceApiAbstraction persistenceApiAbstraction = beanManager.getServices().get(PersistenceApiAbstraction.class);
-      WSApiAbstraction wsApiAbstraction = beanManager.getServices().get(WSApiAbstraction.class);
-      return field.isAnnotationPresent(ejbApiAbstraction.EJB_ANNOTATION_CLASS) || field.isAnnotationPresent(ejbApiAbstraction.RESOURCE_ANNOTATION_CLASS) || field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_UNIT_ANNOTATION_CLASS) || field.isAnnotationPresent(wsApiAbstraction.WEB_SERVICE_REF_ANNOTATION_CLASS); 
-   }
-   
-   protected boolean isPersistenceContextProducerField(WBField<?, ?> field)
-   {
-      PersistenceApiAbstraction persistenceApiAbstraction = beanManager.getServices().get(PersistenceApiAbstraction.class);
-      return field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_CONTEXT_ANNOTATION_CLASS); 
-   }
-         
-
 }

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DecoratorBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,245 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Decorator;
+import javax.inject.Inject;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.DecoratorImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.MethodInjectionPoint;
+import org.jboss.webbeans.injection.WBInjectionPoint;
+import org.jboss.webbeans.introspector.WBClass;
+
+class DecoratorBuilder<T> extends ManagedBeanBuilder<T> implements Decorator<T>
+{
+
+   public static <T> Decorator<T> wrapForResolver(final Decorator<T> decorator)
+   {
+      return new ForwardingDecorator<T>()
+      {
+
+         @Override
+         public Set<Annotation> getQualifiers()
+         {
+            return delegate().getDelegateQualifiers();
+         }
+
+         @Override
+         public Set<Type> getTypes()
+         {
+            return delegate().getTypes();
+         }
+
+         @Override
+         protected Decorator<T> delegate()
+         {
+            return decorator;
+         }
+
+      };
+   }
+
+   /**
+    * Creates a decorator bean
+    * 
+    * @param <T> The type
+    * @param clazz The class
+    * @param manager the current manager
+    * @return a Bean
+    */
+   public static <T> DecoratorBuilder<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   {
+      return new DecoratorBuilder<T>(clazz, manager);
+   }
+
+   private WBInjectionPoint<?, ?> delegateInjectionPoint;
+   private Set<Annotation> delegateBindings;
+   private Type delegateType;
+   private Set<Type> delegateTypes;
+   private Set<Type> decoratedTypes;
+
+   protected DecoratorBuilder(WBClass<T> type, BeanManagerImpl manager)
+   {
+      super(type, manager);
+   }
+
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (!isInitialized())
+      {
+         super.initialize(environment);
+         initDelegateInjectionPoint();
+         initDecoratedTypes();
+         initDelegateBindings();
+         initDelegateType();
+         checkDelegateType();
+      }
+   }
+
+   protected void initDecoratedTypes()
+   {
+      this.decoratedTypes = new HashSet<Type>();
+      this.decoratedTypes.addAll(getAnnotatedItem().getInterfaceOnlyFlattenedTypeHierarchy());
+      this.decoratedTypes.remove(Serializable.class);
+   }
+
+   protected void initDelegateInjectionPoint()
+   {
+      this.delegateInjectionPoint = getDelegateInjectionPoints().iterator().next();
+   }
+
+   @Override
+   protected void checkDelegateInjectionPoints()
+   {
+      for (WBInjectionPoint<?, ?> injectionPoint : getDelegateInjectionPoints())
+      {
+         if (injectionPoint instanceof MethodInjectionPoint<?, ?> && !injectionPoint.isAnnotationPresent(Inject.class))
+         {
+            throw new DefinitionException("Method with @Decorates parameter must be an initializer method " + injectionPoint);
+         }
+      }
+      if (getDelegateInjectionPoints().size() == 0)
+      {
+         throw new DefinitionException("No delegate injection points defined " + this);
+      }
+      else if (getDelegateInjectionPoints().size() > 1)
+      {
+         throw new DefinitionException("Too many delegate injection point defined " + this);
+      }
+   }
+
+   protected void initDelegateBindings()
+   {
+      this.delegateBindings = new HashSet<Annotation>(); 
+      this.delegateBindings.addAll(this.delegateInjectionPoint.getQualifiers());
+   }
+
+   protected void initDelegateType()
+   {
+      this.delegateType = this.delegateInjectionPoint.getBaseType();
+      this.delegateTypes = new HashSet<Type>();
+      delegateTypes.add(delegateType);
+   }
+
+   protected void checkDelegateType()
+   {
+      for (Type decoratedType : getDecoratedTypes())
+      {
+         if (decoratedType instanceof Class)
+         {
+            if (!((Class<?>) decoratedType).isAssignableFrom(delegateInjectionPoint.getJavaClass()))
+            {
+               throw new DefinitionException("The delegate type must extend or implement every decorated type. Decorated type " + decoratedType + "." + this );
+            }
+         }
+         else if (decoratedType instanceof ParameterizedType)
+         {
+            ParameterizedType parameterizedType = (ParameterizedType) decoratedType;
+            if (!delegateInjectionPoint.isParameterizedType())
+            {
+               throw new DefinitionException("The decorated type is parameterized, but the delegate type isn't. Delegate type " + delegateType + "." + this);
+            }
+            if (!Arrays.equals(delegateInjectionPoint.getActualTypeArguments(), parameterizedType.getActualTypeArguments()));
+            Type rawType = ((ParameterizedType) decoratedType).getRawType();
+            if (rawType instanceof Class && !((Class<?>) rawType).isAssignableFrom(delegateInjectionPoint.getJavaClass()))
+            {
+               throw new DefinitionException("The delegate type must extend or implement every decorated type. Decorated type " + decoratedType + "." + this );
+            }
+            else
+            {
+               throw new IllegalStateException("Unable to process " + decoratedType);
+            }
+
+         }
+      }
+   }
+
+   public Set<Annotation> getDelegateQualifiers()
+   {
+      return delegateBindings;
+   }
+
+   public Type getDelegateType()
+   {
+      return delegateType;
+   }
+
+   public Set<Type> getDecoratedTypes()
+   {
+      return decoratedTypes;
+   }
+   
+   public WBInjectionPoint<?, ?> getDelegateInjectionPoint()
+   {
+      return delegateInjectionPoint;
+   }
+
+   /**
+    * The type closure of the delegate type
+    * 
+    * @return the delegateTypes
+    */
+   public Set<Type> getDelegateTypes()
+   {
+      return delegateTypes;
+   }
+   
+   @Override
+   protected void initDecorators()
+   {
+      // No-op, decorators can't have decorators
+   }
+   
+   /* (non-Javadoc)
+    * @see org.jboss.webbeans.bean.SimpleBean#toString()
+    */
+   @Override
+   public String toString()
+   {
+      // TODO Auto-generated method stub
+      return super.toString("decorator");
+   }
+
+   @Override
+   public DecoratorImpl<T> createBean()
+   {
+      return DecoratorImpl.of(getAnnotatedItem(), 
+            getManager(),
+            name,
+            getMergedStereotypes(),
+            getScope(),
+            isAlternative(),
+            isProxyable(),
+            bindings,
+            getSuperclasses(),
+            getPostConstruct(),
+            getPreDestroy(),
+            getSpecializedBean());
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/DisposalMethodBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,263 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.DisposalMethod;
+import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.introspector.WBMethod;
+
+class DisposalMethodBuilder<T> extends AbstractReceiverBeanBuilder<T, Method>
+{
+
+   protected WBMethod<T, ?> disposalMethod;
+   
+   //protected MethodInjectionPoint<T, ?> disposalMethodInjectionPoint;
+   private final String id;
+
+   protected DisposalMethodBuilder(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
+   {
+      super(declaringBean, manager);
+      this.disposalMethod = disposalMethod;
+      //this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
+      this.id = createId("DisposalMethod-" + declaringBean.getName() + "-" + disposalMethod.getSignature().toString());
+      initBindings();
+      initType();
+      initTypes();
+      initStereotypes();
+      initPolicy();
+   }
+   
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      super.initialize(environment);
+      checkDisposalMethod();
+   }
+
+   protected void initType()
+   {
+      disposalMethod.getAnnotatedWBParameters(Disposes.class).get(0).getJavaClass();
+      this.type = (Class<T>) disposalMethod.getAnnotatedWBParameters(Disposes.class).get(0).getJavaClass();
+   }
+
+   @Override
+   public WBMethod<T, ?> getAnnotatedItem()
+   {
+      return disposalMethod;
+   }
+
+   public static <T> DisposalMethodBuilder<T> of(BeanManagerImpl manager, WBMethod<T, ?> disposalMethod, AbstractClassBean<?> declaringBean)
+   {
+      return new DisposalMethodBuilder<T>(manager, disposalMethod, declaringBean);
+   }
+
+   @Override
+   protected void initBindings()
+   {
+      // At least 1 parameter exists, already checked in constructor
+      this.bindings = new HashSet<Annotation>();
+      //this.bindings.addAll(disposalMethodInjectionPoint.getWBParameters().get(0).getQualifiers());
+      this.bindings.addAll(disposalMethod.getWBParameters().get(0).getQualifiers());
+      initDefaultBindings();
+   }
+
+   /**
+    * Initializes the API types
+    */
+   @Override
+   protected void initTypes()
+   {
+      Set<Type> types = new HashSet<Type>();
+      types = new HashSet<Type>();
+      //types.addAll(disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).get(0).getTypeClosure());
+      types.addAll(disposalMethod.getAnnotatedWBParameters(Disposes.class).get(0).getTypeClosure());
+      types.add(Object.class);
+      super.types = types;
+   }
+
+   @Override
+   public String getName()
+   {
+      return null;
+   }
+
+   @Override
+   public Class<? extends Annotation> getScope()
+   {
+      return null;
+   }
+
+   @Override
+   public Set<Type> getTypes()
+   {
+      return types;
+   }
+
+   @Override
+   public String toString()
+   {
+      return disposalMethod.toString();
+   }
+
+   @Override
+   public boolean isNullable()
+   {
+      // Not relevant
+      return false;
+   }
+
+   @Override
+   public boolean isSerializable()
+   {
+      // Not relevant
+      return false;
+   }
+
+   @Override
+   public boolean isProxyable()
+   {
+      return true;
+   }
+
+   public T create(CreationalContext<T> creationalContext)
+   {
+      // Not Relevant
+      return null;
+   }
+
+   private void checkDisposalMethod()
+   {
+      if (!disposalMethod.getWBParameters().get(0).isAnnotationPresent(Disposes.class))
+      {
+         throw new DefinitionException(disposalMethod.toString() + " doesn't have @Dispose as first parameter");
+      }
+      if (disposalMethod.getAnnotatedWBParameters(Disposes.class).size() > 1)
+      {
+         throw new DefinitionException(disposalMethod.toString() + " has more than one @Dispose parameters");
+      }
+      if (disposalMethod.getAnnotatedWBParameters(Observes.class).size() > 0)
+      {
+         throw new DefinitionException("@Observes is not allowed on disposal method, see " + disposalMethod.toString());
+      }
+      if (disposalMethod.getAnnotation(Inject.class) != null)
+      {
+         throw new DefinitionException("@Inject is not allowed on a disposal method, see " + disposalMethod.toString());
+      }
+      if (disposalMethod.getAnnotation(Produces.class) != null)
+      {
+         throw new DefinitionException("@Produces is not allowed on a disposal method, see " + disposalMethod.toString());
+      }
+      if (getDeclaringBean() instanceof SessionBean<?>)
+      {
+         boolean methodDeclaredOnTypes = false;
+         // TODO use annotated item?
+         for (Type type : getDeclaringBean().getTypes())
+         {
+            if (type instanceof Class<?>)
+            {
+               Class<?> clazz = (Class<?>) type;
+               try
+               {
+                  clazz.getDeclaredMethod(disposalMethod.getName(), disposalMethod.getParameterTypesAsArray());
+                  methodDeclaredOnTypes = true;
+               }
+               catch (NoSuchMethodException nsme)
+               {
+                  // No - op
+               }
+            }
+         }
+         if (!methodDeclaredOnTypes)
+         {
+            throw new DefinitionException("Producer method " + toString() + " must be declared on a business interface of " + getDeclaringBean());
+         }
+      }
+   }
+
+   @Override
+   public Class<T> getType()
+   {
+      return type;
+   }
+
+   @Override
+   protected String getDefaultName()
+   {
+      return disposalMethod.getPropertyName();
+   }
+
+   public void destroy(T instance, CreationalContext<T> creationalContext)
+   {
+      // No-op. Producer method dependent objects are destroyed in producer method bean  
+   }
+
+   @Override
+   public String getId()
+   {
+      return id;
+   }
+
+   @Override
+   public AbstractBean<?, ?> getSpecializedBean()
+   {
+      // Doesn't support specialization
+      return null;
+   }
+   
+   @Override
+   protected void initScopeType()
+   {
+      // Disposal methods aren't scoped
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return Collections.emptySet();
+   }
+
+   public DisposalMethod<T> createBean()
+   {
+      return DisposalMethod.of(manager, 
+            name,
+            disposalMethod, 
+            getDeclaringBean(),
+            type,
+            types,
+            getMergedStereotypes(), 
+            isAlternative(),
+            isProxyable(),
+            bindings);
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingBean.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingBean.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * A delegating bean
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T>
+ */
+public abstract class ForwardingBean<T> implements Bean<T>
+{
+
+   /**
+    * Creates an instance of the delegate
+    * 
+    * @return an instance of the delegate
+    */
+   public T create(CreationalContext<T> creationalContext)
+   {
+      return delegate().create(creationalContext);
+   }
+
+   /**
+    * Abstract getter for the delegate
+    * 
+    * @return The delegate
+    */
+   protected abstract Bean<T> delegate();
+
+   /**
+    * Destroys an instance through the delegate
+    * 
+    * @param instance The instance to destroy
+    */
+   public void destroy(T instance, CreationalContext<T> creationalContext)
+   {
+      delegate().destroy(instance, creationalContext);
+   }
+
+   /**
+    * Compares an object with the delegate
+    * 
+    * @return True if equals, false otherwise
+    */
+   @Override
+   public boolean equals(Object obj)
+   {
+      return delegate().equals(obj);
+   }
+
+   public Class<?> getBeanClass()
+   {
+      return delegate().getBeanClass();
+   }
+
+   /**
+    * Gets the binding types of the delegate
+    * 
+    * @return The binding types
+    */
+   public Set<Annotation> getQualifiers()
+   {
+      return delegate().getQualifiers();
+   }
+
+   public Set<InjectionPoint> getInjectionPoints()
+   {
+      return delegate().getInjectionPoints();
+   }
+
+   /**
+    * Gets the name of the delegate
+    * 
+    * @return The name
+    */
+   public String getName()
+   {
+      return delegate().getName();
+   }
+
+   /**
+    * The stereotypes applied to this bean
+    * 
+    * @return stereotypes if any
+    */
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return delegate().getStereotypes();
+   }
+
+   /**
+    * Gets the scope type of the delegate
+    * 
+    * @return The scope type
+    */
+   public Class<? extends Annotation> getScope()
+   {
+      return delegate().getScope();
+   }
+
+   /**
+    * Gets the API types of the delegate
+    * 
+    * @return The API types
+    */
+   public Set<Type> getTypes()
+   {
+      return delegate().getTypes();
+   }
+
+   /**
+    * Gets the hash code of the delegate
+    * 
+    * @return The hash code
+    */
+   @Override
+   public int hashCode()
+   {
+      return delegate().hashCode();
+   }
+
+   /**
+    * Indicates if the delegate is nullable
+    * 
+    * @return True if nullable, false otherwise
+    */
+   public boolean isNullable()
+   {
+      return delegate().isNullable();
+   }
+
+   public boolean isAlternative()
+   {
+      return delegate().isAlternative();
+   }
+
+   /**
+    * Returns a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      return "ForwardingBean " + getName() + " for " + delegate().toString();
+   }
+
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingDecorator.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingDecorator.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ForwardingDecorator.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Decorator;
+
+public abstract class ForwardingDecorator<T> extends ForwardingBean<T> implements Decorator<T>
+{
+
+   @Override
+   protected abstract Decorator<T> delegate();
+
+   public Set<Type> getDecoratedTypes()
+   {
+      return delegate().getDecoratedTypes();
+   }
+
+   public Set<Annotation> getDelegateQualifiers()
+   {
+      return delegate().getDelegateQualifiers();
+   }
+
+   public Type getDelegateType()
+   {
+      return delegate().getDelegateType();
+   }
+
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ManagedBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,310 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.spi.Decorator;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.ManagedBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.ConstructorInjectionPoint;
+import org.jboss.webbeans.injection.WBInjectionPoint;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBConstructor;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.Names;
+import org.jboss.webbeans.util.Reflections;
+
+/**
+ * Represents a simple bean
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T> The type (class) of the bean
+ */
+class ManagedBeanBuilder<T> extends AbstractClassBeanBuilder<T>
+{
+   // Logger
+   private static LogProvider log = Logging.getLogProvider(ManagedBeanBuilder.class);
+
+   // The constructor
+   private ConstructorInjectionPoint<T> constructor;
+   private Set<WBInjectionPoint<?, ?>> ejbInjectionPoints;
+   private Set<WBInjectionPoint<?, ?>> persistenceContextInjectionPoints;
+   private Set<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
+   private Set<WBInjectionPoint<?, ?>> resourceInjectionPoints;
+
+   private ManagedBean<?> specializedBean;
+
+   
+
+   /**
+    * Creates a simple, annotation defined Web Bean
+    * 
+    * @param <T> The type
+    * @param clazz The class
+    * @param manager the current manager
+    * @return A Web Bean
+    */
+   public static <T> ManagedBeanBuilder<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   {
+      return new ManagedBeanBuilder<T>(clazz, manager);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param type The type of the bean
+    * @param manager The Web Beans manager
+    */
+   protected ManagedBeanBuilder(WBClass<T> type, BeanManagerImpl manager)
+   {
+      super(type, manager);
+      initType();
+      initTypes();
+      initBindings();
+   }
+
+   protected InjectionPoint attachCorrectInjectionPoint()
+   {
+      Decorator<?> decorator = getDecorators().get(getDecorators().size() - 1);
+      if (decorator instanceof DecoratorBuilder<?>)
+      {
+         DecoratorBuilder<?> decoratorBean = (DecoratorBuilder<?>) decorator;
+         InjectionPoint outerDelegateInjectionPoint = decoratorBean.getDelegateInjectionPoint();
+         return getManager().replaceOrPushCurrentInjectionPoint(outerDelegateInjectionPoint);
+      }
+      else
+      {
+         throw new IllegalStateException("Cannot operate on user defined decorator");
+      }
+   }
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (!isInitialized())
+      {
+         initConstructor();
+         checkConstructor();
+         super.initialize(environment);
+         initPostConstruct();
+         initPreDestroy();
+         initEEInjectionPoints();
+      }
+   }
+
+   private void initEEInjectionPoints()
+   {
+      this.ejbInjectionPoints = Beans.getEjbInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.persistenceContextInjectionPoints = Beans.getPersistenceContextInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.persistenceUnitInjectionPoints = Beans.getPersistenceUnitInjectionPoints(this, getAnnotatedItem(), getManager());
+      this.resourceInjectionPoints = Beans.getResourceInjectionPoints(this, getAnnotatedItem(), manager);
+   }
+
+   /**
+    * Validates the type
+    */
+   protected void checkType()
+   {
+      if (getAnnotatedItem().isNonStaticMemberClass())
+      {
+         throw new DefinitionException("Simple bean " + type + " cannot be a non-static inner class");
+      }
+      if (!isDependent() && getAnnotatedItem().isParameterizedType())
+      {
+         throw new DefinitionException("Managed bean " + type + " must be @Dependent");
+      }
+      boolean passivating = manager.getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).isPassivating();
+      if (passivating && !Reflections.isSerializable(getBeanClass()))
+      {
+         throw new DefinitionException("Simple bean declaring a passivating scope must have a serializable implementation class " + toString());
+      }
+      if (hasDecorators())
+      {
+         if (getAnnotatedItem().isFinal())
+         {
+            throw new DefinitionException("Bean class which has decorators cannot be declared final " + this);
+         }
+         for (Decorator<?> decorator : getDecorators())
+         {
+            if (decorator instanceof DecoratorBuilder<?>)
+            {
+               DecoratorBuilder<?> decoratorBean = (DecoratorBuilder<?>) decorator;
+               for (WBMethod<?, ?> decoratorMethod : decoratorBean.getAnnotatedItem().getWBMethods())
+               {
+                  WBMethod<?, ?> method = getAnnotatedItem().getWBMethod(decoratorMethod.getSignature());  
+                  if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal())
+                  {
+                     throw new DefinitionException("Decorated bean method " + method + " (decorated by "+ decoratorMethod + ") cannot be declarted final");
+                  }
+               }
+            }
+            else
+            {
+               throw new IllegalStateException("Can only operate on container provided decorators " + decorator);
+            }
+         }
+      }
+   }
+
+   @Override
+   protected void checkBeanImplementation()
+   {
+      super.checkBeanImplementation();
+      if (!isDependent())
+      {
+         for (WBField<?, ?> field : getAnnotatedItem().getWBFields())
+         {
+            if (field.isPublic() && !field.isStatic())
+            {
+               throw new DefinitionException("Normal scoped Web Bean implementation class has a public field " + getAnnotatedItem());
+            }
+         }
+      }
+   }
+   
+   protected void checkConstructor()
+   {
+      if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
+      {
+         throw new DefinitionException("Managed bean constructor must not have a parameter annotated @Disposes " + constructor);
+      }
+      if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
+      {
+         throw new DefinitionException("Managed bean constructor must not have a parameter annotated @Observes " + constructor);
+      }
+   }
+
+   @Override
+   protected void preSpecialize(BeanDeployerEnvironment environment)
+   {
+      super.preSpecialize(environment);
+      if (environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
+      {
+         throw new DefinitionException("Simple bean must specialize a simple bean");
+      }
+   }
+
+   @Override
+   protected void specialize(BeanDeployerEnvironment environment)
+   {
+      if (environment.getClassBean(getAnnotatedItem().getWBSuperclass()) == null)
+      {
+         throw new DefinitionException(toString() + " does not specialize a bean");
+      }
+      AbstractClassBean<?> specializedBean = environment.getClassBean(getAnnotatedItem().getWBSuperclass());
+      if (!(specializedBean instanceof ManagedBean))
+      {
+         throw new DefinitionException(toString() + " doesn't have a simple bean as a superclass " + specializedBean);
+      }
+      else
+      {
+         this.specializedBean = (ManagedBean<?>) specializedBean;
+      }
+   }
+
+
+   /**
+    * Initializes the constructor
+    */
+   protected void initConstructor()
+   {
+      this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
+      // TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
+      addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
+   }
+
+   /**
+    * Returns the constructor
+    * 
+    * @return The constructor
+    */
+   public WBConstructor<T> getConstructor()
+   {
+      return constructor;
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      return toString("simple bean");
+   }
+   
+   protected String toString(String beanType)
+   {
+      StringBuilder buffer = new StringBuilder();
+      buffer.append(Names.scopeTypeToString(getScope()));
+      if (getName() == null)
+      {
+         buffer.append("unnamed ").append(beanType);
+      }
+      else
+      {
+         buffer.append(beanType).append(" '" + getName() + "'");
+      }
+      buffer.append(" ").append(getType().getName()).append(", ");
+      buffer.append(" API types = ").append(Names.typesToString(getTypes())).append(", binding types = " + Names.annotationsToString(getQualifiers()));
+      return buffer.toString();
+   }
+
+   @Override
+   public ManagedBean<?> getSpecializedBean()
+   {
+      return specializedBean;
+   }
+
+   @Override
+   public ManagedBean<T> createBean()
+   {
+      return ManagedBean.of(
+            getAnnotatedItem(),
+            getManager(),
+            name,
+            getMergedStereotypes(),
+            getScope(),
+            isAlternative(),
+            isProxyable(),
+            bindings,
+            getSuperclasses(),
+            getProxyClassForDecorators(),
+            getDecorators(),
+            getPostConstruct(),
+            getPreDestroy(),
+            getSpecializedBean());
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewManagedBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.NewManagedBean;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.literal.NewLiteral;
+
+/**
+ * Represents a @New simple bean
+ * 
+ * @author Nicklas Karlsson 
+ */
+class NewManagedBeanBuilder<T> extends ManagedBeanBuilder<T>
+{
+
+   /**
+    * Creates an instance of a NewSimpleBean from an annotated class
+    * 
+    * @param clazz The annotated class
+    * @param manager The Web Beans manager
+    * @return a new NewSimpleBean instance
+    */
+   public static <T> NewManagedBeanBuilder<T> of(WBClass<T> clazz, BeanManagerImpl manager)
+   {
+      return new NewManagedBeanBuilder<T>(clazz, manager);
+   }
+   
+   private Set<Annotation> bindings;
+
+   /**
+    * Protected constructor
+    * 
+    * @param type An annotated class
+    * @param manager The Web Beans manager
+    */
+   protected NewManagedBeanBuilder(final WBClass<T> type, BeanManagerImpl manager)
+   {
+      super(type, manager);
+      this.bindings = new HashSet<Annotation>();
+      this.bindings.add(new NewLiteral()
+      {
+         
+         public Class<?> value()
+         {
+            return type.getJavaClass();
+         }
+         
+      });
+   }
+
+   /**
+    * Gets the scope type
+    * 
+    * @return @Dependent
+    */
+   @Override
+   public Class<? extends Annotation> getScope()
+   {
+      return Dependent.class;
+   }
+
+   @Override
+   public boolean isAlternative()
+   {
+      return false;
+   }
+
+   /**
+    * Gets the name of the bean
+    * 
+    * @return null
+    */
+   @Override
+   public String getName()
+   {
+      return null;
+   }
+
+   /**
+    * Gets the bindings
+    * 
+    * @returns @New
+    */
+   @Override
+   public Set<Annotation> getQualifiers()
+   {
+      return bindings;
+   }
+
+   @Override
+   public boolean isSpecializing()
+   {
+      return false;
+   }
+
+   @Override
+   public NewManagedBean<T> createBean()
+   {
+      return NewManagedBean.of(
+            getAnnotatedItem(),
+            getManager(),
+            name,
+            getMergedStereotypes(),
+            getScope(),
+            isAlternative(),
+            isAlternative(),
+            bindings,
+            getSuperclasses(),
+            getProxyClassForDecorators(),
+            getDecorators(),
+            getPostConstruct(),
+            getPreDestroy(),
+            getSpecializedBean());
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/NewSessionBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.NewSessionBean;
+import org.jboss.webbeans.ejb.InternalEjbDescriptor;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.literal.NewLiteral;
+import org.jboss.webbeans.resources.ClassTransformer;
+
+/**
+ * Represents a @New enterprise bean
+ * 
+ * @author Nicklas Karlsson
+ */
+class NewSessionBeanBuilder<T> extends SessionBeanBuilder<T>
+{
+
+   /**
+    * Creates an instance of a NewEnterpriseBean from an annotated class
+    * 
+    * @param clazz The annotated class
+    * @param manager The Web Beans manager
+    * @return a new NewEnterpriseBean instance
+    */
+   public static <T> NewSessionBeanBuilder<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   {
+      WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
+      return new NewSessionBeanBuilder<T>(type, ejbDescriptor, manager);
+   }
+   
+   private Set<Annotation> bindings;
+
+   /**
+    * Protected constructor
+    * 
+    * @param type An annotated class
+    * @param manager The Web Beans manager
+    */
+   protected NewSessionBeanBuilder(final WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   {
+      super(type, ejbDescriptor, manager);
+      this.bindings = new HashSet<Annotation>();
+      this.bindings.add(new NewLiteral()
+      {
+         
+         public Class<?> value()
+         {
+            return type.getJavaClass();
+         }
+         
+      });
+   }
+
+   /**
+    * Gets the scope type
+    * 
+    * @return @Dependent
+    */
+   @Override
+   public Class<? extends Annotation> getScope()
+   {
+      return Dependent.class;
+   }
+
+   @Override
+   public boolean isAlternative()
+   {
+      return false;
+   }
+
+   /**
+    * Gets the name of the bean
+    * 
+    * @return null
+    */
+   @Override
+   public String getName()
+   {
+      return null;
+   }
+
+   /**
+    * Gets the bindings
+    * 
+    * @returns @New
+    */
+   @Override
+   public Set<Annotation> getQualifiers()
+   {
+      return bindings;
+   }
+   
+   @Override
+   public boolean isSpecializing()
+   {
+      return false;
+   }
+   
+   @Override
+   protected void checkScopeAllowed()
+   {
+      // No-op
+   }
+
+   @Override
+   public NewSessionBean<T> createBean()
+   {
+      return NewSessionBean.of(getEjbDescriptor(),
+            getManager(),
+            name,
+            types,
+            getMergedStereotypes(),
+            getScope(),
+            isAlternative(),
+            isProxyable(),
+            bindings,
+            getSuperclasses(),
+            getProxyClassForDecorators(),
+            getDecorators(),
+            getPostConstruct(),
+            getPreDestroy(),
+            getProxyClass(),
+            getSpecializedBean());
+   }
+
+   
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,223 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.Set;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.ProducerField;
+import org.jboss.webbeans.bean.ee.EEResourceProducerField;
+import org.jboss.webbeans.bean.ee.PersistenceContextProducerField;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.ejb.EJBApiAbstraction;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
+import org.jboss.webbeans.util.Names;
+import org.jboss.webbeans.ws.WSApiAbstraction;
+
+/**
+ * Represents a producer field
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T>
+ */
+class ProducerFieldBuilder<T> extends AbstractProducerBeanBuilder<T, Field>
+{
+   // The underlying field
+   private WBField<T, ?> field;
+   private final String id;
+   
+   /**
+    * Creates a producer field
+    * 
+    * @param field The underlying method abstraction
+    * @param declaringBean The declaring bean abstraction
+    * @param manager the current manager
+    * @return A producer field
+    */
+   public static <T> ProducerFieldBuilder<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      return new ProducerFieldBuilder<T>(field, declaringBean, manager);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param method The producer field abstraction
+    * @param declaringBean The declaring bean
+    * @param manager The Web Beans manager
+    */
+   protected ProducerFieldBuilder(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      super(declaringBean, manager);
+      this.field = field;
+      initType();
+      initTypes();
+      initBindings();
+      this.id = createId("ProducerField-" + declaringBean.getType().getName() + "-"+ field.getName());
+      initStereotypes();
+      initPolicy();
+   }
+   
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (!isInitialized())
+      {
+         super.initialize(environment);
+      }
+   }
+
+   /**
+    * Gets the annotated item representing the field
+    * 
+    * @return The annotated item
+    */
+   @Override
+   public WBField<T, ?> getAnnotatedItem()
+   {
+      return field;
+   }
+
+   /**
+    * Returns the default name
+    * 
+    * @return The default name
+    */
+   @Override
+   protected String getDefaultName()
+   {
+      return field.getPropertyName();
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder buffer = new StringBuilder();
+      buffer.append("Annotated " + Names.scopeTypeToString(getScope()));
+      if (getName() == null)
+      {
+         buffer.append("unnamed producer field bean");
+      }
+      else
+      {
+         buffer.append("simple producer field bean '" + getName() + "'");
+      }
+      buffer.append(" [" + getBeanClass().getName() + "] for class type [" + getType().getName() + "] API types " + getTypes() + ", binding types " + getQualifiers());
+      return buffer.toString();
+   }
+   
+   @Override
+   public AbstractBean<?, ?> getSpecializedBean()
+   {
+      return null;
+   }
+   
+   @Override
+   public boolean isSpecializing()
+   {
+      return false;
+   }
+   
+   @Override
+   public String getId()
+   {
+      return id;
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return Collections.emptySet();
+   }
+
+   public ProducerField<T> createBean()
+   {
+      if (isPersistenceContextProducerField(field))
+      {
+         return PersistenceContextProducerField.of(field, 
+               getDeclaringBean(), 
+               manager,
+               name,
+               type,
+               types,
+               getMergedStereotypes(), //Should be empty? 
+               getScope(),
+               isAlternative(),
+               isProxyable(),
+               bindings);
+
+      }
+      else if (isEEResourceProducerField(field))
+      {
+         return EEResourceProducerField.of(field, 
+               getDeclaringBean(), 
+               manager,
+               name,
+               type,
+               types,
+               getMergedStereotypes(), //Should be empty? 
+               getScope(),
+               isAlternative(),
+               isProxyable(),
+               bindings);
+      }
+      else
+      {
+         return ProducerField.of(field, 
+               getDeclaringBean(), 
+               manager,
+               name,
+               type,
+               types,
+               getMergedStereotypes(), //Should be empty? 
+               getScope(),
+               isAlternative(),
+               isProxyable(),
+               bindings);
+      }
+   }
+   
+   private Set<Class<? extends Annotation>> createEmptyStereotypes()
+   {
+      return Collections.emptySet();
+   } 
+
+   protected boolean isPersistenceContextProducerField(WBField<?, ?> field)
+   {
+      PersistenceApiAbstraction persistenceApiAbstraction = getManager().getServices().get(PersistenceApiAbstraction.class);
+      return field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_CONTEXT_ANNOTATION_CLASS); 
+   }
+   
+   protected boolean isEEResourceProducerField(WBField<?, ?> field)
+   {
+      EJBApiAbstraction ejbApiAbstraction = getManager().getServices().get(EJBApiAbstraction.class);
+      PersistenceApiAbstraction persistenceApiAbstraction = getManager().getServices().get(PersistenceApiAbstraction.class);
+      WSApiAbstraction wsApiAbstraction = getManager().getServices().get(WSApiAbstraction.class);
+      return field.isAnnotationPresent(ejbApiAbstraction.EJB_ANNOTATION_CLASS) || field.isAnnotationPresent(ejbApiAbstraction.RESOURCE_ANNOTATION_CLASS) || field.isAnnotationPresent(persistenceApiAbstraction.PERSISTENCE_UNIT_ANNOTATION_CLASS) || field.isAnnotationPresent(wsApiAbstraction.WEB_SERVICE_REF_ANNOTATION_CLASS);
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerMethodBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,280 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.Disposes;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.DisposalMethod;
+import org.jboss.webbeans.bean.ProducerMethod;
+import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.MethodInjectionPoint;
+import org.jboss.webbeans.injection.ParameterInjectionPoint;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.introspector.WBParameter;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
+import org.jboss.webbeans.util.Names;
+
+/**
+ * Represents a producer method bean
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T>
+ */
+class ProducerMethodBuilder<T> extends AbstractProducerBeanBuilder<T, Method>
+{
+   // The underlying method
+   private MethodInjectionPoint<T, ?> method;
+
+   private DisposalMethod<?> disposalMethodBean;
+
+   private ProducerMethod<?> specializedBean;
+
+   private final String id;
+
+   /**
+    * Creates a producer method Web Bean
+    * 
+    * @param method The underlying method abstraction
+    * @param declaringBean The declaring bean abstraction
+    * @param manager the current manager
+    * @return A producer Web Bean
+    */
+   public static <T> ProducerMethodBuilder<T> of(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      return new ProducerMethodBuilder<T>(method, declaringBean, manager);
+   }
+
+   protected ProducerMethodBuilder(WBMethod<T, ?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   {
+      super(declaringBean, manager);
+      this.method = MethodInjectionPoint.of(this, method);
+      initType();
+      initTypes();
+      initBindings();
+      this.id = createId("ProducerMethod-" + declaringBean.getType().getName() + "-" + method.getSignature().toString());
+      initStereotypes();
+      initPolicy();
+   }
+
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (!isInitialized())
+      {
+         initProducerMethodInjectableParameters();
+         super.initialize(environment);
+         checkProducerMethod();
+         initDisposalMethod(environment);
+      }
+   }
+
+   /**
+    * Initializes the injection points
+    */
+   protected void initProducerMethodInjectableParameters()
+   {
+      for (WBParameter<?, ?> parameter : method.getWBParameters())
+      {
+         addInjectionPoint(ParameterInjectionPoint.of(this, parameter));
+      }
+   }
+
+   /**
+    * Validates the producer method
+    */
+   protected void checkProducerMethod()
+   {
+      if (getAnnotatedItem().getAnnotatedWBParameters(Observes.class).size() > 0)
+      {
+         throw new DefinitionException("Producer method cannot have parameter annotated @Observes");
+      }
+      else if (getAnnotatedItem().getAnnotatedWBParameters(Disposes.class).size() > 0)
+      {
+         throw new DefinitionException("Producer method cannot have parameter annotated @Disposes");
+      }
+      else if (getDeclaringBean() instanceof SessionBean<?>)
+      {
+         boolean methodDeclaredOnTypes = false;
+         // TODO use annotated item?
+         for (Type type : getDeclaringBean().getTypes())
+         {
+            if (type instanceof Class)
+            {
+               Class<?> clazz = (Class<?>) type;
+               try
+               {
+                  clazz.getDeclaredMethod(getAnnotatedItem().getName(), getAnnotatedItem().getParameterTypesAsArray());
+                  methodDeclaredOnTypes = true;
+               }
+               catch (NoSuchMethodException nsme)
+               {
+                  // No - op
+               }
+            }
+         }
+         if (!methodDeclaredOnTypes)
+         {
+            throw new DefinitionException("Producer method " + toString() + " must be declared on a business interface of " + getDeclaringBean());
+         }
+      }
+   }
+
+   /**
+    * Initializes the remove method
+    */
+   protected void initDisposalMethod(BeanDeployerEnvironment environment)
+   {
+      Set<DisposalMethod<?>> disposalBeans = environment.resolveDisposalBeans(getTypes(), getQualifiers(), getDeclaringBean());
+
+      if (disposalBeans.size() == 1)
+      {
+         this.disposalMethodBean = disposalBeans.iterator().next();
+      }
+      else if (disposalBeans.size() > 1)
+      {
+         // TODO List out found disposal methods
+         throw new DefinitionException("Cannot declare multiple disposal methods for this producer method. Producer method: " + this + ". Disposal methods: " + disposalBeans);
+      }
+   }
+
+   /**
+    * Gets the annotated item representing the method
+    * 
+    * @return The annotated item
+    */
+   @Override
+   public WBMethod<T, ?> getAnnotatedItem()
+   {
+      return method;
+   }
+
+   /**
+    * Returns the default name
+    * 
+    * @return The default name
+    */
+   @Override
+   protected String getDefaultName()
+   {
+      return method.getPropertyName();
+   }
+
+   /**
+    * Returns the disposal method
+    * 
+    * @return The method representation
+    */
+   public DisposalMethod<?> getDisposalMethod()
+   {
+      return disposalMethodBean;
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder buffer = new StringBuilder();
+      buffer.append(Names.scopeTypeToString(getScope()));
+      if (getName() == null)
+      {
+         buffer.append("unnamed producer method bean");
+      }
+      else
+      {
+         buffer.append("simple producer method bean '" + getName() + "'");
+      }
+      buffer.append(" [" + getBeanClass().getName() + "] for class type [" + getType().getName() + "] API types " + getTypes() + ", binding types " + getQualifiers());
+      return buffer.toString();
+   }
+
+   @Override
+   public AbstractBean<?, ?> getSpecializedBean()
+   {
+      return specializedBean;
+   }
+
+   @Override
+   protected void preSpecialize(BeanDeployerEnvironment environment)
+   {
+      if (getDeclaringBean().getAnnotatedItem().getWBSuperclass().getDeclaredWBMethod(getAnnotatedItem().getAnnotatedMethod()) == null)
+      {
+         throw new DefinitionException("Specialized producer method does not override a method on the direct superclass");
+      }
+   }
+
+   @Override
+   protected void specialize(BeanDeployerEnvironment environment)
+   {
+      WBMethod<?, ?> superClassMethod = getDeclaringBean().getAnnotatedItem().getWBSuperclass().getWBMethod(getAnnotatedItem().getAnnotatedMethod());
+      if (environment.getProducerMethod(superClassMethod) == null)
+      {
+         throw new IllegalStateException(toString() + " does not specialize a bean");
+      }
+      this.specializedBean = environment.getProducerMethod(superClassMethod);
+   }
+
+   @Override
+   public String getId()
+   {
+      return id;
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return Collections.emptySet();
+   }
+
+   public ProducerMethod<T> createBean()
+   {
+      return ProducerMethod.of(method, 
+            getDeclaringBean(), 
+            manager,
+            name,
+            type,
+            types,
+            getMergedStereotypes(), 
+            scopeType,
+            isAlternative(),
+            isProxyable(),
+            bindings,
+            disposalMethodBean,
+            specializedBean);
+   }
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/RIBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/RIBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/RIBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.injection.WBInjectionPoint;
+
+/**
+ * Abstract base class with functions specific to RI built-in beans
+ *  
+ * @author Pete Muir
+ */
+abstract class RIBeanBuilder<T> implements Bean<T> 
+{
+   
+   private static final ConcurrentMap<String, AtomicInteger> ids = new ConcurrentHashMap<String, AtomicInteger>();
+   
+   private final BeanManagerImpl manager;
+
+   protected RIBeanBuilder(BeanManagerImpl manager)
+   {
+      this.manager = manager;
+      // TODO better ID strategy (human readable)
+   }
+   
+   protected static String createId(String prefix)
+   {
+      ids.putIfAbsent(prefix, new AtomicInteger());
+      int i = ids.get(prefix).getAndIncrement();
+      return prefix + "-" + i;
+   }
+
+   protected BeanManagerImpl getManager()
+   {
+      return manager;
+   }
+
+   public abstract Class<T> getType();
+   
+   public Class<?> getBeanClass()
+   {
+      return getType();
+   }
+   
+   public abstract void initialize(BeanDeployerEnvironment environment);
+
+   public abstract boolean isSpecializing();
+
+   public boolean isDependent()
+   {
+      return getScope().equals(Dependent.class);
+   }
+
+   public abstract boolean isProxyable();
+
+   public abstract boolean isPrimitive();
+
+   public abstract Set<WBInjectionPoint<?, ?>> getAnnotatedInjectionPoints();
+   
+   @SuppressWarnings("unchecked")
+   public Set<InjectionPoint> getInjectionPoints()
+   {
+      return (Set) getAnnotatedInjectionPoints();
+   }
+
+   public abstract RIBean<?> getSpecializedBean();
+   
+   public abstract String getId();
+   
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj instanceof RIBeanBuilder)
+      {
+         RIBeanBuilder<?> that = (RIBeanBuilder<?>) obj;
+         return this.getId().equals(that.getId());
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   @Override
+   public int hashCode()
+   {
+      return getId().hashCode();
+   }
+
+   public abstract RIBean<T> createBean();
+}

Added: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java	                        (rev 0)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/SessionBeanBuilder.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -0,0 +1,350 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.builder;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import javassist.util.proxy.ProxyFactory;
+
+import javax.decorator.Decorator;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.event.Observes;
+import javax.interceptor.Interceptor;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.SessionBean;
+import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.ejb.InternalEjbDescriptor;
+import org.jboss.webbeans.ejb.api.SessionObjectReference;
+import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
+import org.jboss.webbeans.ejb.spi.EjbServices;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.resources.ClassTransformer;
+import org.jboss.webbeans.util.Beans;
+import org.jboss.webbeans.util.Proxies;
+
+/**
+ * An enterprise bean representation
+ * 
+ * @author Pete Muir
+ * 
+ * @param <T> The type (class) of the bean
+ */
+class SessionBeanBuilder<T> extends AbstractClassBeanBuilder<T>
+{
+   // The EJB descriptor
+   private InternalEjbDescriptor<T> ejbDescriptor;
+
+   private Class<T> proxyClass;
+
+   private SessionBean<?> specializedBean;
+
+   /**
+    * Creates a simple, annotation defined Enterprise Web Bean
+    * 
+    * @param <T> The type
+    * @param clazz The class
+    * @param manager the current manager
+    * @return An Enterprise Web Bean
+    */
+   public static <T> SessionBeanBuilder<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   {
+      WBClass<T> type = manager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
+      return new SessionBeanBuilder<T>(type, ejbDescriptor, manager);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param type The type of the bean
+    * @param manager The Web Beans manager
+    */
+   protected SessionBeanBuilder(WBClass<T> type, InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl manager)
+   {
+      super(type, manager);
+      initType();
+      this.ejbDescriptor = ejbDescriptor;
+      initTypes();
+      initBindings();
+   }
+
+   /**
+    * Initializes the bean and its metadata
+    */
+   @Override
+   public void initialize(BeanDeployerEnvironment environment)
+   {
+      if (!isInitialized())
+      {
+         super.initialize(environment);
+         initProxyClass();
+         checkEJBTypeAllowed();
+         checkConflictingRoles();
+         checkObserverMethods();
+         checkScopeAllowed();
+      }
+   }
+
+   @Override
+   protected void initTypes()
+   {
+      Set<Type> types = new HashSet<Type>();
+      types = new LinkedHashSet<Type>();
+      types.add(Object.class);
+      for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor : ejbDescriptor.getLocalBusinessInterfaces())
+      {
+         types.add(businessInterfaceDescriptor.getInterface());
+      }
+      super.types = types;
+   }
+
+   protected void initProxyClass()
+   {
+      Set<Type> types = new LinkedHashSet<Type>(getTypes());
+      types.add(EnterpriseBeanInstance.class);
+      types.add(Serializable.class);
+      ProxyFactory proxyFactory = Proxies.getProxyFactory(types);
+
+      Class<T> proxyClass = proxyFactory.createClass();
+
+      this.proxyClass = proxyClass;
+   }
+
+   /**
+    * Validates for non-conflicting roles
+    */
+   protected void checkConflictingRoles()
+   {
+      if (getType().isAnnotationPresent(Interceptor.class))
+      {
+         throw new DefinitionException("Enterprise beans cannot be interceptors");
+      }
+      if (getType().isAnnotationPresent(Decorator.class))
+      {
+         throw new DefinitionException("Enterprise beans cannot be decorators");
+      }
+   }
+
+   /**
+    * Check that the scope type is allowed by the stereotypes on the bean and
+    * the bean type
+    */
+   protected void checkScopeAllowed()
+   {
+      if (ejbDescriptor.isStateless() && !isDependent())
+      {
+         throw new DefinitionException("Scope " + getScope() + " is not allowed on stateless enterpise beans for " + getType() + ". Only @Dependent is allowed on stateless enterprise beans");
+      }
+      if (ejbDescriptor.isSingleton() && !(isDependent() || getScope().equals(ApplicationScoped.class)))
+      {
+         throw new DefinitionException("Scope " + getScope() + " is not allowed on singleton enterpise beans for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
+      }
+   }
+
+   /**
+    * Validates specialization
+    */
+   @Override
+   protected void preSpecialize(BeanDeployerEnvironment environment)
+   {
+      super.preSpecialize(environment);
+      // We appear to check this twice?
+      if (!environment.getEjbDescriptors().contains(getAnnotatedItem().getWBSuperclass().getJavaClass()))
+      {
+         throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
+      }
+   }
+
+   @Override
+   protected void specialize(BeanDeployerEnvironment environment)
+   {
+      if (environment.getClassBean(getAnnotatedItem().getWBSuperclass()) == null)
+      {
+         throw new IllegalStateException(toString() + " does not specialize a bean");
+      }
+      AbstractClassBean<?> specializedBean = environment.getClassBean(getAnnotatedItem().getWBSuperclass());
+      if (!(specializedBean instanceof SessionBean<?>))
+      {
+         throw new IllegalStateException(toString() + " doesn't have a session bean as a superclass " + specializedBean);
+      }
+      else
+      {
+         this.specializedBean = (SessionBean<?>) specializedBean; 
+      }
+   }
+
+   /**
+    * Validates the bean type
+    */
+   private void checkEJBTypeAllowed()
+   {
+      if (ejbDescriptor.isMessageDriven())
+      {
+         throw new DefinitionException("Message Driven Beans can't be Web Beans");
+      }
+   }
+
+   /**
+    * Gets a string representation
+    * 
+    * @return The string representation
+    */
+   @Override
+   public String toString()
+   {
+      StringBuilder buffer = new StringBuilder();
+      // buffer.append("Annotated " + Names.scopeTypeToString(getScopeType()) +
+      // Names.ejbTypeFromMetaData(getEjbMetaData()));
+      if (getName() == null)
+      {
+         buffer.append(" unnamed enterprise bean");
+      }
+      else
+      {
+         buffer.append(" enterprise bean '" + getName() + "'");
+      }
+      buffer.append(" [" + getType().getName() + "] ");
+      buffer.append("API types " + getTypes() + ", binding types " + getQualifiers());
+      return buffer.toString();
+   }
+
+   public void postConstruct(T instance, CreationalContext<T> creationalContext)
+   {
+      Beans.injectBoundFields(instance, creationalContext, getManager(), getInjectableFields());
+      Beans.callInitializers(instance, creationalContext, getManager(), getInitializerMethods());
+   }
+
+   public void preDestroy(CreationalContext<T> creationalContext)
+   {
+      creationalContext.release();
+   }
+   
+   @Override
+   protected void initSerializable()
+   {
+      // No-op
+   }
+   
+   @Override
+   public boolean isSerializable()
+   {
+      return true;
+   }
+
+   public InternalEjbDescriptor<T> getEjbDescriptor()
+   {
+      return ejbDescriptor;
+   }
+
+   public boolean isClientCanCallRemoveMethods()
+   {
+      return getEjbDescriptor().isStateful() && isDependent();
+   }
+
+   @Override
+   public SessionBean<?> getSpecializedBean()
+   {
+      return specializedBean;
+   }
+
+   /**
+    * If there are any observer methods, they must be static or business
+    * methods.
+    */
+   protected void checkObserverMethods()
+   {
+      for (WBMethod<?, ?> method : this.annotatedItem.getWBDeclaredMethodsWithAnnotatedParameters(Observes.class))
+      {
+         if (!method.isStatic())
+         {
+            if (!isMethodExistsOnTypes(method))
+            {
+               throw new DefinitionException("Observer method must be static or business method: " + method + " on " + getAnnotatedItem());
+            }
+         }
+      }
+   }
+   
+   // TODO must be a nicer way to do this!
+   public boolean isMethodExistsOnTypes(WBMethod<?, ?> method)
+   {
+      for (Type type : getTypes())
+      {
+         if (type instanceof Class)
+         {
+            for (Method m : ((Class<?>) type).getMethods())
+            {
+               if (method.getName().equals(m.getName()) && Arrays.equals(method.getParameterTypesAsArray(), m.getParameterTypes()))
+               {
+                  return true;
+               }
+            }
+         }
+      }
+      return false;
+   }
+   
+   public SessionObjectReference createReference()
+   {
+      return manager.getServices().get(EjbServices.class).resolveEjb(getEjbDescriptor().delegate());
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return Collections.emptySet();
+   }
+
+   public Class<T> getProxyClass()
+   {
+      return proxyClass;
+   }
+
+   @Override
+   public SessionBean<T> createBean()
+   {
+      return SessionBean.of(getEjbDescriptor(),
+            getManager(),
+            name,
+            types,
+            getMergedStereotypes(),
+            getScope(),
+            isAlternative(),
+            isProxyable(),
+            bindings,
+            getSuperclasses(),
+            getProxyClassForDecorators(),
+            getDecorators(),
+            getPostConstruct(),
+            getPreDestroy(),
+            getProxyClass(),
+            getSpecializedBean());
+   }
+}
+

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/EEResourceProducerField.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -16,12 +16,18 @@
  */
 package org.jboss.webbeans.bean.ee;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import java.util.Set;
+
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.bean.AbstractClassBean;
 import org.jboss.webbeans.bean.ProducerField;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.ejb.EJBApiAbstraction;
 import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 import org.jboss.webbeans.persistence.PersistenceApiAbstraction;
 import org.jboss.webbeans.ws.WSApiAbstraction;
 
@@ -40,14 +46,34 @@
     * @param manager the current manager
     * @return A producer field
     */
-   public static <T> EEResourceProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public static <T> EEResourceProducerField<T> of(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      return new EEResourceProducerField<T>(field, declaringBean, manager);
+      return new EEResourceProducerField<T>(field, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
    }
 
-   protected EEResourceProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   protected EEResourceProducerField(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(field, declaringBean, manager);
+      super(field, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
    }
    
    @Override

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ee/PersistenceContextProducerField.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -16,11 +16,17 @@
  */
 package org.jboss.webbeans.bean.ee;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import java.util.Set;
+
 import javax.persistence.EntityManager;
 
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.bean.AbstractClassBean;
 import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
 
 /**
  * @author pmuir
@@ -37,9 +43,19 @@
     * @param manager the current manager
     * @return A producer field
     */
-   public static <T extends EntityManager> EEResourceProducerField<T> of(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public static <T extends EntityManager> EEResourceProducerField<T> of(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+        Set<Annotation> bindings)
    {
-      return new PersistenceContextProducerField<T>(field, declaringBean, manager);
+      return new PersistenceContextProducerField<T>(field, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
    }
 
    /**
@@ -47,9 +63,19 @@
     * @param declaringBean
     * @param manager
     */
-   protected PersistenceContextProducerField(WBField<T, ?> field, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   protected PersistenceContextProducerField(WBField<T, ?> field, 
+         AbstractClassBean<?> declaringBean, 
+         BeanManagerImpl manager,
+         String name,
+         Class<T> type,
+         Set<Type> types,
+         MergedStereotypes<T, Field> mergedStereotypes, 
+         Class<? extends Annotation> scopeType,
+         boolean policy,
+         boolean proxyable,
+         Set<Annotation> bindings)
    {
-      super(field, declaringBean, manager);
+      super(field, declaringBean, manager, name, type, types, mergedStereotypes, scopeType, policy, proxyable, bindings);
    }
    
    public void dispose(T instance) 

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/util/Reflections.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -302,6 +302,8 @@
     */
    public static boolean isPrimitive(Class<?> type)
    {
+      if (type == null)
+         throw new NullPointerException();
       return type.isPrimitive();
    }
 

Modified: ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
===================================================================
--- ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java	2009-09-21 04:37:58 UTC (rev 3712)
+++ ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/deployment/structure/AccessibleManagerResolutionTest.java	2009-09-21 16:33:40 UTC (rev 3713)
@@ -8,6 +8,8 @@
 import org.jboss.webbeans.ContextualIdStore;
 import org.jboss.webbeans.bean.RIBean;
 import org.jboss.webbeans.bean.ManagedBean;
+import org.jboss.webbeans.bean.builder.spi.BeanBuilderFactory;
+import org.jboss.webbeans.bean.builder.spi.SimpleBeanBuilder;
 import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
 import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
@@ -38,10 +40,9 @@
    private void addBean(BeanManagerImpl manager, Class<?> c)
    {
       WBClass<?> clazz = WBClassImpl.of(c, classTransformer);
-      RIBean<?> bean = ManagedBean.of(clazz, manager);
+      SimpleBeanBuilder<?> builder = BeanBuilderFactory.getInstance().getSimpleBeanBuilder(manager, clazz);
+      Bean<?> bean = builder.getBean();
       manager.addBean(bean);
-      BeanDeployerEnvironment environment = new BeanDeployerEnvironment(new EjbDescriptors(), manager);
-      bean.initialize(environment);
    }
    
    @Test




More information about the weld-commits mailing list