Author: pete.muir(a)jboss.org
Date: 2009-08-03 16:31:21 -0400 (Mon, 03 Aug 2009)
New Revision: 3396
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java
Log:
WBRI-331
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java 2009-08-03
13:07:59 UTC (rev 3395)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/resolution/TypeSafeBeanResolver.java 2009-08-03
20:31:21 UTC (rev 3396)
@@ -18,6 +18,7 @@
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.Callable;
import javax.enterprise.inject.spi.Bean;
@@ -26,6 +27,7 @@
import org.jboss.webbeans.bean.standard.InstanceBean;
import org.jboss.webbeans.util.Beans;
import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.collections.ConcurrentCache;
/**
* @author pmuir
@@ -34,9 +36,11 @@
public class TypeSafeBeanResolver<T extends Bean<?>> extends
TypeSafeResolver<T>
{
- private final BeanManagerImpl manager;
public static final Set<ResolvableTransformer> TRANSFORMERS;
+ private final BeanManagerImpl manager;
+ private final ConcurrentCache<Set<?>, Set<Bean<?>>>
disambiguatedBeans;
+
static
{
TRANSFORMERS = new HashSet<ResolvableTransformer>();
@@ -48,6 +52,7 @@
{
super(beans);
this.manager = manager;
+ this.disambiguatedBeans = new ConcurrentCache<Set<?>,
Set<Bean<?>>>();
}
@Override
@@ -82,43 +87,33 @@
return matched;
}
- public <X> Set<Bean<? extends X>> resolve(Set<Bean<? extends
X>> beans)
+ public <X> Set<Bean<? extends X>> resolve(final Set<Bean<?
extends X>> beans)
{
- if (beans.size() <= 1)
+ return disambiguatedBeans.<Set<Bean<? extends
X>>>putIfAbsent(beans, new Callable<Set<Bean<? extends X>>>()
{
- return beans;
- }
-
- boolean removePolicies = false;
-
- // TODO CACHE!!!!!
-
- for (Bean<? extends X> bean : beans)
- {
- if (bean.isPolicy())
- {
- removePolicies = true;
- }
- }
- // TODO Specialization!
- if (removePolicies)
- {
- Set<Bean<? extends X>> policies = new HashSet<Bean<? extends
X>>();
- for (Bean<? extends X> bean : beans)
+ public Set<Bean<? extends X>> call() throws Exception
{
- if (bean.isPolicy())
+ Set<Bean<? extends X>> disambiguatedBeans = beans;
+ if (disambiguatedBeans.size() > 1)
{
- policies.add(bean);
+ boolean policyPresent = Beans.isPolicyPresent(disambiguatedBeans);
+ disambiguatedBeans = new HashSet<Bean<? extends X>>();
+
+ for (Bean<? extends X> bean : beans)
+ {
+ if (policyPresent ? bean.isPolicy() : true &&
!Beans.isSpecialized(bean, beans, manager.getSpecializedBeans()))
+ {
+ disambiguatedBeans.add(bean);
+ }
+ }
+
}
+ return disambiguatedBeans;
}
-
- return policies;
- }
- else
- {
- return beans;
- }
+
+ });
+
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java 2009-08-03 13:07:59 UTC
(rev 3395)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java 2009-08-03 20:31:21 UTC
(rev 3396)
@@ -20,9 +20,11 @@
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.decorator.Decorates;
+import javax.enterprise.context.spi.Contextual;
import javax.enterprise.inject.BindingType;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
@@ -226,4 +228,43 @@
}
return false;
}
+
+ /**
+ * Check if any of the beans is a policy
+ *
+ * @param beans
+ * @return
+ */
+ public static <X> boolean isPolicyPresent(Set<Bean<? extends X>>
beans)
+ {
+ for (Bean<?> bean : beans)
+ {
+ if (bean.isPolicy())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check if bean is specialized by any of beans
+ *
+ * @param bean
+ * @param beans
+ * @param specializedBeans
+ * @return
+ */
+ public static <X> boolean isSpecialized(Bean<? extends X> bean,
Set<Bean<? extends X>> beans, Map<Contextual<?>,
Contextual<?>> specializedBeans)
+ {
+ if (specializedBeans.containsKey(bean))
+ {
+ if (beans.contains(specializedBeans.get(bean)))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java 2009-08-03
13:07:59 UTC (rev 3395)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/extensions/beanManager/BeanManagerTest.java 2009-08-03
20:31:21 UTC (rev 3396)
@@ -55,9 +55,8 @@
assert bean == passivatingBean;
}
- @Test(groups = "ri-broken")
+ @Test
@SpecAssertion(section = "11.3.8", id = "a")
- //WBRI-331
public void testAmbiguousDependencyResolved()
{
Set<Bean<?>> beans = new HashSet<Bean<?>>();