Class ClassDescriptor

  • All Implemented Interfaces:
    java.lang.Comparable<ClassDescriptor>

    public class ClassDescriptor
    extends java.lang.Object
    implements java.lang.Comparable<ClassDescriptor>
    Describe a business model class. Gives access to attribute, reference and collection descriptors. Includes primary key information.
    Author:
    Richard Smith
    • Field Detail

      • ENDL

        protected static final java.lang.String ENDL
    • Constructor Detail

      • ClassDescriptor

        public ClassDescriptor​(java.lang.String name,
                               java.lang.String supers,
                               boolean isInterface,
                               java.util.Collection<AttributeDescriptor> atts,
                               java.util.Collection<ReferenceDescriptor> refs,
                               java.util.Collection<CollectionDescriptor> cols,
                               java.lang.String fairTerm)
        Construct a ClassDescriptor.
        Parameters:
        name - the fully qualified name of the described class
        supers - a space string of fully qualified interface and superclass names
        isInterface - true if describing an interface
        atts - a Collection of AttributeDescriptors
        refs - a Collection of ReferenceDescriptors
        cols - a Collection of CollectionDescriptors
        fairTerm - URI for class, points to a ontology term describing this term
        Throws:
        java.lang.IllegalArgumentException - if fields are null
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the fully qualified class name described by this ClassDescriptor.
        Returns:
        qualified name of the described Class
      • getSimpleName

        public java.lang.String getSimpleName()
        Returns the simple class name described by this ClassDescriptor.
        Returns:
        simple name of the described Class
      • getType

        public java.lang.Class<? extends FastPathObject> getType()
        Returns the Class described by this ClassDescriptor.
        Returns:
        a Class
      • getSuperclassNames

        public java.util.Set<java.lang.String> getSuperclassNames()
        Return set of superclass class names. The set will never contain "org.intermine.model.InterMineObject".
        Returns:
        set of superclass class names
      • getUnqualifiedName

        public java.lang.String getUnqualifiedName()
        Returns unqualified name of class described by this ClassDescriptor.
        Returns:
        unqualified name of the described Class
      • getFairTerm

        public java.lang.String getFairTerm()
        Returns the URI for this data type. Links to an ontology term that describes this class.
        Returns:
        fairTerm for the described Class
      • getFieldDescriptors

        public java.util.Set<FieldDescriptor> getFieldDescriptors()
        Gets the FieldDescriptors for this class (but not superclasses).
        Returns:
        set of FieldDescriptors
      • getAllFieldDescriptors

        public java.util.Set<FieldDescriptor> getAllFieldDescriptors()
        Gets the FieldDescriptors for this class and all superclasses and interfaces.
        Returns:
        set of FieldDescriptors
      • setAllFieldDescriptors

        protected void setAllFieldDescriptors()
                                       throws MetaDataException
        Sets up the object a little.
        Throws:
        MetaDataException - if something goes wrong
      • getFieldDescriptorByName

        public FieldDescriptor getFieldDescriptorByName​(java.lang.String name)
        Retrieve a FieldDescriptor by name. The class and all superclasses and interfaces are searched.
        Parameters:
        name - the name
        Returns:
        the FieldDescriptor
      • getAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getAttributeDescriptors()
        Gets AttributeDescriptors for this class - i.e. fields that are not references or collections.
        Returns:
        set of attributes for this Class
      • getAllAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getAllAttributeDescriptors()
        Gets all AttributeDescriptors for this class and its super classes - i.e. fields that are not references or collections.
        Returns:
        set of attributes for this Class
      • getReferenceDescriptors

        public java.util.Set<ReferenceDescriptor> getReferenceDescriptors()
        Gets the descriptors for the external object references in this class.
        Returns:
        a Set of ReferenceDescriptors for this Class
      • getAllReferenceDescriptors

        public java.util.Set<ReferenceDescriptor> getAllReferenceDescriptors()
        Gets all ReferenceDescriptors for this class - i.e. including those from superclass.
        Returns:
        a Set of references (but not CollectionDescriptors) for this Class
      • getReferenceDescriptorByName

        public ReferenceDescriptor getReferenceDescriptorByName​(java.lang.String name)
        Gets a ReferenceDescriptor for a field of the given name. Returns null if not found. Does NOT look in any superclasses or interfaces.
        Parameters:
        name - the name of a ReferenceDescriptor to find
        Returns:
        a ReferenceDescriptor
      • getReferenceDescriptorByName

        public ReferenceDescriptor getReferenceDescriptorByName​(java.lang.String name,
                                                                boolean ascend)
        Gets a ReferenceDescriptor for a field of the given name. Returns null if not found. If ascend flag is true will also look in superclasses.
        Parameters:
        name - the name of a ReferenceDescriptor to find
        ascend - if true search in super class hierarchy
        Returns:
        a ReferenceDescriptor
      • getAttributeDescriptorByName

        public AttributeDescriptor getAttributeDescriptorByName​(java.lang.String name)
        Gets an AttributeDescriptor for a field of the given name. Returns null if not found. Does NOT look in any superclasses or interfaces.
        Parameters:
        name - the name of an AttributeDescriptor to find
        Returns:
        an AttributeDescriptor
      • getAttributeDescriptorByName

        public AttributeDescriptor getAttributeDescriptorByName​(java.lang.String name,
                                                                boolean ascend)
        Gets an AttributeDescriptor for a field of the given name. Returns null if not found. If ascend flag is true will also look in superclasses.
        Parameters:
        name - the name of an AttributeDescriptor to find
        ascend - if true search in super class hierarchy
        Returns:
        an AttributeDescriptor
      • getAllCollectionDescriptors

        public java.util.Set<CollectionDescriptor> getAllCollectionDescriptors()
        Gets all CollectionDescriptors for this class - i.e. including those from superclass.
        Returns:
        set of collections for this Class
      • getCollectionDescriptors

        public java.util.Set<CollectionDescriptor> getCollectionDescriptors()
        Gets CollectionDescriptors for this class.
        Returns:
        set of CollectionDescriptors for this Class
      • getCollectionDescriptorByName

        public CollectionDescriptor getCollectionDescriptorByName​(java.lang.String name)
        Gets a CollectionDescriptor for a collection of the given name. Returns null if not found. Does NOT search in any superclasses or interfaces.
        Parameters:
        name - the name of a CollectionDescriptor to find
        Returns:
        a CollectionDescriptor
      • getCollectionDescriptorByName

        public CollectionDescriptor getCollectionDescriptorByName​(java.lang.String name,
                                                                  boolean ascend)
        Gets a CollectionDescriptor for a field of the given name. Returns null if not found. If ascend flag is true will also look in superclasses.
        Parameters:
        name - the name of an CollectionDescriptor to find
        ascend - if true search in super class hierarchy
        Returns:
        an CollectionDescriptor
      • getSuperclassDescriptor

        public ClassDescriptor getSuperclassDescriptor()
        Get the super class of this class (may be null).
        Returns:
        the class descriptor this descriptor extends
        Throws:
        java.lang.IllegalStateException - if model not set
      • getSuperDescriptors

        public java.util.Set<ClassDescriptor> getSuperDescriptors()
        Get a set of ClassDescriptors for the interfaces superclasses that this class implements. The set contains all direct superclasses and interfaces, and may contain some indirect superclasses or interfaces.
        Returns:
        a Set of ClassDescriptors
        Throws:
        java.lang.IllegalStateException - if the model is not set
      • isInterface

        public boolean isInterface()
        True if this class is an interface.
        Returns:
        true if an interface
      • getSubDescriptors

        public java.util.Set<ClassDescriptor> getSubDescriptors()
        Return a Set of ClassDescriptors for all classes that directly extend or implement this class or interface.
        Returns:
        set of subclass ClassDescriptors
        Throws:
        java.lang.IllegalStateException - if the set of subclasses has not been set
      • setModel

        protected void setModel​(Model model)
                         throws MetaDataException
        Set the model for this ClassDescriptor, this is only be called once and will throw an Exception if called again. Is called by Model when the ClassDescriptor is added to it during metadata creation.
        Parameters:
        model - the parent model for this ClassDescriptor
        Throws:
        java.lang.IllegalStateException - if the model is already set
        MetaDataException - if references not found
      • findSuperClassNames

        public static java.util.Set<java.lang.String> findSuperClassNames​(Model model,
                                                                          java.lang.String className)
                                                                   throws MetaDataException
        Return a list of the super class names for the given class name. The search is performed breadth-first and the returned Set is a LinkedHashSet so the direct super class names will be first in the list.
        Parameters:
        model - the Model
        className - the className
        Returns:
        set of super class names
        Throws:
        MetaDataException - if className isn't in the model
      • findInherithance

        public static boolean findInherithance​(Model model,
                                               java.lang.String className,
                                               java.lang.String superClassName)
                                        throws MetaDataException
        Return true if the superClassName given in input is a super class of className
        Parameters:
        model - the Model
        className - the className
        superClassName - the super class name
        Returns:
        true or false
        Throws:
        MetaDataException - if className isn't in the model
      • getModel

        public Model getModel()
        Return the model this class is a part of.
        Returns:
        the parent Model
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toJSONString

        public java.lang.String toJSONString()
        Returns:
        a representation of this class descriptor as JSON.
      • getHumanReadableText

        public java.lang.String getHumanReadableText()
        Returns a String that contains a multi-line human-readable description of the ClassDescriptor.
        Returns:
        a String
      • terseClass

        public static java.lang.String terseClass​(java.lang.String c)
        Strips everything before the last dot out of a String.
        Parameters:
        c - a String
        Returns:
        a String
      • getAllSuperclassNames

        public java.util.Set<java.lang.String> getAllSuperclassNames()
        Get the full inheritance list for this class. This set includes not just this classes' immediate ancestors, but all their ancestors as well, as well as this class' name.
        Returns:
        A set of class names.
      • getAllSuperDescriptors

        public java.util.Set<ClassDescriptor> getAllSuperDescriptors()
        Get the full inheritance list for this class. This set includes not just this classes' immediate ancestors, but all their ancestors as well BUT NOT a class descriptor for InterMineObject.
        Returns:
        ClassDescriptors for all ancestors of this class
      • findFairTerm

        public static java.lang.String findFairTerm​(Model model,
                                                    java.lang.String className)
                                             throws MetaDataException
        Return the fair term for the given class name defined in the model.
        Parameters:
        model - the Model
        className - the className
        Returns:
        the fair term
        Throws:
        MetaDataException - if className isn't in the model