Class ChainedPropertiesLoader
- All Implemented Interfaces:
PropertiesLoader
The ChainedPropertiesLoader can be used to define a chain of PropertiesLoaders that should be used to
load properties. The chain is defined by adding mandatory or optional PropertiesLoaders using the methods
addMandatoryPropertiesLoader(PropertiesLoader) and addOptionalPropertiesLoader(PropertiesLoader).
Each PropertiesResource will then be loaded by the registered PropertiesLoaders-chain. The
PropertiesLoaders registration order is also being used for loading.
A single Properties object is filled by the returned Properties of each PropertiesLoader in
the chain. As a result, properties values by the same key will be overwritten in the returned Properties
instance.
Example: The PropertiesLoaders A & B are registered in the stated order. Then
load(PropertiesResource) is called on the ChainedPropertiesLoader. Now
ChainedPropertiesLoader loops through it's chain: PropertiesLoader A is used to load the
PropertiesResource. The returned Properties are temporarily stored in P. PropertiesLoader B
is used to load the PropertiesResource. The returned Properties are also stored in P. This possibly
overwrites property values with the same key. P is returned by the load(PropertiesResource) method. This is
also true for the method loadList(List).
This implementation is not synchronized. If used by different threads concurrently, external synchronization is necessary.
- Author:
- sts
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMandatoryPropertiesLoader(PropertiesLoader propertiesLoader) Registers a mandatoryPropertiesLoader.voidaddOptionalPropertiesLoader(PropertiesLoader propertiesLoader) Registers an optionalPropertiesLoader.load(PropertiesResource propertiesResource) Loads onePropertiesResourceusing the registeredPropertiesLoaders.loadList(List<? extends PropertiesResource> listPropertiesResources) Loads the givenPropertiesResources by use of the registeredPropertiesLoaders.toString()Methods inherited from class com.saperion.common.config.loader.AbstractPropertiesLoader
loadAsMap
-
Constructor Details
-
ChainedPropertiesLoader
public ChainedPropertiesLoader()
-
-
Method Details
-
addMandatoryPropertiesLoader
Registers a mandatoryPropertiesLoader. The registeredPropertiesLoaderis than used in the methodloadList(List). If it than throws aConfigurationExceptionthis exception is re-thrown and theloadList(List)-method is aborted. The specifiedPropertiesLoadermust not benull.- Parameters:
propertiesLoader- the PropertiesLoader to add.- See Also:
-
addOptionalPropertiesLoader
Registers an optionalPropertiesLoader. The registeredPropertiesLoaderis then used in the methodloadList(List). If it than throws aConfigurationExceptionthis exception is ignored but logged withLogLevel.INFO. The specifiedPropertiesLoadermust not benull.- Parameters:
propertiesLoader- the PropertiesLoader to add.- See Also:
-
load
Loads onePropertiesResourceusing the registeredPropertiesLoaders. The specifiedPropertiesResourcemust not benull.- Parameters:
propertiesResource- thePropertiesResourceto be load.- Returns:
- a
Propertiesinstance containing the load properties. - Throws:
ConfigurationException- if aPropertiesResourcecould not be load by a mandatoryPropertiesLoader.- See Also:
-
loadList
public Properties loadList(List<? extends PropertiesResource> listPropertiesResources) throws ConfigurationException Loads the givenPropertiesResources by use of the registeredPropertiesLoaders. If noPropertiesLoaders are registered, an emptyPropertiesinstance is returned. If an emptyPropertiesResource-Listis given, an emptyPropertiesinstance is returned. All load properties are returned as onePropertiesobject. As a result,Propertiesentries with the same key will be overwritten if loaded more than once. When loading thePropertiesResources the registeredPropertiesLoaders 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 aConfigurationExceptionthis exception is ignored but logged withLogLevel.INFO. When a mandatoryPropertiesLoader(registered by the methodaddMandatoryPropertiesLoader(PropertiesLoader)) throws aConfigurationExceptionthis exception is re-thrown and this method is aborted. The specified list ofPropertiesResources must not benull.- Parameters:
listPropertiesResources- the properties resources to be load.- Returns:
- a
Propertiesinstance containing the load properties. - Throws:
ConfigurationException- if aPropertiesResourcecould not be load by a mandatoryPropertiesLoader.
-
toString
-