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

net.sf.andromedaioc.bean.param.ReferenceValueParser 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;
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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy