org.opensubsystems.core.util
Class SetupReader

java.lang.Object
  extended by org.opensubsystems.core.util.SetupReader
Direct Known Subclasses:
PooledDatabaseConnectionFactorySetupReader

public abstract class SetupReader
extends java.lang.Object

Reads properties from property file for named objects. It allows to specify set of default properties and then override the properties for an instance with specified name. If an overriden property for an object with specified name doesn't exist, the default peroperty will be used. Each property name consist from three parts. base path, reader name and parameter name. Property name looks like .. where xxx is base path (for example oss.receiver) yyy is reader name (for example defaultfax) and zzz is parameter name (for example priority). Result will be oss.receiver.defaultfax.priority

Version:
$Id: SetupReader.java,v 1.6 2007/01/07 06:14:00 bastafidli Exp $
Author:
Martin Cerba
Code reviewer:
Miro Halas
Code reviewed:
1.4 2006/01/12 05:53:08 bastafidli

Field Summary
protected  java.lang.String m_basePath
          Base path of this reader.
protected  java.lang.String m_readerName
          Name of this reader.
protected  java.util.Map m_registeredParametersValues
          Map with parameters values.
protected  java.util.Properties m_settings
          Cached properties to access configuration settins.
static int PARAMETER_TYPE_BOOLEAN
          Constant for parameter data type object
static java.lang.Integer PARAMETER_TYPE_BOOLEAN_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_DOUBLE
          Constant for parameter data type object
static java.lang.Integer PARAMETER_TYPE_DOUBLE_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_FLOAT
          Constant for parameter data type object
static java.lang.Integer PARAMETER_TYPE_FLOAT_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_INTEGER
          Constant for parameter data type
static java.lang.Integer PARAMETER_TYPE_INTEGER_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_LONG
          Constant for parameter data type object
static java.lang.Integer PARAMETER_TYPE_LONG_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_PATH
          Constant for parameter data type object
static java.lang.Integer PARAMETER_TYPE_PATH_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_STRING
          Constant for parameter data type
static java.lang.Integer PARAMETER_TYPE_STRING_OBJ
          Constant for parameter data type object
static int PARAMETER_TYPE_UNKNOWN
          Constant for parameter data type
static java.lang.Integer PARAMETER_TYPE_UNKNOWN_OBJ
          Constant for parameter data type object
 
Constructor Summary
SetupReader(java.lang.String basePath, java.lang.String readerName)
           
 
Method Summary
 java.lang.Boolean getBooleanParameterValue(java.lang.String parameterName)
          Get parameter value as Boolean
 java.lang.Double getDoubleParameterValue(java.lang.String parameterName)
          Get parameter value as Double
 java.lang.Float getFloatParameterValue(java.lang.String parameterName)
          Get parameter value as Float
 java.lang.Integer getIntegerParameterValue(java.lang.String parameterName)
          Get parameter value as Integer
 java.lang.Long getLongParameterValue(java.lang.String parameterName)
          Get parameter value as Long
 java.lang.Object getParameterValue(java.lang.String parameterName)
          Read parameter with specified name.
protected abstract  java.util.Map getRegisteredParametersDefaults()
          this function returns Map for parameter defaults.
protected abstract  java.util.Map getRegisteredParameterTypes()
          this function returns Map for parameter types.
 java.lang.String getStringParameterValue(java.lang.String parameterName)
          Get parameter value as string
protected  java.lang.Object parseValue(int iParameterType, java.lang.String propertyValue)
          Parse specified value according to its type.
protected  void registerParameter(java.lang.String parameterName, java.lang.Integer parameterType, java.lang.String defaultvalue)
          Register parameters which will be read from the property file with this reader.
protected abstract  void registerParameters()
          Implementation can register all parameters in this function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARAMETER_TYPE_UNKNOWN

public static final int PARAMETER_TYPE_UNKNOWN
Constant for parameter data type

See Also:
Constant Field Values

PARAMETER_TYPE_UNKNOWN_OBJ

public static final java.lang.Integer PARAMETER_TYPE_UNKNOWN_OBJ
Constant for parameter data type object


PARAMETER_TYPE_STRING

public static final int PARAMETER_TYPE_STRING
Constant for parameter data type

See Also:
Constant Field Values

PARAMETER_TYPE_STRING_OBJ

public static final java.lang.Integer PARAMETER_TYPE_STRING_OBJ
Constant for parameter data type object


PARAMETER_TYPE_INTEGER

public static final int PARAMETER_TYPE_INTEGER
Constant for parameter data type

See Also:
Constant Field Values

PARAMETER_TYPE_INTEGER_OBJ

public static final java.lang.Integer PARAMETER_TYPE_INTEGER_OBJ
Constant for parameter data type object


PARAMETER_TYPE_DOUBLE

public static final int PARAMETER_TYPE_DOUBLE
Constant for parameter data type object

See Also:
Constant Field Values

PARAMETER_TYPE_DOUBLE_OBJ

public static final java.lang.Integer PARAMETER_TYPE_DOUBLE_OBJ
Constant for parameter data type object


PARAMETER_TYPE_FLOAT

public static final int PARAMETER_TYPE_FLOAT
Constant for parameter data type object

