Class DynamicSource<T>

  • All Implemented Interfaces:
    Source<T>

    public class DynamicSource<T>
    extends AbstractSource<T>
    implements Source<T>

    A dynamic Source implementation which applies a different loading strategy contingent on the path contents.

    • A path starting with "file://" or "http://" will be loaded by the URLSource
    • A path starting with "classpath://" will be loaded by the ClasspathFileSource

    For example:

    • The following instruction creates a dynamic Source that loads files from the file system:
      new DynamicSource("file:///path/my-file.properties")
    • The following instruction creates a dynamic Source that loads a file resource from the Java classpath:
      new DynamicSource("classpath://my-file.properties")

    If unable to determine the source by prefix, the system will do best efforts to load the object by applying different Source implementations.

    Since:
    0.1.0
    Author:
    oswaldo.bapvic.jr (Oswaldo Junior)
    See Also:
    FileSource, ClasspathFileSource
    • Constructor Detail

      • DynamicSource

        public DynamicSource​(String path)
        Builds a new dynamic configuration source from a specific path.
        Parameters:
        path - the path for this configuration source
    • Method Detail

      • load

        public T load​(Mapper<T> mapper)
        Description copied from interface: Source
        Applies a specific configuration loading strategy and returns a mapped bean containing the retrieved data, throwing an exception if the operation fails.
        Specified by:
        load in interface Source<T>
        Parameters:
        mapper - the Mapper to be applied on the source input stream
        Returns:
        the loaded configuration data