提交 9871e94c 编写于 作者: J Juergen Hoeller

SimpleAliasRegistry's "getAliases" method returns transitive aliases now;...

SimpleAliasRegistry's "getAliases" method returns transitive aliases now; @Qualifier value matching takes chained aliases of target beans into account as well
上级 35c36dda
......@@ -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"/>
......
/*
* 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);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册