Class JadConfig

java.lang.Object
com.github.joschi.jadconfig.JadConfig

public class JadConfig extends Object
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 Details

  • Method Details

    • process

      public void process() throws RepositoryException, ValidationException
      Processes the configuration provided by the configured Repository and filling the provided configuration beans. Stops processing on first encountered exception.
      Throws:
      RepositoryException - If an error occurred while reading from the configured Repository
      ValidationException - If any parameter couldn't be successfully validated
    • processFailingLazily

      public void processFailingLazily() throws RepositoryException, LazyValidationException
      Processes the configuration provided by the configured Repository and 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.

      Throws:
      RepositoryException
      LazyValidationException
    • addConverterFactory

      public JadConfig addConverterFactory(ConverterFactory converterFactory)
      Adds a ConverterFactory for processing additional types
      Parameters:
      converterFactory - The ConverterFactory to be added
      Returns:
      the JadConfig instance
    • addConfigurationBean

      public JadConfig addConfigurationBean(Object configurationBean)
      Adds a configuration bean annotated with JadConfig annotations.
      Parameters:
      configurationBean - An object annotated with JadConfig annotations
      Returns:
      the JadConfig instance
    • dump

      public Map<String,String> dump()
      Dumps all configuration parameters as a Map of String.

      If being called before process() it will return the default values of the configuration beans.

      Returns:
      All configuration parameters as String
    • setRepository

      public JadConfig setRepository(Repository repository)
      Set the Repository to load configuration data from.
      Parameters:
      repository - A Repository instance
      Returns:
      the JadConfig instance
    • setRepositories

      public JadConfig setRepositories(Collection<Repository> repositories)
      Set the (sorted) list of Repositorys to load configuration data from.
      Parameters:
      repositories - A collection of Repository instances
      Returns:
      the JadConfig instance
    • setRepositories

      public JadConfig setRepositories(Repository... repositories)
      Set the (sorted) list of Repositorys to load configuration data from.
      Parameters:
      repositories - A collection of Repository instances
      Returns:
      the JadConfig instance
    • getConverterFactories

      public List<ConverterFactory> getConverterFactories()
      Get an unmodifiable list of registered converter factories.
      Returns:
      the list of registered converter factories
    • getConfigurationBeans

      public List<Object> getConfigurationBeans()
      Get an unmodifiable list of registered configuration beans.
      Returns:
      the list of registered configuration beans
    • getRepositories

      public List<Repository> getRepositories()
      Get an unmodifiable list of registered repositories.
      Returns:
      the list of registered repositories