See Also:
Constant Field Values

PARAMETER_TYPE_FLOAT_OBJ

public static final java.lang.Integer PARAMETER_TYPE_FLOAT_OBJ
Constant for parameter data type object


PARAMETER_TYPE_BOOLEAN

public static final int PARAMETER_TYPE_BOOLEAN
Constant for parameter data type object

See Also:
Constant Field Values

PARAMETER_TYPE_BOOLEAN_OBJ

public static final java.lang.Integer PARAMETER_TYPE_BOOLEAN_OBJ
Constant for parameter data type object


PARAMETER_TYPE_LONG

public static final int PARAMETER_TYPE_LONG
Constant for parameter data type object

See Also:
Constant Field Values

PARAMETER_TYPE_LONG_OBJ

public static final java.lang.Integer PARAMETER_TYPE_LONG_OBJ
Constant for parameter data type object


PARAMETER_TYPE_PATH

public static final int PARAMETER_TYPE_PATH
Constant for parameter data type object

See Also:
Constant Field Values

PARAMETER_TYPE_PATH_OBJ

public static final java.lang.Integer PARAMETER_TYPE_PATH_OBJ
Constant for parameter data type object


m_readerName

protected java.lang.String m_readerName
Name of this reader. This name is added to base path to get full parameter name.


m_basePath

protected java.lang.String m_basePath
Base path of this reader. Each property name consist from three parts. base path, reader name and parameter name. Property name looks like .. where xxx is base path (for example oss.receiver) yyy is reader name (for example defaultfax) and zzz is parameter name (for example priority). Result will be oss.receiver.defaultfax.priority


m_settings

protected java.util.Properties m_settings
Cached properties to access configuration settins.


m_registeredParametersValues

protected java.util.Map m_registeredParametersValues
Map with parameters values. Parameters values are readed only once and then is used value from this map. Key is parameter name

Constructor Detail

SetupReader

public SetupReader(java.lang.String basePath,
                   java.lang.String readerName)
Parameters:
basePath - - Base path of reader
readerName - - name of reader
Method Detail

getParameterValue

public java.lang.Object getParameterValue(java.lang.String parameterName)
Read parameter with specified name. The parameter name has to be registered using registerParameter. If such parameter is not registered it returns null.

Parameters:
parameterName - - name of parameter
Returns:
- object with parameter value or null of parameter name is not registered. If you pass in correct parameter name, this method guarantees to return not null value (in case of failure it will return the hardcoded value you passed in).

getStringParameterValue

public java.lang.String getStringParameterValue(java.lang.String parameterName)
Get parameter value as string

Parameters:
parameterName - - name of parameter
Returns:
String - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

getIntegerParameterValue

public java.lang.Integer getIntegerParameterValue(java.lang.String parameterName)
Get parameter value as Integer

Parameters:
parameterName - - name of parameter
Returns:
Integer - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

getDoubleParameterValue

public java.lang.Double getDoubleParameterValue(java.lang.String parameterName)
Get parameter value as Double

Parameters:
parameterName - - name of parameter
Returns:
Double - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

getFloatParameterValue

public java.lang.Float getFloatParameterValue(java.lang.String parameterName)
Get parameter value as Float

Parameters:
parameterName - - name of parameter
Returns:
Float - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

getBooleanParameterValue

public java.lang.Boolean getBooleanParameterValue(java.lang.String parameterName)
Get parameter value as Boolean

Parameters:
parameterName - - name of parameter
Returns:
Boolean - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

getLongParameterValue

public java.lang.Long getLongParameterValue(java.lang.String parameterName)
Get parameter value as Long

Parameters:
parameterName - - name of parameter
Returns:
Long - value of parameter. It will be default value if parameter was not found or null if parameter name is not registered

parseValue

protected java.lang.Object parseValue(int iParameterType,
                                      java.lang.String propertyValue)
Parse specified value according to its type.

Parameters:
iParameterType - - parameter type, one of PARAMETER_TYPE_XXX constants
propertyValue - - value to parse
Returns:
Object - parsed object or null if it cannot be parsed

registerParameter

protected void registerParameter(java.lang.String parameterName,
                                 java.lang.Integer parameterType,
                                 java.lang.String defaultvalue)
Register parameters which will be read from the property file with this reader. This method will try to read from the property file value common to all readers and if it doesn't find one it will use specified default value .

Parameters:
parameterName - - parameter string name. This is just the part of the name which follows the base path and optionally reader name
parameterType - - parameter type - one of PARAMETER_TYPE_XXX constants
defaultvalue - - parameter default value - as string, this should be always valid hardcoded string

registerParameters

protected abstract void registerParameters()
Implementation can register all parameters in this function.


getRegisteredParameterTypes

protected abstract java.util.Map getRegisteredParameterTypes()
this function returns Map for parameter types. This map have to be static. key in map is parameter name and value is Integer type constant

Returns:
Map of parameter types

getRegisteredParametersDefaults

protected abstract java.util.Map getRegisteredParametersDefaults()
this function returns Map for parameter defaults. This map have to be static. key in map is parameter name and value is String default value

Returns:
Map of default values


Copyright © 2003 - 2006 OpenSubsystems s.r.o.