Class MappingWriters

java.lang.Object
org.openehealth.ipf.commons.map.MappingWriters

public final class MappingWriters extends Object
Discovery of MappingWriter implementations through ServiceLoader.
Since:
6.0
  • Method Details

    • discover

      public static List<MappingWriter> discover()
      Returns:
      all writers visible to the current thread's context class loader, falling back to the class loader of this class
    • forExtension

      public static Optional<MappingWriter> forExtension(String extension)
      Parameters:
      extension - a file extension including the leading dot, compared case-insensitively
      Returns:
      the first discovered writer producing that extension
    • forFormat

      public static Optional<MappingWriter> forFormat(String format)
      Parameters:
      format - a format id, compared case-insensitively
      Returns:
      the writer producing that format, empty if none on the classpath does
      Throws:
      IllegalStateException - if several writers claim the same format id
    • forTarget

      public static Optional<MappingWriter> forTarget(String target)
      Resolves a target format named either way, so that a caller - a command line above all - can say xml or .mapping.xml and mean the same writer.
      Parameters:
      target - a format id or a file extension
      Returns:
      the writer producing it, empty if none on the classpath does
    • formats

      public static Set<String> formats()
      Returns:
      the format ids that can currently be written, for diagnostics
    • extensions

      public static Set<String> extensions()
      Returns:
      the extensions that can currently be written, for diagnostics
    • requireKeysAndValues

      public static void requireKeysAndValues(List<? extends Mapping> mappings)
      Rejects entries without a key or a value, which the model tolerates - a Groovy script may declare (null) : 'x' - but no file format can state. Writers call this before writing anything, so that a mapping file is never produced that its own loader rejects.
      Parameters:
      mappings - the mappings to be written
      Throws:
      IllegalArgumentException - naming the first mapping with such an entry