Class TypeManufacturerUtil
- java.lang.Object
-
- uk.co.jemos.podam.typeManufacturers.TypeManufacturerUtil
-
public abstract class TypeManufacturerUtil extends Object
Type Manufacturer utility class. Created by tedonema on 01/07/2015.- Since:
- 6.0.0.RELEASE
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.LoggerLOGThe application logger
-
Constructor Summary
Constructors Constructor Description TypeManufacturerUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Type[]fillTypeArgMap(Map<String,Type> typeArgsMap, Class<?> pojoClass, Type[] genericTypeArgs)Fills type agruments mapstatic AttributeStrategy<?>findAttributeStrategy(DataProviderStrategy strategy, List<Annotation> annotations, Class<?> attributeType)It returns aAttributeStrategyif one was specified in annotations, ornullotherwise.static IntegerfindCollectionSize(DataProviderStrategy strategy, List<Annotation> annotations, Class<?> collectionElementType, Holder<AttributeStrategy<?>> elementStrategyHolder, Holder<AttributeStrategy<?>> keyStrategyHolder)Searches for annotation with information about collection/map size and filling strategiesstatic Method[]findSuitableConstructors(Class<?> factoryClass, Class<?> pojoClass)Finds suitable static constructors for POJO instantiationstatic Type[]mergeActualAndSuppliedGenericTypes(Class<?> attributeType, Type genericAttributeType, Type[] suppliedTypes, Map<String,Type> typeArgsMap)Utility to merge actual types with supplied array of generic type substitutionsstatic Class<?>resolveGenericParameter(Type paramType, Map<String,Type> typeArgsMap, AtomicReference<Type[]> methodGenericTypeArgs)It resolves generic parameter typestatic ObjectreturnAttributeDataStrategyValue(Class<?> attributeType, List<Annotation> annotations, AttributeStrategy<?> attributeStrategy)It retrieves the value for thePodamStrategyValueannotation with which the attribute was annotated
-
-
-
Method Detail
-
findAttributeStrategy
public static AttributeStrategy<?> findAttributeStrategy(DataProviderStrategy strategy, List<Annotation> annotations, Class<?> attributeType) throws InstantiationException, IllegalAccessException, SecurityException, IllegalArgumentException, InvocationTargetException
It returns aAttributeStrategyif one was specified in annotations, ornullotherwise.- Parameters:
strategy- The data provider strategyannotations- The list of annotations, irrelevant annotations will be removedattributeType- Type of attribute expected to be returned- Returns:
AttributeStrategy, ifPodamStrategyValueor bean validation constraint annotation was found among annotations- Throws:
IllegalAccessException- if attribute strategy cannot be instantiatedInstantiationException- if attribute strategy cannot be instantiatedSecurityException- if access security is violatedInvocationTargetException- if invocation failedIllegalArgumentException- if illegal argument provided to a constructor
-
findSuitableConstructors
public static Method[] findSuitableConstructors(Class<?> factoryClass, Class<?> pojoClass)
Finds suitable static constructors for POJO instantiationThis method places required and provided types for object creation into a map, which will be used for type mapping.
- Parameters:
factoryClass- Factory class to produce the POJOpojoClass- Typed class- Returns:
- an array of suitable static constructors found
-
fillTypeArgMap
public static Type[] fillTypeArgMap(Map<String,Type> typeArgsMap, Class<?> pojoClass, Type[] genericTypeArgs)
Fills type agruments mapThis method places required and provided types for object creation into a map, which will be used for type mapping.
- Parameters:
typeArgsMap- a map to fillpojoClass- Typed classgenericTypeArgs- Type arguments provided for a generics object by caller- Returns:
- Array of unused provided generic type arguments
- Throws:
IllegalStateException- If number of typed parameters doesn't match number of provided generic types
-
findCollectionSize
public static Integer findCollectionSize(DataProviderStrategy strategy, List<Annotation> annotations, Class<?> collectionElementType, Holder<AttributeStrategy<?>> elementStrategyHolder, Holder<AttributeStrategy<?>> keyStrategyHolder) throws InstantiationException, IllegalAccessException
Searches for annotation with information about collection/map size and filling strategies- Parameters:
strategy- a data provider strategyannotations- a list of annotations to inspectcollectionElementType- a collection element typeelementStrategyHolder- a holder to pass found element strategy back to the caller, can be nullkeyStrategyHolder- a holder to pass found key strategy back to the caller, can be null- Returns:
- A number of element in collection or null, if no annotation was found
- Throws:
InstantiationException- A strategy cannot be instantiatedIllegalAccessException- A strategy cannot be instantiated
-
mergeActualAndSuppliedGenericTypes
public static Type[] mergeActualAndSuppliedGenericTypes(Class<?> attributeType, Type genericAttributeType, Type[] suppliedTypes, Map<String,Type> typeArgsMap)
Utility to merge actual types with supplied array of generic type substitutions- Parameters:
attributeType- actual type of objectgenericAttributeType- generic type of objectsuppliedTypes- an array of supplied types for generic type substitutiontypeArgsMap- a map relating the generic class arguments ("<T, V>" for example) with their actual types- Returns:
- An array of merged actual and supplied types with generic types resolved
-
resolveGenericParameter
public static Class<?> resolveGenericParameter(Type paramType, Map<String,Type> typeArgsMap, AtomicReference<Type[]> methodGenericTypeArgs)
It resolves generic parameter type- Parameters:
paramType- The generic parameter typetypeArgsMap- A map of resolved typesmethodGenericTypeArgs- Return value posible generic types of the generic parameter type- Returns:
- value for class representing the generic parameter type
-
returnAttributeDataStrategyValue
public static Object returnAttributeDataStrategyValue(Class<?> attributeType, List<Annotation> annotations, AttributeStrategy<?> attributeStrategy) throws IllegalArgumentException
It retrieves the value for thePodamStrategyValueannotation with which the attribute was annotated- Parameters:
attributeType- The attribute type, used for type checkingannotations- Annotations attached to the attributeattributeStrategy- TheAttributeStrategyto use- Returns:
- The value for the
PodamStrategyValueannotation with which the attribute was annotated - Throws:
IllegalArgumentException- If the type of the data strategy defined for thePodamStrategyValueannotation is not assignable to the annotated attribute. This de facto guarantees type safety.
-
-