public static void configureAndSetAdviceChainIfPresent(
     Element adviceChainElement,
     Element txElement,
     BeanDefinition parentBeanDefinition,
     ParserContext parserContext) {
   configureAndSetAdviceChainIfPresent(
       adviceChainElement, txElement, parentBeanDefinition, parserContext, "adviceChain");
 }
Пример #2
0
  @Override
  protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder metadataBuilder =
        BeanDefinitionBuilder.genericBeanDefinition(PollerMetadata.class);
    if (element.hasAttribute("ref")) {
      parserContext
          .getReaderContext()
          .error(
              "the 'ref' attribute must not be present on the top-level 'poller' element", element);
    }

    configureTrigger(element, metadataBuilder, parserContext);

    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        metadataBuilder, element, "max-messages-per-poll");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        metadataBuilder, element, "receive-timeout");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
        metadataBuilder, element, "task-executor");

    Element txElement = DomUtils.getChildElementByTagName(element, "transactional");
    Element adviceChainElement = DomUtils.getChildElementByTagName(element, "advice-chain");
    IntegrationNamespaceUtils.configureAndSetAdviceChainIfPresent(
        adviceChainElement, txElement, metadataBuilder.getRawBeanDefinition(), parserContext);

    if (txElement != null) {
      IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
          metadataBuilder,
          txElement,
          "synchronization-factory",
          "transactionSynchronizationFactory");
    } else if (adviceChainElement != null) {
      IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
          metadataBuilder,
          adviceChainElement,
          "synchronization-factory",
          "transactionSynchronizationFactory");
    }

    String errorChannel = element.getAttribute("error-channel");
    if (StringUtils.hasText(errorChannel)) {
      BeanDefinitionBuilder errorHandler =
          BeanDefinitionBuilder.genericBeanDefinition(MessagePublishingErrorHandler.class);
      errorHandler.addPropertyReference("defaultErrorChannel", errorChannel);
      metadataBuilder.addPropertyValue("errorHandler", errorHandler.getBeanDefinition());
    }
    return metadataBuilder.getBeanDefinition();
  }