Class DescriptorUtil
- java.lang.Object
-
- com.rapiddweller.benerator.factory.DescriptorUtil
-
public class DescriptorUtil extends java.lang.Object
Utility class for parsing and combining descriptor settings.
Created at 31.12.2008 09:28:28- Since:
- 0.5.7
- Author:
- Volker Bergmann
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
convertType(java.lang.Object sourceValue, SimpleTypeDescriptor targetType)
Convert type object.static Generator<?>
createConvertingGenerator(TypeDescriptor descriptor, Generator<?> generator, BeneratorContext context)
Create converting generator generator.static Generator<java.lang.Long>
createDynamicCountGenerator(InstanceDescriptor descriptor, java.lang.Long defaultMin, java.lang.Long defaultMax, boolean resetToMin, BeneratorContext context)
Create dynamic count generator generator.static Generator<?>
createNullQuotaOneGenerator(InstanceDescriptor descriptor, BeneratorContext context)
Create null quota one generator generator.static com.rapiddweller.common.Converter<java.lang.String,java.lang.String>
createStringScriptConverter(BeneratorContext context)
Create string script converter converter.static TypeDescriptor
deriveType(java.lang.String name, TypeDescriptor parentType)
Derive type type descriptor.static com.rapiddweller.common.Converter
getConverter(java.lang.String converterSpec, BeneratorContext context)
Gets converter.static com.rapiddweller.script.Expression<java.lang.Long>
getCount(InstanceDescriptor descriptor)
Calculates the 'count' value.static com.rapiddweller.script.Expression<java.lang.Long>
getCountGranularity(InstanceDescriptor descriptor)
Gets count granularity.static Generator<?>
getGeneratorByName(TypeDescriptor descriptor, BeneratorContext context)
Gets generator by name.static com.rapiddweller.script.Expression<java.lang.Long>
getMaxCount(InstanceDescriptor descriptor, java.lang.Long defaultMax)
Gets max count.protected static java.lang.Integer
getMaxLength(SimpleTypeDescriptor descriptor, DefaultsProvider defaultsProvider)
Gets max length.static com.rapiddweller.script.Expression<java.lang.Long>
getMinCount(InstanceDescriptor descriptor)
Gets min count.static com.rapiddweller.script.Expression<java.lang.Long>
getMinCount(InstanceDescriptor descriptor, java.lang.Long defaultMin)
Gets min count.protected static java.lang.Integer
getMinLength(SimpleTypeDescriptor descriptor)
Gets min length.static <T extends java.lang.Number>
TgetNumberDetail(SimpleTypeDescriptor descriptor, java.lang.String detailName, java.lang.Class<T> targetType)
Gets number detail.protected static int
getOffset(TypeDescriptor descriptor)
Gets offset.static java.text.DateFormat
getPatternAsDateFormat(TypeDescriptor descriptor)
Gets pattern as date format.static char
getSeparator(TypeDescriptor descriptor, BeneratorContext context)
Gets separator.static Uniqueness
getUniqueness(InstanceDescriptor descriptor, BeneratorContext context)
Gets uniqueness.static com.rapiddweller.common.Validator
getValidator(java.lang.String validatorSpec, BeneratorContext context)
Gets validator.static boolean
isNullable(InstanceDescriptor descriptor, BeneratorContext context)
Is nullable boolean.static boolean
isUnique(InstanceDescriptor descriptor, BeneratorContext context)
Is unique boolean.static boolean
isWrappedSimpleType(ComplexTypeDescriptor complexType)
Is wrapped simple type boolean.static void
parseComponentConfig(org.w3c.dom.Element element, TypeDescriptor type, BeneratorContext context)
Parse component config.static <T> Generator<T>
processCyclic(Generator<T> generator, TypeDescriptor descriptor)
Process cyclic generator.static <T> Generator<T>
processOffset(Generator<T> generator, TypeDescriptor descriptor)
Process offset generator.static boolean
shouldNullifyEachNullable(InstanceDescriptor descriptor, BeneratorContext context)
Should nullify each nullable boolean.protected static <T> Generator<T>
wrapWithProxy(Generator<T> generator, TypeDescriptor descriptor)
Wrap with proxy generator.
-
-
-
Method Detail
-
convertType
public static java.lang.Object convertType(java.lang.Object sourceValue, SimpleTypeDescriptor targetType)
Convert type object.- Parameters:
sourceValue
- the source valuetargetType
- the target type- Returns:
- the object
-
isWrappedSimpleType
public static boolean isWrappedSimpleType(ComplexTypeDescriptor complexType)
Is wrapped simple type boolean.- Parameters:
complexType
- the complex type- Returns:
- the boolean
-
createConvertingGenerator
public static Generator<?> createConvertingGenerator(TypeDescriptor descriptor, Generator<?> generator, BeneratorContext context)
Create converting generator generator.- Parameters:
descriptor
- the descriptorgenerator
- the generatorcontext
- the context- Returns:
- the generator
-
getGeneratorByName
public static Generator<?> getGeneratorByName(TypeDescriptor descriptor, BeneratorContext context)
Gets generator by name.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the generator by name
-
getValidator
public static com.rapiddweller.common.Validator getValidator(java.lang.String validatorSpec, BeneratorContext context)
Gets validator.- Parameters:
validatorSpec
- the validator speccontext
- the context- Returns:
- the validator
-
getConverter
public static com.rapiddweller.common.Converter getConverter(java.lang.String converterSpec, BeneratorContext context)
Gets converter.- Parameters:
converterSpec
- the converter speccontext
- the context- Returns:
- the converter
-
getPatternAsDateFormat
public static java.text.DateFormat getPatternAsDateFormat(TypeDescriptor descriptor)
Gets pattern as date format.- Parameters:
descriptor
- the descriptor- Returns:
- the pattern as date format
-
getUniqueness
public static Uniqueness getUniqueness(InstanceDescriptor descriptor, BeneratorContext context)
Gets uniqueness.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the uniqueness
-
isUnique
public static boolean isUnique(InstanceDescriptor descriptor, BeneratorContext context)
Is unique boolean.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the boolean
-
getSeparator
public static char getSeparator(TypeDescriptor descriptor, BeneratorContext context)
Gets separator.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the separator
-
getCount
public static com.rapiddweller.script.Expression<java.lang.Long> getCount(InstanceDescriptor descriptor)
Calculates the 'count' value.- Parameters:
descriptor
- the descriptor- Returns:
- the 'count' value. If a global 'maxCount' was set too, it returns the minimum of 'count' and 'maxCount'. If no 'count' value was specified, it returns null.
-
getMinCount
public static com.rapiddweller.script.Expression<java.lang.Long> getMinCount(InstanceDescriptor descriptor)
Gets min count.- Parameters:
descriptor
- the descriptor- Returns:
- the min count
-
getMinCount
public static com.rapiddweller.script.Expression<java.lang.Long> getMinCount(InstanceDescriptor descriptor, java.lang.Long defaultMin)
Gets min count.- Parameters:
descriptor
- the descriptordefaultMin
- the default min- Returns:
- the min count
-
getMaxCount
public static com.rapiddweller.script.Expression<java.lang.Long> getMaxCount(InstanceDescriptor descriptor, java.lang.Long defaultMax)
Gets max count.- Parameters:
descriptor
- the descriptordefaultMax
- the default max- Returns:
- the max count
-
getCountGranularity
public static com.rapiddweller.script.Expression<java.lang.Long> getCountGranularity(InstanceDescriptor descriptor)
Gets count granularity.- Parameters:
descriptor
- the descriptor- Returns:
- the count granularity
-
createStringScriptConverter
public static com.rapiddweller.common.Converter<java.lang.String,java.lang.String> createStringScriptConverter(BeneratorContext context)
Create string script converter converter.- Parameters:
context
- the context- Returns:
- the converter
-
createDynamicCountGenerator
public static Generator<java.lang.Long> createDynamicCountGenerator(InstanceDescriptor descriptor, java.lang.Long defaultMin, java.lang.Long defaultMax, boolean resetToMin, BeneratorContext context)
Create dynamic count generator generator.- Parameters:
descriptor
- the descriptordefaultMin
- the default mindefaultMax
- the default maxresetToMin
- the reset to mincontext
- the context- Returns:
- the generator
-
getNumberDetail
public static <T extends java.lang.Number> T getNumberDetail(SimpleTypeDescriptor descriptor, java.lang.String detailName, java.lang.Class<T> targetType)
Gets number detail.- Type Parameters:
T
- the type parameter- Parameters:
descriptor
- the descriptordetailName
- the detail nametargetType
- the target type- Returns:
- the number detail
-
parseComponentConfig
public static void parseComponentConfig(org.w3c.dom.Element element, TypeDescriptor type, BeneratorContext context)
Parse component config.- Parameters:
element
- the elementtype
- the typecontext
- the context
-
isNullable
public static boolean isNullable(InstanceDescriptor descriptor, BeneratorContext context)
Is nullable boolean.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the boolean
-
shouldNullifyEachNullable
public static boolean shouldNullifyEachNullable(InstanceDescriptor descriptor, BeneratorContext context)
Should nullify each nullable boolean.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the boolean
-
wrapWithProxy
protected static <T> Generator<T> wrapWithProxy(Generator<T> generator, TypeDescriptor descriptor)
Wrap with proxy generator.- Type Parameters:
T
- the type parameter- Parameters:
generator
- the generatordescriptor
- the descriptor- Returns:
- the generator
-
processCyclic
public static <T> Generator<T> processCyclic(Generator<T> generator, TypeDescriptor descriptor)
Process cyclic generator.- Type Parameters:
T
- the type parameter- Parameters:
generator
- the generatordescriptor
- the descriptor- Returns:
- the generator
-
processOffset
public static <T> Generator<T> processOffset(Generator<T> generator, TypeDescriptor descriptor)
Process offset generator.- Type Parameters:
T
- the type parameter- Parameters:
generator
- the generatordescriptor
- the descriptor- Returns:
- the generator
-
getOffset
protected static int getOffset(TypeDescriptor descriptor)
Gets offset.- Parameters:
descriptor
- the descriptor- Returns:
- the offset
-
getMinLength
protected static java.lang.Integer getMinLength(SimpleTypeDescriptor descriptor)
Gets min length.- Parameters:
descriptor
- the descriptor- Returns:
- the min length
-
getMaxLength
protected static java.lang.Integer getMaxLength(SimpleTypeDescriptor descriptor, DefaultsProvider defaultsProvider)
Gets max length.- Parameters:
descriptor
- the descriptordefaultsProvider
- the defaults provider- Returns:
- the max length
-
createNullQuotaOneGenerator
public static Generator<?> createNullQuotaOneGenerator(InstanceDescriptor descriptor, BeneratorContext context)
Create null quota one generator generator.- Parameters:
descriptor
- the descriptorcontext
- the context- Returns:
- the generator
-
deriveType
public static TypeDescriptor deriveType(java.lang.String name, TypeDescriptor parentType)
Derive type type descriptor.- Parameters:
name
- the nameparentType
- the parent type- Returns:
- the type descriptor
-
-