public final class RenameHandler
extends java.lang.Object
This handles type and enum constant renames. For example, use as follows:
RenameHandler.INSTANCE.renamedType("org.joda.OldName", NewName.class);
RenameHandler.INSTANCE.renamedEnum("CORRECT", Status.VALID);
RenameHandler.INSTANCE.renamedEnum("INCORRECT", Status.INVALID);
From v2.1, renames can be stored on the classpath in configuration files.
The file location is META-INF/org/joda/convert/Renamed.ini.
All files found in this location are read and processed.
The format has two sections [types] and [enums].
The [types] section has lines of the format oldClassName = newClassName.
The [enums] section has lines of the format oldEnumConstantName = enumClassName.newEnumConstantName.
Lines starting with # are treated as comments.
The recommended usage is to edit the static singleton before using other classes.
Editing a static is acceptable because renames are driven by bytecode which is static.
For additional security, an application should lock the rename handler instance
once any types and enums have been registered using lock().
This class is thread-safe with concurrent caches.
| Modifier and Type | Field | Description |
|---|---|---|
static RenameHandler |
INSTANCE |
A mutable global instance.
|
| Modifier and Type | Method | Description |
|---|---|---|
static RenameHandler |
create() |
Creates an instance.
|
static RenameHandler |
create(boolean loadFromClasspath) |
Creates an instance, providing the ability to load types in config files.
|
java.util.Map<java.lang.String,java.lang.Enum<?>> |
getEnumRenames(java.lang.Class<?> type) |
Gets the map of renamed for an enum type.
|
java.util.Set<java.lang.Class<?>> |
getEnumTypesWithRenames() |
Gets the set of enum types that have renames.
|
java.util.Map<java.lang.String,java.lang.Class<?>> |
getTypeRenames() |
Gets the map of renamed types.
|
void |
lock() |
Locks this instance of the rename handler.
|
<T extends java.lang.Enum<T>> |
lookupEnum(java.lang.Class<T> type,
java.lang.String name) |
Lookup an enum from a name, handling renames.
|
java.lang.Class<?> |
lookupType(java.lang.String name) |
Lookup a type from a name, handling renames.
|
void |
renamedEnum(java.lang.String oldName,
java.lang.Enum<?> currentValue) |
Register the fact that an enum constant was renamed.
|
void |
renamedType(java.lang.String oldName,
java.lang.Class<?> currentValue) |
Register the fact that a type was renamed.
|
java.lang.String |
toString() |
public static final RenameHandler INSTANCE
Renamed.ini configuration files.public static RenameHandler create()
This is not normally used as the preferred option is to edit the singleton.
public static RenameHandler create(boolean loadFromClasspath)
This is not normally used as the preferred option is to edit the singleton.
If the flag is set to true, the classpath config files will be used to register types and enums.
loadFromClasspath - whether to load any types in classpath config filespublic void renamedType(java.lang.String oldName,
java.lang.Class<?> currentValue)
This handles the use case where a class is renamed.
oldName - the old name of the type including the package name, not nullcurrentValue - the current type, not nullpublic java.util.Map<java.lang.String,java.lang.Class<?>> getTypeRenames()
An empty map is returned if there are no renames.
public java.lang.Class<?> lookupType(java.lang.String name)
throws java.lang.ClassNotFoundException
name - the name of the type to lookup, not nulljava.lang.ClassNotFoundException - if the name is not a valid typepublic void renamedEnum(java.lang.String oldName,
java.lang.Enum<?> currentValue)
This handles the use case where an enum constant is renamed, but the enum class remains the same.
oldName - the old name of the enum constant, not nullcurrentValue - the current enum constant, not nullpublic java.util.Set<java.lang.Class<?>> getEnumTypesWithRenames()
An empty set is returned if there are no renames.
public java.util.Map<java.lang.String,java.lang.Enum<?>> getEnumRenames(java.lang.Class<?> type)
An empty map is returned if there are no renames.
type - the enum type, not nullpublic <T extends java.lang.Enum<T>> T lookupEnum(java.lang.Class<T> type,
java.lang.String name)
T - the type of the desired enumtype - the enum type, not nullname - the name of the enum to lookup, not nulljava.lang.IllegalArgumentException - if the name is not a valid enum constantpublic void lock()
For additional security, an application should lock the rename handler once any types and enums have been registered.
public java.lang.String toString()
toString in class java.lang.ObjectCopyright © 2010–2018 Joda.org. All rights reserved.