Class PropertiesFileConfiguration
java.lang.Object
org.apache.commons.configuration2.event.BaseEventSource
org.apache.commons.configuration2.AbstractConfiguration
org.apache.commons.configuration2.BaseConfiguration
org.apache.commons.configuration2.PropertiesConfiguration
de.aristaflow.adept2.util.configuration.PropertiesFileConfiguration
- All Implemented Interfaces:
Transactional,Cloneable,Configuration,EventSource,FileBasedConfiguration,ImmutableConfiguration,FileBased,FileLocatorAware,SynchronizerSupport
This class extends a
The default for the list delimiter is
PropertiesConfiguration by the means for an underlying file as
well as optionally automatically saving the configuration in case of changes. When automatically
saving, each change will immediately lead to a save try. Saving will be suspended while the
configuration file is being loaded or already saved. A failed save will be logged, and the change
which caused it will then throw a ConfigurationRuntimeException; the change remains
in memory.The default for the list delimiter is
,. The PropertiesIOFactory writes the
file, keeping the characters outside the Basic Multilingual Plane.
Within a writable transaction, the changes are not saved one by one but once when the transaction
is finished; if that save fails, finishing throws the ConfigurationRuntimeException.
Closing a transaction without finishing it does not restore the values changed in memory, the
next save stores them. Other threads see the changes of a transaction at once unless a lock keeps
them out, as the one of a TransactionalCompositeConfiguration does.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.configuration2.PropertiesConfiguration
PropertiesConfiguration.DefaultIOFactory, PropertiesConfiguration.IOFactory, PropertiesConfiguration.JupIOFactory, PropertiesConfiguration.JupPropertiesReader, PropertiesConfiguration.JupPropertiesWriter, PropertiesConfiguration.PropertiesReader, PropertiesConfiguration.PropertiesWriter -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FileHandlerThe handler for the configuration file.protected final URLThe URL of a stream; the file handler does not have one in case of an input stream.Fields inherited from class org.apache.commons.configuration2.PropertiesConfiguration
DEFAULT_ENCODING, DEFAULT_INCLUDE_LISTENER, NOOP_INCLUDE_LISTENER -
Constructor Summary
ConstructorsConstructorDescriptionPropertiesFileConfiguration(File file, Logger autosaveLogger) Creates a new properties configuration based on the designated file and loads the configuration if the file exists.PropertiesFileConfiguration(String file, Logger autosaveLogger) Creates a new properties configuration based on the designated file and loads the configuration if the file exists.PropertiesFileConfiguration(URL url, InputStream stream) Creates a new properties configuration based on the designated URL and loads the configuration from the designated stream.PropertiesFileConfiguration(URL file, Logger autosaveLogger) Creates a new properties configuration based on the designated file and loads the configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddPropertyInternal(String key, Object value) protected voidbeginWrite(boolean optimize) clone()Refuses to clone this configuration: a copy would share the transactions of the threads and the file handler with it, so that saving the copy would save this configuration.voidCloses the current level of the transaction of the calling thread.voidFinishes the current level of the transaction of the calling thread.Gets the URL of the underlying properties file.voidload()Loads the configuration from the underlying properties file.voidsave()Saves the configuration to the underlying properties file.voidstartTransaction(boolean readOnly) Starts a transaction of the calling thread on this object.Methods inherited from class org.apache.commons.configuration2.PropertiesConfiguration
getFooter, getHeader, getInclude, getIncludeListener, getIncludeOptional, getIOFactory, getLayout, getLocator, initFileLocator, isIncludesAllowed, read, setFooter, setHeader, setInclude, setIncludeListener, setIncludeOptional, setIncludesAllowed, setIOFactory, setLayout, unescapeJava, unescapeJava, writeMethods inherited from class org.apache.commons.configuration2.BaseConfiguration
addPropertyDirect, clearInternal, clearPropertyDirect, containsKeyInternal, containsValueInternal, getKeysInternal, getPropertyInternal, isEmptyInternal, sizeInternalMethods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, clear, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getKeysInternal, getKeysInternal, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setPropertyInternal, setSynchronizer, setThrowExceptionOnMissing, size, subset, unlockMethods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.Configuration
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subsetMethods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
containsKey, containsValue, entrySet, forEach, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, sizeMethods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport
getSynchronizer, lock, setSynchronizer, unlock
-
Field Details
-
fileHandler
The handler for the configuration file. -
streamUrl
The URL of a stream; the file handler does not have one in case of an input stream.
-
-
Constructor Details
-
PropertiesFileConfiguration
public PropertiesFileConfiguration(String file, Logger autosaveLogger) throws ConfigurationException Creates a new properties configuration based on the designated file and loads the configuration if the file exists. If a logger is provided, changes of the configuration will be automatically saved to the underlying file, the file will be created if required. A failed save will be logged, and the change which caused it will throw aConfigurationRuntimeException.- Parameters:
file- The file to base the properties configuration on.autosaveLogger- Whether to automatically save changes to the underlying file. If so, a failed save will be logged to this logger, and the change which caused it will throw aConfigurationRuntimeException. Usenullto not automatically save changes.- Throws:
ConfigurationException- If loading the configuration from the designated file fails, aConfigurationExceptionwill be thrown.
-
PropertiesFileConfiguration
Creates a new properties configuration based on the designated file and loads the configuration if the file exists. If a logger is provided, changes of the configuration will be automatically saved to the underlying file, the file will be created if required. A failed save will be logged, and the change which caused it will throw aConfigurationRuntimeException.- Parameters:
file- The file to base the properties configuration on.autosaveLogger- Whether to automatically save changes to the underlying file. If so, a failed save will be logged to this logger, and the change which caused it will throw aConfigurationRuntimeException. Usenullto not automatically save changes.- Throws:
ConfigurationException- If loading the configuration from the designated file fails, the file cannot be read or the configuration should be automatically saved but the file cannot be written, aConfigurationExceptionwill be thrown.
-
PropertiesFileConfiguration
Creates a new properties configuration based on the designated file and loads the configuration. The file has to exist. If a logger is provided, changes of the configuration will be automatically saved to the underlying file. A failed save will be logged, and the change which caused it will throw aConfigurationRuntimeException.- Parameters:
file- The file to base the properties configuration on.autosaveLogger- Whether to automatically save changes to the underlying file. If so, a failed save will be logged to this logger, and the change which caused it will throw aConfigurationRuntimeException. Usenullto not automatically save changes.- Throws:
ConfigurationException- If loading the configuration from the designated file fails, aConfigurationExceptionwill be thrown. If the file cannot be read or the configuration should be automatically saved but the file cannot be written, theConfigurationExceptionwill wrap aFileNotFoundException.
-
PropertiesFileConfiguration
Creates a new properties configuration based on the designated URL and loads the configuration from the designated stream. Autosaving is not possible since the stream is not an output stream.- Parameters:
url- The URL specifying the properties file. This is merely for information purpose. If you do not have an URL usePropertiesConfigurationdirectly.stream- The input stream to read the configuration from.- Throws:
ConfigurationException- If loading the configuration from the designated file fails, aConfigurationExceptionwill be thrown.
-
-
Method Details
-
addPropertyInternal
Unlike the library, this flattens each element of an iterable or an iterator on its own, as the library does for an array: the library remembers the elements it has visited by identity, so it adds repeated elements which are the same object, such as small numbers, only once.
- Overrides:
addPropertyInternalin classAbstractConfiguration
-
getFileUrl
Gets the URL of the underlying properties file.- Returns:
- The URL of the underlying properties file.
-
load
Loads the configuration from the underlying properties file.- Throws:
ConfigurationException- If there are problems loading the configuration from the underlying properties file, aConfigurationExceptionwill be thrown.
-
save
Saves the configuration to the underlying properties file.- Throws:
ConfigurationException- If there are problems saving the configuration to the underlying properties file, aConfigurationExceptionwill be thrown.
-
startTransaction
public void startTransaction(boolean readOnly) Description copied from interface:TransactionalStarts a transaction of the calling thread on this object. If the calling thread has started one already, this joins it and opens another level. A failed start leaves no level behind.- Specified by:
startTransactionin interfaceTransactional- Parameters:
readOnly- Whether the transaction only reads values. This is set by the outermost start; a nested read-only level joins a writable transaction.
-
finishTransaction
public void finishTransaction()Description copied from interface:TransactionalFinishes the current level of the transaction of the calling thread. Finishing the outermost level commits the transaction, finishing a nested level only ends that level. The level still has to be closed. If committing fails, the outermost level remains unfinished, so that closing it rolls the transaction back.- Specified by:
finishTransactionin interfaceTransactional
-
closeTransaction
public void closeTransaction()Description copied from interface:TransactionalCloses the current level of the transaction of the calling thread. Closing the outermost level rolls the transaction back unless it has been finished, and releases what the transaction holds. This belongs in afinallyblock. So as not to hide the exception which skipped finishing, a failure when rolling back or releasing is logged instead of thrown.- Specified by:
closeTransactionin interfaceTransactional
-
clone
Refuses to clone this configuration: a copy would share the transactions of the threads and the file handler with it, so that saving the copy would save this configuration.- Overrides:
clonein classPropertiesConfiguration- Returns:
- Nothing, this always throws.
- Throws:
ConfigurationRuntimeException- Since this configuration cannot be cloned, aConfigurationRuntimeExceptionwrapping aCloneNotSupportedExceptionwill always be thrown.
-
beginWrite
protected void beginWrite(boolean optimize) - Overrides:
beginWritein classAbstractConfiguration
-