Search in sources :

Example 1 with DEFAULT

use of org.apache.camel.cdi.DefaultLiteral.DEFAULT in project camel by apache.

the class CamelContextProducer method produce.

@Override
public T produce(CreationalContext<T> ctx) {
    T context = super.produce(ctx);
    // Do not override the name if it's been already set (in the bean constructor for example)
    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
        context.setNameStrategy(nameStrategy(annotated));
    }
    // Add bean registry and Camel injector
    if (context instanceof DefaultCamelContext) {
        DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
        adapted.setRegistry(new CdiCamelRegistry(manager));
        adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
    } else {
        // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
        throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }
    // Add event notifier if at least one observer is present
    Set<Annotation> qualifiers = annotated.getAnnotations().stream().filter(isAnnotationType(Named.class).negate().and(q -> manager.isQualifier(q.annotationType()))).collect(toSet());
    qualifiers.add(ANY);
    if (qualifiers.size() == 1) {
        qualifiers.add(DEFAULT);
    }
    qualifiers.retainAll(extension.getObserverEvents());
    if (!qualifiers.isEmpty()) {
        context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
    }
    return context;
}
Also used : InjectionException(javax.enterprise.inject.InjectionException) DefaultCamelContextNameStrategy(org.apache.camel.impl.DefaultCamelContextNameStrategy) DEFAULT(org.apache.camel.cdi.DefaultLiteral.DEFAULT) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1 InjectionException (javax.enterprise.inject.InjectionException)1 DEFAULT (org.apache.camel.cdi.DefaultLiteral.DEFAULT)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultCamelContextNameStrategy (org.apache.camel.impl.DefaultCamelContextNameStrategy)1