Class ConfigMap
java.lang.Object
org.apache.juneau.config.internal.ConfigMap
- All Implemented Interfaces:
ConfigStoreListener
Represents the parsed contents of a configuration.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns the values in this config map as a map of maps.commit()Persist any changes made to this map and signal all listeners.Reads an entry from this map.Returns the keys of the entries in the specified section.Returns the listeners currently associated with this config map.getPreLines(String section) Returns the pre-lines on the specified section.Returns the keys of the entries in the specified section.booleanhasSection(String section) Returnstrue if this config has the specified section.Overwrites the contents of the config file.voidCalled when the physical contents of a config file have changed.register(ConfigEventListener listener) Registers an event listener on this map.removeEntry(String section, String key) Removes an entry.removeImport(String section, String importName) Not implemented.removeSection(String section) Removes a section.rollback()Does a rollback of any changes on this map currently in memory.setEntry(String section, String key, String value, String modifiers, String comment, List<String> preLines) Adds or overwrites an existing entry.Not implemented.setSection(String section, List<String> preLines) Adds a new section or replaces the pre-lines on an existing section.toString()unregister(ConfigEventListener listener) Unregisters an event listener from this map.Serializes this map to the specified writer.
-
Constructor Details
-
ConfigMap
Constructor.- Parameters:
store- The config store.name- The config name.- Throws:
IOException- Thrown by underlying stream.
-
-
Method Details
-
asMap
Returns the values in this config map as a map of maps.This is considered a snapshot copy of the config map.
The returned map is modifiable, but modifications to the returned map are not reflected in the config map.
- Returns:
- A copy of this config as a map of maps.
-
commit
Persist any changes made to this map and signal all listeners.If the underlying contents of the file have changed, this will reload it and apply the changes on top of the modified file.
Subsequent changes made to the underlying file will also be signaled to all listeners.
We try saving the file up to 10 times.
If the file keeps changing on the file system, we throw an exception.- Returns:
- This object.
- Throws:
IOException- Thrown by underlying stream.
-
getEntry
Reads an entry from this map.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.key- The entry key.
Must not benull .- Returns:
- The entry, or
null if the entry doesn't exist.
-
getKeys
Returns the keys of the entries in the specified section.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.- Returns:
- An unmodifiable set of keys, or an empty set if the section doesn't exist.
-
getListeners
Returns the listeners currently associated with this config map.- Returns:
- The listeners currently associated with this config map.
-
getPreLines
Returns the pre-lines on the specified section.The pre-lines are all lines such as blank lines and comments that preceed a section.
- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.- Returns:
- An unmodifiable list of lines, or
null if the section doesn't exist.
-
getSections
Returns the keys of the entries in the specified section.- Returns:
- An unmodifiable set of keys.
-
hasSection
Returnstrue if this config has the specified section.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.- Returns:
true if this config has the specified section.
-
load
public ConfigMap load(String contents, boolean synchronous) throws IOException, InterruptedException Overwrites the contents of the config file.- Parameters:
contents- The new contents of the config file.synchronous- Wait until the change has been persisted before returning this map.- Returns:
- This object.
- Throws:
IOException- Thrown by underlying stream.InterruptedException- Thread was interrupted.
-
onChange
Description copied from interface:ConfigStoreListenerCalled when the physical contents of a config file have changed.- Specified by:
onChangein interfaceConfigStoreListener- Parameters:
newContents- The new config contents;
-
register
Registers an event listener on this map.- Parameters:
listener- The new listener.- Returns:
- This object.
-
removeEntry
Removes an entry.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.key- The entry key.
Must not benull .- Returns:
- This object.
-
removeImport
Not implemented.- Parameters:
section- The section name where to place the import statement.
Must not benull .
Use blank for the default section.importName- The import name.
Must not benull .- Returns:
- This object.
-
removeSection
Removes a section.This eliminates all entries in the section as well.
- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.- Returns:
- This object.
-
rollback
Does a rollback of any changes on this map currently in memory.- Returns:
- This object.
-
setEntry
public ConfigMap setEntry(String section, String key, String value, String modifiers, String comment, List<String> preLines) Adds or overwrites an existing entry.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.key- The entry key.
Must not benull .value- The entry value.
Ifnull , the previous value will not be overwritten.modifiers- Optional modifiers.
Ifnull , the previous value will not be overwritten.comment- Optional comment.
Ifnull , the previous value will not be overwritten.preLines- Optional pre-lines.
Ifnull , the previous value will not be overwritten.- Returns:
- This object.
-
setImport
Not implemented.- Parameters:
section- The section name where to place the import statement.
Must not benull .
Use blank for the default section.importName- The import name.
Must not benull .preLines- Optional comment and blank lines to add immediately before the import statement.
Ifnull , previous pre-lines will not be replaced.- Returns:
- This object.
-
setSection
Adds a new section or replaces the pre-lines on an existing section.- Parameters:
section- The section name.
Must not benull .
Use blank to refer to the default section.preLines- The pre-lines on the section.
Ifnull , the previous value will not be overwritten.- Returns:
- This object.
-
toString
-
unregister
Unregisters an event listener from this map.- Parameters:
listener- The listener to remove.- Returns:
- This object.
-
writeTo
Serializes this map to the specified writer.- Parameters:
w- The writer to serialize to.- Returns:
- The same writer passed in.
- Throws:
IOException- Thrown by underlying stream.
-