Search in sources :

Example 1 with Resolvable

use of org.jboss.weld.resolution.Resolvable in project core by weld.

the class DefaultJsonDataProvider method receiveAvailableBeans.

@Override
public String receiveAvailableBeans(int pageIndex, int pageSize, String filters, String representation) {
    Map<String, String> filterValues = Queries.Filters.parseFilters(filters);
    // First validate input
    if (!filterValues.containsKey(BDA_ID)) {
        return getError("Bean deployment archive id (bdaId) must be specified: " + filters);
    }
    // Find the bean deployment archive
    BeanManagerImpl beanManager = probe.getBeanManager(filterValues.get(BDA_ID));
    if (beanManager == null) {
        return getError("Unable to find the bean deployment archive for: " + filterValues.get(BDA_ID));
    }
    Set<Bean<?>> beans = null;
    // Parse required type
    Type requiredType;
    if (filterValues.get(REQUIRED_TYPE) != null) {
        requiredType = Parsers.parseType(filterValues.get(REQUIRED_TYPE), beanManager.getServices().get(ResourceLoader.class));
    } else {
        requiredType = Object.class;
    }
    if (requiredType == null) {
        return getError("Invalid required type: parsing error or the type is not accessible from the specified bean archive!");
    }
    ResolvableBuilder resolvableBuilder = new ResolvableBuilder(requiredType, beanManager);
    // Parse qualifiers
    List<QualifierInstance> qualifierInstances;
    if (filterValues.get(QUALIFIERS) != null) {
        qualifierInstances = Parsers.parseQualifiers(filterValues.get(QUALIFIERS), beanManager.getServices().get(ResourceLoader.class), beanManager);
    } else {
        qualifierInstances = Collections.singletonList(QualifierInstance.DEFAULT);
    }
    for (QualifierInstance qualifierInstance : qualifierInstances) {
        if (qualifierInstance == null) {
            return getError("Invalid qualifiers: parsing error or one of the qualifier types is not accessible from the specified bean archive!");
        }
        resolvableBuilder.addQualifierUnchecked(qualifierInstance);
    }
    Resolvable resolvable = resolvableBuilder.create();
    // Lookup beans
    beans = beanManager.getBeanResolver().resolve(resolvable, false);
    if (Boolean.valueOf(filterValues.get(RESOLVE))) {
        // Apply resolution rules
        beans = beanManager.getBeanResolver().resolve(beans);
    }
    return JsonObjects.createBeansJson(Queries.find(probe.getOrderedBeans(beans), pageIndex, pageSize, null), probe, beanManager, Representation.from(representation));
}
Also used : Type(java.lang.reflect.Type) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) ResolvableBuilder(org.jboss.weld.resolution.ResolvableBuilder) QualifierInstance(org.jboss.weld.resolution.QualifierInstance) Resolvable(org.jboss.weld.resolution.Resolvable) Bean(javax.enterprise.inject.spi.Bean)

Example 2 with Resolvable

use of org.jboss.weld.resolution.Resolvable in project core by weld.

the class InstanceImpl method resolveBeans.

private Set<Bean<?>> resolveBeans() {
    // Perform typesafe resolution, and possibly attempt to resolve the ambiguity
    Resolvable resolvable = new ResolvableBuilder(getType(), getBeanManager()).addQualifiers(getQualifiers()).setDeclaringBean(getInjectionPoint().getBean()).create();
    TypeSafeBeanResolver beanResolver = getBeanManager().getBeanResolver();
    return beanResolver.resolve(beanResolver.resolve(resolvable, Reflections.isCacheable(getQualifiers())));
}
Also used : TypeSafeBeanResolver(org.jboss.weld.resolution.TypeSafeBeanResolver) ResolvableBuilder(org.jboss.weld.resolution.ResolvableBuilder) Resolvable(org.jboss.weld.resolution.Resolvable)

Aggregations

Resolvable (org.jboss.weld.resolution.Resolvable)2 ResolvableBuilder (org.jboss.weld.resolution.ResolvableBuilder)2 Type (java.lang.reflect.Type)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)1 QualifierInstance (org.jboss.weld.resolution.QualifierInstance)1 TypeSafeBeanResolver (org.jboss.weld.resolution.TypeSafeBeanResolver)1