javax.enterprise.inject.Alternative Java Examples

The following examples show how to use javax.enterprise.inject.Alternative. 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: TestLabeledAlternativeFilter.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isFiltered(Class<?> targetClass)
{
    if (!targetClass.isAnnotationPresent(Alternative.class))
    {
        return false;
    }

    TestLabeled testLabeled = targetClass.getAnnotation(TestLabeled.class);

    if (testLabeled == null)
    {
        return false;
    }

    if (testLabeled.value().equals(activeLabel))
    {
        return false;
    }
    return true;
}
 
Example #2
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public String produceStringConfiguration(InjectionPoint injectionPoint) {
    return super.produceStringConfiguration(injectionPoint);
}
 
Example #3
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Integer produceIntegerConfiguration(InjectionPoint injectionPoint) {
    return super.produceIntegerConfiguration(injectionPoint);
}
 
Example #4
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Long produceLongConfiguration(InjectionPoint injectionPoint) {
    return super.produceLongConfiguration(injectionPoint);
}
 
Example #5
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Boolean produceBooleanConfiguration(InjectionPoint injectionPoint) {
    return super.produceBooleanConfiguration(injectionPoint);
}
 
Example #6
Source File: DatawaveConfigPropertyProducer.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
@Alternative
@Specializes
@Produces
@Dependent
@ConfigProperty(name = "ignored")
// we actually don't need the name
public Float produceFloatConfiguration(InjectionPoint injectionPoint) {
    return super.produceFloatConfiguration(injectionPoint);
}
 
Example #7
Source File: AlternativePriorityAnnotationTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
@AlternativePriority(1000)
@Alternative
public TheUltimateImpl createUltimateImpl() {
    return new TheUltimateImpl();
}
 
Example #8
Source File: ComputedAlternativePriorityTest.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Produces
@Alternative
public String bravo() {
    return "bravo";
}
 
Example #9
Source File: Producers.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Produces
@Alternative
public String bravo() {
    return "bravo";
}
 
Example #10
Source File: BeanBuilder.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * <p>
 * Read the {@link AnnotatedType}, creating a bean from the class and it's
 * annotations.
 * </p>
 * <p/>
 * <p>
 * By default the bean lifecycle will wrap the result of calling
 * {@link BeanManager#createInjectionTarget(AnnotatedType)}.
 * </p>
 * <p/>
 * <p>
 * {@link BeanBuilder} does <em>not</em> support reading members of the class
 * to create producers or observer methods.
 * </p>
 *
 * @param type the type to read
 */
public BeanBuilder<T> readFromType(AnnotatedType<T> type)
{
    this.beanClass = type.getJavaClass();

    if (beanLifecycle == null)
    {
        setDefaultBeanLifecycle(type);
    }

    this.qualifiers = new HashSet<Annotation>();
    this.stereotypes = new HashSet<Class<? extends Annotation>>();
    this.types = new HashSet<Type>();
    for (Annotation annotation : type.getAnnotations())
    {
        if (beanManager.isQualifier(annotation.annotationType()))
        {
            this.qualifiers.add(annotation);
        }
        else if (beanManager.isScope(annotation.annotationType()))
        {
            this.scope = annotation.annotationType();
        }
        else if (beanManager.isStereotype(annotation.annotationType()))
        {
            this.stereotypes.add(annotation.annotationType());
        }
        if (annotation instanceof Named)
        {
            this.name = ((Named) annotation).value();
            if (name == null || name.length() == 0)
            {
                name = createDefaultBeanName(type);
            }
        }
        if (annotation instanceof Alternative)
        {
            this.alternative = true;
        }
    }
    if (type.isAnnotationPresent(Typed.class))
    {
        Typed typed = type.getAnnotation(Typed.class);
        this.types.addAll(Arrays.asList(typed.value()));

    }
    else
    {
        for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass())
        {
            this.types.add(c);
        }
        Collections.addAll(this.types, type.getJavaClass().getInterfaces());
        this.types.add(Object.class);
    }        

    if (qualifiers.isEmpty())
    {
        qualifiers.add(new DefaultLiteral());
    }
    qualifiers.add(new AnyLiteral());

    this.id = ImmutableBeanWrapper.class.getName() + ":" + Annotateds.createTypeId(type);
    return this;
}
 
Example #11
Source File: AnnotatedTypeBuilderTest.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
@Test
public void testTypeLevelAnnotationRedefinition()
{
    AnnotatedTypeBuilder<Cat> builder = new AnnotatedTypeBuilder<Cat>();
    builder.readFromType(Cat.class);

    AnnotatedType<Cat> cat = builder.create();

    assertNotNull(cat);
    assertNotNull(cat.getAnnotation(Named.class));
    assertEquals("cat", cat.getAnnotation(Named.class).value());

    builder.addToClass(new AlternativeLiteral())
            .addToClass(new ApplicationScopedLiteral())
            .removeFromClass(Named.class)
            .addToClass(new NamedLiteral("tomcat"));

    cat = builder.create();
    assertNotNull(cat);

    assertEquals(3, cat.getAnnotations().size());
    assertTrue(cat.isAnnotationPresent(Named.class));
    assertTrue(cat.isAnnotationPresent(Alternative.class));
    assertTrue(cat.isAnnotationPresent(ApplicationScoped.class));
    assertEquals("tomcat", cat.getAnnotation(Named.class).value());
    
    AnnotatedMethod observerMethod = null;
    for (AnnotatedMethod m : cat.getMethods())
    {
        if ("doSomeObservation".equals(m.getJavaMember().getName()))
        {
            observerMethod = m;
            break;
        }
    }
    assertNotNull(observerMethod);
    observerMethod.isAnnotationPresent(Observes.class);
    
    {
        // test reading from an AnnotatedType
        AnnotatedTypeBuilder<Cat> builder2 = new AnnotatedTypeBuilder<Cat>();
        builder2.readFromType(cat);
        builder2.removeFromAll(Named.class);

        final AnnotatedType<Cat> noNameCat = builder2.create();
        assertFalse(noNameCat.isAnnotationPresent(Named.class));
        assertEquals(2, noNameCat.getAnnotations().size());
    }

    {

        // test reading from an AnnotatedType in non-overwrite mode
        AnnotatedTypeBuilder<Cat> builder3 = new AnnotatedTypeBuilder<Cat>();
        builder3.readFromType(cat, true);
        builder3.removeFromAll(Named.class);

        builder3.readFromType(cat, false);

        final AnnotatedType<Cat> namedCat = builder3.create();
        assertTrue(namedCat.isAnnotationPresent(Named.class));
        assertEquals(3, namedCat.getAnnotations().size());
    }
}