Class ChainedPropertiesLoader
- java.lang.Object
-
- com.saperion.common.config.loader.AbstractPropertiesLoader
-
- com.saperion.common.config.loader.ChainedPropertiesLoader
-
- All Implemented Interfaces:
PropertiesLoader
public class ChainedPropertiesLoader extends AbstractPropertiesLoader
The
ChainedPropertiesLoader
can be used to define a chain ofPropertiesLoader
s that should be used to load properties. The chain is defined by adding mandatory or optionalPropertiesLoader
s using the methodsaddMandatoryPropertiesLoader(PropertiesLoader)
andaddOptionalPropertiesLoader(PropertiesLoader)
.Each
PropertiesResource
will then be loaded by the registeredPropertiesLoader
s-chain. ThePropertiesLoader
s registration order is also being used for loading.A single
Properties
object is filled by the returnedProperties
of eachPropertiesLoader
in the chain. As a result, properties values by the same key will be overwritten in the returnedProperties
instance.Example: The
PropertiesLoader
s A & B are registered in the stated order. Thenload(PropertiesResource)
is called on theChainedPropertiesLoader
. NowChainedPropertiesLoader
loops through it's chain:PropertiesLoader
A is used to load thePropertiesResource
. The returnedProperties
are temporarily stored in P.PropertiesLoader
B is used to load thePropertiesResource
. The returnedProperties
are also stored in P. This possibly overwrites property values with the same key. P is returned by theload(PropertiesResource)
method. This is also true for the methodloadList(List)
.This implementation is not synchronized. If used by different threads concurrently, external synchronization is necessary.
- Author:
- sts
- See Also:
load(PropertiesResource)
,loadList(List)
-
-
Constructor Summary
Constructors Constructor Description ChainedPropertiesLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMandatoryPropertiesLoader(PropertiesLoader propertiesLoader)
Registers a mandatoryPropertiesLoader
.void
addOptionalPropertiesLoader(PropertiesLoader propertiesLoader)
Registers an optionalPropertiesLoader
.java.util.Properties
load(PropertiesResource propertiesResource)
Loads onePropertiesResource
using the registeredPropertiesLoader
s.java.util.Properties
loadList(java.util.List<? extends PropertiesResource> listPropertiesResources)
Loads the givenPropertiesResource
s by use of the registeredPropertiesLoader
s.java.lang.String
toString()
-
Methods inherited from class com.saperion.common.config.loader.AbstractPropertiesLoader
loadAsMap
-
-
-
-
Method Detail
-
addMandatoryPropertiesLoader
public void addMandatoryPropertiesLoader(PropertiesLoader propertiesLoader)
Registers a mandatoryPropertiesLoader
. The registeredPropertiesLoader
is than used in the methodloadList(List)
. If it than throws aConfigurationException
this exception is re-thrown and theloadList(List)
-method is aborted. The specifiedPropertiesLoader
must not benull
.- Parameters:
propertiesLoader
- the PropertiesLoader to add.- See Also:
loadList(List)
,load(PropertiesResource)
-
addOptionalPropertiesLoader
public void addOptionalPropertiesLoader(PropertiesLoader propertiesLoader)
Registers an optionalPropertiesLoader
. The registeredPropertiesLoader
is then used in the methodloadList(List)
. If it than throws aConfigurationException
this exception is ignored but logged withLogLevel.INFO
. The specifiedPropertiesLoader
must not benull
.- Parameters:
propertiesLoader
- the PropertiesLoader to add.- See Also:
loadList(List)
,load(PropertiesResource)
-
load
public java.util.Properties load(PropertiesResource propertiesResource) throws ConfigurationException
Loads onePropertiesResource
using the registeredPropertiesLoader
s. The specifiedPropertiesResource
must not benull
.- Parameters:
propertiesResource
- thePropertiesResource
to be load.- Returns:
- a
Properties
instance containing the load properties. - Throws:
ConfigurationException
- if aPropertiesResource
could not be load by a mandatoryPropertiesLoader
.- See Also:
for more information.
-
loadList
public java.util.Properties loadList(java.util.List<? extends PropertiesResource> listPropertiesResources) throws ConfigurationException
Loads the givenPropertiesResource
s by use of the registeredPropertiesLoader
s. If noPropertiesLoader
s are registered, an emptyProperties
instance is returned. If an emptyPropertiesResource
-List
is given, an emptyProperties
instance is returned. All load properties are returned as oneProperties
object. As a result,Properties
entries with the same key will be overwritten if loaded more than once. When loading thePropertiesResource
s the registeredPropertiesLoader
s are used in the same order as they were registered using the methodsaddMandatoryPropertiesLoader(PropertiesLoader)
oraddOptionalPropertiesLoader(PropertiesLoader)
. When an optionalPropertiesLoader
(registered by the methodaddOptionalPropertiesLoader(PropertiesLoader)
) throws aConfigurationException
this exception is ignored but logged withLogLevel.INFO
. When a mandatoryPropertiesLoader
(registered by the methodaddMandatoryPropertiesLoader(PropertiesLoader)
) throws aConfigurationException
this exception is re-thrown and this method is aborted. The specified list ofPropertiesResource
s must not benull
.- Parameters:
listPropertiesResources
- the properties resources to be load.- Returns:
- a
Properties
instance containing the load properties. - Throws:
ConfigurationException
- if aPropertiesResource
could not be load by a mandatoryPropertiesLoader
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-