use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class AbstractConsumerEndpointParser method parseInternal.
@Override
protected final AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder handlerBuilder = this.parseHandler(element, parserContext);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(handlerBuilder, element, "output-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "order");
Element txElement = DomUtils.getChildElementByTagName(element, "transactional");
Element adviceChainElement = DomUtils.getChildElementByTagName(element, IntegrationNamespaceUtils.REQUEST_HANDLER_ADVICE_CHAIN);
@SuppressWarnings("rawtypes") ManagedList adviceChain = IntegrationNamespaceUtils.configureAdviceChain(adviceChainElement, txElement, true, handlerBuilder.getRawBeanDefinition(), parserContext);
if (!CollectionUtils.isEmpty(adviceChain)) {
handlerBuilder.addPropertyValue("adviceChain", adviceChain);
}
AbstractBeanDefinition handlerBeanDefinition = handlerBuilder.getBeanDefinition();
String inputChannelAttributeName = this.getInputChannelAttributeName();
boolean hasInputChannelAttribute = element.hasAttribute(inputChannelAttributeName);
if (parserContext.isNested()) {
String elementDescription = IntegrationNamespaceUtils.createElementDescription(element);
if (hasInputChannelAttribute) {
parserContext.getReaderContext().error("The '" + inputChannelAttributeName + "' attribute isn't allowed for a nested (e.g. inside a <chain/>) endpoint element: " + elementDescription + ".", element);
}
if (!replyChannelInChainAllowed(element)) {
if (StringUtils.hasText(element.getAttribute("reply-channel"))) {
parserContext.getReaderContext().error("The 'reply-channel' attribute isn't" + " allowed for a nested (e.g. inside a <chain/>) outbound gateway element: " + elementDescription + ".", element);
}
}
return handlerBeanDefinition;
} else {
if (!hasInputChannelAttribute) {
String elementDescription = IntegrationNamespaceUtils.createElementDescription(element);
parserContext.getReaderContext().error("The '" + inputChannelAttributeName + "' attribute is required for the top-level endpoint element: " + elementDescription + ".", element);
}
}
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class);
if (!CollectionUtils.isEmpty(adviceChain)) {
builder.addPropertyValue("adviceChain", adviceChain);
}
String handlerBeanName = BeanDefinitionReaderUtils.generateBeanName(handlerBeanDefinition, parserContext.getRegistry());
String[] handlerAlias = IntegrationNamespaceUtils.generateAlias(element);
parserContext.registerBeanComponent(new BeanComponentDefinition(handlerBeanDefinition, handlerBeanName, handlerAlias));
builder.addPropertyReference("handler", handlerBeanName);
String inputChannelName = element.getAttribute(inputChannelAttributeName);
if (!parserContext.getRegistry().containsBeanDefinition(inputChannelName)) {
if (parserContext.getRegistry().containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) {
BeanDefinition channelRegistry = parserContext.getRegistry().getBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME);
ConstructorArgumentValues caValues = channelRegistry.getConstructorArgumentValues();
ValueHolder vh = caValues.getArgumentValue(0, Collection.class);
if (vh == null) {
// although it should never happen if it does we can fix it
caValues.addIndexedArgumentValue(0, new ManagedSet<String>());
}
@SuppressWarnings("unchecked") Collection<String> channelCandidateNames = (Collection<String>) caValues.getArgumentValue(0, Collection.class).getValue();
channelCandidateNames.add(inputChannelName);
} else {
parserContext.getReaderContext().error("Failed to locate '" + IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME + "'", parserContext.getRegistry());
}
}
IntegrationNamespaceUtils.checkAndConfigureFixedSubscriberChannel(element, parserContext, inputChannelName, handlerBeanName);
builder.addPropertyValue("inputChannelName", inputChannelName);
List<Element> pollerElementList = DomUtils.getChildElementsByTagName(element, "poller");
if (!CollectionUtils.isEmpty(pollerElementList)) {
if (pollerElementList.size() != 1) {
parserContext.getReaderContext().error("at most one poller element may be configured for an endpoint", element);
}
IntegrationNamespaceUtils.configurePollerMetadata(pollerElementList.get(0), builder, parserContext);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.ROLE);
AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
String beanName = this.resolveId(element, beanDefinition, parserContext);
parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, beanName));
return null;
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class AbstractRouterParser method parseRouter.
protected final BeanDefinition parseRouter(Element element, ParserContext parserContext) {
BeanDefinition beanDefinition = this.doParseRouter(element, parserContext);
if (beanDefinition != null) {
// check if mapping is provided otherwise returned values will be treated as channel names
List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
if (!CollectionUtils.isEmpty(mappingElements)) {
ManagedMap<String, String> channelMappings = new ManagedMap<String, String>();
for (Element mappingElement : mappingElements) {
String key = mappingElement.getAttribute(this.getMappingKeyAttributeName());
channelMappings.put(key, mappingElement.getAttribute("channel"));
}
beanDefinition.getPropertyValues().add("channelMappings", channelMappings);
}
}
return beanDefinition;
}
use of org.springframework.beans.factory.config.BeanDefinition in project spring-integration by spring-projects.
the class AbstractRouterParser method parseHandler.
@Override
protected final BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(RouterFactoryBean.class);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
if (StringUtils.hasText(element.getAttribute("timeout")) && StringUtils.hasText(element.getAttribute("send-timeout"))) {
parserContext.getReaderContext().error("Only one of 'timeout' and 'send-timeout' is allowed", element);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout", "sendTimeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");
BeanDefinition targetRouterBeanDefinition = this.parseRouter(element, parserContext);
builder.addPropertyValue("targetObject", targetRouterBeanDefinition);
return builder;
}
use of org.springframework.beans.factory.config.BeanDefinition 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.config.BeanDefinition 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