Package com.github.joschi.jadconfig
Class JadConfig
java.lang.Object
com.github.joschi.jadconfig.JadConfig
The main class for JadConfig. It's responsible for parsing the configuration bean(s) that contain(s) the annotated
fields, use a
Repository to read the raw configuration and assign the fields with the correct values.
The configuration bean(s) you pass in the constructor are expected to have one or more Parameter annotations
on them.
You can pass either a single configuration bean or an array of objects. In the case of an array JadConfig will
collect the Parameter annotations from all the objects passed in.- Author:
- jschalanda
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new (empty) instance of JadConfig.JadConfig(Repository repository, Object... configurationBeans) Creates a new instance of JadConfig backed by the providedRepositoryand filling the provided configurationBeans.JadConfig(Collection<Repository> repositories, Object... configurationBeans) Creates a new instance of JadConfig backed by the providedRepositorys and filling the provided configurationBeans. -
Method Summary
Modifier and TypeMethodDescriptionaddConfigurationBean(Object configurationBean) Adds a configuration bean annotated with JadConfig annotations.addConverterFactory(ConverterFactory converterFactory) Adds aConverterFactoryfor processing additional typesdump()Get an unmodifiable list of registered configuration beans.Get an unmodifiable list of registered converter factories.Get an unmodifiable list of registered repositories.voidprocess()Processes the configuration provided by the configuredRepositoryand filling the provided configuration beans.voidProcesses the configuration provided by the configuredRepositoryand filling the provided configuration beans.setRepositories(Repository... repositories) Set the (sorted) list ofRepositorys to load configuration data from.setRepositories(Collection<Repository> repositories) Set the (sorted) list ofRepositorys to load configuration data from.setRepository(Repository repository) Set theRepositoryto load configuration data from.
-
Constructor Details
-
JadConfig
public JadConfig()Creates a new (empty) instance of JadConfig. Configuration beans will have to be added withaddConfigurationBean(Object)and aRepositorywill have to be set withsetRepository(Repository)orsetRepositories(Collection).- See Also:
-
JadConfig
Creates a new instance of JadConfig backed by the providedRepositoryand filling the provided configurationBeans.- Parameters:
repository- ARepositoryfor interfacing with the configuration dataconfigurationBeans- One or more objects annotated with JadConfig annotations
-
JadConfig
Creates a new instance of JadConfig backed by the providedRepositorys and filling the provided configurationBeans.- Parameters:
repositories- A collection ofRepositorys for interfacing with the configuration dataconfigurationBeans- One or more objects annotated with JadConfig annotations
-
-
Method Details
-
process
Processes the configuration provided by the configuredRepositoryand filling the provided configuration beans. Stops processing on first encountered exception.- Throws:
RepositoryException- If an error occurred while reading from the configuredRepositoryValidationException- If any parameter couldn't be successfully validated
-
processFailingLazily
Processes the configuration provided by the configuredRepositoryand filling the provided configuration beans.Instead of stopping processing on first encountered exception, tries to collect all validation problems and in case of any problems aggregate them all into single exception, listing all the field and validation issues.
-
addConverterFactory
Adds aConverterFactoryfor processing additional types- Parameters:
converterFactory- TheConverterFactoryto be added- Returns:
- the JadConfig instance
-
addConfigurationBean
Adds a configuration bean annotated with JadConfig annotations.- Parameters:
configurationBean- An object annotated with JadConfig annotations- Returns:
- the JadConfig instance
-
dump
Dumps all configuration parameters as aMapofString.If being called before
process()it will return the default values of the configuration beans.- Returns:
- All configuration parameters as
String
-
setRepository
Set theRepositoryto load configuration data from.- Parameters:
repository- ARepositoryinstance- Returns:
- the JadConfig instance
-
setRepositories
Set the (sorted) list ofRepositorys to load configuration data from.- Parameters:
repositories- A collection ofRepositoryinstances- Returns:
- the JadConfig instance
-
setRepositories
Set the (sorted) list ofRepositorys to load configuration data from.- Parameters:
repositories- A collection ofRepositoryinstances- Returns:
- the JadConfig instance
-
getConverterFactories
Get an unmodifiable list of registered converter factories.- Returns:
- the list of registered converter factories
-
getConfigurationBeans
Get an unmodifiable list of registered configuration beans.- Returns:
- the list of registered configuration beans
-
getRepositories
Get an unmodifiable list of registered repositories.- Returns:
- the list of registered repositories
-