org.unitils.core.config
Class Configuration

java.lang.Object
  extended by org.unitils.core.config.UnitilsConfiguration
      extended by org.unitils.core.config.Configuration

public class Configuration
extends UnitilsConfiguration

todo javadoc

If classifiers are used, it will first look for a property using all classifiers, then look for a property without the last classifier etc. If still no property was found, it will look for the property without discriminators. E.g. suppose the property name is 'key' and there are 2 classifiers 'a' and 'b'. First it will look for a property with name 'key.a.b', if that doesn't exist it will look for 'key.a', and finally it will try 'key'.

Author:
Tim Ducheyne

Field Summary
protected  Properties overridingProperties
           
protected  Properties properties
           
 
Constructor Summary
Configuration(Properties properties)
          Creates a configuration for the given properties.
 
Method Summary
 Properties getAllProperties()
           
 Boolean getBoolean(String propertyName, String... classifiers)
          Gets the boolean value for the property with the given name.
 List<Boolean> getBooleanList(String propertyName, String... classifiers)
          Gets the list of comma separated boolean values for the property with the given name.
 Class<?> getClass(String propertyName, String... classifiers)
          Gets the class value for the property with the given name.
 List<Class<?>> getClassList(String propertyName, String... classifiers)
          Gets the list of comma separated class values for the property with the given name.
<T extends Enum<T>>
List<T>
getEnumList(Class<T> type, String propertyName, String... classifiers)
          Gets the list of comma separated enum values for the property with the given name.
<T extends Enum<T>>
T
getEnumValue(Class<T> type, String propertyName, String... classifiers)
          Gets the enum value for the property with the given name.
<T> T
getInstanceOf(Class<T> type, String... classifiers)
          Gets an instance of the given type (typically an interface).
<T> List<T>
getInstanceOfList(Class<T> type, String... classifiers)
          Gets the list of comma separated instances of the given type (typically an interface).
 Integer getInteger(String propertyName, String... classifiers)
          Gets the int value for the property with the given name.
 List<Integer> getIntegerList(String propertyName, String... classifiers)
          Gets the list of comma separated int values for the property with the given name.
 Long getLong(String propertyName, String... classifiers)
          Gets the long value for the property with the given name.
 List<Long> getLongList(String propertyName, String... classifiers)
          Gets the list of comma separated long values for the property with the given name.
 Boolean getOptionalBoolean(String propertyName, String... classifiers)
          Gets the boolean value for the property with the given name.
 List<Boolean> getOptionalBooleanList(String propertyName, String... classifiers)
          Gets the list of comma separated boolean values for the property with the given name.
 Class<?> getOptionalClass(String propertyName, String... classifiers)
          Gets the class value for the property with the given name.
 List<Class<?>> getOptionalClassList(String propertyName, String... classifiers)
          Gets the list of comma separated class values for the property with the given name.
<T extends Enum<T>>
List<T>
getOptionalEnumList(Class<T> type, String propertyName, String... classifiers)
          Gets the list of comma separated enum values for the property with the given name.
<T extends Enum<T>>
T
getOptionalEnumValue(Class<T> type, String propertyName, String... classifiers)
          Gets the enum value for the property with the given name.
<T> T
getOptionalInstanceOf(Class<T> type, String... classifiers)
          Gets an instance of the given type (typically an interface).
<T> List<T>
getOptionalInstanceOfList(Class<T> type, String... classifiers)
          Gets the list of comma separated instances of the given type (typically an interface).
 Integer getOptionalInteger(String propertyName, String... classifiers)
          Gets the int value for the property with the given name.
 List<Integer> getOptionalIntegerList(String propertyName, String... classifiers)
          Gets the list of comma separated int values for the property with the given name.
 Long getOptionalLong(String propertyName, String... classifiers)
          Gets the long value for the property with the given name.
 List<Long> getOptionalLongList(String propertyName, String... classifiers)
          Gets the list of comma separated long values for the property with the given name.
 String getOptionalString(String propertyName, String... classifiers)
          Gets the string value for the property with the given name.
 List<String> getOptionalStringList(String propertyName, String... classifiers)
          Gets the list of comma separated string values for the property with the given name.
