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

net.sf.andromedaioc.context.AndromedaContextImpl Maven / Gradle / Ivy

The newest version!
package net.sf.andromedaioc.context;

import net.sf.andromedaioc.bean.wrapper.BeanWrapper;
import net.sf.andromedaioc.exception.BeanNotFoundException;
import net.sf.andromedaioc.model.beans.ReferenceKey;
import net.sf.andromedaioc.resource.ResourceProvider;
import net.sf.andromedaioc.util.BeanUtils;

import java.util.Map;
import java.util.Properties;


public class AndromedaContextImpl implements AndromedaContext {

    private final Map beans;
    private final ResourceProvider resourceProvider;

    public AndromedaContextImpl(Map beans, ResourceProvider resourceProvider) {
        this.beans = beans;
        this.resourceProvider = resourceProvider;
    }

    public  T getBean(String id) {
        BeanWrapper beanWrapper =  beans.get(ReferenceKey.newPlainReferenceKey(id));
        if(beanWrapper == null) {
            throw new BeanNotFoundException(String.format("No bean with id = %s found", id));
        }
        return (T) beanWrapper.getBean();
    }

    public  T getBean(Class type) {
        // TODO: should be optimized
        BeanWrapper beanWrapper = BeanUtils.getBeansWithType(type, beans.values());
        return (T) beanWrapper.getBean();
    }

    public ResourceProvider getResourceProvider() {
        return resourceProvider;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy