INT-3790: Fix Parser for ROLE attribute usage

JIRA: https://jira.spring.io/browse/INT-3790
This commit is contained in:
Artem Bilan
2015-08-08 00:05:09 -04:00
committed by Gary Russell
parent f73898ba8b
commit 56bfe6b0ac
4 changed files with 32 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,60 +18,32 @@ package org.springframework.integration.websocket.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter;
import org.springframework.util.StringUtils;
/**
* The {@link AbstractSingleBeanDefinitionParser} implementation for
* the {@code <websocket:inbound-channel-adapter/>} element.
* The {@link AbstractChannelAdapterParser} implementation for
* the {@code <int-websocket:inbound-channel-adapter/>} element.
*
* @author Artem Bilan
* @since 4.1
*/
public class WebSocketInboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
public class WebSocketInboundChannelAdapterParser extends AbstractChannelAdapterParser {
@Override
protected Class<?> getBeanClass(Element element) {
return WebSocketInboundChannelAdapter.class;
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = super.resolveId(element, definition, parserContext);
if (!element.hasAttribute("channel")) {
// the created channel will get the 'id', so the adapter's bean name includes a suffix
id = id + ".adapter";
}
if (!StringUtils.hasText(id)) {
id = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry());
}
return id;
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(WebSocketInboundChannelAdapter.class);
WebSocketAdapterParsingUtils.configureWebSocketAdapter(builder, parserContext, element);
String channelName = element.getAttribute("channel");
if (!StringUtils.hasText(channelName)) {
channelName = IntegrationNamespaceUtils.createDirectChannel(element, parserContext);
}
builder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "payload-type");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "use-broker");
return builder.getBeanDefinition();
}
}