<T> List<T>
getOptionalValueListOfType(Class<T> type, String propertyName, String... classifiers)
           
<T> T
getOptionalValueOfType(Class<T> type, String propertyName, String... classifiers)
           
 Properties getOverridingProperties()
           
protected  String getProperty(String propertyName)
           
 String getString(String propertyName, String... classifiers)
          Gets the string value for the property with the given name.
 List<String> getStringList(String propertyName, String... classifiers)
          Gets the list of comma separated string values for the property with the given name.
<T> List<T>
getValueListOfType(Class<T> type, String propertyName, String... classifiers)
           
<T> T
getValueOfType(Class<T> type, String propertyName, String... classifiers)
           
protected  String nameToString(String propertyName, String... classifiers)
           
 void setOverridingProperties(Properties overridingProperties)
           
protected  Boolean toBoolean(String value, String propertyName, String... classifiers)
           
protected  Class<?> toClass(String value, String propertyName, String[] classifiers)
           
protected
<T extends Enum<T>>
T
toEnum(Class<T> type, String value, String propertyName, String[] classifiers)
           
protected
<T> T
toInstance(Class<T> type, String value, String propertyName, String... classifiers)
           
protected
<T> T
toInstance(String value, String propertyName, String... classifiers)
           
protected  Integer toInteger(String value, String propertyName, String... classifiers)
           
protected  Long toLong(String value, String propertyName, String... classifiers)
           
protected  List<String> toStringList(String value)
           
protected
<T> T
toValueOfType(Class<T> type, String value, String propertyName, String... classifiers)
           
 
Methods inherited from class org.unitils.core.config.UnitilsConfiguration
containsProperty, getBoolean, getBoolean, getInstance, getInstance, getInt, getInt, getLong, getLong, getProperties, getString, getString, getStringList, getStringList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

properties

protected Properties properties

overridingProperties

protected Properties overridingProperties
Constructor Detail

Configuration

public Configuration(Properties properties)
Creates a configuration for the given properties.

Parameters:
properties - All configuration properties, not null
Method Detail

getOverridingProperties

public Properties getOverridingProperties()

setOverridingProperties

public void setOverridingProperties(Properties overridingProperties)

getAllProperties

public Properties getAllProperties()

getString

public String getString(String propertyName,
                        String... classifiers)
Gets the string value for the property with the given name. If no such property is found or the value is empty, an exception will be raised.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed string value, not null

getOptionalString

public String getOptionalString(String propertyName,
                                String... classifiers)
Gets the string value for the property with the given name. If no such property is found or the value is empty, null is returned.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed string value, null if not found

getStringList

public List<String> getStringList(String propertyName,
                                  String... classifiers)
Gets the list of comma separated string values for the property with the given name. If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed string list, not null

getOptionalStringList

public List<String> getOptionalStringList(String propertyName,
                                          String... classifiers)
Gets the list of comma separated string values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed string list, empty if not found

getBoolean

public Boolean getBoolean(String propertyName,
                          String... classifiers)
Gets the boolean value for the property with the given name. If no such property is found, the value is empty or not a boolean, an exception will be raised.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The boolean value, not null

getOptionalBoolean

public Boolean getOptionalBoolean(String propertyName,
                                  String... classifiers)
Gets the boolean value for the property with the given name. If no such property is found or the value is empty, null is returned. An exception will be raised if the value is not a boolean.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The boolean value, null if not found

getBooleanList

public List<Boolean> getBooleanList(String propertyName,
                                    String... classifiers)
Gets the list of comma separated boolean values for the property with the given name. If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The boolean list, not null

getOptionalBooleanList

public List<Boolean> getOptionalBooleanList(String propertyName,
                                            String... classifiers)
