public ComponentAdapter getComponentAdapterOfType(Class componentType) { // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115 ComponentAdapter adapterByKey = getComponentAdapter(componentType); if (adapterByKey != null) { return adapterByKey; } List found = getComponentAdaptersOfType(componentType); if (found.size() == 1) { return ((ComponentAdapter) found.get(0)); } else if (found.size() == 0) { if (parent != null) { return parent.getComponentAdapterOfType(componentType); } else { return null; } } else { Class[] foundClasses = new Class[found.size()]; for (int i = 0; i < foundClasses.length; i++) { ComponentAdapter componentAdapter = (ComponentAdapter) found.get(i); foundClasses[i] = componentAdapter.getComponentImplementation(); } throw new AmbiguousComponentResolutionException(componentType, foundClasses); } }
constructor = getGreediestSatisfiableConstructor(guardedContainer); } catch (AmbiguousComponentResolutionException e) { e.setComponent(getComponentImplementation()); throw e;
/** * @return Returns a string containing the unresolved class type and the ambiguous keys. */ public String getMessage() { StringBuffer msg = new StringBuffer(); msg.append(component); msg.append(" has ambiguous dependency on "); msg.append(ambiguousDependency); msg.append(", "); msg.append("resolves to multiple classes: "); msg.append(Arrays.asList(getAmbiguousComponentKeys())); return msg.toString(); }
protected Map getMatchingComponentAdapters(PicoContainer container, ComponentAdapter adapter, Class keyType, Class valueType) { final Map map = super.getMatchingComponentAdapters(container, adapter, keyType, valueType); if (map.size() > 1) { throw new AmbiguousComponentResolutionException(valueType, map.keySet().toArray(new Object[map.size()])); } return map; }
constructor = getGreediestSatisfiableConstructor(guardedContainer); } catch (AmbiguousComponentResolutionException e) { e.setComponent(getComponentImplementation()); throw e;
public ComponentAdapter getComponentAdapterOfType(Class componentType) { // See http://jira.codehaus.org/secure/ViewIssue.jspa?key=PICO-115 ComponentAdapter adapterByKey = getComponentAdapter(componentType); if (adapterByKey != null) { return adapterByKey; } List found = getComponentAdaptersOfType(componentType); if (found.size() == 1) { return ((ComponentAdapter) found.get(0)); } else if (found.size() == 0) { if (parent != null) { return parent.getComponentAdapterOfType(componentType); } else { return null; } } else { Class[] foundClasses = new Class[found.size()]; for (int i = 0; i < foundClasses.length; i++) { foundClasses[i] = ((ComponentAdapter) found.get(i)).getComponentImplementation(); } throw new AmbiguousComponentResolutionException(componentType, foundClasses); } }
foundClasses[i] = ((ComponentAdapter) found.get(i)).getComponentImplementation(); throw new AmbiguousComponentResolutionException(expectedType, foundClasses);