Class AbstractSetup

java.lang.Object
de.iip_ecosphere.platform.support.setup.AbstractSetup
All Implemented Interfaces:
PluginsSetup
Direct Known Subclasses:
CollectorSetup, InstalledDependenciesSetup

public abstract class AbstractSetup extends Object implements PluginsSetup
Basic class for a YAML-based component setup. Implementing classes must have a public no-arg constructor. Each property requires a public getter and setter in Java Bean Style.
Author:
Holger Eichelberger, SSE
  • Field Details

    • PARAM_PLUGINS

      public static final String PARAM_PLUGINS
      See Also:
    • DEFAULT_NAME

      public static final String DEFAULT_NAME
      The name of the default setup file, no extension, no path.
      See Also:
    • DEFAULT_FNAME

      public static final String DEFAULT_FNAME
      Name of the default setup file with extension (no path).
      See Also:
    • DEFAULT_OVERRIDE_FNAME

      public static final String DEFAULT_OVERRIDE_FNAME
      Name of the default setup override file with extension (no path).
      See Also:
    • defaultFName

      private static String defaultFName
    • pluginsFolder

      private String pluginsFolder
  • Constructor Details

    • AbstractSetup

      public AbstractSetup()
  • Method Details

    • getDefaultFileName

      public static String getDefaultFileName()
      Returns the default file name used for loading.
      Returns:
      the default file name, by default DEFAULT_FNAME
    • setDefaultFileName

      public static String setDefaultFileName(String name)
      Sets the default file name used for loading, by default DEFAULT_FNAME. [testing]
      Parameters:
      name - the new default filename
      Returns:
      the default filename before
    • setPluginsFolder

      public void setPluginsFolder(String pluginsFolder)
      Changes the (parent) folder where the oktoflow plugins are located. [yaml convention]
      Parameters:
      pluginsFolder - the plugins folder
    • setPluginsFolderFile

      public void setPluginsFolderFile(File pluginsFolder)
      Changes the (parent) folder where the oktoflow plugins are located. [yaml convention]
      Parameters:
      pluginsFolder - the plugins folder
    • getPluginsFolder

      public String getPluginsFolder()
      Description copied from interface: PluginsSetup
      Returns the (parent) folder where the oktoflow plugins are located (the folder itself or by default its sub-folders "plugins" or "oktoPlugins").
      Specified by:
      getPluginsFolder in interface PluginsSetup
      Returns:
      the folder, by default taken from
      invalid reference
      #PARAM_PLUGINS
      (env or sys property), fallback "plugins"
    • readFromYaml

      public static <C> C readFromYaml(Class<C> cls) throws IOException
      Reads a configuration from getDefaultFileName() in the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readFromYamlWithPath

      public static <C> C readFromYamlWithPath(Class<C> cls, String yamlPath) throws IOException
      Reads a configuration from getDefaultFileName() in the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      yamlPath - path within yaml to read from, may be null or empty for none
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readFromYaml

      public static <C> C readFromYaml(Class<C> cls, String filename) throws IOException
      Reads a configuration from the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      filename - the filename (a leading "/" is added if missing for JAR/classpath resource access)
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readFromYamlWithPath

      public static <C> C readFromYamlWithPath(Class<C> cls, String yamlPath, String filename) throws IOException
      Reads a configuration from the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      yamlPath - path within yaml to read from, may be null or empty for none
      filename - the filename (a leading "/" is added if missing for JAR/classpath resource access)
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readFromYaml

      public static <C> C readFromYaml(Class<C> cls, String filename, String overwrite) throws IOException
      Reads a configuration from the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      filename - the filename (a leading "/" is added if missing for JAR/classpath resource access)
      overwrite - the name of an optional file (a leading "/" is added if missing for JAR/classpath resource access, using MultiResourceResolver.SETUP_RESOLVER) overwriting values in filename, may be null for none, does not lead to an exception if file does not exist
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readFromYamlWithPath

      public static <C> C readFromYamlWithPath(Class<C> cls, String yamlPath, String filename, String overwrite) throws IOException
      Reads a configuration from the root folder of the JAR/classpath. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      yamlPath - path within yaml to read from, may be null or empty for none
      filename - the filename (a leading "/" is added if missing for JAR/classpath resource access)
      overwrite - the name of an optional file (a leading "/" is added if missing for JAR/classpath resource access, using MultiResourceResolver.SETUP_RESOLVER) overwriting values in filename, may be null for none, does not lead to an exception if file does not exist
      Returns:
      the configuration instance
      Throws:
      IOException - if the file cannot be read/found, the configuration class cannot be instantiated
    • readMappingFromYaml

      public static Map<String,Object> readMappingFromYaml() throws IOException
      Reads a configuration from the root folder of the JAR/classpath as mapping.
      Returns:
      the setup mapping
      Throws:
      IOException - if the file cannot be read/found
    • readMappingFromYaml

      public static Map<String,Object> readMappingFromYaml(String filename) throws IOException
      Reads a configuration from the root folder of the JAR/classpath as mapping.
      Parameters:
      filename - the filename to read from
      Returns:
      the setup mapping
      Throws:
      IOException - if the file cannot be read/found
    • isNotEmpty

      public static boolean isNotEmpty(String str)
      Returns if a string is valid, i.e. not null and not empty.
      Parameters:
      str - the string
      Returns:
      true for valid and not empty, false else
    • readFromYaml

      public static <C> C readFromYaml(Class<C> cls, InputStream in) throws IOException
      Reads a instance from in. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      in - the stream to read from (ignored if null, else being closed)
      Returns:
      the configuration instance
      Throws:
      IOException - if the data cannot be read, the configuration class cannot be instantiated
    • readFromYaml

      public static <C> C readFromYaml(Class<C> cls, InputStream in, InputStream overwrite) throws IOException
      Reads a instance from in. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      in - the stream to read from (ignored if null, else being closed)
      overwrite - optional stream to overwrite values taken from in
      Returns:
      the configuration instance
      Throws:
      IOException - if the data cannot be read, the configuration class cannot be instantiated
    • readFromYamlWithPath

      public static <C> C readFromYamlWithPath(Class<C> cls, String yamlPath, InputStream in, InputStream overwrite) throws IOException
      Reads a instance from in. Unknown properties are ignored.
      Type Parameters:
      C - the specific type of configuration to read
      Parameters:
      cls - the class of configuration to read
      yamlPath - path within yaml to read from, may be null or empty for none
      in - the stream to read from (ignored if null, else being closed)
      overwrite - optional stream to overwrite values taken from in
      Returns:
      the configuration instance
      Throws:
      IOException - if the data cannot be read, the configuration class cannot be instantiated