Class EnvScalarConstructor


public class EnvScalarConstructor extends Constructor
Construct scalar for format ${VARIABLE} replacing the template with the value from environment. It can also be used to create JavaBeans when the all the arguments are provided.
See Also:
  • Field Details

    • ENV_TAG

      public static final Tag ENV_TAG
      Tag to indicate ENV
    • ENV_FORMAT

      public static final Pattern ENV_FORMAT
      name must be a word -> \w+ value can be any non-space -> \S+
  • Constructor Details

    • EnvScalarConstructor

      public EnvScalarConstructor()
      For simple cases when no JavaBeans are needed
    • EnvScalarConstructor

      public EnvScalarConstructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs, LoaderOptions loadingConfig)
      Create EnvScalarConstructor which can create JavaBeans with variable substitution
      Parameters:
      theRoot - - the class (usually JavaBean) to be constructed
      moreTDs - - collection of classes used by the root class
      loadingConfig - - configuration
  • Method Details

    • apply

      public String apply(String name, String separator, String value, String environment)
      Implement the logic for missing and unset variables
      Parameters:
      name - - variable name in the template
      separator - - separator in the template, can be :-, -, :?, ?
      value - - default value or the error in the template
      environment - - the value from environment for the provided variable
      Returns:
      the value to apply in the template
    • getEnv

      public String getEnv(String key)
      Get value of the environment variable
      Parameters:
      key - - the name of the variable
      Returns:
      value or null if not set