[webbeans-commits] Webbeans SVN: r3633 - in extensions/trunk/bean-utils: src/main/java/org/jboss/webbeans/beanutils and 13 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Sep 1 15:14:48 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-09-01 15:14:48 -0400 (Tue, 01 Sep 2009)
New Revision: 3633

Added:
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingBeanDescriberImpl.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingSimpleBean.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/impl/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/impl/BeansImpl.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/BeanType.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/Beans.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/ExistingBeanDescriber.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/AbstractBeanUtilsTest.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisterBeansObserver.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisteredBean.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Bean.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Custom.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomBean.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultConstructorReceiver.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultFieldReceiver.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultBean.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultConstructorReceiver.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultFieldReceiver.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ExisitingBeanDescriberTest.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/FieldProducer.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/MethodProducer.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ProducerBean.java
   extensions/trunk/bean-utils/src/test/resources/
   extensions/trunk/bean-utils/src/test/resources/META-INF/
   extensions/trunk/bean-utils/src/test/resources/META-INF/services/
   extensions/trunk/bean-utils/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Removed:
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java
   extensions/trunk/bean-utils/src/test/java/org/jboss/webbeans/beanutils/impl/
Modified:
   extensions/trunk/bean-utils/
   extensions/trunk/bean-utils/pom.xml
Log:
Rework how beans are described for existing instances, making sure that all relevant bean types are installed


Property changes on: extensions/trunk/bean-utils
___________________________________________________________________
Name: svn:ignore
   - target
.classpath
.project
.settings

   + target
.classpath
.project
.settings
temp-testng-customsuite.xml
test-output


Modified: extensions/trunk/bean-utils/pom.xml
===================================================================
--- extensions/trunk/bean-utils/pom.xml	2009-08-31 23:43:26 UTC (rev 3632)
+++ extensions/trunk/bean-utils/pom.xml	2009-09-01 19:14:48 UTC (rev 3633)
@@ -37,28 +37,11 @@
       </dependency>
       
       <dependency>
-      	<groupId>org.jboss.test-harness</groupId>
-      	<artifactId>jboss-test-harness</artifactId>
-      	<scope>test</scope>
-      </dependency>
-<!--      
-      <dependency>
-      	<groupId>org.jboss.test-harness</groupId>
-      	<artifactId>jboss-test-harness-jboss-as-50</artifactId>
-      	<scope>test</scope>
-      </dependency>
-      <dependency>
-      	<groupId>org.jboss.webbeans</groupId>
-      	<artifactId>webbeans-core</artifactId>
-      	<scope>test</scope>
-      </dependency>
-      
-      <dependency>
          <groupId>org.jboss.webbeans</groupId>
          <artifactId>webbeans-core-test</artifactId>
          <scope>test</scope>
       </dependency>
-      
+
       <dependency>
          <groupId>org.jboss.ejb3</groupId>
          <artifactId>jboss-ejb3-api</artifactId>
@@ -78,7 +61,7 @@
             </exclusion>
          </exclusions>
       </dependency>
--->      
+
    </dependencies>
 
    <scm>

