}
public Injector getInjector(final MetaClass type) {
final MetaClass erased = type.getErased();
if (!injectors.containsKey(erased)) {
throw new InjectionFailure("could not resolve type for injection: " + erased.getFullyQualifiedName());
}
final List<Injector> injectorList = new ArrayList<Injector>(injectors.get(erased));
final Iterator<Injector> iterator = injectorList.iterator();
Injector inj;
if (injectorList.size() > 1) {
while (iterator.hasNext()) {
inj = iterator.next();
if (type.getParameterizedType() != null) {
if (inj.getQualifyingTypeInformation() != null) {
if (!type.getParameterizedType().isAssignableFrom(inj.getQualifyingTypeInformation())) {
iterator.remove();
}
}
}
if (!inj.isEnabled()) {
iterator.remove();
}
}
}
if (injectorList.size() > 1) {
// perform second pass
final Iterator<Injector> secondIterator = injectorList.iterator();
while (secondIterator.hasNext()) {
if (!secondIterator.next().getInjectedType().equals(erased))
secondIterator.remove();
}
}
if (injectorList.size() > 1) {
throw new InjectionFailure("ambiguous injection type (multiple injectors resolved): "
+ erased.getFullyQualifiedName());
}
if (injectorList.isEmpty()) {
throw new InjectionFailure("could not resolve type for injection: " + erased.getFullyQualifiedName());
}
return injectorList.get(0);
}