Version: 1.1.1

org.biomoby.service.dashboard
Class DashboardConfig

java.lang.Object
  extended by org.biomoby.service.dashboard.DashboardConfig

public abstract class DashboardConfig
extends Object

An abstract class giving access to the global Dashboard configuration. It also allows to add additional configuration files (which may be useful for new panels).

The class uses Apache Commons Configuration - the method get() gives back directly an Apache's CompositeConfiguration instance allowing to fine-tune your configuration (if needed, at all).

Version:
$Id: DashboardConfig.java,v 1.2 2008/11/18 06:40:11 senger Exp $
Author:
Martin Senger

Field Summary
static String DASHBOARD_CONFIG_FILENAME
          A filename indicating a file containing Dasboard run-time properties.
static String PROP_DASHBOARD_CONFIGURATION
          A property name.
 
Constructor Summary
DashboardConfig()
           
 
Method Summary
static boolean addConfigPropertyFile(String configFilename)
          Add new configuration properties from a property file.
static org.apache.commons.configuration.CompositeConfiguration get()
          The main method returning a configuration object.
static int getInt(String key, int defaultValue)
          Get an integer value associated with the given configuration key, or - if not found or not of integer value - get the given default value.
static String getString(String key, String defaultValue)
          Get a string associated with the given configuration key, or - if not found - get the given default value (which still may be null).
static String[] getStrings(String key, String defaultValue)
          Almost the same functionality as getString method.
static boolean isEnabled(String key, boolean defaultValue, String serviceName, Object owner)
          Get a boolean value associated with the given configuration key, or - if not found - get the given default value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DASHBOARD_CONFIG_FILENAME

public static final String DASHBOARD_CONFIG_FILENAME
A filename indicating a file containing Dasboard run-time properties. This file name can be changed by setting Java property PROP_DASHBOARD_CONFIGURATION to point to a different file name.

See Also:
Constant Field Values

PROP_DASHBOARD_CONFIGURATION

public static final String PROP_DASHBOARD_CONFIGURATION
A property name. Its value contains a filename indicating a file containing Dashboard configuration properties. Default value is DASHBOARD_CONFIG_FILENAME.

See Also:
Constant Field Values
Constructor Detail

DashboardConfig

public DashboardConfig()
Method Detail

get

public static org.apache.commons.configuration.CompositeConfiguration get()
The main method returning a configuration object. The returned object is a singleton - but its contents (the properties it carries) can be changed dynamically (the properties are reloaded if their files are modified).

The configuration object contains all Java system properties and properties read from a Dashboard configuration file. This file name is given by the system property PROP_DASHBOARD_CONFIGURATION, or using a default name DASHBOARD_CONFIG_FILENAME. If the filename does not specify an absolute path, the file will be searched automatically in the following locations:

The System properties take precedence over properties read from the Dashboard property file.

The configuration object can be anytime extended by properties from other sources by using either methods defined in the CompositeConfiguration's API, or using a convenient method addConfigPropertyFile(java.lang.String) defined here. Properties from these additional files have higher priority than properties added earlier - except System properties, they are always the most prioritized.

Returns:
a configuration object

addConfigPropertyFile

public static boolean addConfigPropertyFile(String configFilename)
Add new configuration properties from a property file.

The newly added properties have higher priority than properties added earlier - except System properties, they are always the most prioritized.

Parameters:
configFilename - is a filename indicating a file (formatted as a Java properties file) with new properties (see get() explaining where is this file looked for)
Returns:
true if 'configFilename' is successfully added, false otherwise (in which case the cause is recorded in the log)

getString

public static String getString(String key,
                               String defaultValue)
Get a string associated with the given configuration key, or - if not found - get the given default value (which still may be null).

It is a convenient way to say:

 String value = Config.get().getString ("my.property", "yes");

Parameters:
key - is a property name
defaultValue - used if the 'key' cannot be found
Returns:
the property value, or 'defaultValue' if such property does not exist

getStrings

public static String[] getStrings(String key,
                                  String defaultValue)
Almost the same functionality as getString method. The different is the return value: this method allows to return several values of the same property. In the configuration file, a property can be repeated, or can have several comma-separated values.

By the way, the importance of a comma in a property value also means that any 'normal' (the one not meant as a value separator) commas in property values, must be escaped by backslashes.

Returns:
all values of the given property, or - if such property does not exist - return a one-element array with the 'defaultValue' unless the 'defaultValue' is also null in which case return an empty array

getInt

public static int getInt(String key,
                         int defaultValue)
Get an integer value associated with the given configuration key, or - if not found or not of integer value - get the given default value.

Parameters:
key - is a property name
defaultValue - used if the 'key' cannot be found, or if it is not an integer
Returns:
the property value, or 'defaultValue' if such property does not exist

isEnabled

public static boolean isEnabled(String key,
                                boolean defaultValue,
                                String serviceName,
                                Object owner)
Get a boolean value associated with the given configuration key, or - if not found - get the given default value.

Parameters:
key - is a property name
defaultValue - used if the 'key' cannot be found, or if its value is empty
Returns:
true for the property values 'true', 'on', 'yes' (case insensitive), and for an existing property with an empty value. For other values, return false. If the property does not exist at all, the 'defaultValue' is returned.

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010