Search in sources :

Example 1 with Dependency

use of org.jboss.weld.probe.Components.Dependency in project core by weld.

the class JsonObjects method createDependencies.

/**
 * @param parent
 * @param bean
 * @param probe
 * @param isTransient
 * @return
 */
static JsonArrayBuilder createDependencies(Bean<?> parent, Bean<?> bean, Probe probe, boolean isTransient) {
    final BeanManagerImpl beanManager = probe.getBeanManager(bean);
    // Don't create dependencies for built-in beans
    if (beanManager == null) {
        return null;
    }
    JsonArrayBuilder dependenciesBuilder = Json.arrayBuilder(true);
    for (Dependency dep : Components.getDependencies(bean, beanManager, probe)) {
        if (dep.isUnsatisfied()) {
            dependenciesBuilder.add(createDependency(null, dep, probe).add(IS_UNSATISFIED, true));
            continue;
        }
        if (dep.isAmbiguous()) {
            dependenciesBuilder.add(createDependency(null, dep, probe).add(IS_AMBIGUOUS, true));
            continue;
        }
        if (Components.isBuiltinBeanButNotExtension(dep.getBean())) {
            dependenciesBuilder.add(createBuiltInDependency(dep, probe, beanManager, DEPENDENCIES));
            continue;
        }
        // Handle circular dependencies
        if (dep.getBean().equals(parent)) {
            dependenciesBuilder.add(createDependency(dep.getBean(), dep, probe));
            continue;
        }
        JsonObjectBuilder dependency = createDependency(dep.getBean(), dep, probe);
        dependency.add(DECLARING_BEAN, createDeclaringBean(dep.getBean(), probe));
        dependenciesBuilder.add(dependency);
        if (isTransient) {
            dependency.add(DEPENDENCIES, createDependencies(bean, dep.getBean(), probe, true));
        }
    }
    return dependenciesBuilder.isEmpty() ? null : dependenciesBuilder;
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) Dependency(org.jboss.weld.probe.Components.Dependency) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Example 2 with Dependency

use of org.jboss.weld.probe.Components.Dependency in project core by weld.

the class JsonObjects method createDependents.

/**
 * @param parent
 * @param bean
 * @param probe
 * @param isTransient
 * @return
 */
static JsonArrayBuilder createDependents(Bean<?> parent, Bean<?> bean, Probe probe, boolean isTransient) {
    JsonArrayBuilder dependentsBuilder = Json.arrayBuilder(true);
    for (Dependency dependent : Components.getDependents(bean, probe)) {
        // Workaround for built-in beans - these are identified by the set of types
        if (Components.isBuiltinBeanButNotExtension(dependent.getBean())) {
            dependentsBuilder.add(createDependency(probe.getBean(Components.getBuiltinBeanId((AbstractBuiltInBean<?>) dependent.getBean())), dependent, probe));
            continue;
        }
        // Handle circular dependencies
        if (dependent.getBean().equals(parent)) {
            dependentsBuilder.add(createDependency(dependent.getBean(), dependent, probe));
            continue;
        }
        JsonObjectBuilder dependency = createDependency(dependent.getBean(), dependent, probe);
        if (dependent.getInfo() != null) {
            dependency.add(INFO, dependent.getInfo());
            if (dependent.isPotential()) {
                dependency.add(IS_POTENTIAL, true);
            }
        }
        dependency.add(DECLARING_BEAN, createDeclaringBean(dependent.getBean(), probe));
        dependentsBuilder.add(dependency);
        if (isTransient) {
            dependency.add(DEPENDENTS, createDependents(bean, dependent.getBean(), probe, true));
        }
    }
    return dependentsBuilder.isEmpty() ? null : dependentsBuilder;
}
Also used : AbstractBuiltInBean(org.jboss.weld.bean.builtin.AbstractBuiltInBean) JsonArrayBuilder(org.jboss.weld.probe.Json.JsonArrayBuilder) Dependency(org.jboss.weld.probe.Components.Dependency) JsonObjectBuilder(org.jboss.weld.probe.Json.JsonObjectBuilder)

Aggregations

Dependency (org.jboss.weld.probe.Components.Dependency)2 JsonArrayBuilder (org.jboss.weld.probe.Json.JsonArrayBuilder)2 JsonObjectBuilder (org.jboss.weld.probe.Json.JsonObjectBuilder)2 AbstractBuiltInBean (org.jboss.weld.bean.builtin.AbstractBuiltInBean)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1