/** * Expect any scalar parameter 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 */ public ComponentParameter(final Generic<?> componentValueType, final boolean emptyCollection) { this(null, new CollectionComponentParameter(componentValueType, emptyCollection)); }
public Class getCollectionType(final Type expectedType) { if (expectedType instanceof Class) { return getCollectionType((Class) expectedType); } else if (expectedType instanceof ParameterizedType) { final ParameterizedType type = (ParameterizedType) expectedType; return getCollectionType(type.getRawType()); } else if (expectedType instanceof GenericArrayType) { // return getCollectionType(((GenericArrayType) expectedType).getGenericComponentType()); GenericArrayType type = (GenericArrayType) expectedType; Class baseType = getGenericArrayBaseType(type.getGenericComponentType()); return Array.newInstance(baseType, 0).getClass(); } throw new IllegalArgumentException("Unable to get collection type from " + expectedType); }
private Generic<?> getValueType(final Type collectionType) { if (collectionType instanceof Class) { return getValueType((Class) collectionType); } else if (collectionType instanceof ParameterizedType) { return getValueType((ParameterizedType) collectionType); } else if (collectionType instanceof GenericArrayType) { GenericArrayType genericArrayType = (GenericArrayType) collectionType; return Generic.get(getGenericArrayBaseType(genericArrayType.getGenericComponentType())); } throw new IllegalArgumentException("Unable to determine collection type from " + collectionType); }
final ComponentAdapter<?> injecteeAdapter, final Type expectedType, final NameBinding expectedNameBinding, final boolean useNames, final Annotation binding) { final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Map<Object, ComponentAdapter<?>> componentAdapters = getMatchingComponentAdapters(container, forAdapter, keyType, getValueType(expectedType)); return new Resolver() { public boolean isResolved() {
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);
@Override protected Map<Object, ComponentAdapter<?>> getMatchingComponentAdapters(final PicoContainer container, final ComponentAdapter adapter, final Class keyType, final Generic<?> valueType) { final Map<Object, ComponentAdapter<?>> map = super.getMatchingComponentAdapters(container, adapter, keyType, valueType); if (map.size() > 1) { throw new AbstractInjector.AmbiguousComponentResolutionException(valueType, map.keySet().toArray(new Object[map.size()])); } return map; }
private Class getGenericArrayBaseType(final Type expectedType) { if (expectedType instanceof Class) { Class type = (Class) expectedType; return type; } else if (expectedType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) expectedType; return getGenericArrayBaseType(type.getRawType()); } throw new IllegalArgumentException("Unable to get collection type from " + expectedType); }
@Override public void verify(final PicoContainer container, final ComponentAdapter<?> adapter, final Type expectedType, final NameBinding expectedNameBinding, final boolean useNames, final Annotation binding) throws PicoCompositionException { super.verify(container, adapter, getArrayType((Class) expectedType), expectedNameBinding, useNames, binding); }
@Override public void accept(final PicoVisitor visitor) { super.accept(visitor); constraint.accept(visitor); } }
@Override public Resolver resolve(final PicoContainer container, final ComponentAdapter<?> forAdapter, final ComponentAdapter<?> injecteeAdapter, final Type expectedType, final NameBinding expectedNameBinding, final boolean useNames, final Annotation binding) throws PicoCompositionException { final Resolver resolver; return new Parameter.DelegateResolver(super.resolve(container, forAdapter, null, getArrayType((Class) expectedType), expectedNameBinding, useNames, binding)) { @Override public Object resolveInstance(final Type into) { final Object[] array = (Object[]) super.resolveInstance(into); if (array.length == 1) { return array[0]; } return null; } }; }
final ComponentAdapter<?> injecteeAdapter, final Type expectedType, final NameBinding expectedNameBinding, final boolean useNames, final Annotation binding) { final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Map<Object, ComponentAdapter<?>> componentAdapters = getMatchingComponentAdapters(container, forAdapter, keyType, getValueType(expectedType)); return new Resolver() { public boolean isResolved() {
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);
private Class getGenericArrayBaseType(final Type expectedType) { if (expectedType instanceof Class) { Class type = (Class) expectedType; return type; } else if (expectedType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) expectedType; return getGenericArrayBaseType(type.getRawType()); } throw new IllegalArgumentException("Unable to get collection type from " + expectedType); }
final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Generic<?> valueType = getValueType(expectedType); final Collection componentAdapters = getMatchingComponentAdapters(container, adapter, keyType, valueType) .values(); if (componentAdapters.isEmpty()) {
private Generic<?> getValueType(final Type collectionType) { if (collectionType instanceof Class) { return getValueType((Class) collectionType); } else if (collectionType instanceof ParameterizedType) { return getValueType((ParameterizedType) collectionType); } else if (collectionType instanceof GenericArrayType) { GenericArrayType genericArrayType = (GenericArrayType) collectionType; return Generic.get(getGenericArrayBaseType(genericArrayType.getGenericComponentType())); } throw new IllegalArgumentException("Unable to determine collection type from " + collectionType); }
public Class getCollectionType(final Type expectedType) { if (expectedType instanceof Class) { return getCollectionType((Class) expectedType); } else if (expectedType instanceof ParameterizedType) { final ParameterizedType type = (ParameterizedType) expectedType; return getCollectionType(type.getRawType()); } else if (expectedType instanceof GenericArrayType) { // return getCollectionType(((GenericArrayType) expectedType).getGenericComponentType()); GenericArrayType type = (GenericArrayType) expectedType; Class baseType = getGenericArrayBaseType(type.getGenericComponentType()); return Array.newInstance(baseType, 0).getClass(); } throw new IllegalArgumentException("Unable to get collection type from " + expectedType); }
/** * Expect any scalar parameter 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 */ public ComponentParameter(final Generic<?> componentValueType, final boolean emptyCollection) { this(null, new CollectionComponentParameter(componentValueType, emptyCollection)); }
final Class collectionType = getCollectionType(expectedType); if (collectionType != null) { final Generic<?> valueType = getValueType(expectedType); final Collection componentAdapters = getMatchingComponentAdapters(container, adapter, keyType, valueType) .values(); if (componentAdapters.isEmpty()) {
/** * Expect any scalar parameter 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 keyType 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 */ public ComponentParameter(final Class<?> keyType, final Generic<?> componentValueType, final boolean emptyCollection) { this(null, new CollectionComponentParameter(keyType, componentValueType, emptyCollection)); }
/** * Expect any scalar parameter 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 keyType 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 */ public ComponentParameter(final Class<?> keyType, final Generic<?> componentValueType, final boolean emptyCollection) { this(null, new CollectionComponentParameter(keyType, componentValueType, emptyCollection)); }