Class YamlMappingLoader

java.lang.Object
org.openehealth.ipf.commons.map.yaml.YamlMappingLoader
All Implemented Interfaces:
MappingLoader

public class YamlMappingLoader extends Object implements MappingLoader
MappingLoader for *.mapping.yaml files: the same model as the XML format, about 40% fewer keystrokes, and comments that survive - which matters for mapping files that record the code system each code came from next to it.

Property names are bound strictly, so keysystem for keySystem is an error at startup with a line and a column rather than a null found in production later. The JSON Schema shipped at META-INF/ipf/mapping-schema.json covers the same rules for an editor; refer to it from a mapping file with

# yaml-language-server: $schema=http://openehealth.org/schema/ipf-commons-map.json
and IntelliJ and VS Code validate while the file is being typed. It is not used at runtime, which is why the loader repeats its constraints in code.

Values are strings. A YAML scalar that parses as a number or a boolean is rejected rather than coerced: AGN: 1004 is how an entire mapping came to return Integers where every other one returned Strings, and AGN: "1004" is unambiguous.

Since:
6.0
  • Field Details

    • EXTENSION

      public static final String EXTENSION
      Primary file extension this loader claims.
      See Also:
    • SHORT_EXTENSION

      public static final String SHORT_EXTENSION
      Also accepted, for people whose editors expect it.
      See Also:
    • FORMAT

      public static final String FORMAT
      Format id under which this loader can be selected explicitly.
      See Also:
  • Constructor Details

    • YamlMappingLoader

      public YamlMappingLoader()
  • Method Details

    • format

      public String format()
      Description copied from interface: MappingLoader
      Short, stable identifier of the format this loader reads, e.g. xml, yaml or conceptmap-r4-json. It is what a caller names to select this loader regardless of the source's file extension, and it is compared case-insensitively.

      Two loaders on one classpath must not share a format id, since the id is what picks one of them; qualify it the way conceptmap-r4-json does when a format has versions or encodings that a second loader might read.

      Specified by:
      format in interface MappingLoader
      Returns:
      the format id, never null or blank
    • supports

      public boolean supports(URI source)
      Description copied from interface: MappingLoader
      Whether this loader claims a source that nobody named a format for. Implementations decide by file extension: a source it cannot recognize from its name alone is not its own, even if it could read the content, because that is what keeps dispatch predictable.
      Specified by:
      supports in interface MappingLoader
      Parameters:
      source - location of the mapping source, used for its file extension
      Returns:
      whether this loader can read the given source
    • load

      public List<Mapping> load(InputStream in, URI source, MappingFunctionRegistry functions) throws IOException
      Description copied from interface: MappingLoader
      Reads all mappings contained in one source document.
      Specified by:
      load in interface MappingLoader
      Parameters:
      in - the source content; the caller closes the stream
      source - location of the source, for diagnostics
      functions - registry a loader may add functions to, and against which it should validate any Unmatched.Computed reference it produces
      Returns:
      the mappings read, in declaration order
      Throws:
      IOException - if the source cannot be read