Gets the list of comma separated boolean values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The boolean list, empty if not found

getInteger

public Integer getInteger(String propertyName,
                          String... classifiers)
Gets the int value for the property with the given name. If no such property is found, the value is empty or cannot be converted to an int, an exception will be raised.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The int value

getOptionalInteger

public Integer getOptionalInteger(String propertyName,
                                  String... classifiers)
Gets the int value for the property with the given name. If no such property is found or the value is empty, null is returned. An exception will be raised if the value cannot be converted to an int.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The int value, null if not found

getIntegerList

public List<Integer> getIntegerList(String propertyName,
                                    String... classifiers)
Gets the list of comma separated int values for the property with the given name. If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The int list, not null

getOptionalIntegerList

public List<Integer> getOptionalIntegerList(String propertyName,
                                            String... classifiers)
Gets the list of comma separated int values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The int list, empty if not found

getLong

public Long getLong(String propertyName,
                    String... classifiers)
Gets the long value for the property with the given name. If no such property is found, the value is empty or cannot be converted to a long, an exception will be raised.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The long value, not null

getOptionalLong

public Long getOptionalLong(String propertyName,
                            String... classifiers)
Gets the long value for the property with the given name. If no such property is found or the value is empty, null is returned. An exception will be raised if the value cannot be converted to a long.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The long value, null if not found

getLongList

public List<Long> getLongList(String propertyName,
                              String... classifiers)
Gets the list of comma separated long values for the property with the given name. If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed long list, not null

getOptionalLongList

public List<Long> getOptionalLongList(String propertyName,
                                      String... classifiers)
Gets the list of comma separated long values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The long list, empty if not found

getClass

public Class<?> getClass(String propertyName,
                         String... classifiers)
Gets the class value for the property with the given name. If no such property is found, the value is empty or cannot be converted to a class, an exception will be raised.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The class value, not null

getOptionalClass

public Class<?> getOptionalClass(String propertyName,
                                 String... classifiers)
Gets the class value for the property with the given name. If no such property is found or the value is empty, null is returned. An exception will be raised if the value cannot be converted to a class.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The class value, null if not found

getClassList

public List<Class<?>> getClassList(String propertyName,
                                   String... classifiers)
Gets the list of comma separated class values for the property with the given name. If no such property is found, the value is empty or cannot be converted to a class, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The class list, not null

getOptionalClassList

public List<Class<?>> getOptionalClassList(String propertyName,
                                           String... classifiers)
Gets the list of comma separated class values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added. An exception will be raised if the value cannot be converted to a class.

Parameters:
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The class list, empty if not found

getInstanceOf

public <T> T getInstanceOf(Class<T> type,
                           String... classifiers)
Gets an instance of the given type (typically an interface). It will look for a property using the classname and classifiers and create an instance of the classname specified as value.
E.g. if you have following property:

org.package.Reader=org.package.MyReaderImpl

Calling getInstanceOf(Reader.class) will then return an instance of MyReaderImpl

Overrides:
getInstanceOf in class UnitilsConfiguration
Parameters:
type - The type of the instance
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The instance

getOptionalInstanceOf

public <T> T getOptionalInstanceOf(Class<T> type,
                                   String... classifiers)
Gets an instance of the given type (typically an interface). It will look for a property using the classname and classifiers and create an instance of the classname specified as value.
E.g. if you have following property:

org.package.Reader=org.package.MyReaderImpl

Calling getInstanceOf(Reader.class) will then return an instance of MyReaderImpl

Parameters:
type - The type of the instance
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The instance

getInstanceOfList

public <T> List<T> getInstanceOfList(Class<T> type,
                                     String... classifiers)
Gets the list of comma separated instances of the given type (typically an interface). It will look for a property using the classname and classifiers and create an instance of the classname specified as value.
E.g. if you have following property:

org.package.Reader=org.package.MyReaderImpl, org.package.OtherReaderImpl

