Java Code Examples for javax.enterprise.inject.spi.AnnotatedMethod#getJavaMember()

The following examples show how to use javax.enterprise.inject.spi.AnnotatedMethod#getJavaMember() . 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: MetricCdiInjectionExtension.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
private <X> void findAnnotatedMethods(@Observes ProcessManagedBean<X> bean) {
    Package pack = bean.getBean().getBeanClass().getPackage();
    if (pack != null && pack.equals(GaugeRegistrationInterceptor.class.getPackage())) {
        return;
    }
    ArrayList<AnnotatedMember<?>> list = new ArrayList<>();
    for (AnnotatedMethod<? super X> aMethod : bean.getAnnotatedBeanClass().getMethods()) {
        Method method = aMethod.getJavaMember();
        if (!method.isSynthetic() && !Modifier.isPrivate(method.getModifiers())) {
            list.add(aMethod);
        }
    }
    list.addAll(bean.getAnnotatedBeanClass().getConstructors());
    if (!list.isEmpty()) {
        metricsFromAnnotatedMethods.put(bean.getBean(), list);
    }
}
 
Example 2
Source File: FaultToleranceOperation.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
public static FaultToleranceOperation of(AnnotatedMethod<?> annotatedMethod) {
    return new FaultToleranceOperation(annotatedMethod.getDeclaringType().getJavaClass(), annotatedMethod.getJavaMember(),
            isAsync(annotatedMethod),
            returnsCompletionStage(annotatedMethod),
            getConfig(Bulkhead.class, annotatedMethod, BulkheadConfig::new),
            getConfig(CircuitBreaker.class, annotatedMethod, CircuitBreakerConfig::new),
            getConfig(Fallback.class, annotatedMethod, FallbackConfig::new),
            getConfig(Retry.class, annotatedMethod, RetryConfig::new),
            getConfig(Timeout.class, annotatedMethod, TimeoutConfig::new));
}
 
Example 3
Source File: GenericConfig.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
GenericConfig(Class<X> annotationType, AnnotatedMethod<?> annotatedMethod) {
    this(annotatedMethod.getDeclaringType()
            .getJavaClass(), annotatedMethod.getJavaMember(), annotatedMethod, annotationType,
            annotatedMethod.isAnnotationPresent(annotationType) ? annotatedMethod.getAnnotation(annotationType)
                    : annotatedMethod.getDeclaringType()
                            .getAnnotation(annotationType),
            annotatedMethod.isAnnotationPresent(annotationType) ? ElementType.METHOD : ElementType.TYPE);
}
 
Example 4
Source File: CDIInterceptorWrapperImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static Map<Method, List<InterceptorInvoker>> initInterceptorInvokers(BeanManager beanManager,
                                                                             CreationalContext<?> creationalContext,
                                                                             Class<?> restClient) {
    Map<Method, List<InterceptorInvoker>> invokers = new HashMap<>();
    // Interceptor as a key in a map is not entirely correct (custom interceptors) but should work in most cases
    Map<Interceptor<?>, Object> interceptorInstances = new HashMap<>();
    
    AnnotatedType<?> restClientType = beanManager.createAnnotatedType(restClient);

    List<Annotation> classBindings = getBindings(restClientType.getAnnotations(), beanManager);

    for (AnnotatedMethod<?> method : restClientType.getMethods()) {
        Method javaMethod = method.getJavaMember();
        if (javaMethod.isDefault() || method.isStatic()) {
            continue;
        }
        List<Annotation> methodBindings = getBindings(method.getAnnotations(), beanManager);

        if (!classBindings.isEmpty() || !methodBindings.isEmpty()) {
            Annotation[] interceptorBindings = merge(methodBindings, classBindings);

            List<Interceptor<?>> interceptors =
                new ArrayList<>(beanManager.resolveInterceptors(InterceptionType.AROUND_INVOKE, 
                                                                interceptorBindings));
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.finest("Resolved interceptors from beanManager, " + beanManager + ":" + interceptors);
            }

            if (!interceptors.isEmpty()) {
                List<InterceptorInvoker> chain = new ArrayList<>();
                for (Interceptor<?> interceptor : interceptors) {
                    chain.add(
                        new InterceptorInvoker(interceptor, 
                                               interceptorInstances.computeIfAbsent(interceptor, 
                                                   i -> beanManager.getReference(i, 
                                                                                 i.getBeanClass(), 
                                                                                 creationalContext))));
                }
                invokers.put(javaMethod, chain);
            }
        }
    }
    return invokers.isEmpty() ? Collections.emptyMap() : invokers;
}
 
Example 5
Source File: HandlerMethodImpl.java    From deltaspike with Apache License 2.0 4 votes vote down vote up
/**
 * Sole Constructor.
 *
 * @param method found handler
 * @param bm     active BeanManager
 * @throws IllegalArgumentException if method is null, has no params or first param is not annotated with
 *                                  {@link Handles} or {@link BeforeHandles}
 */
public HandlerMethodImpl(final Bean<?> handlerDeclaringBean, final AnnotatedMethod<?> method, final BeanManager bm)
{
    //validation is done by the extension

    final Set<Annotation> tmpQualifiers = new HashSet<Annotation>();

    declaringBean = handlerDeclaringBean;
    handler = method;
    javaMethod = method.getJavaMember();

    handlerParameter = findHandlerParameter(method);

    if (!handlerParameter.isAnnotationPresent(Handles.class)
            && !handlerParameter.isAnnotationPresent(BeforeHandles.class))
    {
        throw new IllegalArgumentException("Method is not annotated with @Handles or @BeforeHandles");
    }

    before = handlerParameter.getAnnotation(BeforeHandles.class) != null;

    if (before)
    {
        ordinal = handlerParameter.getAnnotation(BeforeHandles.class).ordinal();
    }
    else
    {
        ordinal = handlerParameter.getAnnotation(Handles.class).ordinal();
    }

    tmpQualifiers.addAll(BeanUtils.getQualifiers(bm, handlerParameter.getAnnotations()));

    if (tmpQualifiers.isEmpty())
    {
        tmpQualifiers.add(new AnyLiteral());
    }

    qualifiers = tmpQualifiers;
    declaringBeanClass = method.getJavaMember().getDeclaringClass();
    exceptionType = ((ParameterizedType) handlerParameter.getBaseType()).getActualTypeArguments()[0];
}