public class Config extends Object
Modifier and Type | Method and Description |
---|---|
void |
clear()
*
|
Config |
copy()
*
|
void |
createBooleanConfigValue(String id,
String description,
boolean dval)
*
|
void |
createNumericConfigValue(String id,
String description,
int dval)
*
|
void |
createSectionConfigValue(String id,
String description,
String dval)
*
|
boolean |
createSectionListConfigValue(String id,
String description,
String dval)
*
|
boolean |
createStringConfigValue(String id,
String description,
String dval)
*
|
boolean |
getBooleanValue(String section,
String id)
*
|
static Config |
getDefault() |
String |
getDefaultValue(String id)
Gets the default value of the named configuration item.
|
String |
getDescription(String id)
Get the descriptive text of the named configuration item.
|
Map<String,net.messagevortex.Config.ConfigElement> |
getMap() |
int |
getNumericValue(String section,
String id)
*
|
String |
getResouceFilename() |
String[] |
getSectionListValue(String section,
String id)
*
|
String |
getSectionValue(String section,
String id)
*
|
String |
getStringValue(String section,
String id)
*
|
boolean |
isDefaultValue(String section,
String id)
Checks if a specific key is returning default values only.
|
void |
load(String filename)
*
|
boolean |
removeConfigValue(String id)
*
|
boolean |
setBooleanValue(String section,
String id,
boolean value,
int lineNumber)
*
|
int |
setNumericValue(String section,
String id,
int value,
int lineNumber)
*
|
String |
setSectionListValue(String section,
String id,
String value,
int lineNumber)
*
|
String |
setSectionValue(String section,
String id,
String value,
int lineNumber)
*
|
String |
setStringValue(String section,
String id,
String value,
int lineNumber)
*
|
String |
store()
*
|
void |
store(String filename)
*
|
public Config(String ressourceFile) throws IOException
Creates an config object following the spec given in the resource file.
ressourceFile
- filename of the resource fileIOException
- if an error happens while reading the filepublic String getResouceFilename()
public static Config getDefault() throws IOException
IOException
public Config copy()
Returns a deep copy of this config store.
public void clear()
Reverts config store to all default values.
public void createBooleanConfigValue(String id, String description, boolean dval)
Creates a new boolean config value in the store.
id
- the name (id) of the new valuedescription
- the description for the valuedval
- the default valuepublic boolean setBooleanValue(String section, String id, boolean value, int lineNumber)
Sets a boolean value in the application config.
section
- the section of the config to be affected (null for default section)id
- key which should be setvalue
- Value to be set in keylineNumber
- the line number of the respective file (for error messages)NullPointerException
- if key does not exist in configDataClassCastException
- if key is not of type booleanpublic boolean getBooleanValue(String section, String id)
Gets a boolean value from the application config.
section
- the section of the config to be affected (null for default section)id
- key which should be setNullPointerException
- if key does not exist in configDataClassCastException
- if key is not of type booleanpublic void createNumericConfigValue(String id, String description, int dval)
Creates a new numeric config value in the store.
id
- the name (id) of the new valuedescription
- the description for the valuedval
- the default valuepublic void createSectionConfigValue(String id, String description, String dval)
Creates a new section config value in the store.
id
- the name (id) of the new valuedescription
- the description for the valuedval
- the default valuepublic int setNumericValue(String section, String id, int value, int lineNumber)
Sets a numeric value in the application config.
section
- section from which the value should be taken. null defaults to default
sectionid
- key which should be setvalue
- Value to be set in keylineNumber
- the line number of the respective file (for error messages)NullPointerException
- if key does not exist in configDataClassCastException
- if key is not of type booleanpublic int getNumericValue(String section, String id)
Gets a numeric value from the application config.
section
- section from which the value should be taken. null defaults to default sectionid
- key which should be setNullPointerException
- if key does not exist in configDataClassCastException
- if key is not of type booleanpublic boolean createSectionListConfigValue(String id, String description, String dval)
Creates a section_list config item.
Creates a config item with a case insensitive identifier. The content of the item may not be null.
id
- Name of config item (case insensitive)description
- Description of value to be writtendval
- Default content if not setpublic String setSectionListValue(String section, String id, String value, int lineNumber)
Set a section_list value to a config parameter.
section
- section from which the value should be taken. null defaults to default
sectionid
- key which should be setvalue
- Value to be set in keylineNumber
- the line number of the respective file (for error messages)NullPointerException
- when id is unknown or value is nullClassCastException
- when id is not a String settingpublic String[] getSectionListValue(String section, String id)
Sets the value of a section_list type.
section
- section from which the value should be taken. 'Null' defaults to default sectionid
- the id of the value to be retrievedNullPointerException
- when id is unknownClassCastException
- when id is not a String settingpublic String setSectionValue(String section, String id, String value, int lineNumber)
Set a section value to a config parameter.
section
- section from which the value should be taken. Use "null" to get the default
sectionid
- key which should be setvalue
- Value to be set in keylineNumber
- the line number of the respective file (for error messages)NullPointerException
- when id is unknown or value is nullClassCastException
- when id is not a String settingpublic String getSectionValue(String section, String id)
Gets the value of a section type.
section
- section from which the value should be taken. 'Null' defaults to default sectionid
- the id of the value to be retrievedNullPointerException
- when id is unknownClassCastException
- when id is not a String settingpublic boolean createStringConfigValue(String id, String description, String dval)
Creates a String config item.
Creates a config item with a case insensitive identifier. The content of the item may not be null.
id
- Name of config item (case insensitive)description
- Description of value to be writtendval
- Default content if not setpublic boolean removeConfigValue(String id)
Removes a config value declaration from the config container.
id
- the id of the value to be removedpublic String setStringValue(String section, String id, String value, int lineNumber)
Set a String value to a config parameter.
section
- section from which the value should be taken. 'null' defaults to default
sectionid
- Name of config item (case insensitive)value
- Value to be set in keylineNumber
- the line number of the respective file (for error messages)NullPointerException
- when id is unknown or value is nullClassCastException
- when id is not a String settingpublic String getStringValue(String section, String id)
Sets the value of a string type.
section
- section from which the value should be taken. 'null' defaults to default sectionid
- the id of the value to be retrievedNullPointerException
- when id is unknownClassCastException
- when id is not a String settingpublic boolean isDefaultValue(String section, String id)
Checks if a specific key is returning default values only.
section
- the section to be querriedid
- the id of the key to be queriedpublic void load(String filename) throws IOException
Loads a config file and validates input.
Loads and parses a file according to the resources configuration
filename
- name of the property file to be readIOException
- if the file is not parsed properlypublic String store() throws IOException
Writes config to a string.
Writes a commented file according to the configuration
IOException
- if error writing filepublic void store(String filename) throws IOException
Writes a config file.
Writes a commented file according to the configuration
filename
- name of the property file to be writtenIOException
- if error writing to filepublic String getDescription(String id)
id
- identification of the configuration itemCopyright © 2023. All rights reserved.