Interface DeclarativeConfigProperties


public interface DeclarativeConfigProperties
An interface for accessing declarative configuration data.

An instance of DeclarativeConfigProperties is equivalent to a YAML mapping node. It has accessors for reading scalar properties, getStructured(String) for reading children which are themselves mappings, and getStructuredList(String) for reading children which are sequences of mappings.

This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

  • Method Details

    • empty

      Return an empty DeclarativeConfigProperties instance.

      Useful for walking the tree without checking for null. For example, to access a string key nested at .foo.bar.baz, call: config.getStructured("foo", empty()).getStructured("bar", empty()).getString("baz").

    • toMap

      static Map<String,Object> toMap(DeclarativeConfigProperties declarativeConfigProperties)
      Return a map representation of the declarativeConfigProperties.
    • getString

      @Nullable String getString(String name)
      Returns a String configuration property.
      Returns:
      null if the property has not been configured or if the property is not a valid scalar string
    • getString

      default String getString(String name, String defaultValue)
      Returns a String configuration property.
      Returns:
      a String configuration property or defaultValue if a property with name has not been configured or is not a valid scalar string
    • getBoolean

      @Nullable Boolean getBoolean(String name)
      Returns a Boolean configuration property. Implementations should use the same rules as Boolean.parseBoolean(String) for handling the values.
      Returns:
      null if the property has not been configured or if the property is not a valid scalar boolean
    • getBoolean

      default boolean getBoolean(String name, boolean defaultValue)
      Returns a Boolean configuration property.
      Returns:
      a Boolean configuration property or defaultValue if a property with name has not been configured or is not a valid scalar boolean
    • getInt

      @Nullable Integer getInt(String name)
      Returns a Integer configuration property.

      If the underlying config property is Long, it is converted to Integer with Long.intValue() which may result in loss of precision.

      Returns:
      null if the property has not been configured or if the property is not a valid scalar integer
    • getInt

      default int getInt(String name, int defaultValue)
      Returns a Integer configuration property.

      If the underlying config property is Long, it is converted to Integer with Long.intValue() which may result in loss of precision.

      Returns:
      a Integer configuration property or defaultValue if a property with name has not been configured or is not a valid scalar integer
    • getLong

      @Nullable Long getLong(String name)
      Returns a Long configuration property.
      Returns:
      null if the property has not been configured or if the property is not a valid scalar long
    • getLong

      default long getLong(String name, long defaultValue)
      Returns a Long configuration property.
      Returns:
      a Long configuration property or defaultValue if a property with name has not been configured or is not a valid scalar long
    • getDouble

      @Nullable Double getDouble(String name)
      Returns a Double configuration property.
      Returns:
      null if the property has not been configured or if the property is not a valid scalar double
    • getDouble

      default double getDouble(String name, double defaultValue)
      Returns a Double configuration property.
      Returns:
      a Double configuration property or defaultValue if a property with name has not been configured or is not a valid scalar double
    • getScalarList

      @Nullable <T> List<T> getScalarList(String name, Class<T> scalarType)
      Returns a List configuration property. Empty values and values which do not map to the scalarType will be removed.
      Parameters:
      name - the property name
      scalarType - the scalar type, one of String, Boolean, Long or Double
      Returns:
      a List configuration property, or null if the property has not been configured or if the property is not a valid sequence of scalars
      Throws:
      DeclarativeConfigException - if scalarType is not supported
    • getScalarList

      default <T> List<T> getScalarList(String name, Class<T> scalarType, List<T> defaultValue)
      Returns a List configuration property. Entries which are not strings are converted to their string representation.
      Parameters:
      name - the property name
      scalarType - the scalar type, one of String, Boolean, Long or Double
      Returns:
      a List configuration property or defaultValue if a property with name has not been configured or is not a valid sequence of scalars
    • getStructured

      Returns a DeclarativeConfigProperties configuration property.
      Returns:
      a map-valued configuration property, or null if name has not been configured or is not a mapping
    • getStructured

      default DeclarativeConfigProperties getStructured(String name, DeclarativeConfigProperties defaultValue)
      Returns a list of DeclarativeConfigProperties configuration property.
      Returns:
      a map-valued configuration property, or defaultValue if name has not been configured or is not a mapping
    • get

      default DeclarativeConfigProperties get(String name)
      Returns a DeclarativeConfigProperties configuration property, or empty() if a property with name has not been configured.

      This is syntactic sugar for the common operation of calling config.getStructured(name, empty()). If you need to distinguish between a property being set but empty vs. not set, use getStructured(String).

      Returns:
      a map-valued configuration property, or an empty DeclarativeConfigProperties instance if name has not been configured or is not a mapping
    • getStructuredList

      Returns a list of DeclarativeConfigProperties configuration property.
      Returns:
      a list of map-valued configuration property, or null if name has not been configured or is not a sequence of mappings
    • getStructuredList

      default List<DeclarativeConfigProperties> getStructuredList(String name, List<DeclarativeConfigProperties> defaultValue)
      Returns a list of DeclarativeConfigProperties configuration property.
      Returns:
      a list of map-valued configuration property, or defaultValue if name has not been configured or is not a sequence of mappings
    • getPropertyKeys

      Set<String> getPropertyKeys()
      Returns a set of all configuration property keys.
      Returns:
      the configuration property keys
    • getComponentLoader

      io.opentelemetry.common.ComponentLoader getComponentLoader()
      Return a ComponentLoader that should be used to load SPIs.