Search in sources :

Example 1 with Role

use of org.springframework.integration.annotation.Role in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessor method processAnnotationTypeOnMethod.

protected void processAnnotationTypeOnMethod(Object bean, String beanName, Method method, Class<? extends Annotation> annotationType, List<Annotation> annotations) {
    MethodAnnotationPostProcessor<?> postProcessor = MessagingAnnotationPostProcessor.this.postProcessors.get(annotationType);
    if (postProcessor != null && postProcessor.shouldCreateEndpoint(method, annotations)) {
        Method targetMethod = method;
        if (AopUtils.isJdkDynamicProxy(bean)) {
            try {
                targetMethod = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException("Service methods must be extracted to the service " + "interface for JdkDynamicProxy. The affected bean is: '" + beanName + "' " + "and its method: '" + method + "'", e);
            }
        }
        Object result = postProcessor.postProcess(bean, beanName, targetMethod, annotations);
        if (result != null && result instanceof AbstractEndpoint) {
            AbstractEndpoint endpoint = (AbstractEndpoint) result;
            String autoStartup = MessagingAnnotationUtils.resolveAttribute(annotations, "autoStartup", String.class);
            if (StringUtils.hasText(autoStartup)) {
                autoStartup = getBeanFactory().resolveEmbeddedValue(autoStartup);
                if (StringUtils.hasText(autoStartup)) {
                    endpoint.setAutoStartup(Boolean.parseBoolean(autoStartup));
                }
            }
            String phase = MessagingAnnotationUtils.resolveAttribute(annotations, "phase", String.class);
            if (StringUtils.hasText(phase)) {
                phase = getBeanFactory().resolveEmbeddedValue(phase);
                if (StringUtils.hasText(phase)) {
                    endpoint.setPhase(Integer.parseInt(phase));
                }
            }
            Role role = AnnotationUtils.findAnnotation(method, Role.class);
            if (role != null) {
                endpoint.setRole(role.value());
            }
            String endpointBeanName = generateBeanName(beanName, method, annotationType);
            endpoint.setBeanName(endpointBeanName);
            getBeanFactory().registerSingleton(endpointBeanName, endpoint);
            getBeanFactory().initializeBean(endpoint, endpointBeanName);
        }
    }
}
Also used : Role(org.springframework.integration.annotation.Role) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Method(java.lang.reflect.Method)

Aggregations

Method (java.lang.reflect.Method)1 Role (org.springframework.integration.annotation.Role)1 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)1