2.17.2: 2011-06-17

net.sf.basedb.core
Class Config

java.lang.Object
  extended by net.sf.basedb.core.Config

public class Config
extends Object

Use this class to access the configuration settings for BASE.

The configuration settings are always stored in a file named base.config. It should be located at the root of one of the paths in the CLASSPATH environment variable. For Tomcat this means it should be located in the WEB-INF/classes folder.

Version:
2.0
Author:
Nicklas

Field Summary
private static SortedSet<String> allCharsets
           
private static SortedSet<String> commonCharsets
           
private static Properties config
          Variable for holding the configuration properties.
private static File configDir
           
private static boolean isInitialised
           
private static Locale locale
           
private static Properties overridden
          Properties that has been programmatically overridden.
 
Constructor Summary
Config()
           
 
Method Summary
static SortedSet<String> getAllCharsets()
          Get a set containing all character sets known to the current java virtual machine.
static boolean getBoolean(String key)
          Get the configuration setting specified by key as a boolean value.
static String getCharset()
          Get the default character set to use when no other has been specified.
static SortedSet<String> getCommonCharsets()
          Get a set containing the most common character sets used by text files.
static File getConfigDirectory()
          Get the directory where the BASE configuration files are located.
static int getInt(String key)
          Get the configuration setting specified by key as an integer value.
static int getInt(String key, int defaultValue)
          Get the configuration setting specified by key as an integer value.
static Locale getLocale()
          Get the default locale configured for the server.
static long getLong(String key, long defaultValue)
          Get the configuration setting specified by key as a long value.
static String getString(String key)
          Get the configuration setting specified by key as a String value.
static String getString(String key, String defaultValue)
          Get the configuration setting specified by key as a String value.
(package private) static void init()
          Loads the settings from the configuration file.
static void setProperty(String key, String value)
          Programatically set a configuration property that overrides a configuration setting in the base.config file.
(package private) static void unload()
          Unload all settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

config

private static Properties config
Variable for holding the configuration properties.


overridden

private static Properties overridden
Properties that has been programmatically overridden.


isInitialised

private static boolean isInitialised

configDir

private static File configDir

locale

private static Locale locale

commonCharsets

private static SortedSet<String> commonCharsets

allCharsets

private static SortedSet<String> allCharsets
Constructor Detail

Config

public Config()
Method Detail

init

static void init()
          throws ConfigurationException
Loads the settings from the configuration file.

Throws:
ConfigurationException - This exception is thrown if the configuration settings cannot be loaded

unload

static void unload()
Unload all settings.


setProperty

public static void setProperty(String key,
                               String value)
Programatically set a configuration property that overrides a configuration setting in the base.config file. This method should be called before the init() method is called (eg. before Application.start() is called). The configuration can't be changed once BASE has been started. Properties that has been overridden are automatically cleared when BASE is stopped (Application.stop(), unload()).

Parameters:
key - The name of the configuration property
value - The value or null to remove the overridden property
Since:
2.16

getConfigDirectory

public static File getConfigDirectory()
Get the directory where the BASE configuration files are located.

Returns:
The directory as a java.io.File object
Since:
2.6

getString

public static String getString(String key)
Get the configuration setting specified by key as a String value.

Parameters:
key - The key for the setting
Returns:
The value specified by key or null if it is not found

getString

public static String getString(String key,
                               String defaultValue)
Get the configuration setting specified by key as a String value.

Parameters:
key - The key for the setting
defaultValue - The value to return if the key is not found
Returns:
The value specified by key or defaultValue if it is not found or is empty

getInt

public static int getInt(String key)
Get the configuration setting specified by key as an integer value.

Parameters:
key - The key for the setting
Returns:
The value specified by key or 0 if it is not found or is not a number

getInt

public static int getInt(String key,
                         int defaultValue)
Get the configuration setting specified by key as an integer value.

Parameters:
key - The key for the setting
defaultValue - The value to return if the key is not found
Returns:
The value specified by key or defaultValue if it is not found

getLong

public static long getLong(String key,
                           long defaultValue)
Get the configuration setting specified by key as a long value.

Parameters:
key - The key for the setting
defaultValue - The value to return if the key is not found
Returns:
The value specified by key or defaultValue if it is not found

getBoolean

public static boolean getBoolean(String key)
Get the configuration setting specified by key as a boolean value. FALSE is returned if the setting doesn't exist, if it contains an empty string, or one of the values 'no', 'false' or '0'. In all other cases TRUE is returned.

Parameters:
key - The key for the setting
Returns:
The value specified by key

getCharset

public static String getCharset()
Get the default character set to use when no other has been specified. It reads the setting from the defaultCharset setting and uses ISO-8859-1 if not specified.

Returns:
The name of the default charset to use
Since:
2.1.1

getCommonCharsets

public static SortedSet<String> getCommonCharsets()
Get a set containing the most common character sets used by text files. The set is sorted by name.

Returns:
A sorted set
Since:
2.17

getAllCharsets

public static SortedSet<String> getAllCharsets()
Get a set containing all character sets known to the current java virtual machine. The set is sorted by name with the most common character sets first.

Returns:
A sorted set
Since:
2.17

getLocale

public static Locale getLocale()
Get the default locale configured for the server.

Since:
2.16

2.17.2: 2011-06-17