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
ChainedPropertiesLoadercan be used to define a chain ofPropertiesLoaders that should be used to load properties. The chain is defined by adding mandatory or optionalPropertiesLoaders using the methodsaddMandatoryPropertiesLoader(PropertiesLoader)andaddOptionalPropertiesLoader(PropertiesLoader).Each
PropertiesResourcewill then be loaded by the registeredPropertiesLoaders-chain. ThePropertiesLoaders registration order is also being used for loading.A single
Propertiesobject is filled by the returnedPropertiesof eachPropertiesLoaderin the chain. As a result, properties values by the same key will be overwritten in the returnedPropertiesinstance.Example: The
PropertiesLoaders A & B are registered in the stated order. Thenload(PropertiesResource)is called on theChainedPropertiesLoader. NowChainedPropertiesLoaderloops through it's chain:PropertiesLoaderA is used to load thePropertiesResource. The returnedPropertiesare temporarily stored in P.PropertiesLoaderB is used to load thePropertiesResource. The returnedPropertiesare 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 voidaddMandatoryPropertiesLoader(PropertiesLoader propertiesLoader)Registers a mandatoryPropertiesLoader.voidaddOptionalPropertiesLoader(PropertiesLoader propertiesLoader)Registers an optionalPropertiesLoader.java.util.Propertiesload(PropertiesResource propertiesResource)Loads onePropertiesResourceusing the registeredPropertiesLoaders.java.util.PropertiesloadList(java.util.List<? extends PropertiesResource> listPropertiesResources)Loads the givenPropertiesResources by use of the registeredPropertiesLoaders.java.lang.StringtoString()-
Methods inherited from class com.saperion.common.config.loader.AbstractPropertiesLoader
loadAsMap
-
-
-
-
Method Detail
-
addMandatoryPropertiesLoader
public void addMandatoryPropertiesLoader(PropertiesLoader propertiesLoader)
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:
loadList(List),load(PropertiesResource)
-
addOptionalPropertiesLoader
public void addOptionalPropertiesLoader(PropertiesLoader propertiesLoader)
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:
loadList(List),load(PropertiesResource)
-
load
public java.util.Properties load(PropertiesResource propertiesResource) throws ConfigurationException
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:
for more information.
-
loadList
public java.util.Properties loadList(java.util.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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-