Class PropertiesFileConfiguration

  • All Implemented Interfaces:
    Cloneable, org.apache.commons.configuration2.Configuration, org.apache.commons.configuration2.event.EventSource, org.apache.commons.configuration2.FileBasedConfiguration, org.apache.commons.configuration2.ImmutableConfiguration, org.apache.commons.configuration2.io.FileBased, org.apache.commons.configuration2.io.FileLocatorAware, org.apache.commons.configuration2.sync.SynchronizerSupport

    public class PropertiesFileConfiguration
    extends org.apache.commons.configuration2.PropertiesConfiguration
    This class extends a 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.
    The default for the list delimiter is ,.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.apache.commons.configuration2.PropertiesConfiguration

        org.apache.commons.configuration2.PropertiesConfiguration.DefaultIOFactory, org.apache.commons.configuration2.PropertiesConfiguration.IOFactory, org.apache.commons.configuration2.PropertiesConfiguration.JupIOFactory, org.apache.commons.configuration2.PropertiesConfiguration.JupPropertiesReader, org.apache.commons.configuration2.PropertiesConfiguration.JupPropertiesWriter, org.apache.commons.configuration2.PropertiesConfiguration.PropertiesReader, org.apache.commons.configuration2.PropertiesConfiguration.PropertiesWriter
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.apache.commons.configuration2.io.FileHandler fileHandler
      The handler for the configuration file.
      protected URL streamUrl
      The URL of a stream; the file handler does not have on 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

      Constructors 
      Constructor Description
      PropertiesFileConfiguration​(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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      URL getFileUrl()
      Gets the URL of the underlying properties file.
      void load()
      Loads the configuration from the underlying properties file.
      void save()
      Saves the configuration to the underlying properties file.
      • Methods inherited from class org.apache.commons.configuration2.PropertiesConfiguration

        clone, getFooter, getHeader, getInclude, getIncludeListener, getIncludeOptional, getIOFactory, getLayout, initFileLocator, isIncludesAllowed, read, setFooter, setHeader, setInclude, setIncludeListener, setIncludeOptional, setIncludesAllowed, setIOFactory, setLayout, unescapeJava, unescapeJava, write
      • Methods inherited from class org.apache.commons.configuration2.BaseConfiguration

        addPropertyDirect, clearInternal, clearPropertyDirect, containsKeyInternal, getKeysInternal, getPropertyInternal, isEmptyInternal, sizeInternal
      • Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration

        addErrorLogListener, addProperty, addPropertyInternal, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, 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, 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, unlock
      • Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource

        addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
      • Methods inherited from interface org.apache.commons.configuration2.Configuration

        addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subset
      • Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration

        containsKey, 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, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
      • Methods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport

        getSynchronizer, lock, setSynchronizer, unlock
    • Field Detail

      • fileHandler

        protected final org.apache.commons.configuration2.io.FileHandler fileHandler
        The handler for the configuration file.
      • streamUrl

        protected final URL streamUrl
        The URL of a stream; the file handler does not have on in case of an input stream.
    • Constructor Detail

      • PropertiesFileConfiguration

        public PropertiesFileConfiguration​(String file,
                                           Logger autosaveLogger)
                                    throws org.apache.commons.configuration2.ex.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. Problems when saving will be logged appropriately.
        Parameters:
        file - The file to base the properties configuration on.
        autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown.
      • PropertiesFileConfiguration

        public PropertiesFileConfiguration​(File file,
                                           Logger autosaveLogger)
                                    throws org.apache.commons.configuration2.ex.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. Problems when saving will be logged appropriately.
        Parameters:
        file - The file to base the properties configuration on.
        autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
        Throws:
        org.apache.commons.configuration2.ex.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, a ConfigurationException will be thrown.
      • PropertiesFileConfiguration

        public PropertiesFileConfiguration​(URL file,
                                           Logger autosaveLogger)
                                    throws org.apache.commons.configuration2.ex.ConfigurationException
        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. Problems when saving will be logged appropriately.
        Parameters:
        file - The file to base the properties configuration on.
        autosaveLogger - Whether to automatically save changes to the underlying file. If so, problems will be logged to this logger. Use null to not automatically save changes.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown. If the file cannot be read or the configuration should be automatically saved but the file cannot be written, the ConfigurationException will wrap a FileNotFoundException.
      • PropertiesFileConfiguration

        public PropertiesFileConfiguration​(URL url,
                                           InputStream stream)
                                    throws org.apache.commons.configuration2.ex.ConfigurationException
        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 use PropertiesConfiguration directly.
        stream - The input stream to read the configuration from.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If loading the configuration from the designated file fails, a ConfigurationException will be thrown.
    • Method Detail

      • getFileUrl

        public URL getFileUrl()
        Gets the URL of the underlying properties file.
        Returns:
        The URL of the underlying properties file.
      • load

        public void load()
                  throws org.apache.commons.configuration2.ex.ConfigurationException
        Loads the configuration from the underlying properties file.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If there are problems loading the configuration from the underlying properties file, a ConfigurationException will be thrown.
      • save

        public void save()
                  throws org.apache.commons.configuration2.ex.ConfigurationException
        Saves the configuration to the underlying properties file.
        Throws:
        org.apache.commons.configuration2.ex.ConfigurationException - If there are problems saving the configuration to the underlying properties file, a ConfigurationException will be thrown.