@NotThreadSafe @Immutable public class PodamFactoryImpl extends Object implements PodamFactory
| Modifier and Type | Field and Description |
|---|---|
private org.springframework.context.support.AbstractApplicationContext |
applicationContext |
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 org.springframework.messaging.MessageChannel |
messageChannel
The message channel where to send/receive the type request
|
private static String |
RESOLVING_COLLECTION_EXCEPTION_STR |
private DataProviderStrategy |
strategy
The strategy to use to fill data.
|
private static String |
UNCHECKED_STR |
| 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 void |
fillCollection(Collection<? super Object> collection,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It fills a collection with the required number of elements of the
required type.
|
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(Map<? super Object,? super Object> map,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It fills a Map 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.
|
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,
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 Object |
instantiatePojoWithoutConstructors(Class<?> pojoClass,
ManufacturingContext manufacturingCtx,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It attempts to create an instance of the given class
|
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,
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(Class<?> attributeType,
Type genericType,
String attributeName,
ManufacturingContext manufacturingCtx,
List<Annotation> annotations,
Object pojo,
Map<String,Type> typeArgsMap)
It returns an Array with the first element set
|
private Collection<? super Object> |
resolveCollectionValueWhenCollectionIsPojoAttribute(Object pojo,
ManufacturingContext manufacturingCtx,
Class<?> collectionType,
String attributeName,
List<Annotation> annotations,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
It returns a collection of some sort with some data in it.
|
private Map<? super Object,? super Object> |
resolveMapValueWhenMapIsPojoAttribute(Object pojo,
ManufacturingContext manufacturingCtx,
Class<?> attributeType,
String attributeName,
List<Annotation> annotations,
Map<String,Type> typeArgsMap,
Type... genericTypeArgs)
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 String UNCHECKED_STR
private static org.springframework.messaging.MessageChannel messageChannel
private static final org.slf4j.Logger LOG
private org.springframework.context.support.AbstractApplicationContext applicationContext
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 Object instantiatePojoWithoutConstructors(Class<?> pojoClass, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method attempts to create an instance of the given argument for classes without setters. These may be either immutable classes (e.g. with final attributes and no setters) or Java classes (e.g. belonging to the java / javax namespace). In case the class does not provide a public, no-arg constructor (e.g. Calendar), this method attempts to find a , no-args, factory method (e.g. getInstance()) and it invokes it
pojoClass - The name of the class for which an instance filled with values
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
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 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, org.springframework.messaging.MessageHandlingException
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 methodClassNotFoundException - If it was not possible to create a class from a stringIllegalArgumentException - org.springframework.messaging.MessageHandlingException - If there was a problem handling the messageprivate <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, Class<?> collectionType, String attributeName, List<Annotation> annotations, Map<String,Type> typeArgsMap, Type... genericTypeArgs)
pojo - The POJO being analyzedmanufacturingCtx - the manufacturing contextcollectionType - The type of the attribute being evaluatedannotations - The set of annotations for the annotated attribute. It might
be emptyattributeName - The name of the field being settypeArgsMap - a map relating the generic class arguments ("<T, V>" for
example) with their actual typesgenericTypeArgs - The generic type arguments for the current generic class
instancePodamMockeryException - An exception occurred while resolving the collectionIllegalArgumentException - If the field name is null or emptyprivate void fillCollection(Collection<? super Object> collection, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method has a so-called side effect. It updates the collection passed as argument.
collection - The Collection to be filledmanufacturingCtx - 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 it was not possible to create a class from a stringprivate 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, Class<?> attributeType, String attributeName, List<Annotation> annotations, Map<String,Type> typeArgsMap, Type... genericTypeArgs)
pojo - The POJO being initializedmanufacturingCtx - the manufacturing contextattributeType - The type of the POJO map attributeattributeName - The POJO attribute nameannotations - The annotations specified for this attributetypeArgsMap - 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 - PodamMockeryException - If an error occurred while creating the Map objectprivate void fillMap(Map<? super Object,? super Object> map, ManufacturingContext manufacturingCtx, Map<String,Type> typeArgsMap, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
This method has a so-called side-effect. It updates the Map given as argument.
map - The map being initialisedmanufacturingCtx - 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 it was not possible to create a class from a stringprivate 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(Class<?> attributeType, Type genericType, String attributeName, ManufacturingContext manufacturingCtx, List<Annotation> annotations, Object pojo, Map<String,Type> typeArgsMap) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
attributeType - The array typegenericType - The array generic typeattributeName - The array attribute name in enclosing POJO classmanufacturingCtx - the manufacturing contextannotations - The annotations to be consideredpojo - POJO containing attributetypeArgsMap - 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, Class<?> parameterType, Type genericType, List<Annotation> annotations, Map<String,Type> typeArgsMap, ManufacturingContext manufacturingCtx, Type... genericTypeArgs) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException
pojoClass - pojo classparameterType - 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, 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 mapInstantiationException - 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 © 2015. All rights reserved.