Class EnvironmentRepository

java.lang.Object
com.github.joschi.jadconfig.repositories.EnvironmentRepository
All Implemented Interfaces:
Repository

public class EnvironmentRepository extends Object implements Repository
Repository class providing access to environment variables.

All keys are being looked up in upper case unless deactivated with the appropriate constructor (EnvironmentRepository(boolean).

A prefix for all key lookups can be defined with EnvironmentRepository(String). The default prefix is empty.

See Also:
  • Constructor Details

    • EnvironmentRepository

      public EnvironmentRepository()
      Creates a new instance of EnvironmentRepository with the default settings, i. e. no prefix and keys looked up in upper case.
    • EnvironmentRepository

      public EnvironmentRepository(String prefix)
      Creates a new instance of EnvironmentRepository with the given prefix.
      Parameters:
      prefix - The prefix used for key lookups, e. g. "MY_APP_".
    • EnvironmentRepository

      public EnvironmentRepository(boolean upperCase)
      Creates a new instance of EnvironmentRepository with an empty prefix.
      Parameters:
      upperCase - Whether keys should be looked up in upper case.
    • EnvironmentRepository

      public EnvironmentRepository(String prefix, boolean upperCase)
      Creates a new instance of EnvironmentRepository with the given prefix.
      Parameters:
      prefix - The prefix used for key lookups, e. g. "MY_APP_".
      upperCase - Whether keys should be looked up in upper case.
  • Method Details

    • open

      public void open() throws RepositoryException
      Description copied from interface: Repository
      Opens the configuration repository, e. g. create a database connection, open a file on disk for reading
      Specified by:
      open in interface Repository
      Throws:
      RepositoryException - If an error occurred while opening the data source
    • read

      public String read(String name)
      Description copied from interface: Repository
      Reads the configuration parameter name from the backing data source. The name is specific to the underlying data source.
      Specified by:
      read in interface Repository
      Parameters:
      name - The parameter name
      Returns:
      The value of the provided name as String
    • close

      public void close() throws RepositoryException
      Description copied from interface: Repository
      Closes the underlying data source when it isn't require any more.
      Specified by:
      close in interface Repository
      Throws:
      RepositoryException - If an error occurred while closing the underlying data source
    • size

      public int size()