Class ScalarConverterBase

    • Constructor Detail

      • ScalarConverterBase

        public ScalarConverterBase()
    • Method Detail

      • convertForSlot

        public void convertForSlot​(Object raw,
                                   Object dest,
                                   Slot slot,
                                   ConverterContext ctx)
                            throws LinkMLRuntimeException
        Description copied from interface: IConverter
        Converts a raw object into a LinkML object and assigns the result to a slot of another object.
        Specified by:
        convertForSlot in interface IConverter
        Parameters:
        raw - The raw object to convert.
        dest - The object that should received the converted value.
        slot - The slot of the dest object to which the converted value should be assigned.
        ctx - The global converter context.
        Throws:
        LinkMLRuntimeException - If the converter cannot convert the given value, or cannot assign it to the target object/slot.
      • convertImpl

        protected abstract Object convertImpl​(Object raw,
                                              ConverterContext ctx)
                                       throws LinkMLRuntimeException
        Performs the actual type conversion.
        Parameters:
        raw - The raw object to convert. This is guaranteed to be a non-null, non-list, non-dictionary object.
        Returns:
        The converted value.
        Throws:
        LinkMLRuntimeException - If the converter cannot convert the given value.
      • serialiseForSlot

        public Object serialiseForSlot​(Object object,
                                       Slot slot,
                                       ConverterContext ctx)
                                throws LinkMLRuntimeException
        Description copied from interface: IConverter
        Converts a LinkML object into a raw object, when the object is the value of a specific LinkML slot.

        We need such a method because the way to serialise a LinkML object into a raw object will sometimes depend on the slot to which the object belongs (the slot of which it is a value), especially with respect to inlining.

        Specified by:
        serialiseForSlot in interface IConverter
        Parameters:
        object - The LinkML object to convert.
        slot - The slot that the given object is a value of.
        ctx - The global converter context.
        Returns:
        The raw object that represents the original LinkML object.
        Throws:
        LinkMLRuntimeException - If the converter cannot convert the given object.
      • toList

        protected List<Object> toList​(Object raw)
                               throws LinkMLRuntimeException
        Checks that a raw object is a list, and casts it as such.
        Parameters:
        raw - The raw object to cast.
        Returns:
        The input object, cast into a list.
        Throws:
        LinkMLRuntimeException - If the raw object is not in fact a list.