|
|
@ -49,9 +49,13 @@ public class SimpleAliasRegistry implements AliasRegistry { |
|
|
|
this.aliasMap.remove(alias); |
|
|
|
this.aliasMap.remove(alias); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (!allowAliasOverriding()) { |
|
|
|
String registeredName = this.aliasMap.get(alias); |
|
|
|
String registeredName = this.aliasMap.get(alias); |
|
|
|
if (registeredName != null) { |
|
|
|
if (registeredName != null && !registeredName.equals(name)) { |
|
|
|
if (registeredName.equals(name)) { |
|
|
|
|
|
|
|
// An existing alias - no need to re-register
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!allowAliasOverriding()) { |
|
|
|
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" + |
|
|
|
throw new IllegalStateException("Cannot register alias '" + alias + "' for name '" + |
|
|
|
name + "': It is already registered for name '" + registeredName + "'."); |
|
|
|
name + "': It is already registered for name '" + registeredName + "'."); |
|
|
|
} |
|
|
|
} |
|
|
@ -69,6 +73,23 @@ public class SimpleAliasRegistry implements AliasRegistry { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Determine whether the given name has the given alias registered. |
|
|
|
|
|
|
|
* @param name the name to check |
|
|
|
|
|
|
|
* @param alias the alias to look for |
|
|
|
|
|
|
|
* @since 4.2.1 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public boolean hasAlias(String name, String alias) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : this.aliasMap.entrySet()) { |
|
|
|
|
|
|
|
String registeredName = entry.getValue(); |
|
|
|
|
|
|
|
if (registeredName.equals(name)) { |
|
|
|
|
|
|
|
String registeredAlias = entry.getKey(); |
|
|
|
|
|
|
|
return (registeredAlias.equals(alias) || hasAlias(registeredAlias, alias)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void removeAlias(String alias) { |
|
|
|
public void removeAlias(String alias) { |
|
|
|
String name = this.aliasMap.remove(alias); |
|
|
|
String name = this.aliasMap.remove(alias); |
|
|
@ -127,7 +148,12 @@ public class SimpleAliasRegistry implements AliasRegistry { |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!resolvedAlias.equals(alias)) { |
|
|
|
else if (!resolvedAlias.equals(alias)) { |
|
|
|
String existingName = this.aliasMap.get(resolvedAlias); |
|
|
|
String existingName = this.aliasMap.get(resolvedAlias); |
|
|
|
if (existingName != null && !existingName.equals(resolvedName)) { |
|
|
|
if (existingName != null) { |
|
|
|
|
|
|
|
if (existingName.equals(resolvedName)) { |
|
|
|
|
|
|
|
// Pointing to existing alias - just remove placeholder
|
|
|
|
|
|
|
|
this.aliasMap.remove(alias); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
"Cannot register resolved alias '" + resolvedAlias + "' (original: '" + alias + |
|
|
|
"Cannot register resolved alias '" + resolvedAlias + "' (original: '" + alias + |
|
|
|
"') for name '" + resolvedName + "': It is already registered for name '" + |
|
|
|
"') for name '" + resolvedName + "': It is already registered for name '" + |
|
|
@ -144,6 +170,23 @@ public class SimpleAliasRegistry implements AliasRegistry { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Check whether the given name points back to the given alias as an alias |
|
|
|
|
|
|
|
* in the other direction already, catching a circular reference upfront |
|
|
|
|
|
|
|
* and throwing a corresponding IllegalStateException. |
|
|
|
|
|
|
|
* @param name the candidate name |
|
|
|
|
|
|
|
* @param alias the candidate alias |
|
|
|
|
|
|
|
* @see #registerAlias |
|
|
|
|
|
|
|
* @see #hasAlias |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void checkForAliasCircle(String name, String alias) { |
|
|
|
|
|
|
|
if (hasAlias(alias, name)) { |
|
|
|
|
|
|
|
throw new IllegalStateException("Cannot register alias '" + alias + |
|
|
|
|
|
|
|
"' for name '" + name + "': Circular reference - '" + |
|
|
|
|
|
|
|
name + "' is a direct or indirect alias for '" + alias + "' already"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Determine the raw name, resolving aliases to canonical names. |
|
|
|
* Determine the raw name, resolving aliases to canonical names. |
|
|
|
* @param name the user-specified name |
|
|
|
* @param name the user-specified name |
|
|
@ -163,20 +206,4 @@ public class SimpleAliasRegistry implements AliasRegistry { |
|
|
|
return canonicalName; |
|
|
|
return canonicalName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Check whether the given name points back to given alias as an alias |
|
|
|
|
|
|
|
* in the other direction, catching a circular reference upfront and |
|
|
|
|
|
|
|
* throwing a corresponding IllegalStateException. |
|
|
|
|
|
|
|
* @param name the candidate name |
|
|
|
|
|
|
|
* @param alias the candidate alias |
|
|
|
|
|
|
|
* @see #registerAlias |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected void checkForAliasCircle(String name, String alias) { |
|
|
|
|
|
|
|
if (alias.equals(canonicalName(name))) { |
|
|
|
|
|
|
|
throw new IllegalStateException("Cannot register alias '" + alias + |
|
|
|
|
|
|
|
"' for name '" + name + "': Circular reference - '" + |
|
|
|
|
|
|
|
name + "' is a direct or indirect alias for '" + alias + "' already"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|