Search in sources :

Example 91 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-integration by spring-projects.

the class StoredProcOutboundGatewayParser method parseHandler.

@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
    final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(StoredProcOutboundGateway.class);
    final BeanDefinitionBuilder storedProcExecutorBuilder = StoredProcParserUtils.getStoredProcExecutorBuilder(element, parserContext);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "is-function");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "return-value-required");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "use-payload-as-parameter-source");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(storedProcExecutorBuilder, element, "sql-parameter-source-factory");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "skip-undeclared-results");
    final ManagedMap<String, BeanMetadataElement> returningResultSetMap = StoredProcParserUtils.getReturningResultsetBeanDefinitions(element, parserContext);
    if (!returningResultSetMap.isEmpty()) {
        storedProcExecutorBuilder.addPropertyValue("returningResultSetRowMappers", returningResultSetMap);
    }
    final AbstractBeanDefinition storedProcExecutorBuilderBeanDefinition = storedProcExecutorBuilder.getBeanDefinition();
    final String gatewayId = this.resolveId(element, builder.getRawBeanDefinition(), parserContext);
    final String storedProcExecutorBeanName = gatewayId + ".storedProcExecutor";
    parserContext.registerBeanComponent(new BeanComponentDefinition(storedProcExecutorBuilderBeanDefinition, storedProcExecutorBeanName));
    builder.addConstructorArgReference(storedProcExecutorBeanName);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expect-single-result");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout", "sendTimeout");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");
    String replyChannel = element.getAttribute("reply-channel");
    if (StringUtils.hasText(replyChannel)) {
        builder.addPropertyReference("outputChannel", replyChannel);
    }
    return builder;
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 92 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-integration by spring-projects.

the class StoredProcPollingChannelAdapterParser method parseSource.

@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(StoredProcPollingChannelAdapter.class);
    final BeanDefinitionBuilder storedProcExecutorBuilder = StoredProcParserUtils.getStoredProcExecutorBuilder(element, parserContext);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "return-value-required");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "is-function");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(storedProcExecutorBuilder, element, "skip-undeclared-results");
    final ManagedMap<String, BeanMetadataElement> returningResultsetMap = StoredProcParserUtils.getReturningResultsetBeanDefinitions(element, parserContext);
    if (!returningResultsetMap.isEmpty()) {
        storedProcExecutorBuilder.addPropertyValue("returningResultSetRowMappers", returningResultsetMap);
    }
    final AbstractBeanDefinition storedProcExecutorBuilderBeanDefinition = storedProcExecutorBuilder.getBeanDefinition();
    final String storedProcPollingChannelAdapterId = this.resolveId(element, builder.getRawBeanDefinition(), parserContext);
    final String storedProcExecutorBeanName = storedProcPollingChannelAdapterId + ".storedProcExecutor";
    parserContext.registerBeanComponent(new BeanComponentDefinition(storedProcExecutorBuilderBeanDefinition, storedProcExecutorBeanName));
    builder.addConstructorArgReference(storedProcExecutorBeanName);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expect-single-result");
    return builder.getBeanDefinition();
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 93 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-integration by spring-projects.

the class RetrievingJpaOutboundGatewayParser method parseHandler.

