Jumpi v1.2.0

org.jumpi.impl.util
Class ConfigurationHelper

java.lang.Object
  |
  +--org.jumpi.impl.util.ConfigurationHelper

public class ConfigurationHelper
extends java.lang.Object

A helper class providing utilities to get and check configuration properties, and to instantiate configurable components.


Field Summary
static java.lang.String CLASS_KEY_SUFFIX
          The property suffix for instantiable classes.
 
Constructor Summary
ConfigurationHelper()
          Create a ConfigurationHelper instance.
 
Method Summary
static boolean getBooleanProperty(java.lang.String key, Properties props, boolean def)
          Get a boolean property from the property list and provide a default if it is missing.
static java.util.Vector getCommaSeparatedStrings(java.lang.String str)
          Parse and return each string from a comma separated list of strings in a Vector.
static int getIntProperty(java.lang.String key, Properties props, int def)
          Get an integer property from the property list and provide a default if it is missing.
static int getIntProperty(java.lang.String key, Properties props, int def, int lowerbound, int upperbound)
          Get the integer property named by key in the property list or a default if missing.
static int getMandatoryIntProperty(java.lang.String key, Properties props)
          Get the mandatory integer property named by key in the property list.
static int getMandatoryIntProperty(java.lang.String key, Properties props, int lowerbound, int upperbound)
          Get the mandatory integer property named by key in the property list.
static java.lang.String getMandatoryProperty(java.lang.String key, Properties props)
          Get the mandatory property named by key in the property list.
static java.lang.String getProperty(java.lang.String key, Properties props)
          Get a property from the property list.
static java.lang.String getProperty(java.lang.String key, Properties props, java.lang.String def)
          Get a property from the property list and provide a default if it is missing.
static Configurable instantiate(java.lang.String prefix, java.lang.String propname, Properties props)
           Instantiate a Configurable class and configure it given the properties.
static Configurable instantiate(java.lang.String prefix, java.lang.String propname, Properties props, java.lang.String defaultName, java.lang.String defaultClassname)
           Instantiate a Configurable class and configure it given the properties.
static java.util.Vector instantiateList(java.lang.String prefix, java.lang.String listname, Properties props)
          Instantiate and configure a list of Configurable instances.
static Configurable instantiateMandatory(java.lang.String prefix, java.lang.String propname, Properties props)
           Instantiate a Configurable class and configure it given the properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_KEY_SUFFIX

public static final java.lang.String CLASS_KEY_SUFFIX
The property suffix for instantiable classes.

See Also:
Constant Field Values
Constructor Detail

ConfigurationHelper

public ConfigurationHelper()
Create a ConfigurationHelper instance. Not necessarily used since all methods are static, but the methods can still be used from a non static context.

Method Detail

instantiate

public static Configurable instantiate(java.lang.String prefix,
                                       java.lang.String propname,
                                       Properties props)
                                throws java.lang.Exception

Instantiate a Configurable class and configure it given the properties. The prefix + propname property is the property which provides the symbolic name of the configurable instance. If this property does not exist then null is returned.

The property prefix + propname + "." + symbolic-name + ".classname" gives the java classname of the class to instantiate. The instantiated Configurable instance is configured using the prefix + propname + "." + symbolic-name as the fully qualified component name.

Parameters:
prefix - the property name's prefix.
propname - the property suffix part to find the symbolic-name of the instance.
props - the list of all properties.
Returns:
a configured instance, or null if no instance is configured.
Throws:
java.lang.Exception - if any failure condition occurs.
See Also:
Configurable.configure(java.lang.String, org.jumpi.spi.Properties)

instantiate

public static Configurable instantiate(java.lang.String prefix,
                                       java.lang.String propname,
                                       Properties props,
                                       java.lang.String defaultName,
                                       java.lang.String defaultClassname)
                                throws java.lang.Exception

Instantiate a Configurable class and configure it given the properties. The prefix + propname property is the property which provides the symbolic name of the configurable instance. If this property does not exist then use the default classname and component name suffix as provided.

The property prefix + propname + "." + symbolic-name + ".classname" gives the java classname of the class to instantiate. The instantiated Configurable instance is configured using the prefix + propname + "." + symbolic-name as the fully qualified component name.

Parameters:
prefix - the property name's prefix.
propname - the property suffix part to find the symbolic-name of the instance.
props - the list of all properties.
defaultName - the default symbolic name.
defaultClassname - the default classname.
Returns:
a configured instance, or null if no instance is configured.
Throws:
java.lang.Exception - if any failure condition occurs.
See Also:
Configurable.configure(java.lang.String, org.jumpi.spi.Properties)

instantiateMandatory

public static Configurable instantiateMandatory(java.lang.String prefix,
                                                java.lang.String propname,
                                                Properties props)
                                         throws java.lang.Exception

Instantiate a Configurable class and configure it given the properties. The prefix + propname property is the property which provides the symbolic name of the configurable instance. If this property does not exist then an Exception is thrown.

The property prefix + propname + "." + symbolic-name + ".classname" gives the java classname of the class to instantiate. The instantiated Configurable instance is configured using the prefix + propname + "." + symbolic-name as the fully qualified component name.

Parameters:
prefix - the property name's prefix.
propname - the property suffix part to find the symbolic-name of the instance.
props - the list of all properties.
Returns:
a configured instance, or null if no instance is configured.
Throws:
java.lang.Exception - if any failure condition occurs.
See Also:
Configurable.configure(java.lang.String, org.jumpi.spi.Properties)

