Class PropertiesLoader<T>

java.lang.Object
eu.bandm.tools.expander.PropertiesLoader<T>
Type Parameters:
T - the type of references to sources

public abstract class PropertiesLoader<T> extends Object
Loader for properties files from abstract sources.

The special system parameter DEFAULTS is recognized. If it is present, then the value is understood as the relative name of another source from which to load default values. Values in the main source override values from the default source. The parameter DEFAULTS is removed from the set.

How the relative source name is resolved depends on the kind of source. Default loading is recursive; it is an error to specify circular references.

Since:
1.3
See Also:
  • Field Details

    • DEFAULTS_PARAMETER_NAME

      public static final String DEFAULTS_PARAMETER_NAME
      The name of the system parameter that refers to default properties.
  • Constructor Details

    • PropertiesLoader

      protected PropertiesLoader()
      Creates a new instance.
  • Method Details

    • openSource

      protected abstract InputStream openSource(T source) throws IOException
      Opens an input stream for a source.
      Parameters:
      source - the source
      Returns:
      an input stream providing the contents of the source
      Throws:
      IOException - if the source cannot be opened
    • findDefaults

      protected abstract T findDefaults(T mainSource, String defaultsName)
      Finds a source for default properties for a relative name.

      This method is concerned only with resolving the relative name with respect to the referencing source. It does not check whether the default source exists or is accessible.

      Parameters:
      mainSource - the main source containing the reference
      defaultsName - the relative name of the default source
      Returns:
      the default source
    • loadSource

      public Properties loadSource(T source) throws IOException
      Loads properties from a source, resolving defaults if specified.
      Parameters:
      source - the source
      Returns:
      a map of properties containing explicit definitions and (recursively) inherited defaults
      Throws:
      IOException - if any required source cannot be read
    • loadFile

      public static Properties loadFile(File file) throws IOException
      Loads properties from a file.

      A default name is understood as a file pathname relative to the parent directory of the referencing file.

      Parameters:
      file - the source file
      Returns:
      a map of properties containing explicit definitions and (recursively) inherited defaults
      Throws:
      IOException - if any required source cannot be read
    • loadResource

      public static Properties loadResource(ClassLoader classLoader, String resourceName) throws IOException
      Loads properties from a resource.

      A default name is understood as a qualified resource name relative to the given class loader.

      Parameters:
      classLoader - the class loader to query for the main resource and recursive defaults
      resourceName - the qualified resource name
      Returns:
      a map of properties containing explicit definitions and (recursively) inherited defaults
      Throws:
      IOException - if any required source cannot be read