public Injector getInjector(Class<?> injectorType) {
return getInjector(MetaClassFactory.get(injectorType));
}
public Injector getInjector(MetaClass type) {
MetaClass erased = type.getErased();
if (!injectors.containsKey(erased)) {
throw new InjectionFailure("could not resolve type for injection: " + erased.getFullyQualifiedName());
}
List<Injector> injectorList = new ArrayList<Injector>(injectors.get(erased));
Iterator<Injector> iter = injectorList.iterator();
Injector inj;
if (injectorList.size() > 1) {
while (iter.hasNext()) {
inj = iter.next();
if (type.getParameterizedType() != null) {
if (inj.getQualifyingTypeInformation() != null) {
if (!type.getParameterizedType().isAssignableFrom(inj.getQualifyingTypeInformation())) {
iter.remove();
}
}
}
else if (inj.getQualifyingTypeInformation() == null) {
iter.remove();
}
}
}
if (injectorList.size() > 1) {
throw new InjectionFailure("ambiguous injection type (multiple injectors resolved): "
+ erased.getFullyQualifiedName());
}
else if (injectorList.isEmpty()) {
throw new InjectionFailure("could not resolve type for injection: " + erased.getFullyQualifiedName());
}
return injectorList.get(0);
}