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

net.sf.andromedaioc.bean.param.AbstractConstantValueParser Maven / Gradle / Ivy

The newest version!
package net.sf.andromedaioc.bean.param;

import net.sf.andromedaioc.bean.converter.Converter;
import net.sf.andromedaioc.bean.converter.ConverterFactory;

/**
 * Common logic for value parsers
 *
 * @author Alexey Mitrov
 */
public abstract class AbstractConstantValueParser implements ValueParser {

    private final Class type;

    /**
     * Setup required output type of value parser
     *
     * @param type
     */
    protected AbstractConstantValueParser(Class type) {
        this.type = type;
    }

    /**
     * Should return value for corresponding value model
     *
     * @return value for corresponding value model
     */
    protected abstract Object getValue();

    /**
     * Perform parsing and conversion of value
     *
     * @return parsed and converted value
     */
    public ParameterWrapper parse() {
        Object value = getValue();
        if(value == null) {
            return ParameterWrapper.NULL_PARAMETER_WRAPPER;
        }
        Converter converter = ConverterFactory.getConverter(value.getClass(), type);
        return new ConstantParameterWrapper(converter.convert(value));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy