raccoon.core.config
Class StdConfig

java.lang.Object
  extended by raccoon.core.types.AbsComponent
      extended by raccoon.core.types.AbsLoadable
          extended by raccoon.core.types.AbsConfigurableLoadable
              extended by raccoon.core.config.StdConfig
All Implemented Interfaces:
IConfig, IBaseComponent, IConfigurable, ILoadable, ILogable

public class StdConfig
extends AbsConfigurableLoadable
implements IConfig

Improvement to the java.util.PropertyResourceBundle.

Futhermore it standardizes the API seen by the user and provides properties getters of types that the PropertyResourceBundle doesn't.
Instances of this class are returned by the CoreHelper.getConfig() methods. The IConfig properties can be refreshed (i.e. reread from disk) by calling the refresh() method.
A typical properties file would look like this:
log4j.appender.Raccoon = org.apache.log4j.RollingFileAppender
log4j.appender.Raccoon.File = Raccoon.log
log4j.appender.Raccoon.Append = false
log4j.appender.Raccoon.MaxFileSize = 5MB
log4j.appender.Raccoon.MaxBackupIndex = 10
log4j.appender.Raccoon.layout = org.apache.log4j.PatternLayout
log4j.appender.Raccoon.layout.ConversionPattern = %r [%t] %-5p %c{2} %x - %m %n

log4j.rootCategory=debug, Raccoon

All methods throw a RaccoonException if this component isn't active.

Since:
Raccoon v0.1
Version:
$Id: StdConfig.java,v 1.1 2004/08/08 20:19:17 crouvrais Exp $
Author:
Cedric ROUVRAIS

Field Summary
static java.lang.String PTY_PROPERTY_FILE_NAME
          The name of the java property bean containing the resource file name.
 
Fields inherited from class raccoon.core.types.AbsConfigurableLoadable
mConfigurableManager
 
Fields inherited from class raccoon.core.types.AbsLoadable
mIsLoaded
 
Fields inherited from class raccoon.core.types.AbsComponent
mIsInError
 
Fields inherited from interface raccoon.api.config.IConfig
PTY_CONFIG
 
Constructor Summary
StdConfig()
          Default constructor, required by all components for dynamic instanciation.
StdConfig(boolean pBootStrap)
          Instanciates this component and if necessary boot straps.
 
Method Summary
 void configureParameters()
          Configures the various parameters for this component.
 boolean getBoolean(java.lang.String pProperty)
          Reads the value of the propery and converts it to a boolean.
 boolean getBoolean(java.lang.String pProperty, boolean pDefaultValue)
          Reads the value of the propery and converts it to a boolean.
 double getDouble(java.lang.String pProperty)
          Reads the value of the propery and converts it to a double.
 double getDouble(java.lang.String pProperty, double pDefaultValue)
          Reads the value of the propery and converts it to a double.
 int getInt(java.lang.String pProperty)
          Reads the value of the propery and converts it to a integer.
 int getInt(java.lang.String pProperty, int pDefaultValue)
          Reads the value of the propery and converts it to a integer.
 long getLong(java.lang.String pProperty)
          Reads the value of the propery and converts it to a long.
 long getLong(java.lang.String pProperty, long pDefaultValue)
          Reads the value of the propery and converts it to a long.
(package private)  java.lang.String getMissingPropertyMsg(java.lang.String pDesiredProperty)
          Creates an error message to inform the developper that a property is missing from his file.
 java.util.Properties getProperties()
          Extracts all the available properties to a convenient format.
 java.lang.String getPropertyFileName()
          The property file used by this configuration instance
 java.lang.String getString(java.lang.String pProperty)
          Reads the value of the propery and converts it to a String.
 java.lang.String getString(java.lang.String pProperty, java.lang.Object[] pParams)
          Retrieves a Message String from the configuration file and converts it into a String.
 java.lang.String getString(java.lang.String pProperty, java.lang.Object[] pParams, java.lang.String pDefaultValue)
          Retrieves a Message String from the configuration file and converts it into a String.
 java.lang.String getString(java.lang.String pProperty, java.lang.String pDefaultValue)
          Reads the value of the propery and converts it to a String.
 java.util.StringTokenizer getStrings(java.lang.String pProperty)
          Reads the value of the property and returns a StringTokenizer object.
 boolean isAvailable(java.lang.String pProperty)
          Convenience method to check if a specific property is defined.
 void load()
          Loads or initializes the component.
 void refresh()
          Reload the properties from the properties file.
 void setPropertyFileName(java.lang.String pPropertyFileName)
          Defines the name of the property file.
 
Methods inherited from class raccoon.core.types.AbsConfigurableLoadable
isStable, setConfigurableManager, setLogger
 
Methods inherited from class raccoon.core.types.AbsLoadable
getLog, isInError, isInitialised, isRunning, unload
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PTY_PROPERTY_FILE_NAME

public static final java.lang.String PTY_PROPERTY_FILE_NAME
The name of the java property bean containing the resource file name.

See Also:
Constant Field Values
Constructor Detail

StdConfig

public StdConfig()
Default constructor, required by all components for dynamic instanciation.


StdConfig

public StdConfig(boolean pBootStrap)
          throws RaccoonException
Instanciates this component and if necessary boot straps.

Parameters:
pBootStrap - boot strap ?
Throws:
RaccoonException - if the boot strap fails.
Method Detail

configureParameters

public void configureParameters()
Configures the various parameters for this component. This method should configure the instance of IConfigurableManager provided during the invocation of AbsConfigurableLoadable.setConfigurableManager(IConfigurableManager).

Specified by:
configureParameters in interface IConfigurable
Overrides:
configureParameters in class AbsConfigurableLoadable

getPropertyFileName

public java.lang.String getPropertyFileName()
The property file used by this configuration instance

Returns:
the name of the file.

setPropertyFileName

public void setPropertyFileName(java.lang.String pPropertyFileName)
                         throws ResourceNotFoundException
Defines the name of the property file.

Parameters:
pPropertyFileName - the file to use.
Throws:
ResourceNotFoundException - if there is an internal error.

load

public void load()
          throws java.lang.IllegalStateException,
                 LoadableException
Loads or initializes the component.

Specified by:
load in interface ILoadable
Overrides:
load in class AbsConfigurableLoadable
Throws:
LoadableException - if the component couldn't load itself.
java.lang.IllegalStateException - if the component isn't in a state to load itself. for example it is already loaded.

getMissingPropertyMsg

java.lang.String getMissingPropertyMsg(java.lang.String pDesiredProperty)
Creates an error message to inform the developper that a property is missing from his file.

Parameters:
pDesiredProperty - the missing property
Returns:
a user friendly string indication the absence of a given property

isAvailable

public boolean isAvailable(java.lang.String pProperty)
                    throws RaccoonException
Convenience method to check if a specific property is defined.

Specified by:
isAvailable in interface IConfig
Parameters:
pProperty - the property to search for.
Returns:
is the property in the configuration file.
Throws:
RaccoonException - if this component is active.

getBoolean

public boolean getBoolean(java.lang.String pProperty)
                   throws RaccoonException,
                          java.lang.NumberFormatException
Reads the value of the propery and converts it to a boolean. This method will return true if the value of the property is a String(true) or is 1. This method will return false if the value of the property is a String(false) or is 0.

Specified by:
getBoolean in interface IConfig
Parameters:
pProperty - the property to look for
Returns:
the boolean value for the requested property
Throws:
RaccoonException - if the property couldn't be found
java.lang.NumberFormatException - if the specified property isn't a boolean.

getBoolean

public boolean getBoolean(java.lang.String pProperty,
                          boolean pDefaultValue)
Reads the value of the propery and converts it to a boolean. This method will return true if the value of the property is a String(true) or is 1. This method will return false if the value of the property is a String(false) or is 0. This method will return pDefaultvalue if any error occurs.

Specified by:
getBoolean in interface IConfig
Parameters:
pProperty - the property to look for
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the boolean value for the requested property

getInt

public int getInt(java.lang.String pProperty)
           throws RaccoonException,
                  java.lang.NumberFormatException
Reads the value of the propery and converts it to a integer.

Specified by:
getInt in interface IConfig
Parameters:
pProperty - the property to look for
Returns:
the integer value for the requested property
Throws:
RaccoonException - if the property couldn't be found
java.lang.NumberFormatException - if the specified property isn't a int.

getInt

public int getInt(java.lang.String pProperty,
                  int pDefaultValue)
Reads the value of the propery and converts it to a integer. This method will return pDefaultvalue if any error occurs.

Specified by:
getInt in interface IConfig
Parameters:
pProperty - the property to look for
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the integer value for the requested property

getLong

