use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class WireTapParser method parse.
@Override
public String parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(WireTap.class);
String targetRef = element.getAttribute("channel");
if (!StringUtils.hasText(targetRef)) {
parserContext.getReaderContext().error("The 'channel' attribute is required.", element);
}
builder.addConstructorArgReference(targetRef);
String selectorRef = element.getAttribute("selector");
String selectorExpression = element.getAttribute("selector-expression");
if (StringUtils.hasText(selectorRef) && StringUtils.hasText(selectorExpression)) {
parserContext.getReaderContext().error("Only one of 'selector' or 'selector-expression' is allowed", source);
}
if (StringUtils.hasText(selectorRef)) {
builder.addConstructorArgReference(selectorRef);
} else if (StringUtils.hasText(selectorExpression)) {
BeanDefinitionBuilder expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class);
expressionBuilder.addConstructorArgValue(selectorExpression);
BeanDefinitionBuilder eemsBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionEvaluatingSelector.class);
eemsBuilder.addConstructorArgValue(expressionBuilder.getBeanDefinition());
builder.addConstructorArgValue(eemsBuilder.getBeanDefinition());
}
String timeout = element.getAttribute("timeout");
if (StringUtils.hasText(timeout)) {
builder.addPropertyValue("timeout", Long.parseLong(timeout));
}
String id = element.getAttribute("id");
if (StringUtils.hasText(id)) {
BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(builder.getBeanDefinition(), id), parserContext.getRegistry());
return id;
}
return BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry());
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class DatatypeChannelTests method conversionServiceReferenceOverridesDefault.
@Test
public void conversionServiceReferenceOverridesDefault() {
GenericApplicationContext context = new GenericApplicationContext();
Converter<Boolean, Integer> defaultConverter = new Converter<Boolean, Integer>() {
@Override
public Integer convert(Boolean source) {
return source ? 1 : 0;
}
};
GenericConversionService customConversionService = new DefaultConversionService();
customConversionService.addConverter(new Converter<Boolean, Integer>() {
@Override
public Integer convert(Boolean source) {
return source ? 99 : -99;
}
});
BeanDefinitionBuilder conversionServiceBuilder = BeanDefinitionBuilder.genericBeanDefinition(ConversionServiceFactoryBean.class);
conversionServiceBuilder.addPropertyValue("converters", Collections.singleton(defaultConverter));
context.registerBeanDefinition("conversionService", conversionServiceBuilder.getBeanDefinition());
BeanDefinitionBuilder messageConverterBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultDatatypeChannelMessageConverter.class);
messageConverterBuilder.addPropertyValue("conversionService", customConversionService);
context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_DATATYPE_CHANNEL_MESSAGE_CONVERTER_BEAN_NAME, messageConverterBuilder.getBeanDefinition());
BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
channelBuilder.addPropertyValue("datatypes", "java.lang.Integer, java.util.Date");
context.registerBeanDefinition("testChannel", channelBuilder.getBeanDefinition());
context.refresh();
QueueChannel channel = context.getBean("testChannel", QueueChannel.class);
assertTrue(channel.send(new GenericMessage<Boolean>(Boolean.TRUE)));
assertEquals(99, channel.receive().getPayload());
context.close();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class TcpInboundChannelAdapterParser method doParse.
@Override
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TcpReceivingChannelAdapter.class);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, IpAdapterParserUtils.TCP_CONNECTION_FACTORY);
builder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel", "errorChannel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.CLIENT_MODE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.RETRY_INTERVAL);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, IpAdapterParserUtils.SCHEDULER, "taskScheduler");
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class UdpOutboundChannelAdapterParser method parseUdp.
private BeanDefinitionBuilder parseUdp(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder;
String multicast = IpAdapterParserUtils.getMulticast(element);
if (multicast.equals("true")) {
builder = BeanDefinitionBuilder.genericBeanDefinition(MulticastSendingMessageHandler.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.MIN_ACKS_SUCCESS, "minAcksForSuccess");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.TIME_TO_LIVE, "timeToLive");
} else {
builder = BeanDefinitionBuilder.genericBeanDefinition(UnicastSendingMessageHandler.class);
}
IpAdapterParserUtils.addDestinationConfigToConstructor(element, builder, parserContext);
IpAdapterParserUtils.addConstructorValueIfAttributeDefined(builder, element, IpAdapterParserUtils.CHECK_LENGTH);
IpAdapterParserUtils.addConstructorValueIfAttributeDefined(builder, element, IpAdapterParserUtils.ACK);
IpAdapterParserUtils.addConstructorValueIfAttributeDefined(builder, element, IpAdapterParserUtils.ACK_HOST);
IpAdapterParserUtils.addConstructorValueIfAttributeDefined(builder, element, IpAdapterParserUtils.ACK_PORT);
IpAdapterParserUtils.addConstructorValueIfAttributeDefined(builder, element, IpAdapterParserUtils.ACK_TIMEOUT);
String ack = element.getAttribute(IpAdapterParserUtils.ACK);
if (ack.equals("true")) {
if (!StringUtils.hasText(element.getAttribute(IpAdapterParserUtils.ACK_HOST)) || !StringUtils.hasText(element.getAttribute(IpAdapterParserUtils.ACK_PORT)) || !StringUtils.hasText(element.getAttribute(IpAdapterParserUtils.ACK_TIMEOUT))) {
parserContext.getReaderContext().error("When " + IpAdapterParserUtils.ACK + " is true, " + IpAdapterParserUtils.ACK_HOST + ", " + IpAdapterParserUtils.ACK_PORT + ", and " + IpAdapterParserUtils.ACK_TIMEOUT + " must be supplied", element);
}
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.RECEIVE_BUFFER_SIZE);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, IpAdapterParserUtils.TASK_EXECUTOR);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "socket-expression", "socketExpressionString");
return builder;
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class JmsMessageDrivenEndpointParser method parseMessageListenerContainer.
private String parseMessageListenerContainer(Element element, ParserContext parserContext, BeanDefinition adapterBeanDefinition) {
String containerClass = element.getAttribute("container-class");
if (hasExternalContainer(element)) {
if (StringUtils.hasText(containerClass)) {
parserContext.getReaderContext().error("Cannot have both 'container' and 'container-class'", element);
}
for (String containerAttribute : containerAttributes) {
if (element.hasAttribute(containerAttribute)) {
parserContext.getReaderContext().error("The '" + containerAttribute + "' attribute should not be provided when specifying a 'container' reference.", element);
}
}
return element.getAttribute("container");
}
// otherwise, we build a DefaultMessageListenerContainer instance
BeanDefinitionBuilder builder;
if (StringUtils.hasText(containerClass)) {
builder = BeanDefinitionBuilder.genericBeanDefinition(containerClass);
} else {
builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMessageListenerContainer.class);
}
String destinationAttribute = this.expectReply ? "request-destination" : "destination";
String destinationNameAttribute = this.expectReply ? "request-destination-name" : "destination-name";
String pubSubDomainAttribute = this.expectReply ? "request-pub-sub-domain" : "pub-sub-domain";
String destination = element.getAttribute(destinationAttribute);
String destinationName = element.getAttribute(destinationNameAttribute);
boolean hasDestination = StringUtils.hasText(destination);
boolean hasDestinationName = StringUtils.hasText(destinationName);
if (hasDestination == hasDestinationName) {
parserContext.getReaderContext().error("Exactly one of '" + destinationAttribute + "' or '" + destinationNameAttribute + "' is required.", element);
}
builder.addPropertyReference(JmsParserUtils.CONNECTION_FACTORY_PROPERTY, JmsParserUtils.determineConnectionFactoryBeanName(element, parserContext));
if (hasDestination) {
builder.addPropertyReference("destination", destination);
} else {
builder.addPropertyValue("destinationName", destinationName);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, pubSubDomainAttribute, "pubSubDomain");
}
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "transaction-manager");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "selector", "messageSelector");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrent-consumers");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "max-concurrent-consumers");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "max-messages-per-task");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "recovery-interval");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "idle-consumer-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "idle-task-execution-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "cache-level");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "subscription-durable");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "subscription-shared");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "subscription-name");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "client-id");
String beanName = adapterBeanNameRoot(element, parserContext, adapterBeanDefinition) + ".container";
parserContext.getRegistry().registerBeanDefinition(beanName, builder.getBeanDefinition());
return beanName;
}
Aggregations