Class ClassInfo


  • public class ClassInfo
    extends Object
    Holds informations about a LinkML class and its corresponding Java class.

    This class is intended merely as a container of various informations about a given LinkML class, as obtained at runtime from the Java class that represents it.

    • Method Detail

      • getURI

        public String getURI()
        Gets the LinkML URI for the class.

        We can only obtain this if the class has been properly annotated with a LinkURI annotation during code generation.

        Returns:
        The class’s URI, or null if we don't know its URI.
      • isGloballyUnique

        public boolean isGloballyUnique()
        Indicates whether the class represents objects that are globally unique.

        A LinkML class represents globally unique objects iff it has a identifier slot, that is a slot marked with identifier: true.

      • isLocallyUnique

        public boolean isLocallyUnique()
        Indicates whether the class represents objects that are locally unique.

        A LinkML class represents locally unique objects iff it has a key slot, that is a slot marked with key: true.

      • hasIdentifier

        public boolean hasIdentifier()
        Indicates whether the class has any kind of identifier slot, whether it is a proper LinkML identifier slot (globally unique) or a key slot (locally unique).
      • isEligibleForSimpleDict

        public boolean isEligibleForSimpleDict​(boolean write)
        Indicates whether the class is eligible for SimpleDict inlining.

        When deserialising, the class is eligible for this type of inlining if it has both an identifier slot (globally or locally unique, it does not matter) and a primary value slot.

        When serialising, the class is eligible for SimpleDict inlining only if, in addition to the previous criterion, it has no other slots beyond the identifier slot and the primary value slot.

        Parameters:
        write - If true, check for eligibility for SimpleDict serialisation; otherwise, check for eligibility for SimpleDict deserialisation.
        Returns:
        true if the class can be (de)serialised as a SimpleDict, otherwise false.
      • hasTypeDesignator

        public boolean hasTypeDesignator()
        Indicates whether the class has a type designator slot, used to unambiguously specify the runtime type of an object.
      • hasExtensionSlot

        public boolean hasExtensionSlot()
        Indicates whether the class has an additional, non-LinkML-defined slot intended to store non-LinkML-defined attributes.
      • getType

        public Class<?> getType()
        Gets the Java type representing this class.
      • getSlots

        public Collection<Slot> getSlots()
        Gets all the slots defined by the class.

        Note that this includes any slot defined in any ancestor class.

      • getSlot

        public Slot getSlot​(String name)
        Gets a slot by its name.
        Parameters:
        name - The name of the desired slot. Note that this is the original, LinkML-defined slot name, which may be different from the name of the Java field that represents it.
        Returns:
        The corresponding slot, or null if the class has no slot with that name.
      • getSlotByURI

        public Slot getSlotByURI​(String uri)
        Gets a slot by its associated URI.

        The associated URI is the URI specified with the slot_uri slot in the defining LinkML schema (or a URI automatically constructed from the slot name and the schema’s default prefix).

        Parameters:
        uri - The URI of the desired slot.
        Returns:
        The corresponding slot, or null if the class either has no slot with that URI, or at least no slot annotated with the appropriate annotation (this is outside of the control of this runtime, and entirely dependent on the code generator).
      • getTypeDesignatorSlot

        public Slot getTypeDesignatorSlot()
        Gets the slot that acts as the type designator for the class.
        Returns:
        The type designator slot, or null if the class has no such slot.
      • getIdentifierSlot

        public Slot getIdentifierSlot()
        Gets the slot intended to hold the identifier for objects of that class.

        This can be either the identifier slot strictly speaking (for globally unique identifiers) or the key slot (for locally unique identifiers), depending on what the class has.

        Returns:
        The identifier slot, or null if the class has no such slot.
      • getPrimarySlot

        public Slot getPrimarySlot()
        Gets the slot intended to hold the “primary value” of the object.

        The “primary” slot of a LinkML class is the slot to which to assign the value of a dict entry when using the “SimpleDict” inlining mode. As per the rules set forth in LinkML’s documentation, the primary slot is either:

        • the one non-identifier slot, if the class has only one such slot beyond the identifier slot;
        • the one mandatory non-identifier slot, if the class has several non-identifier slots but only one marked as mandatory.

        If the class has more than one non-identifier slot without any single one of them being mandatory, or more than one mandatory non-identifier slot, then the class has no primary slot (and is not eligible for inlining in SimpleDict mode).

        Of note, “identifier slot” here refers to either a proper identifier slot (holding a globally unique identifier) or a key slot (holding a locally unique identifier).

        Returns:
        The primary value slot, or null if the class has no such slot.
      • getExtensionSlot

        public Slot getExtensionSlot()
        Gets the slot intended to store non-LinkML-defined attributes.
        Returns:
        The extension slot, or null if the class has no such slot.
      • newInstance

        public Object newInstance()
                           throws LinkMLRuntimeException
        Creates a new instance of the class.

        This is a convenience method to wrap the exception check that catches reflection errors.

        Of note, all Java classes representing LinkML classes are expected to have a no-argument constructor – which is the default behaviour of the Java code generator in LinkML-Py. This is a general assumption throughout this LinkML-Java runtime.

        Returns:
        The newly created object.
        Throws:
        LinkMLRuntimeException - If the object could not be created.
      • get

        public static ClassInfo get​(Class<?> type)
        Gets the ClassInfo object for the LinkML class represented by the given Java type.
        Parameters:
        type - The Java type representing the desired LinkML class.
        Returns:
        The corresponding ClassInfo object, or null if the given type cannot represent a LinkML class (which can happen if it is a primitive type, a boxed primitive type, a String, or a enumeration).
      • get

        public static ClassInfo get​(String uri)
        Gets the ClassInfo object for the LinkML class identifier by the given URI.

        This requires that the ClassInfo object for that class has already been queried before by the class type using get(Class).

        Parameters:
        uri - The LinkML URI of the class to lookup.
        Returns:
        The corresponding ClassInfo object, or null if the URI does not correspond to a known LinkML class.
      • isClass

        public static boolean isClass​(Class<?> type)
        Helper method to check that the given Java type can represent a LinkML class.
        Parameters:
        type - The Java type to check.
        Returns:
        true if the type is possibly a LinkML class, otherwise false.