Java Code Examples for javax.enterprise.inject.spi.BeanManager#isQualifier()

The following examples show how to use javax.enterprise.inject.spi.BeanManager#isQualifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanUtils.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the qualifiers from a set of annotations.
 *
 * @param beanManager the beanManager to use to determine if an annotation is
 *                    a qualifier
 * @param annotations the annotations to check
 * @return any qualifiers present in <code>annotations</code>
 */
@SuppressWarnings("unchecked")
public static Set<Annotation> getQualifiers(BeanManager beanManager, Iterable<Annotation> annotations)
{
    Set<Annotation> qualifiers = new HashSet<Annotation>();

    for (Annotation annotation : annotations)
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            qualifiers.add(annotation);
        }
    }

    return qualifiers;
}
 
Example 2
Source File: BeanUtils.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Extract the qualifiers from a set of annotations.
 *
 * @param beanManager the beanManager to use to determine if an annotation is
 *                    a qualifier
 * @param annotations the annotations to check
 * @return any qualifiers present in <code>annotations</code>
 */
public static Set<Annotation> getQualifiers(BeanManager beanManager, Annotation[]... annotations)
{
    Set<Annotation> qualifiers = new HashSet<Annotation>();
    for (Annotation[] annotationArray : annotations)
    {
        for (Annotation annotation : annotationArray)
        {
            if (beanManager.isQualifier(annotation.annotationType()))
            {
                qualifiers.add(annotation);
            }
        }
    }
    return qualifiers;
}
 
Example 3
Source File: WeldJunit5Extension.java    From weld-junit with Apache License 2.0 5 votes vote down vote up
private List<Annotation> resolveQualifiers(ParameterContext pc, BeanManager bm) {
    List<Annotation> qualifiers = new ArrayList<>();
    if (pc.getParameter().getAnnotations().length == 0) {
        return Collections.emptyList();
    } else {
        for (Annotation annotation : pc.getParameter().getAnnotations()) {
            // use BeanManager.isQualifier to be able to detect custom qualifiers which don't need to have @Qualifier
            if (bm.isQualifier(annotation.annotationType())) {
                qualifiers.add(annotation);
            }
        }
    }
    return qualifiers;
}
 
Example 4
Source File: OpenEJBEnricher.java    From tomee with Apache License 2.0 5 votes vote down vote up
private MethodParamInjectionPoint(final Method method, final int position, final BeanManager beanManager) {
    this.method = method;
    this.position = position;

    for (final Annotation annotation : method.getParameterAnnotations()[position]) {
        if (beanManager.isQualifier(annotation.annotationType())) {
            qualifiers.add(annotation);
        }
    }
    if (qualifiers.isEmpty()) {
        qualifiers.add(DefaultLiteral.INSTANCE);
    }
    qualifiers.add(AnyLiteral.INSTANCE);
}
 
Example 5
Source File: ExcludeExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private List<Annotation> resolveQualifiers(Set<Annotation> annotations, BeanManager beanManager)
{
    List<Annotation> result = new ArrayList<Annotation>();

    for (Annotation annotation : annotations)
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            result.add(annotation);
        }
    }
    return result;
}
 
Example 6
Source File: MockExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public <X> void onProcessInjectionTarget(@Observes ProcessInjectionTarget<X> processInjectionTarget,
                                         BeanManager beanManager)
{
    if (!isActivated)
    {
        return;
    }

    for (MockFilter mockFilter : mockFilters)
    {
        if (!mockFilter.isMockedImplementationSupported(beanManager, processInjectionTarget.getAnnotatedType()))
        {
            return;
        }
    }

    List<Annotation> qualifiers = new ArrayList<Annotation>();
    for (Annotation annotation : processInjectionTarget.getAnnotatedType().getAnnotations())
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            qualifiers.add(annotation);
        }
    }

    Typed typed = processInjectionTarget.getAnnotatedType().getAnnotation(Typed.class);

    List<Type> foundTypes = new ArrayList<Type>();
    if (typed != null)
    {
        Collections.addAll(foundTypes, typed.value());
    }
    else
    {
        foundTypes.addAll(extractTypes(processInjectionTarget.getAnnotatedType().getJavaClass()));
    }

    if (foundTypes.isEmpty())
    {
        return;
    }

    final InjectionTarget<X> originalInjectionTarget = processInjectionTarget.getInjectionTarget();
    processInjectionTarget.setInjectionTarget(new MockAwareInjectionTargetWrapper<X>(
        beanManager, originalInjectionTarget, foundTypes, qualifiers));
}
 
Example 7
Source File: MockExtension.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
public <X, T> void onProcessProducer(@Observes ProcessProducer<X, T> processProducer, BeanManager beanManager)
{
    if (!isActivated)
    {
        return;
    }

    for (MockFilter mockFilter : mockFilters)
    {
        if (!mockFilter.isMockedImplementationSupported(beanManager, processProducer.getAnnotatedMember()))
        {
            return;
        }
    }

    final Producer<T> originalProducer = processProducer.getProducer();
    AnnotatedMember<X> annotatedMember = processProducer.getAnnotatedMember();
    List<Annotation> qualifiers = new ArrayList<Annotation>();
    for (Annotation annotation : annotatedMember.getAnnotations())
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            qualifiers.add(annotation);
        }
    }

    Typed typed = annotatedMember.getAnnotation(Typed.class);

    List<Type> foundTypes = new ArrayList<Type>();
    if (typed != null)
    {
        Collections.addAll(foundTypes, typed.value());
    }
    else if (annotatedMember.getBaseType() instanceof Class)
    {
        foundTypes.addAll(extractTypes((Class)annotatedMember.getBaseType()));
    }

    if (foundTypes.isEmpty())
    {
        return;
    }

    processProducer.setProducer(new MockAwareProducerWrapper<T>(
        beanManager, originalProducer, foundTypes, qualifiers));
}