All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.ui.DefaultInputHandler Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy