Class 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 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 - 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 Detail

      • 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).