11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2015 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
4949 */
5050public abstract class AbstractBeanDefinitionParser implements BeanDefinitionParser {
5151
52- /** Constant for the id attribute */
52+ /** Constant for the "id" attribute */
5353 public static final String ID_ATTRIBUTE = "id" ;
5454
55- /** Constant for the name attribute */
55+ /** Constant for the " name" attribute */
5656 public static final String NAME_ATTRIBUTE = "name" ;
5757
58+
5859 @ Override
5960 public final BeanDefinition parse (Element element , ParserContext parserContext ) {
6061 AbstractBeanDefinition definition = parseInternal (element , parserContext );
@@ -66,10 +67,12 @@ public final BeanDefinition parse(Element element, ParserContext parserContext)
6667 "Id is required for element '" + parserContext .getDelegate ().getLocalName (element )
6768 + "' when used as a top-level tag" , element );
6869 }
69- String [] aliases = new String [0 ];
70- String name = element .getAttribute (NAME_ATTRIBUTE );
71- if (StringUtils .hasLength (name )) {
72- aliases = StringUtils .trimArrayElements (StringUtils .commaDelimitedListToStringArray (name ));
70+ String [] aliases = null ;
71+ if (shouldParseNameAsAliases ()) {
72+ String name = element .getAttribute (NAME_ATTRIBUTE );
73+ if (StringUtils .hasLength (name )) {
74+ aliases = StringUtils .trimArrayElements (StringUtils .commaDelimitedListToStringArray (name ));
75+ }
7376 }
7477 BeanDefinitionHolder holder = new BeanDefinitionHolder (definition , id , aliases );
7578 registerBeanDefinition (holder , parserContext .getRegistry ());
@@ -170,7 +173,18 @@ protected boolean shouldGenerateIdAsFallback() {
170173 }
171174
172175 /**
173- * Controls whether this parser is supposed to fire a
176+ * Determine whether the element's "name" attribute should get parsed as
177+ * bean definition aliases, i.e. alternative bean definition names.
178+ * <p>The default implementation returns {@code true}.
179+ * @return whether the parser should evaluate the "name" attribute as aliases
180+ * @since 4.1.5
181+ */
182+ protected boolean shouldParseNameAsAliases () {
183+ return true ;
184+ }
185+
186+ /**
187+ * Determine whether this parser is supposed to fire a
174188 * {@link org.springframework.beans.factory.parsing.BeanComponentDefinition}
175189 * event after parsing the bean definition.
176190 * <p>This implementation returns {@code true} by default; that is,
0 commit comments