use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class GlobalChannelInterceptorParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder globalChannelInterceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class);
Object childBeanDefinition = getBeanDefinitionBuilderConstructorValue(element, parserContext);
globalChannelInterceptorBuilder.addConstructorArgValue(childBeanDefinition);
IntegrationNamespaceUtils.setValueIfAttributeDefined(globalChannelInterceptorBuilder, element, "order");
IntegrationNamespaceUtils.setValueIfAttributeDefined(globalChannelInterceptorBuilder, element, CHANNEL_NAME_PATTERN_ATTRIBUTE, "patterns");
return globalChannelInterceptorBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class HeaderEnricherParserSupport method addHeader.
private void addHeader(Element element, ManagedMap<String, Object> headers, ParserContext parserContext, String headerName, Element headerElement, Class<?> headerType, String expression, String overwrite) {
String value = headerElement.getAttribute("value");
String ref = headerElement.getAttribute(REF_ATTRIBUTE);
String method = headerElement.getAttribute(METHOD_ATTRIBUTE);
if (expression == null) {
expression = headerElement.getAttribute(EXPRESSION_ATTRIBUTE);
}
Element beanElement = null;
Element scriptElement = null;
Element expressionElement = null;
List<Element> subElements = DomUtils.getChildElements(headerElement);
if (!subElements.isEmpty()) {
Element subElement = subElements.get(0);
String subElementLocalName = subElement.getLocalName();
if ("bean".equals(subElementLocalName)) {
beanElement = subElement;
} else if ("script".equals(subElementLocalName)) {
scriptElement = subElement;
} else if ("expression".equals(subElementLocalName)) {
expressionElement = subElement;
}
if (beanElement == null && scriptElement == null && expressionElement == null) {
parserContext.getReaderContext().error("Only 'bean', 'script' or 'expression' can be defined as a sub-element", element);
}
}
if (StringUtils.hasText(expression) && expressionElement != null) {
parserContext.getReaderContext().error("The 'expression' attribute and sub-element are mutually exclusive", element);
}
boolean isValue = StringUtils.hasText(value);
boolean isRef = StringUtils.hasText(ref);
boolean hasMethod = StringUtils.hasText(method);
boolean isExpression = StringUtils.hasText(expression) || expressionElement != null;
boolean isScript = scriptElement != null;
BeanDefinition innerComponentDefinition = null;
if (beanElement != null) {
innerComponentDefinition = parserContext.getDelegate().parseBeanDefinitionElement(beanElement).getBeanDefinition();
} else if (isScript) {
innerComponentDefinition = parserContext.getDelegate().parseCustomElement(scriptElement);
}
boolean isCustomBean = innerComponentDefinition != null;
if (hasMethod && isScript) {
parserContext.getReaderContext().error("The 'method' attribute cannot be used when a 'script' sub-element is defined", element);
}
if (isValue == (isRef ^ (isExpression ^ isCustomBean))) {
parserContext.getReaderContext().error("Exactly one of the 'ref', 'value', 'expression' or inner bean is required.", element);
}
BeanDefinitionBuilder valueProcessorBuilder = null;
if (isValue) {
if (hasMethod) {
parserContext.getReaderContext().error("The 'method' attribute cannot be used with the 'value' attribute.", element);
}
if (IntegrationMessageHeaderAccessor.ROUTING_SLIP.equals(headerName)) {
List<String> routingSlipPath = new ManagedList<String>();
routingSlipPath.addAll(Arrays.asList(StringUtils.tokenizeToStringArray(value, ";")));
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(RoutingSlipHeaderValueMessageProcessor.class).addConstructorArgValue(routingSlipPath);
} else {
Object headerValue = (headerType != null) ? new TypedStringValue(value, headerType) : value;
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(StaticHeaderValueMessageProcessor.class).addConstructorArgValue(headerValue);
}
} else if (isExpression) {
if (hasMethod) {
parserContext.getReaderContext().error("The 'method' attribute cannot be used with the 'expression' attribute.", element);
}
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionEvaluatingHeaderValueMessageProcessor.class);
if (expressionElement != null) {
BeanDefinitionBuilder dynamicExpressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicExpression.class);
dynamicExpressionBuilder.addConstructorArgValue(expressionElement.getAttribute("key"));
dynamicExpressionBuilder.addConstructorArgReference(expressionElement.getAttribute("source"));
valueProcessorBuilder.addConstructorArgValue(dynamicExpressionBuilder.getBeanDefinition());
} else {
valueProcessorBuilder.addConstructorArgValue(expression);
}
valueProcessorBuilder.addConstructorArgValue(headerType);
} else if (isCustomBean) {
if (StringUtils.hasText(headerElement.getAttribute("type"))) {
parserContext.getReaderContext().error("The 'type' attribute cannot be used with an inner bean.", element);
}
if (hasMethod || isScript) {
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageProcessingHeaderValueMessageProcessor.class).addConstructorArgValue(innerComponentDefinition);
if (hasMethod) {
valueProcessorBuilder.addConstructorArgValue(method);
}
} else {
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(StaticHeaderValueMessageProcessor.class);
valueProcessorBuilder.addConstructorArgValue(innerComponentDefinition);
}
} else {
if (StringUtils.hasText(headerElement.getAttribute("type"))) {
parserContext.getReaderContext().error("The 'type' attribute cannot be used with the 'ref' attribute.", element);
}
if (hasMethod) {
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageProcessingHeaderValueMessageProcessor.class).addConstructorArgReference(ref).addConstructorArgValue(method);
} else {
valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(StaticHeaderValueMessageProcessor.class).addConstructorArgReference(ref);
}
}
if (StringUtils.hasText(overwrite)) {
valueProcessorBuilder.addPropertyValue("overwrite", overwrite);
}
headers.put(headerName, valueProcessorBuilder.getBeanDefinition());
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class IntegrationManagementParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationManagementConfigurer.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-logging-enabled");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-counts-enabled");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-stats-enabled");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "counts-enabled-patterns", "enabledCountsPatterns");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "stats-enabled-patterns", "enabledStatsPatterns");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "metrics-factory");
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class IntegrationNamespaceUtils method createAdapter.
private static BeanMetadataElement createAdapter(BeanMetadataElement ref, String method, String unqualifiedClassName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE + ".config." + unqualifiedClassName + "FactoryBean");
builder.addPropertyValue("target", ref);
if (StringUtils.hasText(method)) {
builder.addPropertyValue("methodName", method);
}
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class IntegrationNamespaceUtils method configureTransactionDefinition.
/**
* Parse attributes of "transactional" element and configure a {@link DefaultTransactionAttribute}
* with provided "transactionDefinition" properties.
*
* @param txElement The transactional element.
* @return The bean definition.
*/
public static BeanDefinition configureTransactionDefinition(Element txElement) {
BeanDefinitionBuilder txDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultTransactionAttribute.class);
txDefinitionBuilder.addPropertyValue("propagationBehaviorName", "PROPAGATION_" + txElement.getAttribute("propagation"));
txDefinitionBuilder.addPropertyValue("isolationLevelName", "ISOLATION_" + txElement.getAttribute("isolation"));
txDefinitionBuilder.addPropertyValue("timeout", txElement.getAttribute("timeout"));
txDefinitionBuilder.addPropertyValue("readOnly", txElement.getAttribute("read-only"));
return txDefinitionBuilder.getBeanDefinition();
}
Aggregations