liquibase.ui.DefaultInputHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-core Show documentation
Show all versions of liquibase-core Show documentation
Liquibase is a tool for managing and executing database changes.
package liquibase.ui;
import liquibase.util.ObjectUtil;
/**
* Default input handler simply calls {@link liquibase.util.ObjectUtil#convert(Object, Class)}
*/
public class DefaultInputHandler implements InputHandler {
@Override
public ReturnType parseInput(String input, Class returnType) throws IllegalArgumentException {
try {
return ObjectUtil.convert(input, returnType);
} catch (IllegalArgumentException e) {
throw addPrefixToExceptionMessage(e, input);
}
}
protected IllegalArgumentException addPrefixToExceptionMessage(IllegalArgumentException ex, String input) {
if (ex.getCause() != null && ex.getCause().getMessage() != null) {
return new IllegalArgumentException(
String.format("Invalid value: '%s': %s", input, ex.getCause().getMessage()), ex);
}
if (ex.getMessage() != null) {
return new IllegalArgumentException(
String.format("Invalid value: '%s': %s", input, ex.getMessage()), ex);
}
return ex;
}
}