Class ParameterConfigurer<T>

java.lang.Object
de.iip_ecosphere.platform.services.environment.ParameterConfigurer<T>
Type Parameters:
T - the type of the parameter
All Implemented Interfaces:
ValueConfigurer<T>

public class ParameterConfigurer<T> extends Object implements ValueConfigurer<T>
A parameter configurer for a parameter, including a type translator from JSON, a ValueConfigurer for setting the value and an Supplier to obtain the parameter value for failure recovery.
Author:
Holger Eichelberger, SSE
  • Field Details

    • name

      private String name
    • translator

      private de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String,T> translator
    • cfg

      private ValueConfigurer<T> cfg
    • getter

      private Supplier<T> getter
    • cls

      private Class<T> cls
    • sysProperty

      private String sysProperty
  • Constructor Details

    • ParameterConfigurer

      public ParameterConfigurer(String name, Class<T> cls, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String,T> translator, ValueConfigurer<T> cfg)
      Creates a parameter configurer without getter, i.e., implicitly recovery is disabled.
      Parameters:
      name - the name of the parameter
      cls - the class representing the type
      translator - the type translator
      cfg - the parameter value configurer
    • ParameterConfigurer

      public ParameterConfigurer(String name, Class<T> cls, de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String,T> translator, ValueConfigurer<T> cfg, Supplier<T> getter)
      Creates a parameter configurer without getter, i.e., implicitly recovery is disabled.
      Parameters:
      name - the name of the parameter
      cls - the class representing the type
      translator - the type translator
      cfg - the parameter value configurer
      getter - a function returning the actual value of the parameter, used for recovery, may be null for disabling recovery on this parameter
  • Method Details

    • withSystemProperty

      public ParameterConfigurer<T> withSystemProperty(String sysProperty)
      Optional system property that shall be considered during initialization.
      Parameters:
      sysProperty - system property name that shall be used via translator to initialize the parameter, takes precedence
      Returns:
      this (builder style)
    • configure

      public void configure(T value) throws ExecutionException
      Description copied from interface: ValueConfigurer
      Configures the parameter with the given value.
      Specified by:
      configure in interface ValueConfigurer<T>
      Parameters:
      value - the value to use
      Throws:
      ExecutionException - if configuring the value fails for some reason
    • getTranslator

      public de.iip_ecosphere.platform.transport.serialization.TypeTranslator<String,T> getTranslator()
      Returns the type translator to be used for this parameter.
      Returns:
      the type translator
    • getGetter

      public Supplier<T> getGetter()
      Returns the value getter.
      Returns:
      the getter, may be null
    • getName

      public String getName()
      Returns the name of the parameter.
      Returns:
      the name
    • getType

      public Class<T> getType()
      Returns the type of the parameter.
      Returns:
      the type
    • addValue

      public void addValue(Map<String,String> values, Object value)
      Adds the string representation of value to values in terms of the parameter represented by this configurer. Any problem/error will be logged rather than thrown.
      Parameters:
      values - the values to be modified as a side effect
      value - the value to be added
    • getValueFromSysProperty

      private Object getValueFromSysProperty(Object value)
      Returns the object value determined from the attached system property.
      Parameters:
      value - initial value, may be null
      Returns:
      the value if there is a system property and it can be converted/translated, value else