Class ElementConverter
- All Implemented Interfaces:
IConverter
- Direct Known Subclasses:
ClassDefinitionConverter
Element objects).
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 ObjectConverter
klass, prefixExtractor -
Constructor Summary
ConstructorsConstructorDescriptionElementConverter(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
Modifier and TypeMethodDescriptionvoidConverts 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 ObjectConverter
convert, convert, convert, convertForSlot, convertTo, getGlobalIdentifier, getGlobalIdentifierList, getType, normaliseList, serialise, serialise, serialiseForSlot, serialiseInit, serialiseSlot, toIdentifier, toList, toMapMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IConverter
getURI
-
Constructor Details
-
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 Details
-
convertTo
public void convertTo(Map<String, Object> rawMap, Object dest, ConverterContext ctx) throws LinkMLRuntimeExceptionDescription 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 LinkMLRuntimeException Checks 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).
-