use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class DefaultInboundChannelAdapterParser method parseExpression.
private BeanMetadataElement parseExpression(String expressionString, Element expressionElement, Element element, ParserContext parserContext) {
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionEvaluatingMessageSource.class);
BeanDefinition expressionDef = null;
if (StringUtils.hasText(expressionString)) {
expressionDef = new RootBeanDefinition(ExpressionFactoryBean.class);
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(expressionString);
} else {
BeanDefinitionBuilder dynamicExpressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicExpression.class);
String key = expressionElement.getAttribute("key");
String expressionSourceReference = expressionElement.getAttribute("source");
dynamicExpressionBuilder.addConstructorArgValue(key);
dynamicExpressionBuilder.addConstructorArgReference(expressionSourceReference);
expressionDef = dynamicExpressionBuilder.getBeanDefinition();
}
sourceBuilder.addConstructorArgValue(expressionDef);
sourceBuilder.addConstructorArgValue(null);
this.parseHeaderExpressions(sourceBuilder, element, parserContext);
return sourceBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class GatewayParser method parse.
@Override
@SuppressWarnings("rawtypes")
public BeanDefinition parse(final Element element, ParserContext parserContext) {
boolean isNested = parserContext.isNested();
final Map<String, Object> gatewayAttributes = new HashMap<String, Object>();
gatewayAttributes.put("name", element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE));
gatewayAttributes.put("defaultPayloadExpression", element.getAttribute("default-payload-expression"));
gatewayAttributes.put("defaultRequestChannel", element.getAttribute(isNested ? "request-channel" : "default-request-channel"));
gatewayAttributes.put("defaultReplyChannel", element.getAttribute(isNested ? "reply-channel" : "default-reply-channel"));
gatewayAttributes.put("errorChannel", element.getAttribute("error-channel"));
String asyncExecutor = element.getAttribute("async-executor");
if (!element.hasAttribute("async-executor") || StringUtils.hasLength(asyncExecutor)) {
gatewayAttributes.put("asyncExecutor", asyncExecutor);
} else {
gatewayAttributes.put("asyncExecutor", null);
}
gatewayAttributes.put("mapper", element.getAttribute("mapper"));
gatewayAttributes.put("defaultReplyTimeout", element.getAttribute(isNested ? "reply-timeout" : "default-reply-timeout"));
gatewayAttributes.put("defaultRequestTimeout", element.getAttribute(isNested ? "request-timeout" : "default-request-timeout"));
List<Element> headerElements = DomUtils.getChildElementsByTagName(element, "default-header");
if (!CollectionUtils.isEmpty(headerElements)) {
List<Map<String, Object>> headers = new ArrayList<Map<String, Object>>(headerElements.size());
for (Element e : headerElements) {
Map<String, Object> header = new HashMap<String, Object>();
header.put("name", e.getAttribute("name"));
header.put("value", e.getAttribute("value"));
header.put("expression", e.getAttribute("expression"));
headers.add(header);
}
gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[headers.size()]));
}
List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
if (!CollectionUtils.isEmpty(methodElements)) {
Map<String, BeanDefinition> methodMetadataMap = new ManagedMap<String, BeanDefinition>();
for (Element methodElement : methodElements) {
String methodName = methodElement.getAttribute("name");
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class);
methodMetadataBuilder.addPropertyValue("requestChannelName", methodElement.getAttribute("request-channel"));
methodMetadataBuilder.addPropertyValue("replyChannelName", methodElement.getAttribute("reply-channel"));
methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout"));
methodMetadataBuilder.addPropertyValue("replyTimeout", methodElement.getAttribute("reply-timeout"));
boolean hasMapper = StringUtils.hasText(element.getAttribute("mapper"));
Assert.state(!hasMapper || !StringUtils.hasText(element.getAttribute("payload-expression")), "'payload-expression' is not allowed when a 'mapper' is provided");
IntegrationNamespaceUtils.setValueIfAttributeDefined(methodMetadataBuilder, methodElement, "payload-expression");
List<Element> invocationHeaders = DomUtils.getChildElementsByTagName(methodElement, "header");
if (!CollectionUtils.isEmpty(invocationHeaders)) {
Assert.state(!hasMapper, "header elements are not allowed when a 'mapper' is provided");
Map<String, Object> headerExpressions = new ManagedMap<String, Object>();
for (Element headerElement : invocationHeaders) {
BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true);
headerExpressions.put(headerElement.getAttribute("name"), expressionDef);
}
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
}
methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
}
gatewayAttributes.put("methods", methodMetadataMap);
}
gatewayAttributes.put("serviceInterface", element.getAttribute("service-interface"));
BeanDefinitionHolder gatewayHolder = this.registrar.parse(gatewayAttributes);
if (isNested) {
return gatewayHolder.getBeanDefinition();
} else {
BeanDefinitionReaderUtils.registerBeanDefinition(gatewayHolder, parserContext.getRegistry());
return null;
}
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class ChainParser method resolveId.
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) throws BeanDefinitionStoreException {
String id = super.resolveId(element, definition, parserContext);
BeanDefinition containingBeanDefinition = parserContext.getContainingBeanDefinition();
if (containingBeanDefinition != null) {
String nestedChainIdPrefix = (String) containingBeanDefinition.getAttribute(SI_CHAIN_NESTED_ID_ATTRIBUTE);
if (StringUtils.hasText(nestedChainIdPrefix)) {
id = nestedChainIdPrefix + "$child." + id;
}
}
definition.setAttribute(SI_CHAIN_NESTED_ID_ATTRIBUTE, id);
return id;
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class ChainParser method parseChild.
private BeanMetadataElement parseChild(String chainHandlerId, Element element, int order, ParserContext parserContext, BeanDefinition parentDefinition) {
BeanDefinitionHolder holder = null;
String id = element.getAttribute(ID_ATTRIBUTE);
boolean hasId = StringUtils.hasText(id);
String handlerComponentName = chainHandlerId + "$child" + (hasId ? "." + id : "#" + order);
if ("bean".equals(element.getLocalName())) {
holder = parserContext.getDelegate().parseBeanDefinitionElement(element, parentDefinition);
} else {
this.validateChild(element, parserContext);
BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(element, parentDefinition);
if (beanDefinition == null) {
parserContext.getReaderContext().error("child BeanDefinition must not be null", element);
return null;
} else {
holder = new BeanDefinitionHolder(beanDefinition, handlerComponentName + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX);
}
}
holder.getBeanDefinition().getPropertyValues().add("componentName", handlerComponentName);
if (hasId) {
BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
return new RuntimeBeanReference(holder.getBeanName());
}
return holder;
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class DefaultConfiguringBeanFactoryPostProcessor method registerErrorChannel.
/**
* Register an error channel in the given BeanDefinitionRegistry.
*/
private void registerErrorChannel(BeanDefinitionRegistry registry) {
if (this.logger.isInfoEnabled()) {
this.logger.info("No bean named '" + IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME + "' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.");
}
registry.registerBeanDefinition(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, new RootBeanDefinition(PublishSubscribeChannel.class));
BeanDefinition loggingHandler = BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class).addConstructorArgValue("ERROR").getBeanDefinition();
String errorLoggerBeanName = ERROR_LOGGER_BEAN_NAME + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
registry.registerBeanDefinition(errorLoggerBeanName, loggingHandler);
BeanDefinitionBuilder loggingEndpointBuilder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class).addPropertyReference("handler", errorLoggerBeanName).addPropertyValue("inputChannelName", IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
BeanComponentDefinition componentDefinition = new BeanComponentDefinition(loggingEndpointBuilder.getBeanDefinition(), ERROR_LOGGER_BEAN_NAME);
BeanDefinitionReaderUtils.registerBeanDefinition(componentDefinition, registry);
}
Aggregations