AbstractBeanDefinitionParser allows for skipping evaluation of XML "name" attribute
Issue: SPR-12643
This commit is contained in:
parent
d4dac250a8
commit
11bf3b3524
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -150,8 +150,8 @@ public class BeanDefinitionReaderUtils {
|
||||||
// Register aliases for bean name, if any.
|
// Register aliases for bean name, if any.
|
||||||
String[] aliases = definitionHolder.getAliases();
|
String[] aliases = definitionHolder.getAliases();
|
||||||
if (aliases != null) {
|
if (aliases != null) {
|
||||||
for (String aliase : aliases) {
|
for (String alias : aliases) {
|
||||||
registry.registerAlias(beanName, aliase);
|
registry.registerAlias(beanName, alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -49,12 +49,13 @@ import org.springframework.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBeanDefinitionParser implements BeanDefinitionParser {
|
public abstract class AbstractBeanDefinitionParser implements BeanDefinitionParser {
|
||||||
|
|
||||||
/** Constant for the id attribute */
|
/** Constant for the "id" attribute */
|
||||||
public static final String ID_ATTRIBUTE = "id";
|
public static final String ID_ATTRIBUTE = "id";
|
||||||
|
|
||||||
/** Constant for the name attribute */
|
/** Constant for the "name" attribute */
|
||||||
public static final String NAME_ATTRIBUTE = "name";
|
public static final String NAME_ATTRIBUTE = "name";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BeanDefinition parse(Element element, ParserContext parserContext) {
|
public final BeanDefinition parse(Element element, ParserContext parserContext) {
|
||||||
AbstractBeanDefinition definition = parseInternal(element, parserContext);
|
AbstractBeanDefinition definition = parseInternal(element, parserContext);
|
||||||
|
@ -66,11 +67,13 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
|
||||||
"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
|
"Id is required for element '" + parserContext.getDelegate().getLocalName(element)
|
||||||
+ "' when used as a top-level tag", element);
|
+ "' when used as a top-level tag", element);
|
||||||
}
|
}
|
||||||
String[] aliases = new String[0];
|
String[] aliases = null;
|
||||||
|
if (shouldParseNameAsAliases()) {
|
||||||
String name = element.getAttribute(NAME_ATTRIBUTE);
|
String name = element.getAttribute(NAME_ATTRIBUTE);
|
||||||
if (StringUtils.hasLength(name)) {
|
if (StringUtils.hasLength(name)) {
|
||||||
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
|
aliases = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
|
BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
|
||||||
registerBeanDefinition(holder, parserContext.getRegistry());
|
registerBeanDefinition(holder, parserContext.getRegistry());
|
||||||
if (shouldFireEvents()) {
|
if (shouldFireEvents()) {
|
||||||
|
@ -170,7 +173,18 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls whether this parser is supposed to fire a
|
* Determine whether the element's "name" attribute should get parsed as
|
||||||
|
* bean definition aliases, i.e. alternative bean definition names.
|
||||||
|
* <p>The default implementation returns {@code true}.
|
||||||
|
* @return whether the parser should evaluate the "name" attribute as aliases
|
||||||
|
* @since 4.1.5
|
||||||
|
*/
|
||||||
|
protected boolean shouldParseNameAsAliases() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether this parser is supposed to fire a
|
||||||
* {@link org.springframework.beans.factory.parsing.BeanComponentDefinition}
|
* {@link org.springframework.beans.factory.parsing.BeanComponentDefinition}
|
||||||
* event after parsing the bean definition.
|
* event after parsing the bean definition.
|
||||||
* <p>This implementation returns {@code true} by default; that is,
|
* <p>This implementation returns {@code true} by default; that is,
|
||||||
|
|
Loading…
Reference in New Issue