public long getLong(java.lang.String pProperty)
             throws RaccoonException,
                    java.lang.NumberFormatException
Reads the value of the propery and converts it to a long.

Specified by:
getLong in interface IConfig
Parameters:
pProperty - the property to look for
Returns:
the long value for the requested property
Throws:
RaccoonException - if the property couldn't be found
java.lang.NumberFormatException - if the specified property isn't a long.

getLong

public long getLong(java.lang.String pProperty,
                    long pDefaultValue)
Reads the value of the propery and converts it to a long. This method will return pDefaultvalue if any error occurs.

Specified by:
getLong in interface IConfig
Parameters:
pProperty - the property to look for
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the long value for the requested property

getDouble

public double getDouble(java.lang.String pProperty)
                 throws RaccoonException
Reads the value of the propery and converts it to a double.

Specified by:
getDouble in interface IConfig
Parameters:
pProperty - the property to look for
Returns:
the double value for the requested property
Throws:
RaccoonException - if the value can't be found or is invalid.

getDouble

public double getDouble(java.lang.String pProperty,
                        double pDefaultValue)
Reads the value of the propery and converts it to a double. This method will return pDefaultvalue if any error occurs.

Specified by:
getDouble in interface IConfig
Parameters:
pProperty - the property to look for
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the double value for the requested property

getStrings

public java.util.StringTokenizer getStrings(java.lang.String pProperty)
                                     throws RaccoonException
Reads the value of the property and returns a StringTokenizer object.

Specified by:
getStrings in interface IConfig
Parameters:
pProperty - the property for which the data is required.
Returns:
a string tokenizer based in the given property data
Throws:
RaccoonException - if the property couldn't be found.

getString

public java.lang.String getString(java.lang.String pProperty)
                           throws RaccoonException
Reads the value of the propery and converts it to a String.

Specified by:
getString in interface IConfig
Parameters:
pProperty - the property to look for
Returns:
the String value for the requested property
Throws:
RaccoonException - if the value is an invalid String

getString

public java.lang.String getString(java.lang.String pProperty,
                                  java.lang.String pDefaultValue)
Reads the value of the propery and converts it to a String. This method will return pDefaultvalue if any error occurs.

Specified by:
getString in interface IConfig
Parameters:
pProperty - the property to look for
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the String value for the requested property

getString

public java.lang.String getString(java.lang.String pProperty,
                                  java.lang.Object[] pParams)
                           throws RaccoonException
Retrieves a Message String from the configuration file and converts it into a String.

A Message String is a specific String, because each occurrence of {i} in that String will be replaced by Object[i].toString()

For example:
property = "Hello {0}, you have {1}, new Object[] {"Kathleen", "mail"}
Will result in the following String being returned:
"Hello Kathleen, you have mail"

No matter what the implementation behind the scenes is.

Specified by:
getString in interface IConfig
Parameters:
pProperty - the property that is to be retrieved.
pParams - a list of objects implementing the toString() method that will be inserted into the resulting String
Returns:
the value of the given property that has been formatted.
Throws:
RaccoonException - if this method fails

getString

public java.lang.String getString(java.lang.String pProperty,
                                  java.lang.Object[] pParams,
                                  java.lang.String pDefaultValue)
Retrieves a Message String from the configuration file and converts it into a String.

A Message String is a specific String, because each occurrence of {i} in that String will be replaced by Object[i].toString()

For example:
property = "Hello {0}, you have {1}, new Object[] {"Kathleen", "mail"}
Will result in the following String being returned:
"Hello Kathleen, you have mail"

No matter what the implementation behind the scenes is.

This method will return pDefaultvalue if any error occurs.

Specified by:
getString in interface IConfig
Parameters:
pProperty - the property that is to be retrieved.
pParams - a list of objects implementing the toString() method that will be inserted into the resulting String
pDefaultValue - the default value returned if the property is not found in the config file
Returns:
the value of the given property that has been formatted.

refresh

public void refresh()
             throws RaccoonException
Reload the properties from the properties file.

Specified by:
refresh in interface IConfig
Throws:
RaccoonException - if this component hasn't been initialised.

getProperties

public java.util.Properties getProperties()
                                   throws RaccoonException
Extracts all the available properties to a convenient format.

Specified by:
getProperties in interface IConfig
Returns:
all properties as a Properties object
Throws:
RaccoonException - if the component isn't active


Copyright null null. All Rights Reserved.