Class BidiMappingService
- All Implemented Interfaces:
MappingService
- Direct Known Subclasses:
SpringBidiMappingService
MappingService implementation backed by Mappings, which is where the actual
model and the loading of mapping sources live as of IPF 6.0.
This class exists to keep the untyped, null-returning MappingService contract
working for existing applications. It answers exactly what Mappings answers, with
null where that returns an empty Optional.
Two conventions of the Groovy implementation it replaces are gone:
- an empty value is a value: an entry mapping to
""yields"", rather than the mapping's fallback, and a default passed in applies only where there is no value at all; - there is no composite convention: a value containing
~is returned as the string it is rather than as aList, and aCollectionpassed as a key or value is rejected rather than joined. A mapping whose keys or values consist of several parts must either be split into separate mappings, or the calling code joins and splits the parts itself.
New code should use Mappings directly — it is String-typed and returns
Optional. getMappings() hands out the instance this service delegates
to.
Mapping sources are dispatched to a MappingLoader by file extension, so the format of
a mapping file is a decision per file. Reading the legacy .map script format needs
ipf-commons-map-groovy on the classpath.
As of version 3.1, the add/setMappingScript(Resource) methods have been out-factored into the class SpringBidiMappingService located in the ipf-commons-spring module.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version.BidiMappingService(DefaultMappings mappings) Deprecated, for removal: This API element is subject to removal in a future version.Wraps mappings somebody else owns, so that the same content is reachable through both this service and the typedMappingsAPI. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated, for removal: This API element is subject to removal in a future version.Forgets every mapping; the registered functions stay.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Reverse mapping (Optional implementation)Deprecated, for removal: This API element is subject to removal in a future version.Reverse mapping (Optional implementation)getKeySystem(Object mappingKey) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.getValueSystem(Object mappingKey) Deprecated, for removal: This API element is subject to removal in a future version.Set<?> Deprecated, for removal: This API element is subject to removal in a future version.Set<?> Deprecated, for removal: This API element is subject to removal in a future version.voidregisterMappingFunction(String name, Function<String, String> function) Deprecated, for removal: This API element is subject to removal in a future version.voidDeprecated, for removal: This API element is subject to removal in a future version.Registers the functions that a mapping's computed fallback refers to by name, i.e. what<unmatched mode="function" ref="..."/>resolves against.voidsetMappingScript(URL script) Deprecated, for removal: This API element is subject to removal in a future version.voidsetMappingScripts(URL[] scripts) Deprecated, for removal: This API element is subject to removal in a future version.Collection<?> Deprecated, for removal: This API element is subject to removal in a future version.
-
Constructor Details
-
BidiMappingService
public BidiMappingService()Deprecated, for removal: This API element is subject to removal in a future version. -
BidiMappingService
Deprecated, for removal: This API element is subject to removal in a future version.Wraps mappings somebody else owns, so that the same content is reachable through both this service and the typedMappingsAPI. Whoever created the instance configures it; this constructor changes nothing about it.- Parameters:
mappings- the mappings to delegate to
-
-
Method Details
-
getMappings
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- the mappings this service delegates to, for call sites moving to the typed API
-
setMappingScript
Deprecated, for removal: This API element is subject to removal in a future version. -
setMappingScripts
Deprecated, for removal: This API element is subject to removal in a future version. -
clearMappings
public void clearMappings()Deprecated, for removal: This API element is subject to removal in a future version.Forgets every mapping; the registered functions stay. -
setMappingFunctions
Deprecated, for removal: This API element is subject to removal in a future version.Registers the functions that a mapping's computed fallback refers to by name, i.e. what<unmatched mode="function" ref="..."/>resolves against. A function receives the key that had no entry and returns the value for it, so a mapping can derive its answer from its input rather than list it:mappingService.setMappingFunctions(Map.of( "first4", key -> key == null || key.length() <= 4 ? key : key.substring(0, 4)));A mapping source naming a function that is not registered is rejected as it is read, so register them first. As a Spring bean property that happens before any configurer adds mapping resources; a module that ships both a mapping file and the function it names should contribute aMappingFunctionProviderinstead.- Parameters:
functions- functions by name, replacing any registered under the same name before
-
registerMappingFunction
-
getScripts
-
get
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
getin interfaceMappingService- Parameters:
mappingKey- mapping namekey- left side of the mapping- Returns:
- the value mapped by a registered mapping. The implementation of the mapping implements the behavior if the key does not exist.
-
get
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
getin interfaceMappingService- Parameters:
mappingKey- mapping namekey- left side of the mappingdefaultValue- default right side if there is no mapping for the code- Returns:
- the value mapped by a registered mapping. If no mapping exists, the default value if returned. The implementation of the mapping implements the behavior if the key does not exist.
-
getKey
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:MappingServiceReverse mapping (Optional implementation)- Specified by:
getKeyin interfaceMappingService- Parameters:
mappingKey- mapping namevalue- right side of the mapping- Returns:
- the key mapped by a registered mapping. The implementation of the mapping implements the behavior if the value does not exist.
-
getKey
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:MappingServiceReverse mapping (Optional implementation)- Specified by:
getKeyin interfaceMappingService- Parameters:
mappingKey- mapping namevalue- right side of the mappingdefaultKey- default left side- Returns:
- the key mapped by a registered mapping. If no mapping exists, the default value if returned. The implementation of the mapping implements the behavior if the key does not exist.
-
getKeySystem
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
getKeySystemin interfaceMappingService- Parameters:
mappingKey- mapping name- Returns:
- a formal identification of the key system (e.g. an OID)
-
getValueSystem
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
getValueSystemin interfaceMappingService- Parameters:
mappingKey- mapping name- Returns:
- a formal identification of the value system (e.g. an OID)
-
mappingKeys
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
mappingKeysin interfaceMappingService- Returns:
- a set of names of all registered mappings. Changes to the set do not change the registry itself.
-
keys
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
keysin interfaceMappingService- Parameters:
mappingKey- mapping key- Returns:
- key set of a registered mapping. Changes to the set do not change the registry itself.
-
values
Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
valuesin interfaceMappingService- Parameters:
mappingKey- mapping key- Returns:
- value set of a registered mapping. Changes to the set do not change the registry itself.
-
Mappings-DefaultMappingsis the implementation to build on, andSpringMappingsinipf-commons-springthe bean to wire. This class remains as an adapter for applications still holding aMappingService, and is scheduled for removal in IPF 7.0.