Package net.sf.basedb.core
Class Config
java.lang.Object
net.sf.basedb.core.Config
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
Modifier and TypeFieldDescriptionprivate static Properties
Variable for holding the configuration properties.private static File
private static boolean
private static Locale
private static Properties
Properties that has been programmatically overridden. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet a set containing all character sets known to the current java virtual machine.static boolean
getBoolean
(String key) Get the configuration setting specified bykey
as a boolean value.static String
Get the default character set to use when no other has been specified.Get a set containing the most common character sets used by text files.static File
Get the directory where the BASE configuration files are located.static int
Get the configuration setting specified bykey
as an integer value.static int
Get the configuration setting specified bykey
as an integer value.static Locale
Get the default locale configured for the server.static long
Get the configuration setting specified bykey
as a long value.static String
getRequiredString
(String key, String message) Get a required configuration setting.static String
Get the configuration setting specified bykey
as a String value.static String
Get the configuration setting specified bykey
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.
-
Field Details
-
config
Variable for holding the configuration properties. -
overridden
Properties that has been programmatically overridden. -
isInitialised
private static boolean isInitialised -
configDir
-
locale
-
commonCharsets
-
allCharsets
-
-
Constructor Details
-
Config
public Config()
-
-
Method Details
-
init
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
Programatically set a configuration property that overrides a configuration setting in the base.config file. This method should be called before theinit()
method is called (eg. beforeApplication.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 propertyvalue
- The value or null to remove the overridden property- Since:
- 2.16
-
getConfigDirectory
Get the directory where the BASE configuration files are located.- Returns:
- The directory as a
java.io.File
object - Since:
- 2.6
-
getString
Get the configuration setting specified bykey
as a String value.- Parameters:
key
- The key for the setting- Returns:
- The value specified by
key
or null if it is not found
-
getRequiredString
Get a required configuration setting. If the setting doesn't exists or is empty the given message is thrown as a ConfigurationException- Parameters:
key
- The key for the settingmessage
- The error message to throw if the setting doesn't exists- Returns:
- The value specified by
key
- Since:
- 3.0
-
getString
Get the configuration setting specified bykey
as a String value.- Parameters:
key
- The key for the settingdefaultValue
- The value to return if thekey
is not found- Returns:
- The value specified by
key
ordefaultValue
if it is not found or is empty
-
getInt
Get the configuration setting specified bykey
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
Get the configuration setting specified bykey
as an integer value.- Parameters:
key
- The key for the settingdefaultValue
- The value to return if thekey
is not found- Returns:
- The value specified by
key
ordefaultValue
if it is not found
-
getLong
Get the configuration setting specified bykey
as a long value.- Parameters:
key
- The key for the settingdefaultValue
- The value to return if thekey
is not found- Returns:
- The value specified by
key
ordefaultValue
if it is not found
-
getBoolean
Get the configuration setting specified bykey
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
Get the default character set to use when no other has been specified. It reads the setting from thedefaultCharset
setting and usesISO-8859-1
if not specified.- Returns:
- The name of the default charset to use
- Since:
- 2.1.1
-
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
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
Get the default locale configured for the server.- Since:
- 2.16
-