org.syphr.prom
Class PropertiesManagers

java.lang.Object
  extended by org.syphr.prom.PropertiesManagers

public class PropertiesManagers
extends Object

This class provides builder methods to construct managers with various options.

Author:
Gregory P. Moyer

Method Summary
static
<T extends Enum<T> & Defaultable>
Properties
getDefaultProperties(Class<T> keyType, Translator<T> translator)
          Retrieve a Properties instance that contains all of the default values defined for the given Defaultable.
static
<T extends Enum<T>>
Translator<T>
getEnumTranslator(Class<T> enumType)
          Get a simple translator to convert back and forth between Enums and property names (keys).
static Translator<String> getIdentityTranslator()
          Create a translator that returns the string that it is given (no translation).
static Properties getProperties(File file)
          Load values from a file.
static Properties getProperties(URL url)
          Load values from a URL.
static
<T extends Enum<T> & Defaultable>
PropertiesManager<T>
newManager(File file, Class<T> keyType)
          Build a new manager for the given properties file.
static
<T extends Enum<T> & Defaultable>
PropertiesManager<T>
newManager(File file, Class<T> keyType, Evaluator evaluator, ExecutorService executor)
          Build a new manager for the given properties file.
static
<T extends Enum<T> & Defaultable>
PropertiesManager<T>
newManager(File file, Class<T> keyType, ExecutorService executor)
          Build a new manager for the given properties file.
static
<T extends Enum<T> & Defaultable>
PropertiesManager<T>
newManager(File file, Class<T> keyType, Translator<T> translator, ExecutorService executor)
          Build a new manager for the given properties file.
static
<T extends Enum<T>>
PropertiesManager<T>
newManager(File file, File defaultFile, Class<T> keyType)
          Build a new manager for the given properties file.
static
<T extends Enum<T>>
PropertiesManager<T>
newManager(File file, File defaultFile, Class<T> keyType, ExecutorService executor)
          Build a new manager for the given properties file.
static
<T extends Enum<T>>
PropertiesManager<T>
newManager(File file, URL defaultFile, Class<T> keyType)
          Build a new manager for the given properties file.
static
<T extends Enum<T>>
PropertiesManager<T>
newManager(File file, URL defaultFile, Class<T> keyType, ExecutorService executor)
          Build a new manager for the given properties file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newManager

public static <T extends Enum<T>> PropertiesManager<T> newManager(File file,
                                                                  File defaultFile,
                                                                  Class<T> keyType)
                                                       throws IOException
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented by the new manager
defaultFile - a file containing default values for the properties represented by the new manager
keyType - the enumeration of keys in the properties file
Returns:
a new manager
Throws:
IOException - if there is an error while reading the default properties

newManager

public static <T extends Enum<T>> PropertiesManager<T> newManager(File file,
                                                                  URL defaultFile,
                                                                  Class<T> keyType)
                                                       throws IOException
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented by the new manager
defaultFile - a URL containing default values for the properties represented by the new manager
keyType - the enumeration of keys in the properties file
Returns:
a new manager
Throws:
IOException - if there is an error while reading the default properties

newManager

public static <T extends Enum<T>> PropertiesManager<T> newManager(File file,
                                                                  File defaultFile,
                                                                  Class<T> keyType,
                                                                  ExecutorService executor)
                                                       throws IOException
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented by the new manager
defaultFile - a file containing default values for the properties represented by the new manager
keyType - the enumeration of keys in the properties file
executor - a service to handle potentially long running tasks, such as interacting with the file system
Returns:
a new manager
Throws:
IOException - if there is an error while reading the default properties

newManager

public static <T extends Enum<T>> PropertiesManager<T> newManager(File file,
                                                                  URL defaultFile,
                                                                  Class<T> keyType,
                                                                  ExecutorService executor)
                                                       throws IOException
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented by the new manager
defaultFile - a URL containing default values for the properties represented by the new manager
keyType - the enumeration of keys in the properties file
executor - a service to handle potentially long running tasks, such as interacting with the file system
Returns:
a new manager
Throws:
IOException - if there is an error while reading the default properties

newManager

public static <T extends Enum<T> & Defaultable> PropertiesManager<T> newManager(File file,
                                                                               Class<T> keyType)
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented here
keyType - the enumeration of keys in the properties file
Returns:
a new manager

newManager

public static <T extends Enum<T> & Defaultable> PropertiesManager<T> newManager(File file,
                                                                               Class<T> keyType,
                                                                               ExecutorService executor)
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented here
keyType - the enumeration of keys in the properties file
executor - a service to handle potentially long running tasks, such as interacting with the file system
Returns:
a new manager

newManager

public static <T extends Enum<T> & Defaultable> PropertiesManager<T> newManager(File file,
                                                                               Class<T> keyType,
                                                                               Translator<T> translator,
                                                                               ExecutorService executor)
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented here
keyType - the enumeration of keys in the properties file
translator - the translator to convert between Enum names and property keys
executor - a service to handle potentially long running tasks, such as interacting with the file system
Returns:
a new manager

newManager

public static <T extends Enum<T> & Defaultable> PropertiesManager<T> newManager(File file,
                                                                               Class<T> keyType,
                                                                               Evaluator evaluator,
                                                                               ExecutorService executor)
Build a new manager for the given properties file.

Type Parameters:
T - the type of key used for the new manager
Parameters:
file - the file system location of the properties represented here
keyType - the enumeration of keys in the properties file
evaluator - the evaluator to convert nested property references into fully evaluated strings
executor - a service to handle potentially long running tasks, such as interacting with the file system
Returns:
a new manager

getProperties

public static Properties getProperties(File file)
                                throws IOException
Load values from a file.

Parameters:
file - the file containing default values
Returns:
a new properties instance loaded with values from the given file
Throws:
IOException - if there is an error while reading the given file

getProperties

public static Properties getProperties(URL url)
                                throws IOException
Load values from a URL.

Parameters:
url - the URL containing default values
Returns:
a new properties instance loaded with values from the given URL
Throws:
IOException - if there is an error while reading the given URL

getDefaultProperties

public static <T extends Enum<T> & Defaultable> Properties getDefaultProperties(Class<T> keyType,
                                                                               Translator<T> translator)
Retrieve a Properties instance that contains all of the default values defined for the given Defaultable.

Type Parameters:
T - the key type whose default values are requested
Parameters:
keyType - the class that contains the appropriate defaults
translator - a translator to convert between key instances and property names
Returns:
a Properties instance containing the default values stored in the given key type

getIdentityTranslator

public static Translator<String> getIdentityTranslator()
Create a translator that returns the string that it is given (no translation).

Returns:
the identity translator implementation

getEnumTranslator

public static <T extends Enum<T>> Translator<T> getEnumTranslator(Class<T> enumType)
Get a simple translator to convert back and forth between Enums and property names (keys).

Type Parameters:
T - the type of Enum representing the properties
Parameters:
enumType - the Enum class used to represent the properties
Returns:
the Enum translator implementation


Copyright © 2010-2012 Gregory P. Moyer. All Rights Reserved.