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
ConstructorsConstructorDescriptionCreates a new instance ofFileBasedBuilderParametersImplwith an uninitializedFileHandlerobject.Creates a new instance ofFileBasedBuilderParametersImpland associates it with the givenFileHandlerobject. -
Method Summary
Modifier and TypeMethodDescriptionclone()Clones this object.Creates a newFileBasedBuilderParametersImplobject 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 theFileHandlermanaged by this object.Gets a map with all parameters defined by this objects.Gets theReloadingDetectorFactory.Gets the refresh delay for reload operations.voidinheritFrom(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 associatedFileHandleras aFileobject.setFileName(String name) Sets the file name of the associatedFileHandler.Sets theFileSystemof the associatedFileHandler.setLocationStrategy(FileLocationStrategy strategy) Sets theFileLocationStrategyfor resolving the referenced file.Sets the location of the associatedFileHandleras an absolute file path.setReloadingDetectorFactory(ReloadingDetectorFactory reloadingDetectorFactory) Sets the factory for creatingReloadingDetectorobjects.setReloadingRefreshDelay(Long reloadingRefreshDelay) Sets the refresh delay for reloading supportSets the location of the associatedFileHandleras aURLobject.setURL(URL url, URLConnectionOptions urlConnectionOptions) Sets the location of the associatedFileHandleras aURLobject.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 ofFileBasedBuilderParametersImplwith an uninitializedFileHandlerobject. -
FileBasedBuilderParametersImpl
Creates a new instance ofFileBasedBuilderParametersImpland associates it with the givenFileHandlerobject. If the handler is null, a new handler instance is created.- Parameters:
handler- the associatedFileHandler(can be null)
-
-
Method Details
-
fromMap
Creates a newFileBasedBuilderParametersImplobject 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 aFileHandlerand 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 aConfigurationInterpolatororLookups are shared between this and the newly created instance. This implementation also creates a copy of theFileHandler.- Overrides:
clonein classBasicBuilderParameters- Returns:
- a clone of this object
-
getFileHandler
Gets theFileHandlermanaged 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 theConfigurationimplementation 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 (for example 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:
getParametersin interfaceBuilderParameters- Overrides:
getParametersin 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, for example 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:
inheritFromin classBasicBuilderParameters- Parameters:
source- the source properties to inherit from
-
setBasePath
Description copied from interface:FileBasedBuilderPropertiesSets the base path of the associatedFileHandler.- Specified by:
setBasePathin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
path- the base path- Returns:
- a reference to this object for method chaining
-
setEncoding
Description copied from interface:FileBasedBuilderPropertiesSets the encoding of the associatedFileHandler.- Specified by:
setEncodingin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
enc- the encoding- Returns:
- a reference to this object for method chaining
-
setFile
Description copied from interface:FileBasedBuilderPropertiesSets the location of the associatedFileHandleras aFileobject.- Specified by:
setFilein interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
file- theFilelocation- Returns:
- a reference to this object for method chaining
-
setFileName
Description copied from interface:FileBasedBuilderPropertiesSets the file name of the associatedFileHandler.- Specified by:
setFileNamein interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
name- the file name- Returns:
- a reference to this object for method chaining
-
setFileSystem
Description copied from interface:FileBasedBuilderPropertiesSets theFileSystemof the associatedFileHandler.- Specified by:
setFileSystemin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
fs- theFileSystem- Returns:
- a reference to this object for method chaining
-
setLocationStrategy
Description copied from interface:FileBasedBuilderPropertiesSets theFileLocationStrategyfor resolving the referenced file.- Specified by:
setLocationStrategyin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
strategy- theFileLocationStrategy- Returns:
- a reference to this object for method chaining
-
setPath
Description copied from interface:FileBasedBuilderPropertiesSets the location of the associatedFileHandleras an absolute file path.- Specified by:
setPathin 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:FileBasedBuilderPropertiesSets the factory for creatingReloadingDetectorobjects. With this method a custom factory for reloading detectors can be installed. Per default, a factory creatingFileHandlerReloadingDetectorobjects is used.- Specified by:
setReloadingDetectorFactoryin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
reloadingDetectorFactory- theReloadingDetectorFactory- Returns:
- a reference to this object for method chaining
-
setReloadingRefreshDelay
Description copied from interface:FileBasedBuilderPropertiesSets the refresh delay for reloading support- Specified by:
setReloadingRefreshDelayin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
reloadingRefreshDelay- the refresh delay (in milliseconds)- Returns:
- a reference to this object for method chaining
-
setURL
Description copied from interface:FileBasedBuilderPropertiesSets the location of the associatedFileHandleras aURLobject.- Specified by:
setURLin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
url- theURLlocation- Returns:
- a reference to this object for method chaining
-
setURL
Description copied from interface:FileBasedBuilderPropertiesSets the location of the associatedFileHandleras aURLobject.- Specified by:
setURLin interfaceFileBasedBuilderProperties<FileBasedBuilderParametersImpl>- Parameters:
url- theURLlocationurlConnectionOptions- options- Returns:
- a reference to this object for method chaining
-