/** * Check for a successful dependency resolution of the parameter for the expected type. The * dependency can only be satisfied if the expected type is one of the collection types * {@link Array},{@link Collection}or {@link Map}. An empty collection is only a valid * resolution, if the <code>emptyCollection</code> flag was set. * * @param container {@inheritDoc} * @param adapter {@inheritDoc} * @param expectedType {@inheritDoc} * @return <code>true</code> if matching components were found or an empty collective type * is allowed */ public boolean isResolvable(PicoContainer container, ComponentAdapter adapter, Class expectedType) { final Class collectionType = getCollectionType(expectedType); final Class valueType = getValueType(expectedType); return collectionType != null && (emptyCollection || getMatchingComponentAdapters(container, adapter, componentKeyType, valueType).size() > 0); }
final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Class valueType = getValueType(expectedType);
/** * Resolve the parameter for the expected type. The method will return <code>null</code> * If the expected type is not one of the collection types {@link Array}, * {@link Collection}or {@link Map}. An empty collection is only a valid resolution, if * the <code>emptyCollection</code> flag was set. * * @param container {@inheritDoc} * @param adapter {@inheritDoc} * @param expectedType {@inheritDoc} * @return the instance of the collection type or <code>null</code> * @throws PicoInitializationException {@inheritDoc} */ public Object resolveInstance(PicoContainer container, ComponentAdapter adapter, Class expectedType) { // type check is done in isResolvable Object result = null; final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Map adapterMap = getMatchingComponentAdapters(container, adapter, componentKeyType, getValueType(expectedType)); if (Array.class.isAssignableFrom(collectionType)) { result = getArrayInstance(container, expectedType, adapterMap); } else if (Map.class.isAssignableFrom(collectionType)) { result = getMapInstance(container, expectedType, adapterMap); } else if (Collection.class.isAssignableFrom(collectionType)) { result = getCollectionInstance(container, expectedType, adapterMap); } else { throw new PicoIntrospectionException(expectedType.getName() + " is not a collective type"); } } return result; }