Search in sources :

Example 96 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class IntegrationFlowBeanPostProcessor method registerComponent.

@SuppressWarnings("unchecked")
private void registerComponent(Object component, String beanName, String parentName, BeanDefinitionCustomizer... customizers) {
    BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) component.getClass(), () -> component).applyCustomizers(customizers).getRawBeanDefinition();
    ((BeanDefinitionRegistry) this.beanFactory).registerBeanDefinition(beanName, beanDefinition);
    if (parentName != null) {
        this.beanFactory.registerDependentBean(parentName, beanName);
    }
    this.beanFactory.getBean(beanName);
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 97 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class JmsMessageDrivenEndpointParser method parseMessageListener.

private String parseMessageListener(Element element, ParserContext parserContext, BeanDefinition adapterBeanDefinition) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ChannelPublishingJmsMessageListener.class);
    builder.addPropertyValue("expectReply", this.expectReply);
    if (this.expectReply) {
        IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-request-payload");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-reply-payload");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "correlation-key");
        int defaults = 0;
        if (StringUtils.hasText(element.getAttribute(DEFAULT_REPLY_DESTINATION_ATTRIB))) {
            defaults++;
        }
        if (StringUtils.hasText(element.getAttribute(DEFAULT_REPLY_QUEUE_NAME_ATTRIB))) {
            defaults++;
        }
        if (StringUtils.hasText(element.getAttribute(DEFAULT_REPLY_TOPIC_NAME_ATTRIB))) {
            defaults++;
        }
        if (defaults > 1) {
            parserContext.getReaderContext().error("At most one of '" + DEFAULT_REPLY_DESTINATION_ATTRIB + "', '" + DEFAULT_REPLY_QUEUE_NAME_ATTRIB + "', or '" + DEFAULT_REPLY_TOPIC_NAME_ATTRIB + "' may be provided.", element);
        }
        IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, DEFAULT_REPLY_DESTINATION_ATTRIB);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, DEFAULT_REPLY_QUEUE_NAME_ATTRIB);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, DEFAULT_REPLY_TOPIC_NAME_ATTRIB);
        IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_TIME_TO_LIVE);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_PRIORITY);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, REPLY_DELIVERY_PERSISTENT);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, EXPLICIT_QOS_ENABLED_FOR_REPLIES);
        IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel");
    } else {
        String channelName = element.getAttribute("channel");
        if (!StringUtils.hasText(channelName)) {
            channelName = IntegrationNamespaceUtils.createDirectChannel(element, parserContext);
        }
        builder.addPropertyReference("requestChannel", channelName);
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout", "requestTimeout");
        IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload", "extractRequestPayload");
    }
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "header-mapper");
    String alias = adapterBeanNameRoot(element, parserContext, adapterBeanDefinition) + ".listener";
    BeanDefinition beanDefinition = builder.getBeanDefinition();
    String beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition, parserContext.getRegistry());
    BeanComponentDefinition component = new BeanComponentDefinition(beanDefinition, beanName, new String[] { alias });
    parserContext.registerBeanComponent(component);
    return beanName;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) JmsMessageDrivenEndpoint(org.springframework.integration.jms.JmsMessageDrivenEndpoint)

Example 98 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class AbstractRemoteFileStreamingInboundChannelAdapterParser method parseSource.

