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.

    Of note, to obtain most of the informations collected here, the LinkML-Java runtime is dependent on the Java class having been properly annotated during code generation.

    Use the get(Class) static method to obtain an instance of that class. The instance object can then be used to inquire about most aspects of the LinkML class it represents, such as the list of its slots, whether it has an identifier slot, a type designator slot, etc.

    For the methods that concern a slot, it does not matter whether the slot is defined in the very LinkML class that this object represents, or in any of its parent classes. For example, given the following schema:

     slots:
       id:
         designates_type: true
     
     classes:
       Foo:
         slots:
           - id
       Bar:
         is_a: Foo
     

    a ClassInfo object for the Bar class would indicate (through the hasTypeDesignator() method) that the class has a type designator – because indeed it does have one, even if it is defined in its parent class Foo.

    • Method Detail

      • getURI

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

        The URI of a LinkML class is used for two purposes:

        • to represent the class in RDF serialisations;
        • to resolve URI-typed type designator values.
        Returns:
        The class’s URI, or null if we don't know its URI (the only way this could happen is if the class had not been properly annotated during code generation).
      • getName

        public String getName()
        Gets the name of the class. This may not necessarily be the original name as defined in the LinkML schema – the name may have been transformed into a “PascalCase” form (e.g. mapping set would be transformed into MappingSet).
        Returns:
        The class name.
      • 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. An “identifier slot” in the context of this method can be either a proper LinkML identifier slot (a slot marked with identifier: true, intended to hold a globally unique identifier) or a key slot (a slot marked with key: true, intended to hold a locally unique identifier).
      • 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. Such a slot is intended to hold a value that 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.

        The “extension slot” is how the LinkML-Java runtime supports LinkML’s extra_slots.allowed feature, by which a LinkML class is allowed to contain “extra slots” that do not correspond to any slot or attribute defined in the LinkML schema.

      • getType

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

        public Collection<Slot> getSlots()
        Gets all the slots carried 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.
      • 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.
      • getParents

        public List<ClassInfo> getParents()
        Gets all the superclasses of this class.
        Returns:
        The list of superclasses. The list is ordered from the closest parent (the immediate superclass) to the farthest one. It only includes classes that represent LinkML classes (i.e., it does not include Object). The list may be empty if the class has no superclass.
      • 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.

        Importantly, the runtime currently has no way of pro-actively searching for a class by its URI, so this method can only work if the ClassInfo object for the desired class has already been queried before (at least once) 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.