SimpleAliasRegistry's "getAliases" method returns transitive aliases now; @Qualifier value matching takes chained aliases of target beans into account as well
This commit is contained in:
parent
35c36dda4b
commit
9871e94cad
|
@ -11,7 +11,9 @@
|
|||
<property name="name" value="LarryBean"/>
|
||||
</bean>
|
||||
|
||||
<alias name="larryBean" alias="stooge"/>
|
||||
<alias name="larryBean" alias="someAlias"/>
|
||||
|
||||
<alias name="someAlias" alias="stooge"/>
|
||||
|
||||
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
|
||||
<property name="name" value="Larry"/>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
|
@ -79,16 +79,27 @@ public class SimpleAliasRegistry implements AliasRegistry {
|
|||
}
|
||||
|
||||
public String[] getAliases(String name) {
|
||||
List<String> aliases = new ArrayList<String>();
|
||||
List<String> result = new ArrayList<String>();
|
||||
synchronized (this.aliasMap) {
|
||||
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
|
||||
String registeredName = entry.getValue();
|
||||
if (registeredName.equals(name)) {
|
||||
aliases.add(entry.getKey());
|
||||
}
|
||||
retrieveAliases(name, result);
|
||||
}
|
||||
return StringUtils.toStringArray(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transitively retrieve all aliases for the given name.
|
||||
* @param name the target name to find aliases for
|
||||
* @param result the resulting aliases list
|
||||
*/
|
||||
private void retrieveAliases(String name, List<String> result) {
|
||||
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) {
|
||||
String registeredName = entry.getValue();
|
||||
if (registeredName.equals(name)) {
|
||||
String alias = entry.getKey();
|
||||
result.add(alias);
|
||||
retrieveAliases(alias, result);
|
||||
}
|
||||
}
|
||||
return StringUtils.toStringArray(aliases);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue