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

org.jboss.windup.ui.DefaultValueAdapter Maven / Gradle / Ivy

package org.jboss.windup.ui;

import java.util.concurrent.Callable;

import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.windup.config.ConfigurationOption;
import org.jboss.windup.util.ThemeProvider;

/**
 * An adapter between {@link ConfigurationOption#getDefaultValue()} default values, and
 * {@link UIInput#setDefaultValue(Callable)}
 *
 * @author Lincoln Baxter, III
 */
public class DefaultValueAdapter implements Callable {
    private ConfigurationOption option;
    private Class expectedType;

    public DefaultValueAdapter(ConfigurationOption option, Class expectedType) {
        this.option = option;
        this.expectedType = expectedType;
    }

    public DefaultValueAdapter(ConfigurationOption option) {
        this(option, null);
    }

    @Override
    @SuppressWarnings("unchecked")
    public T call() throws Exception {
        Object val = this.option.getDefaultValue();
        if (val != null && this.expectedType != null && !this.expectedType.isAssignableFrom(val.getClass())) {
            throw new IllegalStateException(ThemeProvider.getInstance().getTheme().getBrandNameAcronym() + " option " + option.getName() +
                    " was expected to return " + expectedType.getName() + " but returned " + val.getClass());
        }
        return (T) val;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy