INT-2607: refactor 'resolveId' with pC.isNested()

* add delegation to `BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry(), parserContext.isNested())`
in the `AbstractBeanDefinitionParser#resolveId()` implementations when it is necessary.
* remove redundant `shouldGenerateId()` & `shouldGenerateIdAsFallback()` when they don't make sense.
* additional simple polishing in the affected classes.
* remove TODO & forced 'id' attribute from JpaOutboundGatewayTests-context.xml to check that this solution works as was booked.

JIRA: https://jira.springsource.org/browse/INT-2607
This commit is contained in:
Artem Bilan
2012-06-21 16:42:06 +03:00
committed by Gary Russell
parent 284464383d
commit 25a2efe59c
8 changed files with 29 additions and 78 deletions

View File

@@ -52,7 +52,7 @@ public abstract class AbstractChannelAdapterParser extends AbstractBeanDefinitio
id = id + ".adapter";
}
else if (!StringUtils.hasText(id)) {
id = parserContext.getReaderContext().generateBeanName(definition);
id = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry(), parserContext.isNested());
}
return id;
}

View File

@@ -32,15 +32,18 @@ import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
* Base class parser for elements that create Message Endpoints.
*
*
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*/
public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinitionParser {
@@ -51,13 +54,16 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
protected static final String EXPRESSION_ATTRIBUTE = "expression";
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = element.getAttribute(ID_ATTRIBUTE);
if (!StringUtils.hasText(id)) {
id = element.getAttribute("name");
}
if (!StringUtils.hasText(id)) {
id = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry(), parserContext.isNested());
}
return id;
}
/**
@@ -130,4 +136,4 @@ public abstract class AbstractConsumerEndpointParser extends AbstractBeanDefinit
parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, beanName));
return null;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -25,8 +25,8 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
/**
* Base class for url-based outbound gateway parsers.
*
* Base class for url-based outbound gateway parsers.
*
* @author Mark Fisher
*/
public abstract class AbstractOutboundGatewayParser extends AbstractConsumerEndpointParser {
@@ -38,19 +38,6 @@ public abstract class AbstractOutboundGatewayParser extends AbstractConsumerEndp
return "request-channel";
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = super.resolveId(element, definition, parserContext);
if (!StringUtils.hasText(id)) {
id = element.getAttribute("name");
}
if (!StringUtils.hasText(id)) {
id = parserContext.getReaderContext().generateBeanName(definition);
}
return id;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(this.getGatewayClassName(element));

View File

@@ -30,14 +30,6 @@ import org.w3c.dom.Element;
*/
public class JdbcOutboundGatewayParser extends AbstractConsumerEndpointParser {
protected boolean shouldGenerateId() {
return false;
}
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
String dataSourceRef = element.getAttribute("data-source");

View File

@@ -32,14 +32,6 @@ import org.w3c.dom.Element;
*/
public class StoredProcOutboundGatewayParser extends AbstractConsumerEndpointParser {
protected boolean shouldGenerateId() {
return false;
}
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {

View File

@@ -208,9 +208,7 @@
</int:chain>
<int:chain input-channel="updatingGatewayInsideChain" output-channel="studentReplyChannel">
<!--TODO JPA outbound-gateway must have 'id' inside the chain because
'org.springframework.integration.jpa.outbound.JpaOutboundGatewayFactoryBean#0' isn't registered as bean-->
<jpa:updating-outbound-gateway id="gatewayInsideChain" entity-manager="entityManager"
<jpa:updating-outbound-gateway entity-manager="entityManager"
entity-class="org.springframework.integration.jpa.test.entity.StudentDomain"/>
</int:chain>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -35,17 +35,6 @@ public class XPathMessageSplitterParser extends AbstractConsumerEndpointParser {
private final XPathExpressionParser xpathParser = new XPathExpressionParser();
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(XPathMessageSplitter.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -16,11 +16,13 @@
package org.springframework.integration.xml.config;
import org.springframework.integration.xml.selector.XmlValidatingMessageSelector;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.FilterFactoryBean;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.util.StringUtils;
@@ -28,36 +30,22 @@ import org.springframework.util.StringUtils;
/**
* @author Jonas Partner
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointParser {
private static String SELECTOR_CLASSNAME = "org.springframework.integration.xml.selector.XmlValidatingMessageSelector";
private static String FILTER_CLASSNAME = "org.springframework.integration.config.FilterFactoryBean";
/** Constant that defines a W3C XML Schema. */
public static final String SCHEMA_W3C_XML = "http://www.w3.org/2001/XMLSchema";
/** Constant that defines a RELAX NG Schema. */
public static final String SCHEMA_RELAX_NG = "http://relaxng.org/ns/structure/1.0";
@Override
protected boolean shouldGenerateId() {
return false;
}
@Override
protected boolean shouldGenerateIdAsFallback() {
return true;
}
@Override
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FILTER_CLASSNAME);
BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.genericBeanDefinition(FilterFactoryBean.class);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(filterBuilder, element, "discard-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "throw-exception-on-rejection");
BeanDefinitionBuilder selectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(SELECTOR_CLASSNAME);
BeanDefinitionBuilder selectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(XmlValidatingMessageSelector.class);
String validator = element.getAttribute("xml-validator");
String schemaLocation = element.getAttribute("schema-location");
boolean validatorDefined = StringUtils.hasText(validator);
@@ -70,14 +58,13 @@ public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointPa
selectorBuilder.addConstructorArgValue(schemaLocation);
// it is a restriction with the default value of 'xml-schema' which
// corresponds to 'http://www.w3.org/2001/XMLSchema'
String schemaType = "xml-schema".equals(element.getAttribute("schema-type"))
? SCHEMA_W3C_XML : SCHEMA_RELAX_NG;
String schemaType = "xml-schema".equals(element.getAttribute("schema-type")) ? SCHEMA_W3C_XML : SCHEMA_RELAX_NG;
selectorBuilder.addConstructorArgValue(schemaType);
}
else {
selectorBuilder.addConstructorArgReference(validator);
}
selectorBuilder.addPropertyValue("throwExceptionOnRejection", element.getAttribute("throw-exception-on-rejection"));
IntegrationNamespaceUtils.setValueIfAttributeDefined(selectorBuilder, element, "throw-exception-on-rejection");
filterBuilder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
return filterBuilder;
}