/** * 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); }
/** * Expect any scalar paramter of the appropriate type or the collecting type * {@link java.lang.reflect.Array},{@link java.util.Collection}or {@link java.util.Map}. * The components in the collection will be of the specified type. * * @param componentValueType the component's type (ignored for an Array) * @param emptyCollection <code>true</code> allows the collection to be empty * @since 1.1 */ public ComponentParameter(Class componentValueType, boolean emptyCollection) { this(null, new CollectionComponentParameter(componentValueType, emptyCollection)); }
/** * 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; }
final PicoContainer parent = container.getParent(); if (parent != null) { adapterMap.putAll(getMatchingComponentAdapters(parent, adapter, keyType, valueType)); continue; if (keyType.isAssignableFrom(key.getClass()) && evaluate(componentAdapter)) { adapterMap.put(key, componentAdapter);
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; }
public void accept(PicoVisitor visitor) { super.accept(visitor); constraint.accept(visitor); } }
public boolean isResolvable(PicoContainer container, ComponentAdapter adapter, Class expectedType) throws PicoIntrospectionException { return super.isResolvable(container, adapter, getArrayType(expectedType)); }
final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Class valueType = getValueType(expectedType); final Collection componentAdapters = getMatchingComponentAdapters(container, adapter, componentKeyType, valueType).values(); if (componentAdapters.isEmpty()) { if (!emptyCollection) { throw new PicoIntrospectionException(expectedType.getName() + " not resolvable, no components of type " + getValueType(expectedType).getName() + " available");
/** * Expect any scalar paramter of the appropriate type or the collecting type * {@link java.lang.reflect.Array},{@link java.util.Collection}or {@link java.util.Map}. * The components in the collection will be of the specified type and their adapter's key * must have a particular type. * * @param componentKeyType the component adapter's key type * @param componentValueType the component's type (ignored for an Array) * @param emptyCollection <code>true</code> allows the collection to be empty * @since 1.1 */ public ComponentParameter(Class componentKeyType, Class componentValueType, boolean emptyCollection) { this(null, new CollectionComponentParameter(componentKeyType, componentValueType, emptyCollection)); }