Class FileBasedBuilderParametersImpl
java.lang.Object
org.apache.commons.configuration2.builder.BasicBuilderParameters
org.apache.commons.configuration2.builder.FileBasedBuilderParametersImpl
- All Implemented Interfaces:
Cloneable
,BasicBuilderProperties<BasicBuilderParameters>
,BuilderParameters
,FileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Direct Known Subclasses:
HierarchicalBuilderParametersImpl
,PropertiesBuilderParametersImpl
public class FileBasedBuilderParametersImpl
extends BasicBuilderParameters
implements FileBasedBuilderProperties<FileBasedBuilderParametersImpl>
An implementation of BuilderParameters
which contains parameters related to Configuration
implementations that are loaded from files.
The parameters defined here are interpreted by builder implementations that can deal with file-based configurations. Note that these parameters are typically no initialization properties of configuration objects (i.e. they are not passed to set methods after the creation of the result configuration). Rather, the parameters object is stored as a whole in the builder's map with initialization parameters and can be accessed from there.
This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
during configuration of a ConfigurationBuilder
.
- Since:
- 2.0
-
Field Summary
Fields inherited from interface org.apache.commons.configuration2.builder.BuilderParameters
RESERVED_PARAMETER_PREFIX
-
Constructor Summary
ConstructorDescriptionCreates a new instance ofFileBasedBuilderParametersImpl
with an uninitializedFileHandler
object.Creates a new instance ofFileBasedBuilderParametersImpl
and associates it with the givenFileHandler
object. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clones this object.Creates a newFileBasedBuilderParametersImpl
object from the content of the given map.fromParameters
(Map<String, ?> params) Looks up an instance of this class in the specified parameters map.fromParameters
(Map<String, ?> params, boolean createIfMissing) Looks up an instance of this class in the specified parameters map and optionally creates a new one if none is found.Gets theFileHandler
managed by this object.Gets a map with all parameters defined by this objects.Gets theReloadingDetectorFactory
.Gets the refresh delay for reload operations.void
inheritFrom
(Map<String, ?> source) Inherits properties from the specified map.setBasePath
(String path) Sets the base path of the associatedFileHandler
.setEncoding
(String enc) Sets the encoding of the associatedFileHandler
.Sets the location of the associatedFileHandler
as aFile
object.setFileName
(String name) Sets the file name of the associatedFileHandler
.Sets theFileSystem
of the associatedFileHandler
.setLocationStrategy
(FileLocationStrategy strategy) Sets theFileLocationStrategy
for resolving the referenced file.Sets the location of the associatedFileHandler
as an absolute file path.setReloadingDetectorFactory
(ReloadingDetectorFactory reloadingDetectorFactory) Sets the factory for creatingReloadingDetector
objects.setReloadingRefreshDelay
(Long reloadingRefreshDelay) Sets the refresh delay for reloading supportSets the location of the associatedFileHandler
as aURL
object.setURL
(URL url, URLConnectionOptions urlConnectionOptions) Sets the location of the associatedFileHandler
as aURL
object.Methods inherited from class org.apache.commons.configuration2.builder.BasicBuilderParameters
copyPropertiesFrom, fetchBeanHelper, fetchInterpolatorSpecification, fetchProperty, merge, setBeanHelper, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setSynchronizer, setThrowExceptionOnMissing, storeProperty
-
Constructor Details
-
FileBasedBuilderParametersImpl
public FileBasedBuilderParametersImpl()Creates a new instance ofFileBasedBuilderParametersImpl
with an uninitializedFileHandler
object. -
FileBasedBuilderParametersImpl
Creates a new instance ofFileBasedBuilderParametersImpl
and associates it with the givenFileHandler
object. If the handler is null, a new handler instance is created.- Parameters:
handler
- the associatedFileHandler
(can be null)
-
-
Method Details
-
fromMap
Creates a newFileBasedBuilderParametersImpl
object from the content of the given map. WhilefromParameters()
expects that an object already exists and is stored in the given map, this method creates a new instance based on the content of the map. The map can contain properties of aFileHandler
and some additional settings which are stored directly in the newly created object. If the map is null, an uninitialized instance is returned.- Parameters:
map
- the map with properties (must not be null)- Returns:
- the newly created instance
- Throws:
ClassCastException
- if the map contains invalid data
-
fromParameters
Looks up an instance of this class in the specified parameters map. This is equivalent tofromParameters(params, false
;}- Parameters:
params
- the map with parameters (must not be null- Returns:
- the instance obtained from the map or null
- Throws:
IllegalArgumentException
- if the map is null
-
fromParameters
public static FileBasedBuilderParametersImpl fromParameters(Map<String, ?> params, boolean createIfMissing) Looks up an instance of this class in the specified parameters map and optionally creates a new one if none is found. This method can be used to obtain an instance of this class which has been stored in a parameters map. It is compatible with thegetParameters()
method.- Parameters:
params
- the map with parameters (must not be nullcreateIfMissing
- determines the behavior if no instance is found in the map; if true, a new instance with default settings is created; if false, null is returned- Returns:
- the instance obtained from the map or null
- Throws:
IllegalArgumentException
- if the map is null
-
clone
Clones this object. This is useful because multiple builder instances may use a similar set of parameters. However, single instances of parameter objects must not assigned to multiple builders. Therefore, cloning a parameters object provides a solution for this use case. This method creates a new parameters object with the same content as this one. The internal map storing the parameter values is cloned, too, also collection structures contained in this map. However, no a full deep clone operation is performed. Objects like aConfigurationInterpolator
orLookup
s are shared between this and the newly created instance. This implementation also creates a copy of theFileHandler
.- Overrides:
clone
in classBasicBuilderParameters
- Returns:
- a clone of this object
-
getFileHandler
Gets theFileHandler
managed by this object. This object is updated every time the file location is changed.- Returns:
- the managed
FileHandler
-
getParameters
Gets a map with all parameters defined by this objects. The keys of the map correspond to concrete properties supported by theConfiguration
implementation class the builder produces. The values are the corresponding property values. The return value must not be null. This implementation returns a copy of the internal parameters map with the values set so far. Collection structures (e.g. for lookup objects) are stored as defensive copies, so the original data cannot be modified. This implementation returns a map which contains this object itself under a specific key. The staticfromParameters()
method can be used to extract an instance from a parameters map. Of course, the properties inherited from the base class are also added to the result map.- Specified by:
getParameters
in interfaceBuilderParameters
- Overrides:
getParameters
in classBasicBuilderParameters
- Returns:
- a map with builder parameters
-
getReloadingDetectorFactory
Gets theReloadingDetectorFactory
. Result may be null which means that the default factory is to be used.- Returns:
- the
ReloadingDetectorFactory
-
getReloadingRefreshDelay
Gets the refresh delay for reload operations. Result may be null if this value has not been set.- Returns:
- the reloading refresh delay
-
inheritFrom
Inherits properties from the specified map. This can be used for instance to reuse parameters from one builder in another builder - also in parent-child relations in which a parent builder creates child builders. The purpose of this method is to let a concrete implementation decide which properties can be inherited. Because parameters are basically organized as a map it would be possible to simply copy over all properties from the source object. However, this is not appropriate in all cases. For instance, some properties - like aConfigurationInterpolator
- are tightly connected to a configuration and cannot be reused in a different context. For other properties, e.g. a file name, it does not make sense to copy it. Therefore, an implementation has to be explicit in the properties it wants to take over. This implementation takes some properties defined in this class into account.- Overrides:
inheritFrom
in classBasicBuilderParameters
- Parameters:
source
- the source properties to inherit from
-
setBasePath
Description copied from interface:FileBasedBuilderProperties
Sets the base path of the associatedFileHandler
.- Specified by:
setBasePath
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
path
- the base path- Returns:
- a reference to this object for method chaining
-
setEncoding
Description copied from interface:FileBasedBuilderProperties
Sets the encoding of the associatedFileHandler
.- Specified by:
setEncoding
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
enc
- the encoding- Returns:
- a reference to this object for method chaining
-
setFile
Description copied from interface:FileBasedBuilderProperties
Sets the location of the associatedFileHandler
as aFile
object.- Specified by:
setFile
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
file
- theFile
location- Returns:
- a reference to this object for method chaining
-
setFileName
Description copied from interface:FileBasedBuilderProperties
Sets the file name of the associatedFileHandler
.- Specified by:
setFileName
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
name
- the file name- Returns:
- a reference to this object for method chaining
-
setFileSystem
Description copied from interface:FileBasedBuilderProperties
Sets theFileSystem
of the associatedFileHandler
.- Specified by:
setFileSystem
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
fs
- theFileSystem
- Returns:
- a reference to this object for method chaining
-
setLocationStrategy
Description copied from interface:FileBasedBuilderProperties
Sets theFileLocationStrategy
for resolving the referenced file.- Specified by:
setLocationStrategy
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
strategy
- theFileLocationStrategy
- Returns:
- a reference to this object for method chaining
-
setPath
Description copied from interface:FileBasedBuilderProperties
Sets the location of the associatedFileHandler
as an absolute file path.- Specified by:
setPath
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
path
- the path location- Returns:
- a reference to this object for method chaining
-
setReloadingDetectorFactory
public FileBasedBuilderParametersImpl setReloadingDetectorFactory(ReloadingDetectorFactory reloadingDetectorFactory) Description copied from interface:FileBasedBuilderProperties
Sets the factory for creatingReloadingDetector
objects. With this method a custom factory for reloading detectors can be installed. Per default, a factory creatingFileHandlerReloadingDetector
objects is used.- Specified by:
setReloadingDetectorFactory
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
reloadingDetectorFactory
- theReloadingDetectorFactory
- Returns:
- a reference to this object for method chaining
-
setReloadingRefreshDelay
Description copied from interface:FileBasedBuilderProperties
Sets the refresh delay for reloading support- Specified by:
setReloadingRefreshDelay
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
reloadingRefreshDelay
- the refresh delay (in milliseconds)- Returns:
- a reference to this object for method chaining
-
setURL
Description copied from interface:FileBasedBuilderProperties
Sets the location of the associatedFileHandler
as aURL
object.- Specified by:
setURL
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
url
- theURL
location- Returns:
- a reference to this object for method chaining
-
setURL
Description copied from interface:FileBasedBuilderProperties
Sets the location of the associatedFileHandler
as aURL
object.- Specified by:
setURL
in interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>
- Parameters:
url
- theURL
locationurlConnectionOptions
- options- Returns:
- a reference to this object for method chaining
-