Calling getInstanceOf(Reader.class) will then return an instance of MyReaderImpl and OtherReaderImpl

If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
type - The type of the instance
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The instance list, not null

getOptionalInstanceOfList

public <T> List<T> getOptionalInstanceOfList(Class<T> type,
                                             String... classifiers)
Gets the list of comma separated instances of the given type (typically an interface). It will look for a property using the classname and classifiers and create an instance of the classname specified as value.
E.g. if you have following property:

org.package.Reader=org.package.MyReaderImpl, org.package.OtherReaderImpl

Calling getInstanceOf(Reader.class) will then return an instance of MyReaderImpl and OtherReaderImpl

If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
type - The type of the instance
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The trimmed string list, empty if not found

getEnumValue

public <T extends Enum<T>> T getEnumValue(Class<T> type,
                                          String propertyName,
                                          String... classifiers)
Gets the enum value for the property with the given name. If no such property is found, the value is empty or cannot be converted to the given enum type, an exception will be raised.

Parameters:
type - The enum type, not null
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The enum value, not null

getOptionalEnumValue

public <T extends Enum<T>> T getOptionalEnumValue(Class<T> type,
                                                  String propertyName,
                                                  String... classifiers)
Gets the enum value for the property with the given name. If no such property is found or the value is empty, null is returned. An exception will be raised if the value cannot be converted to a the given enum type.

Parameters:
type - The enum type, not null
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The enum value, null if not found

getEnumList

public <T extends Enum<T>> List<T> getEnumList(Class<T> type,
                                               String propertyName,
                                               String... classifiers)
Gets the list of comma separated enum values for the property with the given name. If no such property is found or the value is empty, an exception will be raised. Empty elements (",,") will not be added.

Parameters:
type - The enum type, not null
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The enum list, not null

getOptionalEnumList

public <T extends Enum<T>> List<T> getOptionalEnumList(Class<T> type,
                                                       String propertyName,
                                                       String... classifiers)
Gets the list of comma separated enum values for the property with the given name. If no such property is found or the value is empty, an empty list is returned. Empty elements (",,") will not be added.

Parameters:
type - The enum type, not null
propertyName - The name, not null
classifiers - An optional list of classifiers for the property name (see class javadoc for more info)
Returns:
The enum list, empty if not found

getValueOfType

public <T> T getValueOfType(Class<T> type,
                            String propertyName,
                            String... classifiers)

getOptionalValueOfType

public <T> T getOptionalValueOfType(Class<T> type,
                                    String propertyName,
                                    String... classifiers)

getValueListOfType

public <T> List<T> getValueListOfType(Class<T> type,
                                      String propertyName,
                                      String... classifiers)

getOptionalValueListOfType

public <T> List<T> getOptionalValueListOfType(Class<T> type,
                                              String propertyName,
                                              String... classifiers)

nameToString

protected String nameToString(String propertyName,
                              String... classifiers)

getProperty

protected String getProperty(String propertyName)

toBoolean

protected Boolean toBoolean(String value,
                            String propertyName,
                            String... classifiers)

toInteger

protected Integer toInteger(String value,
                            String propertyName,
                            String... classifiers)

toLong

protected Long toLong(String value,
                      String propertyName,
                      String... classifiers)

toStringList

protected List<String> toStringList(String value)

toEnum

protected <T extends Enum<T>> T toEnum(Class<T> type,
                                       String value,
                                       String propertyName,
                                       String[] classifiers)

toInstance

protected <T> T toInstance(String value,
                           String propertyName,
                           String... classifiers)

toClass

protected Class<?> toClass(String value,
                           String propertyName,
                           String[] classifiers)

toInstance

protected <T> T toInstance(Class<T> type,
                           String value,
                           String propertyName,
                           String... classifiers)

toValueOfType

protected <T> T toValueOfType(Class<T> type,
                              String value,
                              String propertyName,
                              String... classifiers)


Copyright © 2014. All Rights Reserved.