public final class DBManConfigurationHelper extends java.lang.Object implements DBManConfigurationHelperI
This class provides functionality to watch a specified configuration file for any modifications. When a change is detected, it initiates an update process by notifying the registered ConfChangeEventListenerI-s to ensure that the application's configuration remains consistent with the latest changes in the file.
| Constructor and Description |
|---|
DBManConfigurationHelper(java.io.File _confFile)
Constructs a DBManConfigurationHelper to monitor the specified configuration file.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEventListener(ConfChangeEventListenerI listener)
Registers a listener to receive notifications when the configuration changes.
|
void |
commentOut(java.lang.String _section,
java.lang.String _variable,
java.lang.String _comment)
Comments out a specific variable in memory only.
|
java.lang.String |
doUpdate()
Checks for updates using the internal last-modified timestamp stored in the properties.
|
java.lang.String |
doUpdate(long l)
Performs a semi-automatic reload if the configuration file on disk is newer than the specified timestamp.
|
void |
fireConfChangeEvent()
Fires a configuration change event to all registered listeners.
|
java.lang.String |
getCommentedOut(java.lang.String _section,
java.lang.String _variable)
Retrieves the comment text of a commented-out value of a variable, if it exists.
|
bini |
getConf()
Retrieves the underlying configuration object.
|
ErrorHandler |
getErrorHandler()
Retrieves the error handler associated with this configuration helper.
|
java.lang.String |
getInifileName()
Gets the name of the INI file currently being used.
|
java.util.Properties |
getSectionAsProperties(java.lang.String section)
Gets a complete section wrapped into a Properties object.
|
java.util.Properties |
getSectionAsProperties(java.lang.String section,
java.util.Properties props)
Gets a complete section wrapped into a Properties object.
|
java.lang.String |
getSourceFilePath()
Returns the absolute path where the configuration file is located.
|
java.lang.String |
getval(java.lang.String section,
java.lang.String variable)
Legacy method to get a value from the Inifile.
|
java.lang.String |
getval(java.lang.String section,
java.lang.String variable,
java.lang.String $default)
Legacy method to get a value with a default from the Inifile.
|
java.lang.String |
getvalAndVerify(java.lang.String section,
java.lang.String variable,
java.lang.String $default,
netrexx.lang.Rexx props) |
boolean |
getValueAsBool(java.lang.String _section,
java.lang.String _variable)
Retrieves a configuration value parsed as a boolean.
|
boolean |
getValueAsBool(java.lang.String _section,
java.lang.String _variable,
boolean _default)
Retrieves a configuration value parsed as a boolean, falling back to a default.
|
int |
getValueAsInt(java.lang.String _section,
java.lang.String _variable)
Retrieves a configuration value parsed as an integer, falling back to a default.
|
int |
getValueAsInt(java.lang.String _section,
java.lang.String _variable,
int _default)
Retrieves a configuration value parsed as an integer, falling back to a default.
|
java.lang.String |
getValueAsString(java.lang.String _section,
java.lang.String _variable)
Retrieves a configuration value as a String.
|
java.lang.String |
getValueAsString(java.lang.String _section,
java.lang.String _variable,
java.lang.String _default)
Retrieves a configuration value as a String, falling back to a default.
|
java.lang.String |
getvalWithUpdateAllowed(java.lang.String section,
java.lang.String variable)
Gets a value from the INI file, reloading it if necessary before retrieval.
|
boolean |
hasSection(java.lang.String section)
Checks if a specific section exists within the configuration.
|
java.lang.String |
mergeStateWithSource(java.io.BufferedReader _reader) |
void |
removeEventListener(ConfChangeEventListenerI listener)
Unregisters an existing configuration change listener.
|
void |
save()
Persists the current in-memory configuration to the file system.
|
java.lang.String |
save(java.io.BufferedReader _reader)
Deprecated.
|
void |
setSourceFilePath(java.lang.String $14) |
void |
setval(java.lang.String _section,
java.lang.String _variable,
java.lang.String _value)
Sets a configuration value.
|
java.nio.file.WatchService |
startWatchService()
Starts a WatchService for the watched path.
|
void |
stopWatchService(java.nio.file.WatchService watcher)
Stops the WatchService.
|
public DBManConfigurationHelper(java.io.File _confFile)
throws java.io.IOException,
java.io.FileNotFoundException
_confFile - The configuration file to monitor.IOException - If an I/O error occurs while accessing the file.FileNotFoundException - If the specified file does not exist.public java.nio.file.WatchService startWatchService()
throws java.io.IOException
IOException - If an I/O error occurs.public void stopWatchService(java.nio.file.WatchService watcher)
watcher - The WatchService instance to stop.public void addEventListener(ConfChangeEventListenerI listener)
DBManConfigurationHelperIaddEventListener in interface DBManConfigurationHelperIlistener - The ConfChangeEventListenerI to register.public void removeEventListener(ConfChangeEventListenerI listener)
DBManConfigurationHelperIremoveEventListener in interface DBManConfigurationHelperIlistener - The ConfChangeEventListenerI to remove.public void fireConfChangeEvent()
DBManConfigurationHelperIThis method creates a new ConfChangeEvent with the current last modified time
of the configuration file and notifies all registered listeners by calling their
ConfChangeEventListenerI.processConfChangeEvent(ConfChangeEvent) method.
If a listener throws an exception, it is logged as an error.
fireConfChangeEvent in interface DBManConfigurationHelperIpublic java.lang.String doUpdate(long l)
DBManConfigurationHelperIdoUpdate in interface DBManConfigurationHelperIl - The timestamp (in milliseconds) of the current configuration to check against.String containing the new modification timestamp if an update occurred,
or "0" if the file has not changed.public java.lang.String doUpdate()
DBManConfigurationHelperIThis behaves similarly to DBManConfigurationHelperI.doUpdate(long), but automatically uses the
current known timestamp of the loaded configuration.
doUpdate in interface DBManConfigurationHelperIpublic java.lang.String getInifileName()
DBManConfigurationHelperIgetInifileName in interface DBManConfigurationHelperIpublic bini getConf()
DBManConfigurationHelperIgetConf in interface DBManConfigurationHelperIbini configuration object.public ErrorHandler getErrorHandler()
DBManConfigurationHelperIgetErrorHandler in interface DBManConfigurationHelperIErrorHandler instance.public java.lang.String getvalAndVerify(java.lang.String section,
java.lang.String variable,
java.lang.String $default,
netrexx.lang.Rexx props)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic java.lang.String getval(java.lang.String section,
java.lang.String variable)
DBManConfigurationHelperIgetval in interface DBManConfigurationHelperIsection - The section name in the configuration file.variable - The specific key/variable within that section.public java.lang.String getval(java.lang.String section,
java.lang.String variable,
java.lang.String $default)
DBManConfigurationHelperIgetval in interface DBManConfigurationHelperIsection - The section name in the configuration file.variable - The specific key/variable within that section.$default - The value to return if the section or variable is missing.defaultValue.public java.lang.String getValueAsString(java.lang.String _section,
java.lang.String _variable)
DBManConfigurationHelperIgetValueAsString in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section.public java.lang.String getValueAsString(java.lang.String _section,
java.lang.String _variable,
java.lang.String _default)
DBManConfigurationHelperIgetValueAsString in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section._default - The value to return if the section or variable is missing.defaultValue.public boolean getValueAsBool(java.lang.String _section,
java.lang.String _variable)
DBManConfigurationHelperIgetValueAsBool in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section.public boolean getValueAsBool(java.lang.String _section,
java.lang.String _variable,
boolean _default)
DBManConfigurationHelperIgetValueAsBool in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section._default - The boolean value to return if the entry is missing or cannot be parsed.public int getValueAsInt(java.lang.String _section,
java.lang.String _variable)
DBManConfigurationHelperIgetValueAsInt in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section.public int getValueAsInt(java.lang.String _section,
java.lang.String _variable,
int _default)
DBManConfigurationHelperIgetValueAsInt in interface DBManConfigurationHelperI_section - The section name in the configuration file._variable - The specific key/variable within that section._default - The integer value to return if the entry is missing or cannot be parsed.public java.lang.String getvalWithUpdateAllowed(java.lang.String section,
java.lang.String variable)
DBManConfigurationHelperIgetvalWithUpdateAllowed in interface DBManConfigurationHelperIsection - The section name.variable - The variable key.public java.util.Properties getSectionAsProperties(java.lang.String section)
DBManConfigurationHelperIgetSectionAsProperties in interface DBManConfigurationHelperIsection - The section name to retrieve.public java.util.Properties getSectionAsProperties(java.lang.String section,
java.util.Properties props)
DBManConfigurationHelperIgetSectionAsProperties in interface DBManConfigurationHelperIsection - The section name to retrieve.props - An existing Properties object to populate, or null to create a new one.public boolean hasSection(java.lang.String section)
DBManConfigurationHelperIhasSection in interface DBManConfigurationHelperIsection - The name of the section to verify.true if the section exists; false otherwise.public void setval(java.lang.String _section,
java.lang.String _variable,
java.lang.String _value)
DBManConfigurationHelperIsetval in interface DBManConfigurationHelperI_section - The section name._variable - The variable key._value - The value to set.public void commentOut(java.lang.String _section,
java.lang.String _variable,
java.lang.String _comment)
DBManConfigurationHelperIis called.commentOut in interface DBManConfigurationHelperI_section - The section containing the variable._variable - The variable to comment out._comment - The comment text to store (optional).public java.lang.String getCommentedOut(java.lang.String _section,
java.lang.String _variable)
DBManConfigurationHelperIgetCommentedOut in interface DBManConfigurationHelperI_section - The section name._variable - The variable key.public void save()
throws java.io.IOException,
java.io.FileNotFoundException
DBManConfigurationHelperIThis method reads the original configuration file to preserve formatting and comments, merges the current values, and overwrites the current configuration file.
save in interface DBManConfigurationHelperIjava.io.IOException - If an I/O error occurs while reading the template or writing the file.java.io.FileNotFoundException - If the source file cannot be found.@Deprecated public java.lang.String save(java.io.BufferedReader _reader)
mergeStateWithSource(BufferedReader)public java.lang.String mergeStateWithSource(java.io.BufferedReader _reader)
public java.lang.String getSourceFilePath()
DBManConfigurationHelperIThis is particularly useful for generating detailed error messages, logging, and debugging configuration loading issues.
getSourceFilePath in interface DBManConfigurationHelperIpublic void setSourceFilePath(java.lang.String $14)
Copyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.