@Override
protected BeanDefinitionBuilder parseHandler(Element gatewayElement, ParserContext parserContext) {
    final BeanDefinitionBuilder jpaOutboundGatewayBuilder = super.parseHandler(gatewayElement, parserContext);
    final BeanDefinitionBuilder jpaExecutorBuilder = JpaParserUtils.getOutboundGatewayJpaExecutorBuilder(gatewayElement, parserContext);
    BeanDefinition firstResultExpression = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("first-result", "first-result-expression", parserContext, gatewayElement, false);
    if (firstResultExpression != null) {
        jpaExecutorBuilder.addPropertyValue("firstResultExpression", firstResultExpression);
    }
    BeanDefinition maxResultsExpression = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("max-results", "max-results-expression", parserContext, gatewayElement, false);
    if (maxResultsExpression != null) {
        jpaExecutorBuilder.addPropertyValue("maxResultsExpression", maxResultsExpression);
    }
    if (StringUtils.hasText(gatewayElement.getAttribute("id-expression"))) {
        String[] otherAttributes = { "jpa-query", "native-query", "named-query", "first-result", "first-result-expression", "max-results", "max-results-expression", "delete-in-batch", "expect-single-result", "parameter-source-factory", "use-payload-as-parameter-source" };
        StringBuilder others = new StringBuilder();
        for (String otherAttribute : otherAttributes) {
            if (gatewayElement.hasAttribute(otherAttribute) && StringUtils.hasText(gatewayElement.getAttribute(otherAttribute))) {
                if (others.length() > 0) {
                    others.append(", ");
                }
                others.append(otherAttribute);
            }
        }
        boolean childElementsExist = !CollectionUtils.isEmpty(DomUtils.getChildElementsByTagName(gatewayElement, "parameter"));
        if (others.length() > 0 || childElementsExist) {
            parserContext.getReaderContext().error((others.length() == 0 ? "" : "'" + others.toString() + "' " + (childElementsExist ? "and " : "")) + (childElementsExist ? "child elements " : "") + "not allowed with an 'id-expression' attribute.", gatewayElement);
        }
        BeanDefinition idExpressionDef = IntegrationNamespaceUtils.createExpressionDefIfAttributeDefined("id-expression", gatewayElement);
        jpaExecutorBuilder.addPropertyValue("idExpression", idExpressionDef);
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "delete-after-poll");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "flush-after-delete", "flush");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "delete-in-batch");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "expect-single-result");
    final BeanDefinition jpaExecutorBuilderBeanDefinition = jpaExecutorBuilder.getBeanDefinition();
    final String gatewayId = resolveId(gatewayElement, jpaOutboundGatewayBuilder.getRawBeanDefinition(), parserContext);
    final String jpaExecutorBeanName = gatewayId + ".jpaExecutor";
    parserContext.registerBeanComponent(new BeanComponentDefinition(jpaExecutorBuilderBeanDefinition, jpaExecutorBeanName));
    return jpaOutboundGatewayBuilder.addPropertyReference("jpaExecutor", jpaExecutorBeanName).addPropertyValue("gatewayType", OutboundGatewayType.RETRIEVING);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 94 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-integration by spring-projects.

the class UpdatingJpaOutboundGatewayParser method parseHandler.

@Override
protected BeanDefinitionBuilder parseHandler(Element gatewayElement, ParserContext parserContext) {
    BeanDefinitionBuilder jpaOutboundGatewayBuilder = super.parseHandler(gatewayElement, parserContext);
    BeanDefinitionBuilder jpaExecutorBuilder = JpaParserUtils.getOutboundGatewayJpaExecutorBuilder(gatewayElement, parserContext);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "persist-mode");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "flush");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "flush-size");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(jpaExecutorBuilder, gatewayElement, "clear-on-flush");
    final BeanDefinition jpaExecutorBuilderBeanDefinition = jpaExecutorBuilder.getBeanDefinition();
    final String gatewayId = resolveId(gatewayElement, jpaOutboundGatewayBuilder.getRawBeanDefinition(), parserContext);
    final String jpaExecutorBeanName = gatewayId + ".jpaExecutor";
    parserContext.registerBeanComponent(new BeanComponentDefinition(jpaExecutorBuilderBeanDefinition, jpaExecutorBeanName));
    return jpaOutboundGatewayBuilder.addPropertyReference("jpaExecutor", jpaExecutorBeanName).addPropertyValue("gatewayType", OutboundGatewayType.UPDATING);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 95 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project geronimo-xbean by apache.

the class XBeanNamespaceHandler method parse.

public BeanDefinition parse(Element element, ParserContext parserContext) {
    this.parserContext = parserContext;
    this.qnameHelper = new XBeanQNameHelper(parserContext.getReaderContext());
    BeanDefinitionHolder holder = parseBeanFromExtensionElement(element);
    // a 2nd level could be a nested <beans> from Spring 3.1 onwards
    if (element.getParentNode() == element.getOwnerDocument() || element.getParentNode().getParentNode() == element.getOwnerDocument() || element.getParentNode().getParentNode().getParentNode() == element.getOwnerDocument()) {
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
        parserContext.getReaderContext().fireComponentRegistered(componentDefinition);
    }
    return holder.getBeanDefinition();
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)133 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)75 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)52 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)47 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)47 Element (org.w3c.dom.Element)29 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)22 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)22 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)20 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 ManagedList (org.springframework.beans.factory.support.ManagedList)14 Nullable (org.springframework.lang.Nullable)10 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)9 Test (org.junit.jupiter.api.Test)6 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)5 NodeList (org.w3c.dom.NodeList)5 Test (org.junit.Test)4 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)3 PropertyValue (org.springframework.beans.PropertyValue)3