Deleted: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java	2009-08-31 23:43:26 UTC (rev 3632)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -1,60 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors. 
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
-package org.jboss.webbeans.beanutils;
-
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-
-import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.introspector.WBClass;
-import org.jboss.webbeans.introspector.jlr.WBClassImpl;
-import org.jboss.webbeans.resources.ClassTransformer;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class BeanDescriber<T>
-{
-   public static <T> Bean<T> describeBean(AnnotatedType<T> type, BeanManager beanManager)
-   {
-      if (type == null)
-         throw new IllegalArgumentException("Null type");
-      if (beanManager == null)
-         throw new IllegalArgumentException("Null beanManager");
-      if (beanManager instanceof BeanManagerImpl == false)
-         throw new IllegalArgumentException("BeanManager is not an instance of BeanManagerImpl");
-      
-      WBClass<T> clazz = type instanceof WBClass ? 
-            (WBClass<T>)type :
-               WBClassImpl.of(type, ((BeanManagerImpl)beanManager).getServices().get(ClassTransformer.class));
-      
-      Bean<T> bean = SimpleBean.of(clazz, (BeanManagerImpl)beanManager);
-      
-      //TODO How to get BeanDeployerEnvironment?
-      ((SimpleBean<T>)bean).initialize(null);
-      return bean;
-   }
-}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingBeanDescriberImpl.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingBeanDescriberImpl.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingBeanDescriberImpl.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.exisiting;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.NewSimpleBean;
+import org.jboss.webbeans.bean.ProducerFieldBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.beanutils.impl.BeansImpl;
+import org.jboss.webbeans.beanutils.spi.Beans;
+import org.jboss.webbeans.beanutils.spi.ExistingBeanDescriber;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.introspector.jlr.WBClassImpl;
+import org.jboss.webbeans.resources.ClassTransformer;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExistingBeanDescriberImpl
+{
+   /**
+    * Takes an existing bean instance and creates the Beans wrapping it.
+    * 
+    * @param type the annotated type of the bean
+    * @param env the bean deployer environment
+    * @param beanManager the bean manager used to create the bean
+    * @param instance the instance we want to wrap
+    * @return Beans instance representing the beans to be installed in the bean manager
+    */
+   public static <T> Beans<T> describePreinstantiatedBean(ExistingBeanDescriber describer, BeanDeployerEnvironment env, AnnotatedType<T> type, BeanManager beanManager, T instance)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      if (beanManager == null)
+         throw new IllegalArgumentException("Null beanManager");
+      if (beanManager instanceof BeanManagerImpl == false)
+         throw new IllegalArgumentException("BeanManager is not an instance of BeanManagerImpl");
+      
+      WBClass<T> clazz = type instanceof WBClass ? 
+            (WBClass<T>)type :
+               WBClassImpl.of(type, ((BeanManagerImpl)beanManager).getServices().get(ClassTransformer.class));
+      
+      BeansImpl<T> beans = new BeansImpl<T>();
+
+      ExistingSimpleBean<T> bean = (ExistingSimpleBean<T>)createSimpleBean(clazz, env, (BeanManagerImpl)beanManager, instance); 
+      beans.setMainBean(bean);
+      beans.setNewBean(createNewBean(clazz, env, (BeanManagerImpl)beanManager));
+      
+      for (WBMethod<?, ?> method : clazz.getDeclaredWBAnnotatedMethods(Produces.class))
+      {
+         beans.addMethodProducerBean(createProducerMethodBean(bean, env, (BeanManagerImpl)beanManager, (WBMethod<T, ?>)method));
+      }
+   
+      for (WBField<?, ?> field : clazz.getDeclaredAnnotatedWBFields(Produces.class))
+      {
+         beans.addFieldProducerBean(createProducerFieldBean(bean, env, (BeanManagerImpl)beanManager, (WBField<T, ?>)field));
+      }
+      
+      return beans;
+   }
+   
+   private static <T> Bean<T> createSimpleBean(WBClass<T> clazz, BeanDeployerEnvironment env, BeanManagerImpl beanManager, T instance)
+   {
+      ExistingSimpleBean<T> bean = ExistingSimpleBean.of(clazz, beanManager, instance);
+      
+      //TODO How to get BeanDeployerEnvironment?
+      bean.initialize(env);
+      return bean;
+   }
+   
+   private static <T> Bean<T> createNewBean(WBClass<T> clazz, BeanDeployerEnvironment env, BeanManagerImpl beanManager)
+   {
+      NewSimpleBean<T> bean = NewSimpleBean.of(clazz, beanManager);
+      
+      //TODO How to get BeanDeployerEnvironment?
+      bean.initialize(env);
+      return bean;
+   }
+   
+   private static <T> Bean<T> createProducerMethodBean(AbstractClassBean<T>  declaringBean, BeanDeployerEnvironment env, BeanManagerImpl beanManager, WBMethod<T, ?> method)
+   {
+      ProducerMethodBean<T> bean = ProducerMethodBean.of(method, declaringBean, beanManager);
+      
+      //TODO How to get BeanDeployerEnvironment?
+      bean.initialize(env);
+      return bean;
+   }
+   
+   
+   private static <T> Bean<T> createProducerFieldBean(AbstractClassBean<T>  declaringBean, BeanDeployerEnvironment env, BeanManagerImpl beanManager, WBField<T, ?> field)
+   {
+      ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean, beanManager);
+      
+      //TODO How to get BeanDeployerEnvironment?
+      bean.initialize(env);
+      return bean;
+   }
+   
+}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingSimpleBean.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingSimpleBean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/exisiting/ExistingSimpleBean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.exisiting;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.introspector.WBClass;
+
+/**
+ * used to create a bean implementation for an existing instance
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExistingSimpleBean<T> extends SimpleBean<T>
+{
+   
+   T instance;
+   
+   /**
+    * Constructor
+    * 
+    * @param <T> The type
+    * @param clazz The class
+    * @param manager the current manager
+    * @param instance the existing instance
+    * @return A Web Bean
+    */
+   protected ExistingSimpleBean(WBClass<T> type, BeanManagerImpl manager, T instance)
+   {
+      super(type, manager);
+      this.instance = instance;
+   }
+   
+   /**
+    * 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> ExistingSimpleBean<T> of(WBClass<T> clazz, BeanManagerImpl manager, T instance)
+   {
+      return new ExistingSimpleBean<T>(clazz, manager, instance);
+   }
+   
+   /**
+    * Return the instance rather than creating a new bean
+    * @param creationalContext the creational context
+    * @return the instance
+    */
+   @Override
+   public T create(CreationalContext<T> creationalContext)
+   {
+      creationalContext.push(instance);
+      return instance;
+   }
+
+   /**
+    * Return the instance rather than creating a new bean
+    * @param creationalContext the creational context
+    * @return the instance
+    */
+   @Override
+   public T produce(CreationalContext<T> ctx)
+   {
+      ctx.release();
+      return instance;
+   }
+}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/impl/BeansImpl.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/impl/BeansImpl.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/impl/BeansImpl.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,105 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.webbeans.beanutils.spi.Beans;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeansImpl<T> implements Beans<T>
+{
+   private Bean<T> mainBean;
+   
+   private Bean<T> newBean;
+   
+   private Set<Bean<T>> methodProducerBeans;
+   
+   private Set<Bean<T>> fieldProducerBeans;
+   
+   public Set<Bean<T>> getFieldProducerBeans()
+   {
+      return fieldProducerBeans;
+   }
+   
+   public void addFieldProducerBean(Bean<T> bean)
+   {
+      if (fieldProducerBeans == null)
+         fieldProducerBeans = new HashSet<Bean<T>>();
+      
+      fieldProducerBeans.add(bean);
+   }
+   
+   public Bean<T> getMainBean()
+   {
+      return mainBean;
+   }
+
+   public void setMainBean(Bean<T> bean)
+   {
+      mainBean = bean;
+   }
+
+   public Set<Bean<T>> getMethodProducerBeans()
+   {
+      return methodProducerBeans;
+   }
+
+   public void addMethodProducerBean(Bean<T> bean)
+   {
+      if (methodProducerBeans == null)
+         methodProducerBeans = new HashSet<Bean<T>>();
+      
+      methodProducerBeans.add(bean);
+   }
+   
+   public Bean<T> getNewBean()
+   {
+      return newBean;
+   }
+
+   public void setNewBean(Bean<T> bean)
+   {
+      newBean = bean;
+   }
+   
+   public Set<Bean<T>> getAllBeans()
+   {
+      Set<Bean<T>> beans = new HashSet<Bean<T>>();
+
+      beans.add(mainBean);
+      beans.add(newBean);
+      if (fieldProducerBeans != null)
+         beans.addAll(fieldProducerBeans);
+      if (methodProducerBeans != null)
+         beans.addAll(methodProducerBeans);
+      
+      return beans;
+   }
+}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/BeanType.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/BeanType.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/BeanType.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.spi;
+
+/**
+ * Enum to look up beans in the map returned by BeanDescriber.getBeans()
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public enum BeanType 
+{
+   
+   MAIN,
+   NEW,
+   PRODUCER_METHOD,
+   PRODUCER_FIELD
+}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/Beans.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/Beans.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/Beans.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.spi;
+
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Beans<T>
+{
+   Bean<T> getMainBean();
+   
+   Bean<T> getNewBean();
+   
+   Set<Bean<T>> getMethodProducerBeans();
+   
+   Set<Bean<T>> getFieldProducerBeans();
+   
+   Set<Bean<T>> getAllBeans();
+}

Copied: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/ExistingBeanDescriber.java (from rev 3632, extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java)
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/ExistingBeanDescriber.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/spi/ExistingBeanDescriber.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.webbeans.beanutils.spi;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.webbeans.beanutils.exisiting.ExistingBeanDescriberImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+
+/**
+ * Utilities to create beans that take an existing instance
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExistingBeanDescriber
+{
+   private static final ExistingBeanDescriber EXISTING_BEAN_DESCRIBER = new ExistingBeanDescriber();
+   
+   private ExistingBeanDescriber()
+   {
+      
+   }
+   
+   /**
+    * Takes an existing bean instance and creates the Beans wrapping it
+    * 
+    * @param type the annotated type of the bean
+    * @param the bean deployer environment
+    * @param beanManager the bean manager used to create the bean
+    * @param instance the instance we want to wrap
+    */
+   public static <T> Beans<T> describePreinstantiatedBean(AnnotatedType<T> type, BeanDeployerEnvironment env, BeanManager beanManager, T instance)
+   {
+      return ExistingBeanDescriberImpl.describePreinstantiatedBean(EXISTING_BEAN_DESCRIBER, env, type, beanManager, instance);
+   }
+   
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/AbstractBeanUtilsTest.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/AbstractBeanUtilsTest.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/AbstractBeanUtilsTest.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,128 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils;
+
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.bootstrap.BeanDeployment;
+import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.webbeans.mock.MockEELifecycle;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractBeanUtilsTest
+{
+   /**
+    * Contains the web beans deployment
+    */
+   MockEELifecycle lifecycle;
+   
+   boolean deployedWebBeans;
+
+   /**
+    * Initialises the lifecycle with the classes to deploy once deployWebBeans() is called
+    * 
+    * @param classes the classes to deploy
+    */
+   protected void initialiseEnvironment(Class<?>...classes)
+   {
+      lifecycle = new MockEELifecycle();
+      lifecycle.getDeployment().getArchive().setBeanClasses(Arrays.asList(classes));
+      lifecycle.initialize();
+   }
+   
+   /**
+    * Deploys classes as web beans and sets {@link #lifecycle} to point to the created lifecycle
+    * 
+    * @throws Exception if an error occured
+    */
+   protected void deployWebBeans() throws Exception
+   {
+      if (lifecycle == null)
+         throw new IllegalStateException("Lifecycle needs to be initialised by calling initialiseEnvironment()");
+      lifecycle.beginApplication();
+      lifecycle.beginSession();
+      lifecycle.beginRequest();
+      deployedWebBeans = true;
+   }
+   
+   
+   /**
+    * Undeploys the webbeans deployed if {@link #lifecycle} is set
+    */
+   protected void undeployWebBeans() throws Exception
+   {
+      lifecycle = null;
+      if (lifecycle != null)
+      {
+         if (deployedWebBeans)
+         {
+            lifecycle.endRequest();
+            lifecycle.endSession();
+            lifecycle.endApplication();
+         }
+         lifecycle = null;
+      }
+   }
+
+
+   /**
+    * Gets the current bean manager used. 
+    * 
+    * @return the bean manager
+    */
+   protected BeanManager getCurrentManager() throws Exception
+   {
+      if (lifecycle == null)
+         throw new IllegalStateException("Lifecycle needs to be initialised by calling initialiseEnvironment()");
+      return lifecycle.getBootstrap().getManager(lifecycle.getDeployment().getArchive());
+   }
+   
+   protected BeanDeployerEnvironment getBeanDeployerEnvironment() throws Exception
+   {
+      if (lifecycle == null)
+         throw new IllegalStateException("Lifecycle needs to be initialised by calling initialiseEnvironment()");
+
+      WebBeansBootstrap bootstrap = lifecycle.getBootstrap();
+     
+      //TODO: Hack
+      Field field = WebBeansBootstrap.class.getDeclaredField("beanDeployments");
+      field.setAccessible(true);
+      Map<BeanDeploymentArchive, BeanDeployment> deployments = (Map<BeanDeploymentArchive, BeanDeployment>)field.get(bootstrap);
+      
+      assert deployments != null;
+      assert deployments.size() == 1;
+      BeanDeployment deployment = deployments.entrySet().iterator().next().getValue();
+      
+      return deployment.getBeanDeployer().getEnvironment();
+      
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisterBeansObserver.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisterBeansObserver.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisterBeansObserver.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,63 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.beanutils.spi.Beans;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Artifact
+public class RegisterBeansObserver implements Extension
+{
+   static List<Beans<?>> beans = new ArrayList<Beans<?>>();
+   
+   public static void clear()
+   {
+      beans.clear();
+   }
+   
+   public static void addBeans(Beans<?> beans)
+   {
+      RegisterBeansObserver.beans.add(beans);
+   }
+   
+   public void observe(@Observes AfterBeanDiscovery afterBeanDiscovery)
+   {
+      for (Beans<?> beans : RegisterBeansObserver.beans)
+      {   
+         for(Bean<?> bean : beans.getAllBeans())
+            afterBeanDiscovery.addBean(bean);
+      }
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisteredBean.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisteredBean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/RegisteredBean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegisteredBean<T>
+{
+   private final T instance;
+   private final T annotatedType;
+   
+   public RegisteredBean(T annotatedType, T instance)
+   {
+      this.annotatedType = annotatedType;
+      this.instance = instance;
+   }
+
+   public T getInstance()
+   {
+      return instance;
+   }
+
+   public T getAnnotatedType()
+   {
+      return annotatedType;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Bean.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Bean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Bean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Bean
+{
+
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Custom.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Custom.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/Custom.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME) 
+ at Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
+public @interface Custom 
+{
+
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomBean.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomBean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomBean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CustomBean implements Bean
+{
+
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultConstructorReceiver.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultConstructorReceiver.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultConstructorReceiver.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CustomDefaultConstructorReceiver
+{
+   Bean defaultBean;
+
+   Bean customBean;
+   
+   @Inject 
+   public CustomDefaultConstructorReceiver(@Default Bean defaultBean, @Custom Bean customBean)
+   {
+      this.defaultBean = defaultBean;
+      this.customBean = customBean;
+   }
+
+   public Bean getDefaultBean()
+   {
+      return defaultBean;
+   }
+
+   public Bean getCustomBean()
+   {
+      return customBean;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultFieldReceiver.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultFieldReceiver.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/CustomDefaultFieldReceiver.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CustomDefaultFieldReceiver
+{
+   @Inject @Default 
+   Bean defaultBean;
+
+   @Inject @Custom 
+   Bean customBean;
+
+   public Bean getDefaultBean()
+   {
+      return defaultBean;
+   }
+
+   public Bean getCustomBean()
+   {
+      return customBean;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultBean.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultBean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultBean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Default
+public class DefaultBean implements Bean
+{
+
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultConstructorReceiver.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultConstructorReceiver.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultConstructorReceiver.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultConstructorReceiver
+{
+   Bean defaultBean;
+   
+   @Inject
+   public DefaultConstructorReceiver(@Default Bean defaultBean)
+   {
+      this.defaultBean = defaultBean;
+   }
+
+   public Bean getBean()
+   {
+      return defaultBean;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultFieldReceiver.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultFieldReceiver.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/DefaultFieldReceiver.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.inject.Inject;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultFieldReceiver
+{
+   @Inject @Default 
+   Bean defaultBean;
+
+   public Bean getBean()
+   {
+      return defaultBean;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ExisitingBeanDescriberTest.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ExisitingBeanDescriberTest.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ExisitingBeanDescriberTest.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,199 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.test.webbeans.beanutils.AbstractBeanUtilsTest;
+import org.jboss.test.webbeans.beanutils.RegisterBeansObserver;
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.beanutils.spi.Beans;
+import org.jboss.webbeans.beanutils.spi.ExistingBeanDescriber;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
+import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ExisitingBeanDescriberTest extends AbstractBeanUtilsTest
+{
+   @BeforeMethod
+   public void beforeMethod()
+   {
+      RegisterBeansObserver.clear();
+   }
+   
+   @Test
+   public void testExisitingInstanceInField() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(DefaultFieldReceiver.class);
+         DefaultBean bean = new DefaultBean();
+         registerBeans(bean);
+         deployWebBeans();
+
+         DefaultFieldReceiver receiver = assertBean(DefaultFieldReceiver.class);
+         assert receiver.getBean() != null;
+         assert receiver.getBean() == bean;
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   @Test
+   public void testExistingInstanceInConstructor() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(DefaultConstructorReceiver.class);
+         DefaultBean bean = new DefaultBean();
+         registerBeans(bean);
+         deployWebBeans();
+
+         DefaultConstructorReceiver receiver = assertBean(DefaultConstructorReceiver.class);
+         assert receiver.getBean() != null;
+         assert receiver.getBean() == bean;
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   @Test
+   public void testExistingInstanceFromMethodProducerInField() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(CustomDefaultFieldReceiver.class);
+         MethodProducer bean = new MethodProducer();
+         registerBeans(bean);
+         deployWebBeans();
+
+         CustomDefaultFieldReceiver receiver = assertBean(CustomDefaultFieldReceiver.class);
+         assert receiver.getDefaultBean() != null;
+         assert receiver.getDefaultBean() == bean.getDefaultBean();
+         assert receiver.getCustomBean() != null;
+         assert receiver.getCustomBean() == bean.getCustomBean();
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   @Test
+   public void testExistingInstanceFromMethodProducerInConstructor() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(CustomDefaultConstructorReceiver.class);
+         MethodProducer bean = new MethodProducer();
+         registerBeans(bean);
+         deployWebBeans();
+
+         CustomDefaultConstructorReceiver receiver = assertBean(CustomDefaultConstructorReceiver.class);
+         assert receiver.getDefaultBean() != null;
+         assert receiver.getDefaultBean() == bean.getDefaultBean();
+         assert receiver.getCustomBean() != null;
+         assert receiver.getCustomBean() == bean.getCustomBean();
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   @Test
+   public void testExistingInstanceFromFieldProducerInField() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(CustomDefaultFieldReceiver.class);
+         FieldProducer bean = new FieldProducer();
+         registerBeans(bean);
+         deployWebBeans();
+
+         CustomDefaultFieldReceiver receiver = assertBean(CustomDefaultFieldReceiver.class);
+         assert receiver.getDefaultBean() != null;
+         assert receiver.getDefaultBean() == bean.getDefaultBean();
+         assert receiver.getCustomBean() != null;
+         assert receiver.getCustomBean() == bean.getCustomBean();
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   @Test
+   public void testExistingInstanceFromFieldProducerInConstructor() throws Exception
+   {
+      try
+      {
+         initialiseEnvironment(CustomDefaultConstructorReceiver.class);
+         FieldProducer bean = new FieldProducer();
+         registerBeans(bean);
+         deployWebBeans();
+
+         CustomDefaultConstructorReceiver receiver = assertBean(CustomDefaultConstructorReceiver.class);
+         assert receiver.getDefaultBean() != null;
+         assert receiver.getDefaultBean() == bean.getDefaultBean();
+         assert receiver.getCustomBean() != null;
+         assert receiver.getCustomBean() == bean.getCustomBean();
+      }
+      finally
+      {
+         undeployWebBeans();
+      }
+   }
+   
+   private <T> void registerBeans(T instance) throws Exception
+   {
+      AnnotatedType<T> type = getCurrentManager().createAnnotatedType((Class<T>)instance.getClass());
+      Beans<T> beans = ExistingBeanDescriber.describePreinstantiatedBean(type, getBeanDeployerEnvironment(), getCurrentManager(), instance);
+      RegisterBeansObserver.addBeans(beans);
+   }
+   
+   private <T> T assertBean(Class<T> type) throws Exception
+   {
+      Set<Bean<?>> beans = getCurrentManager().getBeans(type);
+      assert beans.size() == 1;
+      Bean<T> bean = (Bean<T>)beans.iterator().next();
+      CreationalContext<T> context = getCurrentManager().createCreationalContext(null);
+      T t = bean.create(context);
+      return t;
+   }
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/FieldProducer.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/FieldProducer.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/FieldProducer.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.Produces;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class FieldProducer
+{
+   @Produces @Default Bean defaultBean = new DefaultBean();
+   
+   @Produces @Custom Bean customBean = new CustomBean();
+   
+   public Bean getDefaultBean()
+   {
+      return defaultBean;
+   }
+   
+   public Bean getCustomBean()
+   {
+      return customBean;
+   }
+   
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/MethodProducer.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/MethodProducer.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/MethodProducer.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.inject.Produces;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MethodProducer
+{
+   Bean defaultBean = new DefaultBean();
+   
+   Bean customBean = new CustomBean();
+   
+   @Produces @Default
+   public Bean getDefaultBean()
+   {
+      return defaultBean;
+   }
+   
+   @Produces @Custom
+   public Bean getCustomBean()
+   {
+      return customBean;
+   }
+   
+}

Added: extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ProducerBean.java
===================================================================
--- extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ProducerBean.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/java/org/jboss/test/webbeans/beanutils/existing/ProducerBean.java	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.webbeans.beanutils.existing;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ProducerBean
+{
+   
+}

Added: extensions/trunk/bean-utils/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/bean-utils/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension	                        (rev 0)
+++ extensions/trunk/bean-utils/src/test/resources/META-INF/services/javax.enterprise.inject.spi.Extension	2009-09-01 19:14:48 UTC (rev 3633)
@@ -0,0 +1 @@
+org.jboss.test.webbeans.beanutils.RegisterBeansObserver
\ No newline at end of file




More information about the weld-commits mailing list