Class PodamFactoryImpl
- java.lang.Object
-
- uk.co.jemos.podam.api.PodamFactoryImpl
-
- All Implemented Interfaces:
PodamFactory
@NotThreadSafe @Immutable public class PodamFactoryImpl extends Object implements PodamFactory
The PODAM factory implementation- Since:
- 1.0.0
- Author:
- mtedone
-
-
Field Summary
Fields Modifier and Type Field Description private ClassInfoStrategyclassInfoStrategyThe strategy to use to introspect data.private PodamFactoryexternalFactoryExternal factory to delegate production this factory cannot handleprivate static org.slf4j.LoggerLOGApplication loggerprivate static StringMAP_CREATION_EXCEPTION_STRprivate static StringRESOLVING_COLLECTION_EXCEPTION_STRprivate DataProviderStrategystrategyThe strategy to use to fill data.
-
Constructor Summary
Constructors Constructor Description PodamFactoryImpl()Default constructor.PodamFactoryImpl(DataProviderStrategy strategy)Constructor with non-default strategyPodamFactoryImpl(PodamFactory externalFactory)Constructor with non-default external factoryPodamFactoryImpl(PodamFactory externalFactory, DataProviderStrategy strategy)Full constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private <T> TdoManufacturePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Manufactures and populates the pojo classprivate voidfillArray(Object array, String attributeName, Class<?> elementType, Type genericElementType, List<Annotation> annotations, ManufacturingContext manufacturingCtx)It fills an Array with the required number of elements of the required type.private voidfillCollection(ManufacturingContext manufacturingCtx, List<Annotation> annotations, String attributeName, Collection<? super Object> collection, Class<?> collectionElementType, Type... genericTypeArgs)It fills a collection with the required number of elements of the required type.private voidfillMap(MapArguments mapArguments, ManufacturingContext manufacturingCtx)It fills a Map with the required number of elements of the required type.private Class<?>findInheretedCollectionElementType(Collection<Object> collection, ManufacturingContext manufacturingCtx, AtomicReference<Type[]> elementGenericTypeArgs, Type... genericTypeArgs)Tries to find collection element type from collection objectprivate MapArgumentsfindInheretedMapElementType(Map<Object,Object> map, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Finds key and element type argumentsClassInfoStrategygetClassStrategy()It returns the class info strategy for this factory.PodamFactorygetExternalFactory()It returns the external factory assigned to this factory.private ObjectgetMapKeyOrElementValue(MapKeyOrElementsArguments keyOrElementsArguments, ManufacturingContext manufacturingCtx)It fills a Map key or value with the appropriate value, considering attribute-level customisation.private Object[]getParameterValuesForConstructor(Constructor<?> constructor, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Given a constructor it manufactures and returns the parameter values required to invoke itprivate Object[]getParameterValuesForMethod(Method method, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Given a method it manufactures and returns the parameter values required to invoke itDataProviderStrategygetStrategy()It returns the strategy for this factory.private <T> TgetValueForAbstractType(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Type[] genericTypeArgs)Returns a value for an abstract type or interface if possible.private <T> TinstantiatePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)It creates and returns an instance of the given class if at least one of its constructors has been annotated withPodamConstructorprivate <T> TinstantiatePojoWithFactory(Class<?> factoryClass, Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)It attempts to create an instance of the given class with a static method of the factoryprivate ObjectmanufactureAttributeValue(Object pojo, ManufacturingContext manufacturingCtx, Class<?> attributeType, Type genericAttributeType, List<Annotation> annotations, String attributeName, Type... genericTypeArgs)It manufactures and returns the value for a POJO attribute.private ObjectmanufactureParameterValue(Class<?> pojoClass, String parameterName, Class<?> parameterType, Type genericType, List<Annotation> annotations, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Manufactures and returns the parameter value for method required to invoke it<T> TmanufacturePojo(Class<T> pojoClass, Type... genericTypeArgs)Generic method which returns an instance of the given class filled with dummy values, using the default data provider strategy.private <T> TmanufacturePojoInternal(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Generic method which returns an instance of the given class filled with values dictated by the strategy<T> TmanufacturePojoWithFullData(Class<T> pojoClass, Type... genericTypeArgs)Generic method which returns an instance of the given class filled with dummy values, using the default data provider strategy.<T> TpopulatePojo(T pojo, Type... genericTypeArgs)Generic method which populates an instance of the given class with dummy values, using the default data provider strategy.private <T> TpopulatePojoInternal(T pojo, List<Annotation> annotations, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Fills given class filled with values dictated by the strategyprivate <T> booleanpopulateReadOnlyField(T pojo, ClassAttribute attribute, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)Fills a field with a getterprivate <T> booleanpopulateReadWriteField(T pojo, ClassAttribute attribute, ManufacturingContext manufacturingCtx)Fills a field with a setterprivate ObjectresolveArrayElementValue(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata)It returns an Array with the first element setprivate Collection<? super Object>resolveCollectionValueWhenCollectionIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata)It returns a collection of some sort with some data in it.private Map<? super Object,? super Object>resolveMapValueWhenMapIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata)It manufactures and returns a Map with at least one element in itprivate <T> TresortToExternalFactory(ManufacturingContext manufacturingCtx, String msg, Class<T> pojoClass, Type... genericTypeArgs)Delegates POJO manufacturing to an external factoryPodamFactorysetClassStrategy(ClassInfoStrategy classInfoStrategy)Sets the class info strategy for this factoryPodamFactorysetExternalFactory(PodamFactory externalFactory)Sets an external factory for this factory to delegate requests it cannot processPodamFactorysetStrategy(DataProviderStrategy strategy)Sets the data provider strategy for this factory
-
-
-
Field Detail
-
RESOLVING_COLLECTION_EXCEPTION_STR
private static final String RESOLVING_COLLECTION_EXCEPTION_STR
- See Also:
- Constant Field Values
-
MAP_CREATION_EXCEPTION_STR
private static final String MAP_CREATION_EXCEPTION_STR
- See Also:
- Constant Field Values
-
LOG
private static final org.slf4j.Logger LOG
Application logger
-
externalFactory
private PodamFactory externalFactory
External factory to delegate production this factory cannot handleThe default is
NullExternalFactory.
-
strategy
private DataProviderStrategy strategy
The strategy to use to fill data.The default is
RandomDataProviderStrategyImpl.
-
classInfoStrategy
private ClassInfoStrategy classInfoStrategy
The strategy to use to introspect data.The default is
DefaultClassInfoStrategy.
-
-
Constructor Detail
-
PodamFactoryImpl
public PodamFactoryImpl()
Default constructor.
-
PodamFactoryImpl
public PodamFactoryImpl(DataProviderStrategy strategy)
Constructor with non-default strategy- Parameters:
strategy- The strategy to use to fill data
-
PodamFactoryImpl
public PodamFactoryImpl(PodamFactory externalFactory)
Constructor with non-default external factory- Parameters:
externalFactory- External factory to delegate production this factory cannot handle
-
PodamFactoryImpl
public PodamFactoryImpl(PodamFactory externalFactory, DataProviderStrategy strategy)
Full constructor.- Parameters:
externalFactory- External factory to delegate production this factory cannot handlestrategy- The strategy to use to fill data
-
-
Method Detail
-
manufacturePojoWithFullData
public <T> T manufacturePojoWithFullData(Class<T> pojoClass, Type... genericTypeArgs)
Generic method which returns an instance of the given class filled with dummy values, using the default data provider strategy. In order to instantiate class, constructor with the most parameters is used.This method uses
RandomDataProviderStrategyImplas the default implementation.- Specified by:
manufacturePojoWithFullDatain interfacePodamFactory- Type Parameters:
T- The type for which a filled instance is required- Parameters:
pojoClass- The name of the class for which an instance filled with values is requiredgenericTypeArgs- The generic Type arguments for a generic class instance- Returns:
- An instance of <T> filled with dummy values
-
manufacturePojo
public <T> T manufacturePojo(Class<T> pojoClass, Type... genericTypeArgs)
Generic method which returns an instance of the given class filled with dummy values, using the default data provider strategy.This method uses
RandomDataProviderStrategyImplas the default implementation.- Specified by:
manufacturePojoin interfacePodamFactory- Type Parameters:
T- The type for which a filled instance is required- Parameters:
pojoClass- The name of the class for which an instance filled with values is requiredgenericTypeArgs- The generic Type arguments for a generic class instance- Returns:
- An instance of <T> filled with dummy values
-
populatePojo
public <T> T populatePojo(T pojo, Type... genericTypeArgs)Generic method which populates an instance of the given class with dummy values, using the default data provider strategy.This method uses
RandomDataProviderStrategyImplas the default implementation.- Specified by:
populatePojoin interfacePodamFactory- Type Parameters:
T- The type for which a filled instance is required- Parameters:
pojo- The instance to be filled with valuesgenericTypeArgs- The generic Type arguments for a generic class instance- Returns:
- The same instance of object for chaining
-
getStrategy
public DataProviderStrategy getStrategy()
It returns the strategy for this factory.- Specified by:
getStrategyin interfacePodamFactory- Returns:
- the strategy
-
setStrategy
public PodamFactory setStrategy(DataProviderStrategy strategy)
Sets the data provider strategy for this factory- Specified by:
setStrategyin interfacePodamFactory- Parameters:
strategy- A data provider strategy to be used by this factory- Returns:
- instance of the factory for chaining
-
getClassStrategy
public ClassInfoStrategy getClassStrategy()
It returns the class info strategy for this factory.- Specified by:
getClassStrategyin interfacePodamFactory- Returns:
- the class info strategy for this factory
-
setClassStrategy
public PodamFactory setClassStrategy(ClassInfoStrategy classInfoStrategy)
Sets the class info strategy for this factory- Specified by:
setClassStrategyin interfacePodamFactory- Parameters:
classInfoStrategy- A class info strategy to be used by this factory- Returns:
- instance of the factory for chaining
-
getExternalFactory
public PodamFactory getExternalFactory()
It returns the external factory assigned to this factory.- Specified by:
getExternalFactoryin interfacePodamFactory- Returns:
- the strategy
-
setExternalFactory
public PodamFactory setExternalFactory(PodamFactory externalFactory)
Sets an external factory for this factory to delegate requests it cannot process- Specified by:
setExternalFactoryin interfacePodamFactory- Parameters:
externalFactory- An external factory to be used by this factory- Returns:
- instance of this factory for chaining
-
instantiatePojoWithFactory
private <T> T instantiatePojoWithFactory(Class<?> factoryClass, Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It attempts to create an instance of the given class with a static method of the factoryThis method attempts to instantiate POJO with a static method of provided factory, for example, getInstance().
- Type Parameters:
T- The type of Pojo class- Parameters:
factoryClass- The factory class, which will be used for POJO instantiationpojoClass- The name of the class for which an instance filled with valuesmanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- An instance of the given class
- Throws:
IllegalArgumentException- If an illegal argument was passed to the constructorInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
instantiatePojo
private <T> T instantiatePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws SecurityException
It creates and returns an instance of the given class if at least one of its constructors has been annotated withPodamConstructor- Type Parameters:
T- The type of the instance to return- Parameters:
pojoClass- The class of which an instance is requiredmanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- an instance of the given class if at least one of its
constructors has been annotated with
PodamConstructor - Throws:
SecurityException- If an security was violated
-
doManufacturePojo
private <T> T doManufacturePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)
Manufactures and populates the pojo class- Type Parameters:
T- The type of the instance to return- Parameters:
pojoClass- the class to instantiatemanufacturingCtx- the initialized manufacturing contextgenericTypeArgs- generic arguments for the pojo class- Returns:
- instance of @pojoClass or null in case it cannot be instantiated
-
manufacturePojoInternal
private <T> T manufacturePojoInternal(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
Generic method which returns an instance of the given class filled with values dictated by the strategy- Type Parameters:
T- The type for which a filled instance is required- Parameters:
pojoClass- The name of the class for which an instance filled with values is requiredpojoMetadata- attribute metadata for POJOs produced recursivelymanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- An instance of <T> filled with dummy values
- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If manufactured class cannot be loadedPodamMockeryException- if a problem occurred while creating a POJO instance or while setting its state
-
populatePojoInternal
private <T> T populatePojoInternal(T pojo, List<Annotation> annotations, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundExceptionFills given class filled with values dictated by the strategy- Type Parameters:
T- The type for which should be populated- Parameters:
pojo- An instance to be filled with dummy valuesannotations- a list of annotations attached to this POJO defined elsewheremanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- An instance of <T> filled with dummy values
- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If manufactured class cannot be loaded
-
populateReadOnlyField
private <T> boolean populateReadOnlyField(T pojo, ClassAttribute attribute, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundExceptionFills a field with a getter- Type Parameters:
T- The type for which should be populated- Parameters:
pojo- The POJO being filled with valuesattribute- a attribute we are fillingmanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- true, if attribute was found and populated
- Throws:
ClassNotFoundException- If class being manufactured cannot be loadedInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory method
-
populateReadWriteField
private <T> boolean populateReadWriteField(T pojo, ClassAttribute attribute, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundExceptionFills a field with a setter- Type Parameters:
T- The type for which should be populated- Parameters:
pojo- The POJO being filled with valuesattribute- a attribute we are fillingmanufacturingCtx- the manufacturing context- Returns:
- true, if attribute was found and populated
- Throws:
ClassNotFoundException- If class being manufactured cannot be loadedInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory method
-
manufactureAttributeValue
private Object manufactureAttributeValue(Object pojo, ManufacturingContext manufacturingCtx, Class<?> attributeType, Type genericAttributeType, List<Annotation> annotations, String attributeName, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It manufactures and returns the value for a POJO attribute.- Parameters:
pojo- The POJO being filled with valuesmanufacturingCtx- the manufacturing contextattributeType- The type of the attribute for which a value is being manufacturedgenericAttributeType- The generic type of the attribute for which a value is being manufacturedannotations- The annotations for the attribute being consideredattributeName- The attribute namegenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- The value for an attribute
- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodIllegalArgumentException-- If an illegal argument was passed
- If an invalid value was set for a precise value in an annotation and such value could not be converted to the desired type
ClassNotFoundException- If class being manufactured cannot be loaded
-
resortToExternalFactory
private <T> T resortToExternalFactory(ManufacturingContext manufacturingCtx, String msg, Class<T> pojoClass, Type... genericTypeArgs)
Delegates POJO manufacturing to an external factory- Type Parameters:
T- The type of the instance to return- Parameters:
manufacturingCtx- the manufacturing contextmsg- Message to log, must contain two parameterspojoClass- The class of which an instance is requiredgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- instance of POJO produced by external factory or null
-
resolveCollectionValueWhenCollectionIsPojoAttribute
private Collection<? super Object> resolveCollectionValueWhenCollectionIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata)
It returns a collection of some sort with some data in it.- Parameters:
pojo- The POJO being analyzedmanufacturingCtx- the manufacturing contextattributeMetadata- The attribute's metadata- Returns:
- a collection of some sort with some data in it
- Throws:
PodamMockeryException- An exception occurred while resolving the collectionIllegalArgumentException- If the field name is null or empty
-
findInheretedCollectionElementType
private Class<?> findInheretedCollectionElementType(Collection<Object> collection, ManufacturingContext manufacturingCtx, AtomicReference<Type[]> elementGenericTypeArgs, Type... genericTypeArgs)
Tries to find collection element type from collection object- Parameters:
collection- The collection to be filledmanufacturingCtx- the manufacturing contextelementGenericTypeArgs- parameter to return generic arguments of collection elementgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- class type of collection element
-
fillCollection
private void fillCollection(ManufacturingContext manufacturingCtx, List<Annotation> annotations, String attributeName, Collection<? super Object> collection, Class<?> collectionElementType, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It fills a collection with the required number of elements of the required type.This method has a so-called side effect. It updates the collection passed as argument.
- Parameters:
manufacturingCtx- the manufacturing contextannotations- The annotations for this attributeattributeName- The attribute name of collection in enclosing POJO classcollection- The Collection to be filledcollectionElementType- The type of the collection elementgenericTypeArgs- The generic type arguments for the current generic class instance- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
resolveMapValueWhenMapIsPojoAttribute
private Map<? super Object,? super Object> resolveMapValueWhenMapIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata)
It manufactures and returns a Map with at least one element in it- Parameters:
pojo- The POJO being initializedmanufacturingCtx- the manufacturing contextattributeMetadata- The attribute's metadata- Returns:
- Map with at least one element in it
- Throws:
IllegalArgumentException-- If the attribute name is null or empty
- If the array of types of the Map has length different from 2
PodamMockeryException- If an error occurred while creating the Map object
-
findInheretedMapElementType
private MapArguments findInheretedMapElementType(Map<Object,Object> map, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)
Finds key and element type arguments- Parameters:
map- The map being initializedmanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- Inherited map key and element types
-
fillMap
private void fillMap(MapArguments mapArguments, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It fills a Map with the required number of elements of the required type.This method has a so-called side-effect. It updates the Map given as argument.
- Parameters:
mapArguments- The arguments POJOmanufacturingCtx- Manufacturing context- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
getMapKeyOrElementValue
private Object getMapKeyOrElementValue(MapKeyOrElementsArguments keyOrElementsArguments, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It fills a Map key or value with the appropriate value, considering attribute-level customisation.- Parameters:
keyOrElementsArguments- The arguments POJOmanufacturingCtx- manufacturing context- Returns:
- A Map key or value
- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodIllegalArgumentException-- If an illegal argument was passed
- If an invalid value was set for a precise value in an annotation and such value could not be converted to the desired type
ClassNotFoundException- If manufactured class could not be loaded
-
fillArray
private void fillArray(Object array, String attributeName, Class<?> elementType, Type genericElementType, List<Annotation> annotations, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It fills an Array with the required number of elements of the required type.This method has a so-called side-effect. It updates the Map given as argument.
- Parameters:
array- The array POJOattributeName- The attribute name of collection in enclosing POJO classelementType- The generic type of the collection elementgenericElementType- The generic type of the collection elementannotations- The annotations for this attributemanufacturingCtx- Manufacturing context- Throws:
InstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
resolveArrayElementValue
private Object resolveArrayElementValue(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
It returns an Array with the first element set- Parameters:
pojo- POJO containing attributemanufacturingCtx- the manufacturing contextattributeMetadata- The attribute's metadata- Returns:
- Array with the first element set
- Throws:
IllegalArgumentException- If an illegal argument was passed to the constructorInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
getParameterValuesForConstructor
private Object[] getParameterValuesForConstructor(Constructor<?> constructor, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
Given a constructor it manufactures and returns the parameter values required to invoke it- Parameters:
constructor- The constructor for which parameter values are requiredpojoClass- The POJO class containing the constructormanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- The parameter values required to invoke the constructor
- Throws:
IllegalArgumentException- If an illegal argument was passed to the constructorInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
getParameterValuesForMethod
private Object[] getParameterValuesForMethod(Method method, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
Given a method it manufactures and returns the parameter values required to invoke it- Parameters:
method- The method for which parameter values are requiredpojoClass- The POJO class containing the constructormanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- The parameter values required to invoke the method
- Throws:
IllegalArgumentException- If an illegal argument was passed to the methodInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
manufactureParameterValue
private Object manufactureParameterValue(Class<?> pojoClass, String parameterName, Class<?> parameterType, Type genericType, List<Annotation> annotations, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
Manufactures and returns the parameter value for method required to invoke it- Parameters:
pojoClass- pojo classparameterName- name of parameterparameterType- type of parametergenericType- generic type of parameterannotations- parameter annotationsmanufacturingCtx- the manufacturing contextgenericTypeArgs- The generic type arguments for the current generic class instance- Returns:
- The parameter values required to invoke the constructor
- Throws:
IllegalArgumentException- If an illegal argument was passed to the constructorInstantiationException- If an exception occurred during instantiationIllegalAccessException- If security was violated while creating the objectInvocationTargetException- If an exception occurred while invoking the constructor or factory methodClassNotFoundException- If it was not possible to create a class from a string
-
getValueForAbstractType
private <T> T getValueForAbstractType(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Type[] genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
Returns a value for an abstract type or interface if possible.- Type Parameters:
T- The type of the value to be returned- Parameters:
pojoClass- The Pojo classpojoMetadata- The Pojo metadatamanufacturingCtx- The manufacturing contextgenericTypeArgs- The generic type arguments map- Returns:
- a value or null, if manufacturing didn't succeed
- Throws:
InstantiationException- If a problem occurred while instantiating the objectIllegalAccessException- If a problem occurred while instantiating the objectInvocationTargetException- If a problem occurred while instantiating the objectClassNotFoundException- If a problem occurred while instantiating the object
-
-