use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class RetryAdviceParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(RequestHandlerRetryAdvice.class);
BeanDefinitionBuilder retryTemplateBuilder = BeanDefinitionBuilder.genericBeanDefinition(RetryTemplate.class);
boolean customTemplate = false;
Element backOffPolicyEle = DomUtils.getChildElementByTagName(element, "fixed-back-off");
BeanDefinitionBuilder backOffBuilder = null;
if (backOffPolicyEle != null) {
backOffBuilder = BeanDefinitionBuilder.genericBeanDefinition(FixedBackOffPolicy.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(backOffBuilder, backOffPolicyEle, "interval", "backOffPeriod");
} else {
backOffPolicyEle = DomUtils.getChildElementByTagName(element, "exponential-back-off");
if (backOffPolicyEle != null) {
backOffBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExponentialBackOffPolicy.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(backOffBuilder, backOffPolicyEle, "initial", "initialInterval");
IntegrationNamespaceUtils.setValueIfAttributeDefined(backOffBuilder, backOffPolicyEle, "multiplier");
IntegrationNamespaceUtils.setValueIfAttributeDefined(backOffBuilder, backOffPolicyEle, "maximum", "maxInterval");
}
}
if (backOffBuilder != null) {
retryTemplateBuilder.addPropertyValue("backOffPolicy", backOffBuilder.getBeanDefinition());
customTemplate = true;
}
String maxAttemptsAttr = element.getAttribute("max-attempts");
if (StringUtils.hasText(maxAttemptsAttr)) {
BeanDefinitionBuilder retryPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(SimpleRetryPolicy.class);
IntegrationNamespaceUtils.setValueIfAttributeDefined(retryPolicyBuilder, element, "max-attempts");
retryTemplateBuilder.addPropertyValue("retryPolicy", retryPolicyBuilder.getBeanDefinition());
customTemplate = true;
}
if (customTemplate) {
builder.addPropertyValue("retryTemplate", retryTemplateBuilder.getBeanDefinition());
}
String recoveryChannelAttr = element.getAttribute("recovery-channel");
if (StringUtils.hasText(recoveryChannelAttr)) {
BeanDefinitionBuilder emsrBuilder = BeanDefinitionBuilder.genericBeanDefinition(ErrorMessageSendingRecoverer.class);
emsrBuilder.addConstructorArgReference(recoveryChannelAttr);
IntegrationNamespaceUtils.setValueIfAttributeDefined(emsrBuilder, element, "send-timeout");
builder.addPropertyValue("recoveryCallback", emsrBuilder.getBeanDefinition());
}
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class PointToPointChannelParser method buildBeanDefinition.
@Override
protected BeanDefinitionBuilder buildBeanDefinition(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = null;
Element queueElement = null;
String fixedSubscriberChannel = element.getAttribute("fixed-subscriber");
boolean isFixedSubscriber = "true".equals(fixedSubscriberChannel.trim().toLowerCase());
// configure a queue-based channel if any queue sub-element is defined
String channel = element.getAttribute(ID_ATTRIBUTE);
if ((queueElement = DomUtils.getChildElementByTagName(element, "queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(QueueChannel.class);
boolean hasStoreRef = this.parseStoreRef(builder, queueElement, channel, false);
boolean hasQueueRef = this.parseQueueRef(builder, queueElement);
if (!hasStoreRef || !hasQueueRef) {
boolean hasCapacity = this.parseQueueCapacity(builder, queueElement);
if (hasCapacity && hasQueueRef) {
parserContext.getReaderContext().error("The 'capacity' attribute is not allowed when providing a 'ref' to a custom queue.", element);
}
if (hasCapacity && hasStoreRef) {
parserContext.getReaderContext().error("The 'capacity' attribute is not allowed" + " when providing a 'message-store' to a custom MessageGroupStore.", element);
}
}
if (hasStoreRef && hasQueueRef) {
parserContext.getReaderContext().error("The 'message-store' attribute is not allowed when providing a 'ref' to a custom queue.", element);
}
} else if ((queueElement = DomUtils.getChildElementByTagName(element, "priority-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(PriorityChannel.class);
boolean hasCapacity = this.parseQueueCapacity(builder, queueElement);
String comparatorRef = queueElement.getAttribute("comparator");
if (StringUtils.hasText(comparatorRef)) {
builder.addConstructorArgReference(comparatorRef);
}
if (parseStoreRef(builder, queueElement, channel, true)) {
if (StringUtils.hasText(comparatorRef)) {
parserContext.getReaderContext().error("The 'message-store' attribute is not allowed" + " when providing a 'comparator' to a priority queue.", element);
}
if (hasCapacity) {
parserContext.getReaderContext().error("The 'capacity' attribute is not allowed" + " when providing a 'message-store' to a custom MessageGroupStore.", element);
}
}
} else if ((queueElement = DomUtils.getChildElementByTagName(element, "rendezvous-queue")) != null) {
builder = BeanDefinitionBuilder.genericBeanDefinition(RendezvousChannel.class);
}
Element dispatcherElement = DomUtils.getChildElementByTagName(element, "dispatcher");
// verify that a dispatcher is not provided if a queue sub-element exists
if (queueElement != null && dispatcherElement != null) {
parserContext.getReaderContext().error("The 'dispatcher' sub-element and any queue sub-element are mutually exclusive.", element);
return null;
}
if (queueElement != null) {
if (isFixedSubscriber) {
parserContext.getReaderContext().error("The 'fixed-subscriber' attribute is not allowed when a <queue/> child element is present.", element);
}
return builder;
}
if (dispatcherElement == null) {
// configure the default DirectChannel with a RoundRobinLoadBalancingStrategy
builder = BeanDefinitionBuilder.genericBeanDefinition(isFixedSubscriber ? FixedSubscriberChannel.class : DirectChannel.class);
} else {
if (isFixedSubscriber) {
parserContext.getReaderContext().error("The 'fixed-subscriber' attribute is not allowed" + " when a <dispatcher/> child element is present.", element);
}
// configure either an ExecutorChannel or DirectChannel based on existence of 'task-executor'
String taskExecutor = dispatcherElement.getAttribute("task-executor");
if (StringUtils.hasText(taskExecutor)) {
builder = BeanDefinitionBuilder.genericBeanDefinition(ExecutorChannel.class);
builder.addConstructorArgReference(taskExecutor);
} else {
builder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class);
}
// unless the 'load-balancer' attribute is explicitly set to 'none'
// or 'load-balancer-ref' is explicitly configured,
// configure the default RoundRobinLoadBalancingStrategy
String loadBalancer = dispatcherElement.getAttribute("load-balancer");
String loadBalancerRef = dispatcherElement.getAttribute("load-balancer-ref");
if (StringUtils.hasText(loadBalancer) && StringUtils.hasText(loadBalancerRef)) {
parserContext.getReaderContext().error("'load-balancer' and 'load-balancer-ref' are mutually exclusive", element);
}
if (StringUtils.hasText(loadBalancerRef)) {
builder.addConstructorArgReference(loadBalancerRef);
} else {
if ("none".equals(loadBalancer)) {
builder.addConstructorArgValue(null);
}
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, dispatcherElement, "failover");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, dispatcherElement, "max-subscribers");
}
return builder;
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class RecipientListRouterParser method doParseRouter.
@Override
protected BeanDefinition doParseRouter(Element element, ParserContext parserContext) {
BeanDefinitionBuilder recipientListRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(RecipientListRouter.class);
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "recipient");
ManagedList<BeanDefinition> recipientList = new ManagedList<BeanDefinition>();
for (Element childElement : childElements) {
BeanDefinitionBuilder recipientBuilder = BeanDefinitionBuilder.genericBeanDefinition(Recipient.class);
recipientBuilder.addConstructorArgReference(childElement.getAttribute("channel"));
String expression = childElement.getAttribute("selector-expression");
if (StringUtils.hasText(expression)) {
BeanDefinition selectorDef = new RootBeanDefinition(ExpressionEvaluatingSelector.class);
selectorDef.getConstructorArgumentValues().addGenericArgumentValue(expression);
String selectorBeanName = parserContext.getReaderContext().registerWithGeneratedName(selectorDef);
recipientBuilder.addConstructorArgReference(selectorBeanName);
}
recipientList.add(recipientBuilder.getBeanDefinition());
}
if (recipientList.size() > 0) {
recipientListRouterBuilder.addPropertyValue("recipients", recipientList);
}
return recipientListRouterBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class ResourceInboundChannelAdapterParser method parseSource.
@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition(ResourceRetrievingMessageSource.class);
sourceBuilder.addConstructorArgValue(element.getAttribute("pattern"));
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(sourceBuilder, element, "pattern-resolver");
boolean hasFilter = element.hasAttribute("filter");
if (hasFilter) {
String filterValue = element.getAttribute("filter");
if (StringUtils.hasText(filterValue)) {
sourceBuilder.addPropertyReference("filter", filterValue);
}
} else {
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(AcceptOnceCollectionFilter.class);
sourceBuilder.addPropertyValue("filter", filterBuilder.getBeanDefinition());
}
return sourceBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project spring-integration by spring-projects.
the class ScatterGatherParser method parseHandler.
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
String scatterChannel = element.getAttribute("scatter-channel");
boolean hasScatterChannel = StringUtils.hasText(scatterChannel);
Element scatterer = DomUtils.getChildElementByTagName(element, "scatterer");
boolean hasScatterer = scatterer != null;
if (hasScatterChannel & hasScatterer) {
parserContext.getReaderContext().error("'scatter-channel' attribute and 'scatterer' sub-element are mutually exclusive", element);
}
if (!hasScatterChannel & !hasScatterer) {
parserContext.getReaderContext().error("The 'scatter-channel' attribute or 'scatterer' sub-element must be specified", element);
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ScatterGatherHandler.class);
AbstractBeanDefinition scatterGatherDefinition = builder.getRawBeanDefinition();
String id = resolveId(element, scatterGatherDefinition, parserContext);
if (hasScatterChannel) {
builder.addConstructorArgReference(scatterChannel);
} else {
BeanDefinition scattererDefinition = null;
if (!hasScatterer) {
scattererDefinition = new RootBeanDefinition(RecipientListRouter.class);
} else {
scattererDefinition = SCATTERER_PARSER.parse(scatterer, new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), scatterGatherDefinition));
}
String scattererId = id + ".scatterer";
if (hasScatterer && scatterer.hasAttribute(ID_ATTRIBUTE)) {
scattererId = scatterer.getAttribute(ID_ATTRIBUTE);
}
parserContext.getRegistry().registerBeanDefinition(scattererId, scattererDefinition);
builder.addConstructorArgValue(new RuntimeBeanReference(scattererId));
}
Element gatherer = DomUtils.getChildElementByTagName(element, "gatherer");
BeanDefinition gathererDefinition = null;
if (gatherer == null) {
try {
gatherer = documentBuilderFactory.newDocumentBuilder().newDocument().createElement("aggregator");
} catch (ParserConfigurationException e) {
parserContext.getReaderContext().error(e.getMessage(), element);
}
}
gathererDefinition = GATHERER_PARSER.parse(gatherer, new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), scatterGatherDefinition));
String gathererId = id + ".gatherer";
if (gatherer != null && gatherer.hasAttribute(ID_ATTRIBUTE)) {
gathererId = gatherer.getAttribute(ID_ATTRIBUTE);
}
parserContext.getRegistry().registerBeanDefinition(gathererId, gathererDefinition);
builder.addConstructorArgValue(new RuntimeBeanReference(gathererId));
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "gather-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "gather-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");
return builder;
}
Aggregations