Search in sources :

Example 1 with ObserverMethodConfigurator

use of javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator in project core by weld.

the class ObserverMethodConfiguratorImpl method read.

@Override
public ObserverMethodConfigurator<T> read(AnnotatedMethod<?> method) {
    checkArgumentNotNull(method);
    Set<AnnotatedParameter<?>> eventParameters = method.getParameters().stream().filter((p) -> p.isAnnotationPresent(Observes.class) || p.isAnnotationPresent(ObservesAsync.class)).collect(Collectors.toSet());
    checkEventParams(eventParameters, method.getJavaMember());
    AnnotatedParameter<?> eventParameter = eventParameters.iterator().next();
    Observes observesAnnotation = eventParameter.getAnnotation(Observes.class);
    if (observesAnnotation != null) {
        reception(observesAnnotation.notifyObserver());
        transactionPhase(observesAnnotation.during());
    } else {
        reception(eventParameter.getAnnotation(ObservesAsync.class).notifyObserver());
    }
    Priority priority = method.getAnnotation(Priority.class);
    if (priority != null) {
        priority(priority.value());
    }
    beanClass(eventParameter.getDeclaringCallable().getDeclaringType().getJavaClass());
    observedType(eventParameter.getBaseType());
    qualifiers(Configurators.getQualifiers(eventParameter));
    return this;
}
Also used : EventLogger(org.jboss.weld.logging.EventLogger) Preconditions.checkArgumentNotNull(org.jboss.weld.util.Preconditions.checkArgumentNotNull) ObserverMethod(javax.enterprise.inject.spi.ObserverMethod) ObservesAsync(javax.enterprise.event.ObservesAsync) HashSet(java.util.HashSet) Reception(javax.enterprise.event.Reception) Parameter(java.lang.reflect.Parameter) Observes(javax.enterprise.event.Observes) Formats(org.jboss.weld.util.reflection.Formats) EventContext(javax.enterprise.inject.spi.EventContext) Method(java.lang.reflect.Method) SyntheticObserverMethod(org.jboss.weld.event.SyntheticObserverMethod) CovariantTypes(org.jboss.weld.resolution.CovariantTypes) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) Extension(javax.enterprise.inject.spi.Extension) Set(java.util.Set) ObserverException(javax.enterprise.event.ObserverException) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) Collectors(java.util.stream.Collectors) Priority(javax.annotation.Priority) Type(java.lang.reflect.Type) ObserverMethodConfigurator(javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator) Annotation(java.lang.annotation.Annotation) Collections(java.util.Collections) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) TransactionPhase(javax.enterprise.event.TransactionPhase) ObservesAsync(javax.enterprise.event.ObservesAsync) AnnotatedParameter(javax.enterprise.inject.spi.AnnotatedParameter) Observes(javax.enterprise.event.Observes) Priority(javax.annotation.Priority)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 Type (java.lang.reflect.Type)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Priority (javax.annotation.Priority)1 ObserverException (javax.enterprise.event.ObserverException)1 Observes (javax.enterprise.event.Observes)1 ObservesAsync (javax.enterprise.event.ObservesAsync)1 Reception (javax.enterprise.event.Reception)1 TransactionPhase (javax.enterprise.event.TransactionPhase)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 AnnotatedParameter (javax.enterprise.inject.spi.AnnotatedParameter)1 EventContext (javax.enterprise.inject.spi.EventContext)1 Extension (javax.enterprise.inject.spi.Extension)1 ObserverMethod (javax.enterprise.inject.spi.ObserverMethod)1 ObserverMethodConfigurator (javax.enterprise.inject.spi.configurator.ObserverMethodConfigurator)1