Search in sources :

Example 6 with AbstractBuiltInBean

use of org.jboss.weld.bean.builtin.AbstractBuiltInBean 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;
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) Annotation(java.lang.annotation.Annotation) SessionBean(org.jboss.weld.bean.SessionBean) ExtensionBean(org.jboss.weld.bean.builtin.ExtensionBean) ForwardingBean(org.jboss.weld.bean.ForwardingBean) ManagedBean(org.jboss.weld.bean.ManagedBean) AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) Bean(javax.enterprise.inject.spi.Bean) AmbiguousResolutionException(javax.enterprise.inject.AmbiguousResolutionException) BeanManager(javax.enterprise.inject.spi.BeanManager) HashSet(java.util.HashSet)

Aggregations

AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)6 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)3 ExtensionBean (org.jboss.weld.bean.builtin.ExtensionBean)3 Annotation (java.lang.annotation.Annotation)2 HashSet (java.util.HashSet)2 AmbiguousResolutionException (javax.enterprise.inject.AmbiguousResolutionException)2 Bean (javax.enterprise.inject.spi.Bean)2 ForwardingBean (org.jboss.weld.bean.ForwardingBean)2 ManagedBean (org.jboss.weld.bean.ManagedBean)2 SessionBean (org.jboss.weld.bean.SessionBean)2 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)2 ContextualStore (org.jboss.weld.serialization.spi.ContextualStore)2 ArrayList (java.util.ArrayList)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 AbstractProducerBean (org.jboss.weld.bean.AbstractProducerBean)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 ObserverMethodImpl (org.jboss.weld.event.ObserverMethodImpl)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 BeanKind (org.jboss.weld.probe.Components.BeanKind)1 Dependency (org.jboss.weld.probe.Components.Dependency)1