Class ElementConverter

java.lang.Object
org.incenp.linkml.core.converters.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. 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.

  • 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 - If true, 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 LinkMLRuntimeException
      Description copied from class: ObjectConverter
      Converts a raw map into an instance of a LinkML object, where the object already exists.
      Overrides:
      convertTo in class ObjectConverter
      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 the dest object 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:
      true if 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).