Example usage for org.springframework.integration.context IntegrationContextUtils PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME

List of usage examples for org.springframework.integration.context IntegrationContextUtils PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME

Introduction

In this page you can find the example usage for org.springframework.integration.context IntegrationContextUtils PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME.

Prototype

String PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME

To view the source code for org.springframework.integration.context IntegrationContextUtils PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME.

Click Source Link

Usage

From source file:org.springframework.integration.config.PublisherRegistrar.java

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    Map<String, Object> annotationAttributes = importingClassMetadata
            .getAnnotationAttributes(EnablePublisher.class.getName());

    String value = (annotationAttributes == null
            ? (String) AnnotationUtils.getDefaultValue(EnablePublisher.class)
            : (String) annotationAttributes.get("value"));
    if (!registry.containsBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME)) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder
                .genericBeanDefinition(PublisherAnnotationBeanPostProcessor.class)
                .setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        if (StringUtils.hasText(value)) {
            builder.addPropertyValue("defaultChannelName", value);
            if (logger.isInfoEnabled()) {
                logger.info("Setting '@Publisher' default-output-channel to '" + value + "'.");
            }// w w  w .  j  ava  2  s.  com
        }

        registry.registerBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME,
                builder.getBeanDefinition());
    } else {
        BeanDefinition beanDefinition = registry
                .getBeanDefinition(IntegrationContextUtils.PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME);
        MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
        PropertyValue defaultChannelPropertyValue = propertyValues.getPropertyValue("defaultChannelName");
        if (StringUtils.hasText(value)) {
            if (defaultChannelPropertyValue == null) {
                propertyValues.addPropertyValue("defaultChannelName", value);
                if (logger.isInfoEnabled()) {
                    logger.info("Setting '@Publisher' default-output-channel to '" + value + "'.");
                }
            } else if (!value.equals(defaultChannelPropertyValue.getValue())) {
                throw new BeanDefinitionStoreException("When more than one enable publisher definition "
                        + "(@EnablePublisher or <annotation-config>)"
                        + " is found in the context, they all must have the same 'default-publisher-channel' value.");
            }
        }
    }
}