@SuppressWarnings("unchecked")
@Override
public <V> TypeContainer getTypeContainer(ClassInjector injector, Class<V> type, Map<String, Class<? extends V>[]> inheritanceTree, Annotation qualifier,
ClassLoader classLoader) {
TypeContainerConfig<V> config = (TypeContainerConfig<V>) configs.get(type.getName());
TypeContainer container;
LOGGER.debug("getTypeContainer - type {}, qualifier {}", type, qualifier);
if (config != null && (config.getImplementation() != null || config.getProvider() != null)) {
LOGGER.debug("getTypeContainer - config exists");
if (config.getCondition() != null && !config.getCondition().fulfilled(injector, type, inheritanceTree, qualifier, classLoader)) {
LOGGER.debug("getTypeContainer - condition not fulfilled");
return null;
}
container = new TypeContainer(null, null);
if (config.getFactoryMethod() != null) {
LOGGER.debug("getTypeContainer - using factory method");
container.setType(config.getImplementation());
container.gatherInformation();
container.setSingleton(config.isSingleton());
container.setInstanceMode(InstanceMode.FACTORY_METHOD);
container.setFactoryMethod(config.getFactoryMethod());
container.setConstructor(null);
container.setProvider(null);
} else if (config.getProvider() != null) {
LOGGER.debug("getTypeContainer - using provider");
container.setInstanceMode(InstanceMode.PROVIDER);
container.setProvider(config.getProvider());
container.setFactoryMethod(null);
container.setConstructor(null);
} else {
LOGGER.debug("getTypeContainer - using constructor");
container.setType(config.getImplementation());
container.gatherInformation();
container.setSingleton(config.isSingleton());
container.setInstanceMode(InstanceMode.CONSTRUCTOR);
container.setConstructor(config.getConstructor());
container.setFactoryMethod(null);
container.setProvider(null);
}
return container;
}