@Override
protected final BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
    BeanDefinition templateDefinition = FileParserUtils.parseRemoteFileTemplate(element, parserContext, false, getTemplateClass());
    BeanDefinitionBuilder messageSourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(getMessageSourceClass());
    messageSourceBuilder.addConstructorArgValue(templateDefinition);
    BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("remote-directory", "remote-directory-expression", parserContext, element, false);
    if (expressionDef != null) {
        messageSourceBuilder.addPropertyValue("remoteDirectoryExpression", expressionDef);
    }
    String remoteFileSeparator = element.getAttribute("remote-file-separator");
    messageSourceBuilder.addPropertyValue("remoteFileSeparator", remoteFileSeparator);
    FileParserUtils.configureFilter(messageSourceBuilder, element, parserContext, getSimplePatternFileListFilterClass(), getRegexPatternFileListFilterClass(), getPersistentAcceptOnceFileListFilterClass());
    String comparator = element.getAttribute("comparator");
    if (StringUtils.hasText(comparator)) {
        messageSourceBuilder.addConstructorArgReference(comparator);
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(messageSourceBuilder, element, "max-fetch-size");
    return messageSourceBuilder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 99 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class FileParserUtils method parseRemoteFileTemplate.

public static BeanDefinition parseRemoteFileTemplate(Element element, ParserContext parserContext, boolean atLeastOneRemoteDirectoryAttributeRequired, Class<? extends RemoteFileOperations<?>> templateClass) {
    BeanDefinitionBuilder templateBuilder = BeanDefinitionBuilder.genericBeanDefinition(templateClass);
    templateBuilder.addConstructorArgReference(element.getAttribute("session-factory"));
    // configure MessageHandler properties
    IntegrationNamespaceUtils.setValueIfAttributeDefined(templateBuilder, element, "temporary-file-suffix");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(templateBuilder, element, "use-temporary-file-name");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(templateBuilder, element, "auto-create-directory");
    BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("remote-directory", "remote-directory-expression", parserContext, element, atLeastOneRemoteDirectoryAttributeRequired);
    if (expressionDef != null) {
        templateBuilder.addPropertyValue("remoteDirectoryExpression", expressionDef);
    }
    expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("temporary-remote-directory", "temporary-remote-directory-expression", parserContext, element, false);
    if (expressionDef != null) {
        templateBuilder.addPropertyValue("temporaryRemoteDirectoryExpression", expressionDef);
    }
    // configure remote FileNameGenerator
    String remoteFileNameGenerator = element.getAttribute("remote-filename-generator");
    String remoteFileNameGeneratorExpression = element.getAttribute("remote-filename-generator-expression");
    boolean hasRemoteFileNameGenerator = StringUtils.hasText(remoteFileNameGenerator);
    boolean hasRemoteFileNameGeneratorExpression = StringUtils.hasText(remoteFileNameGeneratorExpression);
    if (hasRemoteFileNameGenerator || hasRemoteFileNameGeneratorExpression) {
        if (hasRemoteFileNameGenerator && hasRemoteFileNameGeneratorExpression) {
            parserContext.getReaderContext().error("at most one of 'remote-filename-generator-expression' or 'remote-filename-generator' " + "is allowed on a remote file outbound adapter", element);
        }
        if (hasRemoteFileNameGenerator) {
            templateBuilder.addPropertyReference("fileNameGenerator", remoteFileNameGenerator);
        } else {
            BeanDefinitionBuilder fileNameGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultFileNameGenerator.class);
            fileNameGeneratorBuilder.addPropertyValue("expression", remoteFileNameGeneratorExpression);
            templateBuilder.addPropertyValue("fileNameGenerator", fileNameGeneratorBuilder.getBeanDefinition());
        }
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(templateBuilder, element, "charset");
    templateBuilder.addPropertyValue("remoteFileSeparator", element.getAttribute("remote-file-separator"));
    return templateBuilder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 100 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.

the class FileParserUtils method configureFilter.

static void configureFilter(BeanDefinitionBuilder synchronizerBuilder, Element element, ParserContext parserContext, Class<? extends FileListFilter<?>> patternClass, Class<? extends FileListFilter<?>> regexClass, Class<? extends AbstractPersistentAcceptOnceFileListFilter<?>> persistentAcceptOnceFileListFilterClass) {
    String filter = element.getAttribute("filter");
    String filterExpression = element.getAttribute("filter-expression");
    String fileNamePattern = element.getAttribute("filename-pattern");
    String fileNameRegex = element.getAttribute("filename-regex");
    boolean hasFilter = StringUtils.hasText(filter);
    boolean hasFilterExpression = StringUtils.hasText(filterExpression);
    boolean hasFileNamePattern = StringUtils.hasText(fileNamePattern);
    boolean hasFileNameRegex = StringUtils.hasText(fileNameRegex);
    if (hasFilter || hasFilterExpression || hasFileNamePattern || hasFileNameRegex) {
        int count = 0;
        if (hasFilter) {
            count++;
        }
        if (hasFileNamePattern) {
            count++;
        }
        if (hasFileNameRegex) {
            count++;
        }
        if (hasFilterExpression) {
            count++;
        }
        if (count != 1) {
            parserContext.getReaderContext().error("at most one of 'filename-pattern', " + "'filename-regex', 'filter' or 'filter-expression' is allowed on remote file inbound adapter", element);
        }
        if (hasFilter) {
            synchronizerBuilder.addPropertyReference("filter", filter);
        } else if (hasFilterExpression) {
            BeanDefinition expressionFilterBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFileListFilter.class).addConstructorArgValue(filterExpression).getBeanDefinition();
            synchronizerBuilder.addPropertyValue("filter", expressionFilterBeanDefinition);
        } else if (hasFileNamePattern) {
            BeanDefinition patternFilter = BeanDefinitionBuilder.genericBeanDefinition(patternClass).addConstructorArgValue(fileNamePattern).getBeanDefinition();
            composeFilters(synchronizerBuilder, persistentAcceptOnceFileListFilterClass, patternFilter);
        } else {
            BeanDefinition regexFilter = BeanDefinitionBuilder.genericBeanDefinition(regexClass).addConstructorArgValue(fileNameRegex).getBeanDefinition();
            composeFilters(synchronizerBuilder, persistentAcceptOnceFileListFilterClass, regexFilter);
        }
    }
}
Also used : ExpressionFileListFilter(org.springframework.integration.file.filters.ExpressionFileListFilter) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)601 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)188 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)116 Test (org.junit.jupiter.api.Test)112 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)89 Element (org.w3c.dom.Element)72 Test (org.junit.Test)66 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)53 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)41 ManagedList (org.springframework.beans.factory.support.ManagedList)39 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)36 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)35 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)34 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)34 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)31 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)30 Method (java.lang.reflect.Method)28 ArrayList (java.util.ArrayList)28 Map (java.util.Map)27