Class TypeManufacturerUtil


  • public abstract class TypeManufacturerUtil
    extends Object
    Type Manufacturer utility class. Created by tedonema on 01/07/2015.
    Since:
    6.0.0.RELEASE
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
        The application logger
    • Constructor Detail

      • TypeManufacturerUtil

        public TypeManufacturerUtil()
    • Method Detail

      • findSuitableConstructors

        public static Method[] findSuitableConstructors​(Class<?> factoryClass,
                                                        Class<?> pojoClass)
        Finds suitable static constructors for POJO instantiation

        This 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 POJO
        pojoClass - 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 map

        This method places required and provided types for object creation into a map, which will be used for type mapping.

        Parameters:
        typeArgsMap - a map to fill
        pojoClass - Typed class
        genericTypeArgs - 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 strategy
        annotations - a list of annotations to inspect
        collectionElementType - a collection element type
        elementStrategyHolder - a holder to pass found element strategy back to the caller, can be null
        keyStrategyHolder - 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 instantiated
        IllegalAccessException - 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 object
        genericAttributeType - generic type of object
        suppliedTypes - an array of supplied types for generic type substitution
        typeArgsMap - 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 type
        typeArgsMap - A map of resolved types
        methodGenericTypeArgs - Return value posible generic types of the generic parameter type
        Returns:
        value for class representing the generic parameter type