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 and Description |
|---|---|
| private final ConcurrentHashMap | enumRenames
The enum renames. |
| public static final RenameHandler | INSTANCE
A mutable global instance. |
| private volatile boolean | locked
The lock flag. |
| private static final boolean | LOG
Errors in class initialization are hard to debug. |
| private final ConcurrentHashMap | typeRenames
The type renames. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public static RenameHandler | |
| public static RenameHandler | Returns: a new instance, not nullwhether to load any types in classpath config files loadFromClasspath)Creates an instance, providing the ability to load types in config files. |
| private static RenameHandler | |
| public Map | Returns: a copy of the set of enum renames, not nullthe enum type, not null type)Gets the map of renamed for an enum type. |
| public Set | Returns: a copy of the set of enum types with renames, not nullGets the set of enum types that have renames. |
| public Map | Returns: a copy of the set of enum types with renames, not nullGets the map of renamed types. |
| private void | |
| private List | |
| public void | |
| public < the type of the desired enum T extends Enum | Returns: the enum value, not nullthe enum type, not null type, String the name of the enum to lookup, not null name)Lookup an enum from a name, handling renames. |
| public Class | Returns: the type, not nullthe name of the type to lookup, not null name)Lookup a type from a name, handling renames. |
| private void | |
| public void | renamedEnum(String
the old name of the enum constant, not null oldName, Enum<?> the current enum constant, not null currentValue)Register the fact that an enum constant was renamed. |
| public void | renamedType(String
the old name of the type including the package name, not null oldName, Class<?> the current type, not null currentValue)Register the fact that a type was renamed. |
| public String |
| enumRenames | back to summary |
|---|---|
| private final ConcurrentHashMap<Class<?>, Map<String, Enum<?>>> enumRenames The enum renames. | |
| INSTANCE | back to summary |
|---|---|
| public static final RenameHandler INSTANCE A mutable global instance.
This is a singleton instance which is mutated.
It will be populated by the contents of the | |
| locked | back to summary |
|---|---|
| private volatile boolean locked The lock flag. | |
| LOG | back to summary |
|---|---|
| private static final boolean LOG Errors in class initialization are hard to debug. Set -Dorg.joda.convert.debug=true on the command line to add extra logging to System.err Note This also forces | |
| typeRenames | back to summary |
|---|---|
| private final ConcurrentHashMap<String, Class<?>> typeRenames The type renames. | |
| RenameHandler | back to summary |
|---|---|
| private RenameHandler() Restricted constructor. | |
| checkNotLocked | back to summary |
|---|---|
| private void checkNotLocked() | |
| create | back to summary |
|---|---|
| public static RenameHandler create() Creates an instance. This is not normally used as the preferred option is to edit the singleton.
| |
| create | back to summary |
|---|---|
| public static RenameHandler create(boolean loadFromClasspath) Creates an instance, providing the ability to load types in config files. 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.
| |
| createInstance | back to summary |
|---|---|
| private static RenameHandler createInstance() | |
| getEnumRenames | back to summary |
|---|---|
| public Map Gets the map of renamed for an enum type. An empty map is returned if there are no renames. | |
| getEnumTypesWithRenames | back to summary |
|---|---|
| public Set Gets the set of enum types that have renames. An empty set is returned if there are no renames. | |
| getTypeRenames | back to summary |
|---|---|
| public Map Gets the map of renamed types. An empty map is returned if there are no renames. | |
| loadFromClasspath | back to summary |
|---|---|
| private void loadFromClasspath() | |
| loadRenameFile | back to summary |
|---|---|
| private List | |
| lock | back to summary |
|---|---|
| public void lock() Locks this instance of the rename handler. For additional security, an application should lock the rename handler once any types and enums have been registered. | |
| lookupEnum | back to summary |
|---|---|
| public <T extends Enum Lookup an enum from a name, handling renames.
| |
| lookupType | back to summary |
|---|---|
| public Class Lookup a type from a name, handling renames.
| |
| parseRenameFile | back to summary |
|---|---|
| private void parseRenameFile(List<String> lines, URL url) | |
| renamedEnum | back to summary |
|---|---|
| public void renamedEnum(String oldName, Enum<?> currentValue) Register the fact that an enum constant was renamed. This handles the use case where an enum constant is renamed, but the enum class remains the same. | |
| renamedType | back to summary |
|---|---|
| public void renamedType(String oldName, Class<?> currentValue) Register the fact that a type was renamed. This handles the use case where a class is renamed. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |