@NotThreadSafe @Immutable public class PodamFactoryImpl extends Object implements PodamFactory
| Modifier and Type | Field and Description |
|---|---|
private ClassInfoStrategy |
classInfoStrategy
The strategy to use to introspect data.
|
private PodamFactory |
externalFactory
External factory to delegate production this factory cannot handle
|
private static org.slf4j.Logger |
LOG
Application logger
|
private static String |
MAP_CREATION_EXCEPTION_STR |
private static Map<String,Type> |
NULL_TYPE_ARGS_MAP
Empty type map
|
private static String |
RESOLVING_COLLECTION_EXCEPTION_STR |
private DataProviderStrategy |
strategy
The strategy to use to fill data.
|
| Constructor and Description |
|---|
PodamFactoryImpl()
Default constructor.
|
PodamFactoryImpl(DataProviderStrategy strategy)
Constructor with non-default strategy
|
PodamFactoryImpl(PodamFactory externalFactory)
Constructor with non-default external factory
|
PodamFactoryImpl(PodamFactory externalFactory,
DataProviderStrategy strategy)
Full constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private <T> T |
doManufacturePojo(Class<T> pojoClass,
ManufacturingContext manufacturingCtx,
Type... genericTypeArgs)
Manufactures and populates the pojo class
|
private void |
fillCollection(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 void |
fillMap(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,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
Tries to find collection element type from collection object
|
private MapArguments |
findInheretedMapElementType(Map<Object,Object> map,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
Finds key and element type arguments
|
ClassInfoStrategy |
getClassStrategy()
It returns the class info strategy for this factory.
|
PodamFactory |
getExternalFactory()
It returns the external factory assigned to this factory.
|
private Object |
getMapKeyOrElementValue(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,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
Given a constructor it manufactures and returns the parameter values
required to invoke it
|
private Object[] |
getParameterValuesForMethod(Method method,
Class<?> pojoClass,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
Given a method it manufactures and returns the parameter values
required to invoke it
|
DataProviderStrategy |
getStrategy()
It returns the strategy for this factory.
|
private <T> T |
getValueForAbstractType(Class<T> pojoClass,
AttributeMetadata pojoMetadata,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type[] genericTypeArgs)
Returns a value for an abstract type or interface if possible.
|
private <T> T |
instantiatePojo(Class<T> pojoClass,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It creates and returns an instance of the given class if at least one of
its constructors has been annotated with
PodamConstructor |
private <T> T |
instantiatePojoWithFactory(Class<?> factoryClass,
Class<T> pojoClass,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It attempts to create an instance of the given class with a static method
of the factory
|
private Object |
manufactureAttributeValue(Object pojo,
ManufacturingContext manufacturingCtx,
Class<?> attributeType,
Type genericAttributeType,
List<Annotation> annotations,
String attributeName,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It manufactures and returns the value for a POJO attribute.
|
private Object |
manufactureParameterValue(Class<?> pojoClass,
String parameterName,
Class<?> parameterType,
Type genericType,
List<Annotation> annotations,
Map<String,Type> typeArgsMap,
ManufacturingContext manufacturingCtx,
Type... genericTypeArgs)
Manufactures and returns the parameter value for method required to
invoke it
|
<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.
|
private <T> T |
manufacturePojoInternal(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> 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.
|
<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.
|
private <T> T |
populatePojoInternal(T pojo,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
Fills given class filled with values dictated by the strategy
|
private Object |
resolveArrayElementValue(Object pojo,
ManufacturingContext manufacturingCtx,
AttributeMetadata attributeMetadata,
Map<String,Type> typeArgsMap)
It returns an Array with the first element set
|
private Collection<? super Object> |
resolveCollectionValueWhenCollectionIsPojoAttribute(Object pojo,
ManufacturingContext manufacturingCtx,
AttributeMetadata attributeMetadata,
Map<String,Type> typeArgsMap)
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,
Map<String,Type> typeArgsMap)
It manufactures and returns a Map with at least one element in it
|
private <T> T |
resortToExternalFactory(ManufacturingContext manufacturingCtx,
String msg,
Class<T> pojoClass,
Type... genericTypeArgs)
Delegates POJO manufacturing to an external factory
|
PodamFactory |
setClassStrategy(ClassInfoStrategy classInfoStrategy)
Sets the class info strategy for this factory
|
PodamFactory |
setExternalFactory(PodamFactory externalFactory)
Sets an external factory for this factory to delegate requests it cannot
process
|
PodamFactory |
setStrategy(DataProviderStrategy strategy)
Sets the data provider strategy for this factory
|
private static final String RESOLVING_COLLECTION_EXCEPTION_STR
private static final String MAP_CREATION_EXCEPTION_STR
private static final org.slf4j.Logger LOG
private PodamFactory externalFactory
The default is NullExternalFactory.
private DataProviderStrategy strategy
The default is RandomDataProviderStrategyImpl.
private ClassInfoStrategy classInfoStrategy
The default is DefaultClassInfoStrategy.
public PodamFactoryImpl()
public PodamFactoryImpl(DataProviderStrategy strategy)
strategy - The strategy to use to fill datapublic PodamFactoryImpl(PodamFactory externalFactory)
externalFactory - External factory to delegate production this factory cannot
handlepublic PodamFactoryImpl(PodamFactory externalFactory, DataProviderStrategy strategy)
externalFactory - External factory to delegate production this factory cannot
handlestrategy - The strategy to use to fill datapublic <T> T manufacturePojoWithFullData(Class<T> pojoClass, Type... genericTypeArgs)
This method uses RandomDataProviderStrategyImpl as the default
implementation.
manufacturePojoWithFullData in interface PodamFactoryT - The type for which a filled instance is requiredpojoClass - The name of the class for which an instance filled with values
is requiredgenericTypeArgs - The generic Type arguments for a generic class instancepublic <T> T manufacturePojo(Class<T> pojoClass, Type... genericTypeArgs)
This method uses RandomDataProviderStrategyImpl as the default
implementation.
manufacturePojo in interface PodamFactoryT - The type for which a filled instance is requiredpojoClass - The name of the class for which an instance filled with values
is requiredgenericTypeArgs - The generic Type arguments for a generic class instancepublic <T> T populatePojo(T pojo,
Type... genericTypeArgs)
This method uses RandomDataProviderStrategyImpl as the default
implementation.
populatePojo in interface PodamFactoryT - The type for which a filled instance is requiredpojo - The instance to be filled with valuesgenericTypeArgs - The generic Type arguments for a generic class instancepublic DataProviderStrategy getStrategy()
getStrategy in interface PodamFactorypublic PodamFactory setStrategy(DataProviderStrategy strategy)
setStrategy in interface PodamFactorystrategy - A data provider strategy to be used by this factorypublic ClassInfoStrategy getClassStrategy()
getClassStrategy in interface PodamFactorypublic PodamFactory setClassStrategy(ClassInfoStrategy classInfoStrategy)
setClassStrategy in interface PodamFactoryclassInfoStrategy - A class info strategy to be used by this factorypublic PodamFactory getExternalFactory()
getExternalFactory in interface PodamFactorypublic PodamFactory setExternalFactory(PodamFactory externalFactory)
setExternalFactory in interface PodamFactoryexternalFactory - An external factory to be used by this factoryprivate <T> T instantiatePojoWithFactory(Class<?> factoryClass, Class<T> pojoClass, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method attempts to instantiate POJO with a static method of provided factory, for example, getInstance().
T - The type of Pojo classfactoryClass - The factory class, which will be used for POJO instantiationpojoClass - The name of the class for which an instance filled with valuesmanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceIllegalArgumentException - 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 stringprivate <T> T instantiatePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws SecurityException
PodamConstructorT - The type of the instance to returnpojoClass - The class of which an instance is requiredmanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instancePodamConstructorSecurityException - If an security was violatedprivate <T> T doManufacturePojo(Class<T> pojoClass, ManufacturingContext manufacturingCtx, Type... genericTypeArgs)
T - The type of the instance to returnpojoClass - the class to instantiatemanufacturingCtx - the initialized manufacturing contextgenericTypeArgs - generic arguments for the pojo classprivate <T> T manufacturePojoInternal(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
T - The type for which a filled instance is requiredpojoClass - 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
instanceInstantiationException - 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 stateprivate <T> T populatePojoInternal(T pojo,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
throws InstantiationException,
IllegalAccessException,
InvocationTargetException,
ClassNotFoundException
T - The type for which should be populatedpojo - An instance to be filled with dummy valuesmanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceInstantiationException - 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 loadedprivate Object manufactureAttributeValue(Object pojo, ManufacturingContext manufacturingCtx, Class<?> attributeType, Type genericAttributeType, List<Annotation> annotations, String attributeName, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
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 nametypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceInstantiationException - 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 - ClassNotFoundException - If class being manufactured cannot be loadedprivate <T> T resortToExternalFactory(ManufacturingContext manufacturingCtx, String msg, Class<T> pojoClass, Type... genericTypeArgs)
T - The type of the instance to returnmanufacturingCtx - 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
instanceprivate Collection<? super Object> resolveCollectionValueWhenCollectionIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata, Map<String,Type> typeArgsMap)
pojo - The POJO being analyzedmanufacturingCtx - the manufacturing contextattributeMetadata - The attribute's metadatatypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesPodamMockeryException - An exception occurred while resolving the collectionIllegalArgumentException - If the field name is null or emptyprivate Class<?> findInheretedCollectionElementType(Collection<Object> collection, ManufacturingContext manufacturingCtx, AtomicReference<Type[]> elementGenericTypeArgs, Map<String,Type> typeArgsMap, Type... genericTypeArgs)
collection - The collection to be filledmanufacturingCtx - the manufacturing contextelementGenericTypeArgs - parameter to return generic arguments of collection elementtypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceprivate void fillCollection(ManufacturingContext manufacturingCtx, List<Annotation> annotations, String attributeName, Collection<? super Object> collection, Class<?> collectionElementType, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method has a so-called side effect. It updates the collection passed as argument.
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
instanceInstantiationException - 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 stringprivate Map<? super Object,? super Object> resolveMapValueWhenMapIsPojoAttribute(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata, Map<String,Type> typeArgsMap)
pojo - The POJO being initializedmanufacturingCtx - the manufacturing contextattributeMetadata - The attribute's metadatatypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesIllegalArgumentException - PodamMockeryException - If an error occurred while creating the Map objectprivate MapArguments findInheretedMapElementType(Map<Object,Object> map, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs)
map - The map being initializedmanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceprivate void fillMap(MapArguments mapArguments, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method has a so-called side-effect. It updates the Map given as argument.
mapArguments - The arguments POJOmanufacturingCtx - Manufacturing contextInstantiationException - 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 stringprivate Object getMapKeyOrElementValue(MapKeyOrElementsArguments keyOrElementsArguments, ManufacturingContext manufacturingCtx) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
keyOrElementsArguments - The arguments POJOmanufacturingCtx - manufacturing contextInstantiationException - 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 - ClassNotFoundException - If manufactured class could not be loadedprivate Object resolveArrayElementValue(Object pojo, ManufacturingContext manufacturingCtx, AttributeMetadata attributeMetadata, Map<String,Type> typeArgsMap) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
pojo - POJO containing attributemanufacturingCtx - the manufacturing contextattributeMetadata - The attribute's metadatatypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesIllegalArgumentException - 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 stringprivate Object[] getParameterValuesForConstructor(Constructor<?> constructor, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
constructor - The constructor for which parameter values are requiredpojoClass - The POJO class containing the constructormanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceIllegalArgumentException - 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 stringprivate Object[] getParameterValuesForMethod(Method method, Class<?> pojoClass, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
method - The method for which parameter values are requiredpojoClass - The POJO class containing the constructormanufacturingCtx - the manufacturing contexttypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instanceIllegalArgumentException - 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 stringprivate Object manufactureParameterValue(Class<?> pojoClass, String parameterName, Class<?> parameterType, Type genericType, List<Annotation> annotations, Map<String,Type> typeArgsMap, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
pojoClass - pojo classparameterName - name of parameterparameterType - type of parametergenericType - generic type of parameterannotations - parameter annotationstypeArgsMap - map for resolving generic typesmanufacturingCtx - the manufacturing contextgenericTypeArgs - The generic type arguments for the current generic class
instanceIllegalArgumentException - 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 stringprivate <T> T getValueForAbstractType(Class<T> pojoClass, AttributeMetadata pojoMetadata, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type[] genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
T - The type of the value to be returnedpojoClass - The Pojo classpojoMetadata - The Pojo metadatamanufacturingCtx - The manufacturing contextgenericTypeArgs - The generic type arguments maptypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesInstantiationException - 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 objectCopyright © 2016. All rights reserved.