Class ElementConverter
- java.lang.Object
-
- org.incenp.linkml.core.ObjectConverter
-
- org.incenp.linkml.schema.ElementConverter
-
- All Implemented Interfaces:
IConverter
- Direct Known Subclasses:
ClassDefinitionConverter
public class ElementConverter extends ObjectConverter
A converter object specifically intended to convert schema elements (i.e.Elementobjects).We need a special converter because we must take into account that schema elements (class, slot, enumeration, and type definitions) in a given schema can be overridden by another schema depending on the position of each schema in the import chains.
The LinkML specification does not say how overriding should work – in fact, the specification explicitly says that multiple definitions of a single element across several schemas in the imports closure is an error and should be treated as such, so the question of which definition overrides another should be moot.
However LinkML-Py does not treat multiple definitions as errors, and instead has an explicit overriding logic to deal with them (logic that is only “documented” in a comment in the SchemaView code…). Presumably that logic is the expected behaviour.
The sole purpose of this converter is to check prior to convert an element object if the object is overridden from another schema, and if so skip conversion altogether.
-
-
Field Summary
-
Fields inherited from class org.incenp.linkml.core.ObjectConverter
klass
-
-
Constructor Summary
Constructors Constructor Description ElementConverter(Class<? extends org.incenp.linkml.schema.model.Element> klass, SchemaProcessingContext context)Creates a new converter for the specified type of element.ElementConverter(Class<? extends org.incenp.linkml.schema.model.Element> klass, SchemaProcessingContext context, boolean checkOverriding)Creates a new converter for the specified type of element.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconvertTo(Map<String,Object> rawMap, Object dest, ConverterContext ctx)Converts a raw map into an instance of a LinkML object, where the object already exists.protected booleanisOverridden(org.incenp.linkml.schema.model.Element element)Checks whether the schema schema is overridden by another one about the given element.-
Methods inherited from class org.incenp.linkml.core.ObjectConverter
convert, convert, convert, convertForSlot, convertTo, getGlobalIdentifier, getGlobalIdentifierList, getType, normaliseList, serialise, serialise, serialiseForSlot, toIdentifier, toList, toMap
-
-
-
-
Constructor Detail
-
ElementConverter
public ElementConverter(Class<? extends org.incenp.linkml.schema.model.Element> klass, SchemaProcessingContext context)
Creates a new converter for the specified type of element.- Parameters:
klass- The type of element to convert.context- The context for which elements are to be converted.
-
ElementConverter
public ElementConverter(Class<? extends org.incenp.linkml.schema.model.Element> klass, SchemaProcessingContext context, boolean checkOverriding)
Creates a new converter for the specified type of element.- Parameters:
klass- The type of element to convert.context- The context for which elements are to be converted.checkOverriding- Iftrue, this class will not check whether a given element is overridden. This is intended to allow subclasses to perform this check themselves.
-
-
Method Detail
-
convertTo
public void convertTo(Map<String,Object> rawMap, Object dest, ConverterContext ctx) throws LinkMLRuntimeException
Description copied from class:ObjectConverterConverts a raw map into an instance of a LinkML object, where the object already exists.- Overrides:
convertToin classObjectConverter- Parameters:
rawMap- The raw map to convert.dest- The instance of the LinkML object whose slots should be filled with values from the raw map.ctx- The global converter context.- Throws:
LinkMLRuntimeException- If a slot of thedestobject cannot be assigned.
-
isOverridden
protected boolean isOverridden(org.incenp.linkml.schema.model.Element element) throws LinkMLRuntimeExceptionChecks whether the schema schema is overridden by another one about the given element.If the current schema is found to override a prior definition (instead of being overridden itself), then this method ensures that the current schema takes precedence.
- Parameters:
element- The element to check.- Returns:
trueif the element is overridden, and therefore does not need to be processed any further.- Throws:
LinkMLRuntimeException- If an error occurs when deleting the prior definition, if any (this should never happen).
-
-