org.unitils.util
Class ModuleUtils

java.lang.Object
  extended by org.unitils.util.ModuleUtils

public class ModuleUtils
extends Object

Class containing utility methods for module specific configuration. Contains a method for retrieving all annotation property defaults (getAnnotationPropertyDefaults(Class,java.util.Properties,Class[]) ). The object that this method returns can later be used to get replace the default placeholder of an annotation property for the default value as configured in the unitils configuration.

Author:
Tim Ducheyne, Filip Neven

Field Summary
static String DEFAULT_ENUM_VALUE_NAME
          The default name of the default enum value.
 
Constructor Summary
ModuleUtils()
           
 
Method Summary
static String getAnnotationPropertyDefault(Class<? extends Module> moduleClass, Class<? extends Annotation> annotationClass, String name, Properties configuration)
          Returns the default for annotation property of the given annotation with the given name for the given moduleclass.
static Map<Class<? extends Annotation>,Map<String,String>> getAnnotationPropertyDefaults(Class<? extends Module> moduleClass, Properties configuration, Class<? extends Annotation>... annotationClasses)
          Returns an object that represents the default values for the properties of the given annotations and the given module.
static Class<?> getClassValueReplaceDefault(Class<? extends Annotation> annotation, String annotationPropertyName, Class<?> value, Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues, Class<?> defaultValueClass)
          Replaces default enum value with the given default enum value.
static
<T extends Enum<?>>
T
getEnumValueReplaceDefault(Class<? extends Annotation> annotation, String annotationPropertyName, T enumValue, Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues)
          Replaces default enum value with the given default enum value.
static
<T extends Enum<?>>
T
getEnumValueReplaceDefault(Class<? extends Annotation> annotation, String annotationPropertyName, T enumValue, Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues, String defaultValueName)
          Replaces default enum value with the given default enum value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENUM_VALUE_NAME

public static final String DEFAULT_ENUM_VALUE_NAME
The default name of the default enum value.

See Also:
Constant Field Values
Constructor Detail

ModuleUtils

public ModuleUtils()
Method Detail

getAnnotationPropertyDefaults

public static Map<Class<? extends Annotation>,Map<String,String>> getAnnotationPropertyDefaults(Class<? extends Module> moduleClass,
                                                                                                Properties configuration,
                                                                                                Class<? extends Annotation>... annotationClasses)
Returns an object that represents the default values for the properties of the given annotations and the given module.

Parameters:
moduleClass - The class of the module for which we want the default annotation property values
configuration - The unitils configuration
annotationClasses - The annotations for which we want the default values
Returns:
An object that returns the annotation property default values

getAnnotationPropertyDefault

public static String getAnnotationPropertyDefault(Class<? extends Module> moduleClass,
                                                  Class<? extends Annotation> annotationClass,
                                                  String name,
                                                  Properties configuration)
Returns the default for annotation property of the given annotation with the given name for the given moduleclass.

Parameters:
moduleClass - The module class, not null
annotationClass - The annotation class, not null
name - The property suffix, not null
configuration - The unitils config, not null
Returns:
the default value

getEnumValueReplaceDefault

public static <T extends Enum<?>> T getEnumValueReplaceDefault(Class<? extends Annotation> annotation,
                                                               String annotationPropertyName,
                                                               T enumValue,
                                                               Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues)
Replaces default enum value with the given default enum value. If enumValue contains the value DEFAULT_ENUM_VALUE_NAME the defaultValue will be returned otherwise the enumValue itself will be returned.

Parameters:
annotation - the annotation, not null
annotationPropertyName - the name of the annotation property
enumValue - the value to check, not null
allDefaultValues - the map with values to return in case of a default, not null
Returns:
the enumValue or the defaultValue in case of a default

getEnumValueReplaceDefault

public static <T extends Enum<?>> T getEnumValueReplaceDefault(Class<? extends Annotation> annotation,
                                                               String annotationPropertyName,
                                                               T enumValue,
                                                               Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues,
                                                               String defaultValueName)
Replaces default enum value with the given default enum value. If enumValue contains the value DEFAULT_ENUM_VALUE_NAME the defaultValue will be returned otherwise the enumValue itself will be returned.

Parameters:
annotation - the annotation, not null
annotationPropertyName - the name of the annotation property
enumValue - the value to check, not null
allDefaultValues - the map with values to return in case of a default, not null
defaultValueName - the name of the default value
Returns:
the enumValue or the defaultValue in case of a default

getClassValueReplaceDefault

public static Class<?> getClassValueReplaceDefault(Class<? extends Annotation> annotation,
                                                   String annotationPropertyName,
                                                   Class<?> value,
                                                   Map<Class<? extends Annotation>,Map<String,String>> allDefaultValues,
                                                   Class<?> defaultValueClass)
Replaces default enum value with the given default enum value. If enumValue contains the value DEFAULT_ENUM_VALUE_NAME the defaultValue will be returned otherwise the enumValue itself will be returned.

Parameters:
annotation - the annotation, not null
annotationPropertyName - the name of the annotation property
value - the value to check, not null
allDefaultValues - the map with values to return in case of a default, not null
defaultValueClass - the name of the default value
Returns:
the enumValue or the defaultValue in case of a default


Copyright © 2011. All Rights Reserved.