Search in sources :

Example 61 with BeanDefinitionHolder

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

the class AmqpInboundChannelAdapterParser method createDirectChannel.

private String createDirectChannel(Element element, ParserContext parserContext) {
    String channelId = element.getAttribute("id");
    if (!StringUtils.hasText(channelId)) {
        parserContext.getReaderContext().error("The channel-adapter's 'id' attribute is required when no 'channel' " + "reference has been provided, because that 'id' would be used for the created channel.", element);
    }
    BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.integration.channel.DirectChannel");
    BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelId);
    BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
    return channelId;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Example 62 with BeanDefinitionHolder

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

the class MessagingGatewayRegistrar method parse.

public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) {
    String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression");
    @SuppressWarnings("unchecked") Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders");
    String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel");
    String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel");
    String errorChannel = (String) gatewayAttributes.get("errorChannel");
    String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor");
    String mapper = (String) gatewayAttributes.get("mapper");
    boolean hasMapper = StringUtils.hasText(mapper);
    boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression);
    Assert.state(!hasMapper || !hasDefaultPayloadExpression, "'defaultPayloadExpression' is not allowed when a 'mapper' is provided");
    boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders);
    Assert.state(!hasMapper || !hasDefaultHeaders, "'defaultHeaders' are not allowed when a 'mapper' is provided");
    BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayProxyFactoryBean.class);
    if (hasDefaultHeaders || hasDefaultPayloadExpression) {
        BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class);
        if (hasDefaultPayloadExpression) {
            methodMetadataBuilder.addPropertyValue("payloadExpression", defaultPayloadExpression);
        }
        Map<String, Object> headerExpressions = new ManagedMap<String, Object>();
        for (Map<String, Object> header : defaultHeaders) {
            String headerValue = (String) header.get("value");
            String headerExpression = (String) header.get("expression");
            boolean hasValue = StringUtils.hasText(headerValue);
            if (hasValue == StringUtils.hasText(headerExpression)) {
                throw new BeanDefinitionStoreException("exactly one of 'value' or 'expression' " + "is required on a gateway's header.");
            }
            BeanDefinition expressionDef = new RootBeanDefinition(hasValue ? LiteralExpression.class : ExpressionFactoryBean.class);
            expressionDef.getConstructorArgumentValues().addGenericArgumentValue(hasValue ? headerValue : headerExpression);
            headerExpressions.put((String) header.get("name"), expressionDef);
        }
        methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
        gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition());
    }
    if (StringUtils.hasText(defaultRequestChannel)) {
        gatewayProxyBuilder.addPropertyValue("defaultRequestChannelName", defaultRequestChannel);
    }
    if (StringUtils.hasText(defaultReplyChannel)) {
        gatewayProxyBuilder.addPropertyValue("defaultReplyChannelName", defaultReplyChannel);
    }
    if (StringUtils.hasText(errorChannel)) {
        gatewayProxyBuilder.addPropertyValue("errorChannelName", errorChannel);
    }
    if (asyncExecutor == null || AnnotationConstants.NULL.equals(asyncExecutor)) {
        gatewayProxyBuilder.addPropertyValue("asyncExecutor", null);
    } else if (StringUtils.hasText(asyncExecutor)) {
        gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor);
    }
    if (StringUtils.hasText(mapper)) {
        gatewayProxyBuilder.addPropertyReference("mapper", mapper);
    }
    gatewayProxyBuilder.addPropertyValue("defaultRequestTimeoutExpressionString", gatewayAttributes.get("defaultRequestTimeout"));
    gatewayProxyBuilder.addPropertyValue("defaultReplyTimeoutExpressionString", gatewayAttributes.get("defaultReplyTimeout"));
    gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods"));
    String serviceInterface = (String) gatewayAttributes.get("serviceInterface");
    if (!StringUtils.hasText(serviceInterface)) {
        serviceInterface = "org.springframework.integration.gateway.RequestReplyExchanger";
    }
    String id = (String) gatewayAttributes.get("name");
    if (!StringUtils.hasText(id)) {
        id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1));
    }
    gatewayProxyBuilder.addConstructorArgValue(serviceInterface);
    AbstractBeanDefinition beanDefinition = gatewayProxyBuilder.getBeanDefinition();
    beanDefinition.addMetadataAttribute(new BeanMetadataAttribute(IntegrationConfigUtils.FACTORY_BEAN_OBJECT_TYPE, serviceInterface));
    return new BeanDefinitionHolder(beanDefinition, id);
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) LiteralExpression(org.springframework.expression.common.LiteralExpression) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeanMetadataAttribute(org.springframework.beans.BeanMetadataAttribute) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) MultiValueMap(org.springframework.util.MultiValueMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 63 with BeanDefinitionHolder

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

the class IntegrationRegistrar method registerHeaderChannelRegistry.

/**
 * Register a {@link DefaultHeaderChannelRegistry} in the given {@link BeanDefinitionRegistry}, if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 */
private void registerHeaderChannelRegistry(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        if (logger.isInfoEnabled()) {
            logger.info("No bean named '" + IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME + "' has been explicitly defined. " + "Therefore, a default DefaultHeaderChannelRegistry will be created.");
        }
        BeanDefinitionBuilder schedulerBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultHeaderChannelRegistry.class);
        BeanDefinitionHolder replyChannelRegistryComponent = new BeanDefinitionHolder(schedulerBuilder.getBeanDefinition(), IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(replyChannelRegistryComponent, registry);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 64 with BeanDefinitionHolder

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

the class IntegrationRegistrar method registerDefaultConfiguringBeanFactoryPostProcessor.

/**
 * Register {@code DefaultConfiguringBeanFactoryPostProcessor}, if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 */
private void registerDefaultConfiguringBeanFactoryPostProcessor(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationContextUtils.DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class);
        BeanDefinitionHolder postProcessorHolder = new BeanDefinitionHolder(postProcessorBuilder.getBeanDefinition(), IntegrationContextUtils.DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME);
        BeanDefinitionReaderUtils.registerBeanDefinition(postProcessorHolder, registry);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 65 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project camunda-bpm-platform by camunda.

the class ActivitiAnnotationDrivenBeanDefinitionParser method registerStateHandlerAnnotationBeanFactoryPostProcessor.

private void registerStateHandlerAnnotationBeanFactoryPostProcessor(Element element, ParserContext context) {
    Class clz = StateHandlerAnnotationBeanFactoryPostProcessor.class;
    BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(clz.getName());
    BeanDefinitionHolder postProcessorHolder = new BeanDefinitionHolder(postProcessorBuilder.getBeanDefinition(), ActivitiContextUtils.ANNOTATION_STATE_HANDLER_BEAN_FACTORY_POST_PROCESSOR_BEAN_NAME);
    configureProcessEngine(postProcessorBuilder.getBeanDefinition(), element);
    BeanDefinitionReaderUtils.registerBeanDefinition(postProcessorHolder, context.getRegistry());
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Aggregations

BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)94 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)30 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)18 Element (org.w3c.dom.Element)18 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)16 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)12 ManagedList (org.springframework.beans.factory.support.ManagedList)11 Node (org.w3c.dom.Node)11 ArrayList (java.util.ArrayList)8 ManagedMap (org.springframework.beans.factory.support.ManagedMap)6 LinkedHashSet (java.util.LinkedHashSet)5 Test (org.junit.jupiter.api.Test)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)5 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 NodeList (org.w3c.dom.NodeList)5 Method (java.lang.reflect.Method)4 HashSet (java.util.HashSet)4