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:
Juergen Hoeller 2009-02-17 18:18:33 +00:00
parent 35c36dda4b
commit 9871e94cad
2 changed files with 22 additions and 9 deletions

View File

@ -11,7 +11,9 @@
<property name="name" value="LarryBean"/> <property name="name" value="LarryBean"/>
</bean> </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"> <bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<property name="name" value="Larry"/> <property name="name" value="Larry"/>

View File

@ -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"); * 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.
@ -79,16 +79,27 @@ public class SimpleAliasRegistry implements AliasRegistry {
} }
public String[] getAliases(String name) { public String[] getAliases(String name) {
List<String> aliases = new ArrayList<String>(); List<String> result = new ArrayList<String>();
synchronized (this.aliasMap) { synchronized (this.aliasMap) {
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) { retrieveAliases(name, result);
String registeredName = entry.getValue(); }
if (registeredName.equals(name)) { return StringUtils.toStringArray(result);
aliases.add(entry.getKey()); }
}
/**
* 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);
} }
/** /**