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));