Search in sources :

Example 1 with TypeLiteral

use of javax.enterprise.util.TypeLiteral in project camel by apache.

the class CdiEventEndpoint method createProducer.

@Override
public Producer createProducer() throws IllegalAccessException {
    // FIXME: to be replaced once event firing with dynamic parameterized type
    // is properly supported (see https://issues.jboss.org/browse/CDI-516)
    TypeLiteral<T> literal = new TypeLiteral<T>() {
    };
    for (Field field : TypeLiteral.class.getDeclaredFields()) {
        if (field.getType().equals(Type.class)) {
            field.setAccessible(true);
            field.set(literal, type);
            break;
        }
    }
    InjectionTarget<AnyEvent> target = manager.createInjectionTarget(manager.createAnnotatedType(AnyEvent.class));
    CreationalContext<AnyEvent> ctx = manager.createCreationalContext(null);
    AnyEvent instance = target.produce(ctx);
    target.inject(instance, ctx);
    return new CdiEventProducer<>(this, instance.event.select(literal, qualifiers.stream().toArray(Annotation[]::new)));
}
Also used : Field(java.lang.reflect.Field) TypeLiteral(javax.enterprise.util.TypeLiteral)

Aggregations

Field (java.lang.reflect.Field)1 TypeLiteral (javax.enterprise.util.TypeLiteral)1