ComponentAdapter (@NotNull DefaultPicoContainer container, Class<?> expectedType, @NotNull Object excludeKey) { ComponentAdapter byKey = container.getComponentAdapter(expectedType); if (byKey != null && !excludeKey.equals(byKey.getComponentKey())) { return byKey; } List<ComponentAdapter> found = container.getComponentAdaptersOfType(expectedType); ComponentAdapter exclude = null; for (ComponentAdapter work : found) { if (work.getComponentKey().equals(excludeKey)) { exclude = work; } } found.remove(exclude); if (found.size() == 0) { return container.getParent() == null ? null : container.getParent().getComponentAdapterOfType(expectedType); } else if (found.size() == 1) { return found.get(0); } else { Class<?>[] foundClasses = new Class[found.size()]; for (int i = 0; i < foundClasses.length; i++) { foundClasses[i] = found.get(i).getComponentImplementation(); } throw new AmbiguousComponentResolutionException(expectedType, foundClasses); } }