instantiateList

public static java.util.Vector instantiateList(java.lang.String prefix,
                                               java.lang.String listname,
                                               Properties props)
                                        throws java.lang.Exception
Instantiate and configure a list of Configurable instances. The prefix + listname property must provide a list of comma separated names of the instances. The properties prefix + listname + "." + name + ".classname" provide the classname of the java class for instantiation. Each instance is instantiated and configured. The fully qualified name of the configured instances is prefix + listname + "." + name. An empty Vector is returned if no names are provided.

Parameters:
prefix - the property prefix.
listname - the property suffix to give the comma separated names list.
props - all properties.
Returns:
a list of configured Configurable instances.
Throws:
java.lang.Exception - if any failure condition occurs.
java.lang.IllegalArgumentException - if any parameters are missing.

getCommaSeparatedStrings

public static java.util.Vector getCommaSeparatedStrings(java.lang.String str)
Parse and return each string from a comma separated list of strings in a Vector. Empty strings are not considered and not passed into the result.

Parameters:
str - the comma separated string to be parsed.
Returns:
the list of strings which were comma separated in str, preserving order.
Throws:
java.lang.IllegalArgumentException - if str is null.

getMandatoryProperty

public static java.lang.String getMandatoryProperty(java.lang.String key,
                                                    Properties props)
                                             throws java.lang.Exception
Get the mandatory property named by key in the property list. An Exception is thrown if the property does not exist.

Parameters:
key - the property key.
props - the list of all properties.
Returns:
the property value.
Throws:
java.lang.Exception - if the property is not found.
java.lang.IllegalArgumentException - if missing parameters.

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           Properties props,
                                           java.lang.String def)
                                    throws java.lang.Exception
Get a property from the property list and provide a default if it is missing.

Parameters:
key - the property key.
props - the list of all properties.
def - the default value which is returned if key is not in props.
Returns:
a property value or default if the property key does not exist in props.
Throws:
java.lang.Exception - if any failure condition occurs.
java.lang.IllegalArgumentException - if any parameters are missing.

getProperty

public static java.lang.String getProperty(java.lang.String key,
                                           Properties props)
                                    throws java.lang.Exception
Get a property from the property list.

Parameters:
key - the property key.
props - the list of all properties.
Returns:
a property value or null if key does not exist in props.
Throws:
java.lang.Exception - if any failure condition occurs.
java.lang.IllegalArgumentException - if any parameters are missing.

getMandatoryIntProperty

public static int getMandatoryIntProperty(java.lang.String key,
                                          Properties props)
                                   throws java.lang.Exception
Get the mandatory integer property named by key in the property list. An Exception is thrown if the property does not exist.

Parameters:
key - the property key.
props - the list of all properties.
Returns:
the property value.
Throws:
java.lang.Exception - if the property is not found.
java.lang.IllegalArgumentException - if missing parameters.

getMandatoryIntProperty

public static int getMandatoryIntProperty(java.lang.String key,
                                          Properties props,
                                          int lowerbound,
                                          int upperbound)
                                   throws java.lang.Exception
Get the mandatory integer property named by key in the property list. An Exception is thrown if the property does not exist.

Parameters:
key - the property key.
props - the list of all properties.
lowerbound - lower inclusive limit for property value, Integer.MAX_INT to disable check.
upperbound - higher inclusive limit for property value, Integer.MIN_INT to disable check.
Returns:
the property value.
Throws:
java.lang.Exception - if the property is not found.

getIntProperty

public static int getIntProperty(java.lang.String key,
                                 Properties props,
                                 int def)
                          throws java.lang.Exception
Get an integer property from the property list and provide a default if it is missing.

Parameters:
key - the property key.
props - the list of all properties.
def - the default value which is returned if key is not in props.
Returns:
a property value or default if the property key does not exist in props.
Throws:
java.lang.Exception - if any failure condition occurs.

getIntProperty

public static int getIntProperty(java.lang.String key,
                                 Properties props,
                                 int def,
                                 int lowerbound,
                                 int upperbound)
                          throws java.lang.Exception
Get the integer property named by key in the property list or a default if missing. Perform a bounds check on the value or default.

Parameters:
key - the property key.
props - the list of all properties.
def - value to take in the absensce of a value.
lowerbound - lower inclusive limit for property value, Integer.MAX_INT to disable check.
upperbound - higher inclusive limit for property value, Integer.MIN_INT to disable check.
Returns:
the property value.
Throws:
java.lang.Exception - if the property is not found.

getBooleanProperty

public static boolean getBooleanProperty(java.lang.String key,
                                         Properties props,
                                         boolean def)
                                  throws java.lang.Exception
Get a boolean property from the property list and provide a default if it is missing. The string value of the property must be case insensitive "false" to be recognised as boolean false, and case insensitive "true" to be recognised as boolean true.

Parameters:
key - the property key.
props - the list of all properties.
def - the default value which is returned if key is not in props.
Returns:
a property value or default if the property key does not exist in props.
Throws:
java.lang.Exception - if any failure condition occurs.
java.lang.IllegalArgumentException - if any parameters are missing.

Jumpi v1.2.0

Copyright © 2003, Peter Jonathan Klauser.