Interface MappingLoader
- All Known Implementing Classes:
ConceptMapJsonLoader, ConceptMapLoader, ConceptMapXmlLoader, GroovyMappingLoader, XmlMappingLoader, YamlMappingLoader
public interface MappingLoader
Turns a mapping source document into
Mappings: a SimpleMapping for every
table the source declares, and, where the format spreads one translation over several tables,
a CompositeMapping over them, listed after its parts.
Implementations are discovered with ServiceLoader, so a single
Mappings instance can hold mappings written in different formats. The format is a
decision per mapping file, and it is reached in either of two ways:
- by file extension, through
supports(URI). This is the default and needs no configuration - a*.mapping.xmlfile finds its loader on its own. - by
format id, when the caller names one. Extensions cannot always decide: a mapping fetched fromhttps://tx.example.org/ConceptMap/genderhas no extension at all, a file may be calledgender.xmlfor reasons outside IPF's control, and two loaders may be able to read one and the same extension. Naming the format bypassessupports(URI)entirely.
META-INF/services/org.openehealth.ipf.commons.map.MappingLoader.- Since:
- 6.0
-
Method Summary
Modifier and TypeMethodDescriptionformat()Short, stable identifier of the format this loader reads, e.g.static booleanhasExtension(URI source, String extension) load(InputStream in, URI source, MappingFunctionRegistry functions) Reads all mappings contained in one source document.load(InputStream in, URI source, MappingFunctionRegistry functions, Consumer<String> warnings) Reads all mappings contained in one source document, reporting what the model cannot hold.static StringbooleanWhether this loader claims a source that nobody named a format for.
-
Method Details
-
format
String format()Short, stable identifier of the format this loader reads, e.g.xml,yamlorconceptmap-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-jsondoes when a format has versions or encodings that a second loader might read.- Returns:
- the format id, never
nullor blank
-
supports
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.- Parameters:
source- location of the mapping source, used for its file extension- Returns:
- whether this loader can read the given source
-
load
List<Mapping> load(InputStream in, URI source, MappingFunctionRegistry functions) throws IOException Reads all mappings contained in one source document.- Parameters:
in- the source content; the caller closes the streamsource- location of the source, for diagnosticsfunctions- registry a loader may add functions to, and against which it should validate anyUnmatched.Computedreference it produces- Returns:
- the mappings read, in declaration order
- Throws:
IOException- if the source cannot be readMappingException- if the source is not valid for this format
-
load
default List<Mapping> load(InputStream in, URI source, MappingFunctionRegistry functions, Consumer<String> warnings) throws IOException Reads all mappings contained in one source document, reporting what the model cannot hold.A format that can state more than the model - the legacy Groovy DSL binds arbitrary objects where the model holds strings - reports each such loss to
warnings, one message per mapping, starting with the mapping's name.MappingConvertercollects them. The default implementation has nothing to report.- Parameters:
in- the source content; the caller closes the streamsource- location of the source, for diagnosticsfunctions- registry a loader may add functions towarnings- receives a human-readable message for every loss the loader has to make- Returns:
- the mappings read, in declaration order
- Throws:
IOException- if the source cannot be readMappingException- if the source is not valid for this format
-
path
-
hasExtension
-