T
- the concrete type of Configuration
objects created by this
builderpublic class FileBasedConfigurationBuilder<T extends FileBasedConfiguration> extends BasicConfigurationBuilder<T>
A specialized ConfigurationBuilder
implementation which can handle
configurations read from a FileHandler
.
This class extends its base class by the support of a
FileBasedBuilderParametersImpl
object, and especially of the
FileHandler
contained in this object. When the builder creates a new
object the resulting Configuration
instance is associated with the
FileHandler
. If the FileHandler
has a location set, the
Configuration
is directly loaded from this location.
The FileHandler
is kept by this builder and can be queried later on.
It can be used for instance to save the current Configuration
after
it was modified. Some care has to be taken when changing the location of the
FileHandler
: The new location is recorded and also survives an
invocation of the resetResult()
method. However, when the builder's
initialization parameters are reset by calling resetParameters()
the
location is reset, too.
Constructor and Description |
---|
FileBasedConfigurationBuilder(Class<? extends T> resCls)
Creates a new instance of
FileBasedConfigurationBuilder which
produces result objects of the specified class. |
FileBasedConfigurationBuilder(Class<? extends T> resCls,
Map<String,Object> params)
Creates a new instance of
FileBasedConfigurationBuilder which
produces result objects of the specified class and sets initialization
parameters. |
FileBasedConfigurationBuilder(Class<? extends T> resCls,
Map<String,Object> params,
boolean allowFailOnInit)
Creates a new instance of
FileBasedConfigurationBuilder which
produces result objects of the specified class and sets initialization
parameters and the allowFailOnInit flag. |
Modifier and Type | Method and Description |
---|---|
FileBasedConfigurationBuilder<T> |
configure(BuilderParameters... params)
Appends the content of the specified
BuilderParameters objects to
the current initialization parameters. |
static String |
getDefaultEncoding(Class<?> configClass)
Returns the default encoding for the specified configuration class.
|
FileHandler |
getFileHandler()
Returns the
FileHandler associated with this builder. |
protected void |
initFileHandler(FileHandler handler)
Initializes the new current
FileHandler . |
protected void |
initResultInstance(T obj)
Initializes a newly created result object.
|
boolean |
isAutoSave()
Returns a flag whether auto save mode is currently active.
|
void |
save()
Convenience method which saves the associated configuration.
|
void |
setAutoSave(boolean enabled)
Enables or disables auto save mode.
|
static void |
setDefaultEncoding(Class<?> configClass,
String encoding)
Sets a default encoding for a specific configuration class.
|
BasicConfigurationBuilder<T> |
setParameters(Map<String,Object> params)
Sets the initialization parameters of this builder.
|
addEventListener, addParameters, connectToReloadingController, copyEventListeners, copyEventListeners, createResult, createResultDeclaration, createResultInstance, fetchBeanHelper, fireBuilderEvent, getConfiguration, getParameters, getResultClass, getResultDeclaration, installEventListener, isAllowFailOnInit, removeEventListener, reset, resetParameters, resetResult
public FileBasedConfigurationBuilder(Class<? extends T> resCls)
FileBasedConfigurationBuilder
which
produces result objects of the specified class.resCls
- the result class (must not be nullIllegalArgumentException
- if the result class is nullpublic FileBasedConfigurationBuilder(Class<? extends T> resCls, Map<String,Object> params)
FileBasedConfigurationBuilder
which
produces result objects of the specified class and sets initialization
parameters.resCls
- the result class (must not be nullparams
- a map with initialization parametersIllegalArgumentException
- if the result class is nullpublic FileBasedConfigurationBuilder(Class<? extends T> resCls, Map<String,Object> params, boolean allowFailOnInit)
FileBasedConfigurationBuilder
which
produces result objects of the specified class and sets initialization
parameters and the allowFailOnInit flag.resCls
- the result class (must not be nullparams
- a map with initialization parametersallowFailOnInit
- the allowFailOnInit flagIllegalArgumentException
- if the result class is nullpublic static String getDefaultEncoding(Class<?> configClass)
configClass
- the configuration class in questionpublic static void setDefaultEncoding(Class<?> configClass, String encoding)
configClass
- the name of the configuration class (must not be
null)encoding
- the default encoding for this classIllegalArgumentException
- if the class is nullpublic FileBasedConfigurationBuilder<T> configure(BuilderParameters... params)
BuilderParameters
objects to
the current initialization parameters. Calling this method multiple times
will create a union of the parameters provided. This method is overridden here to change the result type.configure
in class BasicConfigurationBuilder<T extends FileBasedConfiguration>
params
- an arbitrary number of objects with builder parameterspublic FileHandler getFileHandler()
FileHandler
associated with this builder. If already
a result object has been created, this FileHandler
can be used to
save it. Otherwise, the FileHandler
from the initialization
parameters is returned (which is not associated with a FileBased
object). Result is never null.FileHandler
associated with this builderpublic BasicConfigurationBuilder<T> setParameters(Map<String,Object> params)
FileHandler
has to be initialized from
initialization parameters rather than reusing the existing one.setParameters
in class BasicConfigurationBuilder<T extends FileBasedConfiguration>
params
- the new initialization parameters of this builder; can be
null, then all initialization parameters are removedpublic void save() throws ConfigurationException
FileHandler
.
The file handler is then used to store the configuration.ConfigurationException
- if an error occurspublic boolean isAutoSave()
public void setAutoSave(boolean enabled)
enabled
- true if auto save mode is to be enabled,
false otherwiseprotected void initResultInstance(T obj) throws ConfigurationException
BeanHelper
class to initialize the
object's property based on the BeanDeclaration
returned by
BasicConfigurationBuilder.getResultDeclaration()
. Note: This method is invoked in a
synchronized block. This is required because internal state is accessed.
Sub classes must not call this method without proper synchronization. This implementation deals with the creation and
initialization of a FileHandler
associated with the new result
object.initResultInstance
in class BasicConfigurationBuilder<T extends FileBasedConfiguration>
obj
- the object to be initializedConfigurationException
- if an error occursprotected void initFileHandler(FileHandler handler) throws ConfigurationException
FileHandler
. When a new result object
is created, a new FileHandler
is created, too, and associated
with the result object. This new handler is passed to this method. If a
location is defined, the result object is loaded from this location.
Note: This method is called from a synchronized block.handler
- the new current FileHandler
ConfigurationException
- if an error occursCopyright © 2001–2020 The Apache Software Foundation. All rights reserved.