Author: pete.muir(a)jboss.org
Date: 2010-07-23 13:51:07 -0400 (Fri, 23 Jul 2010)
New Revision: 6770
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/FieldSetter.java
Log:
use resolve
Modified:
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/FieldSetter.java
===================================================================
---
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/FieldSetter.java 2010-07-23
17:47:07 UTC (rev 6769)
+++
extensions/trunk/impl/src/main/java/org/jboss/weld/extensions/bean/generic/FieldSetter.java 2010-07-23
17:51:07 UTC (rev 6770)
@@ -17,9 +17,9 @@
package org.jboss.weld.extensions.bean.generic;
import java.lang.reflect.Field;
-import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -45,20 +45,15 @@
public void set(Object instance, CreationalContext<?> ctx)
{
- Set<Bean<?>> beans = beanManager.getBeans(field.getType(), qualifier);
- if (beans.size() == 0)
+ Bean<?> bean = beanManager.resolve(beanManager.getBeans(field.getType(),
qualifier));
+ if (bean == null)
{
- throw new RuntimeException("Could not resolve bean for Generic Producer
field " + field.getDeclaringClass() + "." + field.getName() + " Type:
" + field.getType() + " Qualifiers:" + qualifier);
+ throw new UnsatisfiedResolutionException("Could not resolve bean for
Generic Producer field " + field.getDeclaringClass() + "." +
field.getName() + " Type: " + field.getType() + " Qualifiers:" +
qualifier);
}
- if (beans.size() > 1)
- {
- throw new RuntimeException("More than 1 bean resolved for Generic Producer
field " + field.getDeclaringClass() + "." + field.getName());
- }
- Bean<?> bean = beans.iterator().next();
- Object dep = beanManager.getReference(bean, field.getType(), ctx);
+ Object value = beanManager.getReference(bean, field.getType(), ctx);
try
{
- field.set(instance, dep);
+ field.set(instance, value);
}
catch (IllegalArgumentException e)
{
Show replies by date