Class AbstractYAMLBasedConfiguration

All Implemented Interfaces:
Cloneable, Configuration, EventSource, HierarchicalConfiguration<ImmutableNode>, ImmutableConfiguration, ImmutableHierarchicalConfiguration, SynchronizerSupport, InMemoryNodeModelSupport, NodeKeyResolver<ImmutableNode>, NodeModelSupport<ImmutableNode>
Direct Known Subclasses:
JSONConfiguration, YAMLConfiguration

public class AbstractYAMLBasedConfiguration extends BaseHierarchicalConfiguration

A base class for configuration implementations based on YAML structures.

This base class offers functionality related to YAML-like data structures based on maps. Such a map has strings as keys and arbitrary objects as values. The class offers methods to transform such a map into a hierarchy of ImmutableNode objects and vice versa.

Since:
2.2
  • Constructor Details

    • AbstractYAMLBasedConfiguration

      protected AbstractYAMLBasedConfiguration()
      Creates a new instance of AbstractYAMLBasedConfiguration.
    • AbstractYAMLBasedConfiguration

      protected AbstractYAMLBasedConfiguration(HierarchicalConfiguration<ImmutableNode> c)
      Creates a new instance of AbstractYAMLBasedConfiguration as a copy of the specified configuration.
      Parameters:
      c - the configuration to be copied
  • Method Details

    • load

      protected void load(Map<String,Object> map)
      Loads this configuration from the content of the specified map. The data in the map is transformed into a hierarchy of ImmutableNode objects.
      Parameters:
      map - the map to be processed
    • constructMap

      protected Map<String,Object> constructMap(ImmutableNode node)
      Constructs a YAML map, i.e. String -> Object from a given configuration node.
      Parameters:
      node - The configuration node to create a map from.
      Returns:
      A Map that contains the configuration node information.
    • addEntry

      private static void addEntry(Map<String,Object> map, String key, Object value)
      Adds a key value pair to a map, taking list structures into account. If a key is added which is already present in the map, this method ensures that a list is created.
      Parameters:
      map - the map
      key - the key
      value - the value
    • constructHierarchy

      private static List<ImmutableNode> constructHierarchy(String key, Object elem)
      Creates a part of the hierarchical nodes structure of the resulting configuration. The passed in element is converted into one or multiple configuration nodes. (If list structures are involved, multiple nodes are returned.)
      Parameters:
      key - the key of the new node(s)
      elem - the element to be processed
      Returns:
      a list with configuration nodes representing the element
    • parseMap

      private static List<ImmutableNode> parseMap(Map<String,Object> map, String key)
      Parses a map structure. The single keys of the map are processed recursively.
      Parameters:
      map - the map to be processed
      key - the key under which this map is to be stored
      Returns:
      a node representing this map
    • parseCollection

      private static List<ImmutableNode> parseCollection(Collection<Object> col, String key)
      Parses a collection structure. The elements of the collection are processed recursively.
      Parameters:
      col - the collection to be processed
      key - the key under which this collection is to be stored
      Returns:
      a node representing this collection
    • rethrowException

      static void rethrowException(Exception e) throws ConfigurationException
      Internal helper method to wrap an exception in a ConfigurationException.
      Parameters:
      e - the exception to be wrapped
      Throws:
      ConfigurationException - the resulting exception