net.sf.andromedaioc.bean.param.ReferenceValueParser 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;
import net.sf.andromedaioc.bean.wrapper.BeanWrapper;
import net.sf.andromedaioc.exception.BeanNotFoundException;
import net.sf.andromedaioc.model.beans.ReferenceKey;
import net.sf.andromedaioc.model.beans.ValueModel;
import java.util.Map;
public class ReferenceValueParser implements ValueParser {
private final ValueModel valueModel;
private final Class> type;
private final Map beans;
public ReferenceValueParser(ValueModel valueModel, Class> type, Map beans) {
this.valueModel = valueModel;
this.type = type;
this.beans = beans;
}
public ParameterWrapper parse() {
if(beans.containsKey(valueModel.getReference())){
BeanWrapper bean = beans.get(valueModel.getReference());
Converter converter = ConverterFactory.getConverter(bean.getBeanClass(), type);
return new BeanParameterWrapper(bean, converter);
} else {
throw new BeanNotFoundException(valueModel.getReference().getId());
}
}
}