Author: pete.muir(a)jboss.org
Date: 2009-03-23 08:59:18 -0400 (Mon, 23 Mar 2009)
New Revision: 2145
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
Log:
Split out a bean deployer environment
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23
12:34:19 UTC (rev 2144)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23
12:59:18 UTC (rev 2145)
@@ -26,6 +26,7 @@
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.WrappedAnnotatedField;
import org.jboss.webbeans.introspector.WrappedAnnotatedMethod;
@@ -41,25 +42,29 @@
private static final LogProvider log = Logging.getLogProvider(BeanDeployer.class);
- private final Set<RIBean<?>> beans;
- private final Set<ObserverImpl<?>> observers;
+ private final BeanDeployerEnvironment beanDeployerEnvironment;
private final Set<AnnotatedClass<?>> classes;
private final ManagerImpl manager;
public BeanDeployer(ManagerImpl manager)
{
this.manager = manager;
- this.beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ this.beanDeployerEnvironment = new BeanDeployerEnvironment();
this.classes = new HashSet<AnnotatedClass<?>>();
- this.observers = new HashSet<ObserverImpl<?>>();
}
- public BeanDeployer addBean(RIBean<?> bean)
+ public <T> BeanDeployer addBean(AnnotatedItem<T, ?> item, RIBean<T>
bean)
{
- this.beans.add(bean);
+ this.beanDeployerEnvironment.addBean(item, bean);
return this;
}
+ public <T> BeanDeployer addBean(RIBean<T> bean)
+ {
+ this.beanDeployerEnvironment.addBean(null, bean);
+ return this;
+ }
+
public BeanDeployer addClass(Class<?> clazz)
{
if (!clazz.isAnnotation() && !clazz.isEnum())
@@ -96,13 +101,15 @@
public BeanDeployer deploy()
{
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployerEnvironment.getBeans());
for (RIBean<?> bean : beans)
{
bean.initialize();
log.info("Bean: " + bean);
}
manager.setBeans(beans);
- for (ObserverImpl<?> observer : observers)
+ for (ObserverImpl<?> observer : beanDeployerEnvironment.getObservers())
{
observer.initialize();
log.info("Observer : " + observer);
@@ -110,17 +117,12 @@
}
return this;
}
-
- public Set<RIBean<?>> getBeans()
+
+ public BeanDeployerEnvironment getBeanDeployerEnvironment()
{
- return beans;
+ return beanDeployerEnvironment;
}
- protected void printBeans()
- {
-
- }
-
/**
* Creates a Web Bean from a bean abstraction and adds it to the set of
* created beans
@@ -130,10 +132,10 @@
* @param bean
* The bean representation
*/
- protected void createBean(AbstractClassBean<?> bean, final
AnnotatedClass<?> annotatedClass)
+ protected <T> void createBean(AbstractClassBean<T> bean, final
AnnotatedClass<T> annotatedClass)
{
- beans.add(bean);
+ addBean(annotatedClass, bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
@@ -158,10 +160,10 @@
}
}
- private void createProducerMethod(AbstractClassBean<?> declaringBean,
AnnotatedMethod<?> annotatedMethod)
+ private <T> void createProducerMethod(AbstractClassBean<?> declaringBean,
AnnotatedMethod<T> annotatedMethod)
{
- ProducerMethodBean<?> bean = ProducerMethodBean.of(annotatedMethod,
declaringBean, manager);
- beans.add(bean);
+ ProducerMethodBean<T> bean = ProducerMethodBean.of(annotatedMethod,
declaringBean, manager);
+ addBean(annotatedMethod, bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
}
@@ -183,10 +185,10 @@
}
}
- private void createProducerField(AbstractClassBean<?> declaringBean,
AnnotatedField<?> field)
+ private <T> void createProducerField(AbstractClassBean<?> declaringBean,
AnnotatedField<T> field)
{
- ProducerFieldBean<?> bean = ProducerFieldBean.of(field, declaringBean,
manager);
- beans.add(bean);
+ ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean,
manager);
+ addBean(field, bean);
}
private void createProducerFields(AbstractClassBean<?> declaringBean,
AnnotatedClass<?> annotatedClass)
@@ -213,22 +215,22 @@
private void createObserverMethod(AbstractClassBean<?> declaringBean,
AnnotatedMethod<?> method)
{
ObserverImpl<?> observer = ObserverFactory.create(method, declaringBean,
manager);
- observers.add(observer);
+ beanDeployerEnvironment.getObservers().add(observer);
}
- private void createSimpleBean(AnnotatedClass<?> annotatedClass)
+ private <T> void createSimpleBean(AnnotatedClass<T> annotatedClass)
{
- SimpleBean<?> bean = SimpleBean.of(annotatedClass, manager);
+ SimpleBean<T> bean = SimpleBean.of(annotatedClass, manager);
createBean(bean, annotatedClass);
- beans.add(NewSimpleBean.of(annotatedClass, manager));
+ addBean(NewSimpleBean.of(annotatedClass, manager));
}
- private void createEnterpriseBean(AnnotatedClass<?> annotatedClass)
+ private <T> void createEnterpriseBean(AnnotatedClass<T> annotatedClass)
{
// TODO Don't create enterprise bean if it has no local interfaces!
- EnterpriseBean<?> bean = EnterpriseBean.of(annotatedClass, manager);
+ EnterpriseBean<T> bean = EnterpriseBean.of(annotatedClass, manager);
createBean(bean, annotatedClass);
- beans.add(NewEnterpriseBean.of(annotatedClass, manager));
+ addBean(NewEnterpriseBean.of(annotatedClass, manager));
}
/**
Added:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
(rev 0)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-03-23
12:59:18 UTC (rev 2145)
@@ -0,0 +1,62 @@
+package org.jboss.webbeans.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.event.ObserverImpl;
+import org.jboss.webbeans.injection.resolution.ResolvableAnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+
+public class BeanDeployerEnvironment
+{
+
+ private static final AnnotatedItem<?, ?> OTHER_BEANS_ANNOTATED_ITEM =
ResolvableAnnotatedClass.of(BeanDeployerEnvironment.class, new Annotation[0]);
+
+ private final Map<AnnotatedItem<?, ?>, Set<RIBean<?>>>
beanMap;
+ private final Set<ObserverImpl<?>> observers;
+
+ public BeanDeployerEnvironment()
+ {
+ this.beanMap = new HashMap<AnnotatedItem<?,?>,
Set<RIBean<?>>>();
+ this.observers = new HashSet<ObserverImpl<?>>();
+ }
+
+ public Map<AnnotatedItem<?, ?>, Set<RIBean<?>>> getBeanMap()
+ {
+ return beanMap;
+ }
+
+ public void addBean(AnnotatedItem<?, ?> key, RIBean<?> value)
+ {
+ if (key == null)
+ {
+ key = OTHER_BEANS_ANNOTATED_ITEM;
+ }
+ if (!beanMap.containsKey(key))
+ {
+ beanMap.put(key, new HashSet<RIBean<?>>());
+ }
+ beanMap.get(key).add(value);
+ }
+
+ public Set<RIBean<?>> getBeans()
+ {
+ Set<RIBean<?>> beans = new HashSet<RIBean<?>>();
+ for (Entry<AnnotatedItem<?, ?>, Set<RIBean<?>>> entry :
beanMap.entrySet())
+ {
+ beans.addAll(entry.getValue());
+ }
+ return beans;
+ }
+
+ public Set<ObserverImpl<?>> getObservers()
+ {
+ return observers;
+ }
+
+}
Property changes on:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23
12:34:19 UTC (rev 2144)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23
12:59:18 UTC (rev 2145)
@@ -2,6 +2,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Set;
+import java.util.TreeSet;
import javax.inject.AnnotationLiteral;
@@ -17,6 +19,7 @@
import org.jboss.webbeans.bean.standard.InstanceBean;
import org.jboss.webbeans.bean.standard.ManagerBean;
import org.jboss.webbeans.bootstrap.BeanDeployer;
+import org.jboss.webbeans.bootstrap.BootstrapOrderingBeanComparator;
import org.jboss.webbeans.literal.NewLiteral;
import org.jboss.webbeans.mock.MockEjbDescriptor;
import org.jboss.webbeans.mock.MockServletLifecycle;
@@ -61,13 +64,15 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 4;
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 2))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 4;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0,
2))
{
assert !(bean instanceof NewBean);
assert bean instanceof SimpleBean;
}
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(2, 4))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(2,
4))
{
assert (bean instanceof NewBean);
assert bean instanceof SimpleBean;
@@ -82,13 +87,15 @@
manager.getEjbDescriptorCache().add(MockEjbDescriptor.of(Lion.class));
manager.getEjbDescriptorCache().add(MockEjbDescriptor.of(Gazelle.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 4;
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 2))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 4;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0,
2))
{
assert !(bean instanceof NewBean);
assert bean instanceof EnterpriseBean;
}
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(2, 4))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(2,
4))
{
assert (bean instanceof NewBean);
assert bean instanceof EnterpriseBean;
@@ -102,17 +109,19 @@
beanDeployer.addBean(EventBean.of(manager)).addBean(InjectionPointBean.of(manager)).addBean(InstanceBean.of(manager)).addBean(ManagerBean.of(manager));
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 4))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0,
4))
{
assert bean instanceof AbstractStandardBean;
}
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(4, 6))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(4,
6))
{
assert !(bean instanceof NewBean);
assert bean instanceof SimpleBean;
}
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(6, 8))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(6,
8))
{
assert (bean instanceof NewBean);
assert bean instanceof SimpleBean;
@@ -125,12 +134,14 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Cow.class, Tuna.class, RoadRunner.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 6;
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(0, 4))
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 6;
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(0,
4))
{
assert bean.getType().getName().startsWith("org.jboss.webbeans");
}
- for (RIBean<?> bean : new
ArrayList<RIBean<?>>(beanDeployer.getBeans()).subList(4, 6))
+ for (RIBean<?> bean : new ArrayList<RIBean<?>>(beans).subList(4,
6))
{
assert bean.getType().getName().startsWith("com.acme");
}
@@ -145,8 +156,10 @@
int indexOfProducerDeclaringBean = 0;
int indexOfProducer = 0;
int i = 0;
- assert beanDeployer.getBeans().size() == 5;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 5;
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(TarantulaProducer.class) &&
!bean.getBindings().contains(new NewLiteral()))
{
@@ -167,12 +180,14 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Spider.class, Tarantula.class,
DefangedTarantula.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
int indexOfSpider = 0;
int indexOfTarantula = 0;
int indexOfDefangedTarantula = 0;
int i = 0;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(Spider.class))
{
@@ -198,13 +213,15 @@
BeanDeployer beanDeployer = new BeanDeployer(manager);
beanDeployer.addClasses(Arrays.asList(Shop.class, JewelryShop.class, Tuna.class));
beanDeployer.createBeans();
- assert beanDeployer.getBeans().size() == 8;
+ Set<RIBean<?>> beans = new TreeSet<RIBean<?>>(new
BootstrapOrderingBeanComparator());
+ beans.addAll(beanDeployer.getBeanDeployerEnvironment().getBeans());
+ assert beans.size() == 8;
int indexOfShop = 0;
int indexOfJewelryShop = 0;
int indexOfExpensiveGift = 0;
int indexOfNecklace = 0;
int i = 0;
- for (RIBean<?> bean : beanDeployer.getBeans())
+ for (RIBean<?> bean : beans)
{
if (bean.getType().equals(Shop.class) &&
!bean.getBindings().contains(new NewLiteral()))
{