All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jodd.petite.SetInjectionPoint Maven / Gradle / Ivy

Go to download

Jodd Petite is slick and lightweight DI container that uses annotations and supports sufficient most of features offered by other containers.

There is a newer version: 6.0.2
Show newest version
// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.petite;

import jodd.util.ReflectUtil;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * Set injection point.
 */
public class SetInjectionPoint {

	public static final SetInjectionPoint[] EMPTY = new SetInjectionPoint[0];

	public final Field field;

	public final Class type;

	public final Class targetClass;

	public SetInjectionPoint(Field field) {
		this.field = field;
		this.type = resolveSetType(field);

		this.targetClass = ReflectUtil.getComponentType(field.getGenericType());
		if (targetClass == null) {
			throw new PetiteException("Unknown Petite set component type " +
					field.getDeclaringClass().getSimpleName() + '.' + field.getName());
		}
	}

	@SuppressWarnings({"unchecked"})
	protected Class resolveSetType(Field field) {
		Class type = (Class) field.getType();

		if (type == Collection.class ||
				type == Set.class ||
				type == HashSet.class) {
			return type;
		}
		throw new PetiteException("Unsupported Petite set type: " + type.getName());
	}

	/**
	 * Creates target set for injection. For now it creates HashSet,
	 * but custom implementation can change this setting.
	 */
	public Collection createSet(int length) {
		return new HashSet(length);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy