net.sf.andromedaioc.context.AndromedaContextImpl 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.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;
}
}