use of org.springframework.beans.factory.config.BeanDefinitionHolder 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.BeanDefinitionHolder 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.BeanDefinitionHolder in project spring-integration by spring-projects.
the class ChannelInterceptorParser method parseInterceptors.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ManagedList parseInterceptors(Element element, ParserContext parserContext) {
ManagedList interceptors = new ManagedList();
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
String localName = child.getLocalName();
if ("bean".equals(localName)) {
BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(childElement);
holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder);
parserContext.registerBeanComponent(new BeanComponentDefinition(holder));
interceptors.add(new RuntimeBeanReference(holder.getBeanName()));
} else if ("ref".equals(localName)) {
String ref = childElement.getAttribute("bean");
interceptors.add(new RuntimeBeanReference(ref));
} else {
BeanDefinitionRegisteringParser parser = this.parsers.get(localName);
if (parser == null) {
parserContext.getReaderContext().error("unsupported interceptor element '" + localName + "'", childElement);
}
String interceptorBeanName = parser.parse(childElement, parserContext);
interceptors.add(new RuntimeBeanReference(interceptorBeanName));
}
}
}
return interceptors;
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-integration by spring-projects.
the class DefaultConfiguringBeanFactoryPostProcessor method registerNullChannel.
/**
* Register a null channel in the given BeanDefinitionRegistry. The bean name is defined by the constant
* {@link IntegrationContextUtils#NULL_CHANNEL_BEAN_NAME}.
*/
private void registerNullChannel(BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME)) {
BeanDefinition nullChannelDefinition = registry.getBeanDefinition(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
if (NullChannel.class.getName().equals(nullChannelDefinition.getBeanClassName())) {
return;
} else {
throw new IllegalStateException("The bean name '" + IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME + "' is reserved.");
}
} else {
RootBeanDefinition nullChannelDef = new RootBeanDefinition();
nullChannelDef.setBeanClassName(IntegrationConfigUtils.BASE_PACKAGE + ".channel.NullChannel");
BeanDefinitionHolder nullChannelHolder = new BeanDefinitionHolder(nullChannelDef, IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
BeanDefinitionReaderUtils.registerBeanDefinition(nullChannelHolder, registry);
}
}
use of org.springframework.beans.factory.config.BeanDefinitionHolder in project spring-integration by spring-projects.
the class IntegrationConfigUtils method autoCreateDirectChannel.
public static void autoCreateDirectChannel(String channelName, BeanDefinitionRegistry registry) {
BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelName);
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
}
Aggregations