use of javax.enterprise.inject.AmbiguousResolutionException in project core by weld.
the class Reports method addInvalidDependencies.
private static void addInvalidDependencies(Probe probe, HtmlTag body) {
body.add(HtmlTag.aname(DEPS));
body.add(HtmlTag.h2(TITLE_DEPS));
HtmlTag table = HtmlTag.stripedTable().appendTo(HtmlTag.div(DEPS).appendTo(body));
HtmlTag.tr().add(HtmlTag.th(""), HtmlTag.th("Declaring Bean"), HtmlTag.th("Problem")).appendTo(table);
int idx = 0;
for (Bean<?> bean : probe.getBeans()) {
final BeanManagerImpl beanManager = probe.getBeanManager(bean);
// Don't process built-in beans
if (beanManager == null) {
continue;
}
Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
if (injectionPoints != null && !injectionPoints.isEmpty()) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (injectionPoint.isDelegate()) {
// Do not process delegate injection points
continue;
}
Set<Bean<?>> beans = beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]));
if (beans.isEmpty()) {
// Unsatisfied
HtmlTag.tr().add(HtmlTag.td(++idx + "."), HtmlTag.td(bean.toString()).add(HtmlTag.td("Unsatisfied dependency at " + injectionPoint))).appendTo(table);
try {
beanManager.resolve(beans);
} catch (AmbiguousResolutionException e) {
// Ambiguous
HtmlTag.tr().add(HtmlTag.td(++idx + "."), HtmlTag.td(bean.toString()).add(HtmlTag.td("Ambiguous dependency at " + injectionPoint))).appendTo(table);
}
}
}
}
}
}
use of javax.enterprise.inject.AmbiguousResolutionException in project core by weld.
the class Components method getDependencies.
/**
* @param bean
* @param beanManager
* @param probe
* @return the set of dependencies
*/
static Set<Dependency> getDependencies(Bean<?> bean, BeanManager beanManager, Probe probe) {
Set<Dependency> dependencies = new HashSet<Dependency>();
Set<InjectionPoint> injectionPoints = bean.getInjectionPoints();
if (injectionPoints != null && !injectionPoints.isEmpty()) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (injectionPoint.isDelegate()) {
// Do not include delegate injection points
continue;
}
Set<Bean<?>> beans = beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]));
if (beans.isEmpty()) {
dependencies.add(Dependency.createUnsatisfied(injectionPoint, null));
} else {
try {
Bean<?> dependency = beanManager.resolve(beans);
if (isBuiltinBeanButNotExtension(dependency)) {
dependency = probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependency));
}
dependencies.add(new Dependency(dependency, injectionPoint));
} catch (AmbiguousResolutionException e) {
dependencies.add(Dependency.createAmbiguous(injectionPoint, null));
}
}
}
}
return dependencies;
}
use of javax.enterprise.inject.AmbiguousResolutionException in project core by weld.
the class Components method getDependents.
/**
* @param bean
* @param beans
* @param probe
* @param firstMatch
* @return the set of dependents
*/
static Set<Dependency> getDependents(Bean<?> bean, Collection<Bean<?>> beans, Probe probe, boolean firstMatch) {
Set<Dependency> dependents = new HashSet<Dependency>();
for (Bean<?> candidate : beans) {
if (candidate.equals(bean)) {
continue;
}
BeanManager beanManager = probe.getBeanManager(candidate);
if (beanManager == null) {
// Don't process built-in beans
continue;
}
Set<InjectionPoint> injectionPoints = candidate.getInjectionPoints();
if (injectionPoints != null && !injectionPoints.isEmpty()) {
for (InjectionPoint injectionPoint : injectionPoints) {
if (injectionPoint.isDelegate()) {
// Do not include delegate injection points
continue;
}
Set<Bean<?>> foundBeans = beanManager.getBeans(injectionPoint.getType(), injectionPoint.getQualifiers().toArray(new Annotation[injectionPoint.getQualifiers().size()]));
if (foundBeans.isEmpty()) {
continue;
}
Bean<?> candidateDependency;
try {
candidateDependency = beanManager.resolve(foundBeans);
} catch (AmbiguousResolutionException e) {
continue;
}
if (candidateDependency.getBeanClass().equals(InstanceImpl.class)) {
Bean<?> lazilyFetched = getInstanceResolvedBean(beanManager, injectionPoint);
if (lazilyFetched != null && lazilyFetched.equals(bean)) {
dependents.add(Dependency.createPotential(candidate, injectionPoint, INFO_FETCHING_LAZILY));
if (firstMatch) {
break;
} else {
continue;
}
}
}
boolean satisfies = false;
if (isBuiltinBeanButNotExtension(candidateDependency)) {
satisfies = bean.equals(probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) candidateDependency)));
} else {
satisfies = bean.equals(candidateDependency);
}
if (satisfies) {
dependents.add(new Dependency(candidate, injectionPoint));
if (firstMatch) {
break;
} else {
continue;
}
}
}
}
}
return dependents;
}
Aggregations