net.sf.andromedaioc.bean.param.AbstractConstantValueParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of andromeda-ioc Show documentation
Show all versions of andromeda-ioc Show documentation
Inversion of Control Framework for Android
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));
}
}