Class Model


  • public class Model
    extends java.lang.Object
    Represents a named business model, makes available metadata for each class within model.
    Author:
    Richard Smith
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Model.ModelAST
      A Map with slightly more type information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String ENDL  
    • Constructor Summary

      Constructors 
      Constructor Description
      Model​(java.lang.String name, java.lang.String packageName, int version, java.util.Collection<ClassDescriptor> clds)
      Construct a Model with a name and set of ClassDescriptors.
      Model​(java.lang.String name, java.lang.String namespace, java.util.Collection<ClassDescriptor> classes)
      Construct a model without a version.
    • Field Detail

      • ENDL

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

      • Model

        public Model​(java.lang.String name,
                     java.lang.String packageName,
                     int version,
                     java.util.Collection<ClassDescriptor> clds)
              throws MetaDataException
        Construct a Model with a name and set of ClassDescriptors. The model will be set to this in each of the ClassDescriptors. NB This method should only be called by members of the modelproduction package, eventually it may be replaced with a static addModel method linked to getInstanceByName.
        Parameters:
        name - name of model
        packageName - the package name of the model
        version - The version of this model.
        clds - a Set of ClassDescriptors in the model
        Throws:
        MetaDataException - if inconsistencies found in model
      • Model

        public Model​(java.lang.String name,
                     java.lang.String namespace,
                     java.util.Collection<ClassDescriptor> classes)
              throws MetaDataException
        Construct a model without a version.
        Parameters:
        name - The name of the model.
        namespace - The namespace for this model.
        classes - The classes within this model.
        Throws:
        MetaDataException - if inconsistencies found in model
    • Method Detail

      • getInstanceByName

        public static Model getInstanceByName​(java.lang.String name)
        Return a Model for specified model name (loading Model if necessary)
        Parameters:
        name - the name of the model
        Returns:
        the relevant metadata
      • addModel

        public static void addModel​(java.lang.String name,
                                    Model model)
        Adds model to known models.
        Parameters:
        name - the model name
        model - the model
      • getPackageName

        public java.lang.String getPackageName()
        Return name of the model's package.
        Returns:
        package name
      • getDirectSubs

        public java.util.Set<ClassDescriptor> getDirectSubs​(ClassDescriptor cld)
        Get the ClassDescriptors for the direct subclasses of a class
        Parameters:
        cld - the parent ClassDescriptor
        Returns:
        the ClassDescriptors of its children
      • getAllSubs

        public java.util.Set<ClassDescriptor> getAllSubs​(ClassDescriptor cld)
        Get the ClassDescriptors for the all subclasses of a class
        Parameters:
        cld - the parent ClassDescriptor
        Returns:
        the ClassDescriptors of all descedents
      • getClassDescriptorByName

        public ClassDescriptor getClassDescriptorByName​(java.lang.String name)
        Get a ClassDescriptor by name, null if no ClassDescriptor of given name in Model.
        Parameters:
        name - unqualified or fully-qualified class name of ClassDescriptor requested
        Returns:
        the requested ClassDescriptor. Returns null if no match was found.
      • getClassDescriptors

        public java.util.Set<ClassDescriptor> getClassDescriptors()
        Get all ClassDescriptors in this model.
        Returns:
        a set of all ClassDescriptors in the model
      • hasClassDescriptor

        public boolean hasClassDescriptor​(java.lang.String name)
        Return true if named ClassDescriptor is found in the model. Looking for fully qualified classname, eg. org.intermine.model.bio.Gene.
        Parameters:
        name - named of ClassDescriptor search for
        Returns:
        true if named descriptor found
      • getClassNames

        public java.util.Set<java.lang.String> getClassNames()
        Get a Set of fully qualified class names in this model (i.e. including package name).
        Returns:
        Set of fully qualified class names
      • getName

        public java.lang.String getName()
        Get the name of this model - i.e. package name.
        Returns:
        name of the 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
      • toJsonAST

        public Model.ModelAST toJsonAST()
        Returns a data structure suitable for serialisation, eg. as JSON.
        Returns:
        Information about this model.
      • toAdditionsXML

        public java.lang.String toAdditionsXML()
        Used to generate the SO additions file
        Returns:
        the model as an additions file
      • getClassDescriptorsForClass

        public java.util.Set<ClassDescriptor> getClassDescriptorsForClass​(java.lang.Class<?> c)
        Takes a Class, and generates a Set of all ClassDescriptors that are the Class or any of its parents. The Class may be a dynamic class - ie not in the model, although at least one of its parents are in the model.
        Parameters:
        c - a Class
        Returns:
        a Set of ClassDescriptor objects
      • getFieldDescriptorsForClass

        public java.util.Map<java.lang.String,​FieldDescriptor> getFieldDescriptorsForClass​(java.lang.Class<?> c)
        Takes a Class, and generates a Map of all FieldDescriptors that are the class fields or any of its parents. The Class may be a dynamic class - ie not in the model, although at least one of its parents are in the model.
        Parameters:
        c - a Class
        Returns:
        a Map of FieldDescriptor objects
      • getCollectionsForClass

        public java.util.Map<java.lang.String,​java.lang.Class<?>> getCollectionsForClass​(java.lang.Class<?> c)
        Takes a Class, and generates a Map of all the collections that are in the Class or any of its parents. The Class may be a dynamic class - ie not in the model, although at least one of its parents are in the model.
        Parameters:
        c - a Class
        Returns:
        a Map from String collection name to Class element type
      • getQualifiedTypeName

        public java.lang.String getQualifiedTypeName​(java.lang.String className)
                                              throws java.lang.ClassNotFoundException
        Return the qualified name of the given unqualified class name. The className must be in the given model or in the java.lang package or one of java.util.Date, java.math.BigDecimal, or org.intermine.objectstore.query.ClobAccess.
        Parameters:
        className - the name of the class
        Returns:
        the fully qualified name of the class
        Throws:
        java.lang.ClassNotFoundException - if the class can't be found
      • getTopDownLevelTraversal

        public java.util.List<ClassDescriptor> getTopDownLevelTraversal()
        Return the classes in the model in level order from shallowest to deepest, the order of nodes at any given level is undefined. The list does not include InterMineObject.
        Returns:
        ClassDescriptors from the model in depth order
      • getBottomUpLevelTraversal

        public java.util.List<ClassDescriptor> getBottomUpLevelTraversal()
        Return the classes in the model in level order from deepest to shallowest, the order of nodes at any given level is undefined. The list does not include InterMineObject.
        Returns:
        ClassDescriptors from the model in reverse depth order
      • getSimpleObjectClassDescriptors

        protected java.util.Set<ClassDescriptor> getSimpleObjectClassDescriptors()
        Return ClassDescriptors for simple objects only - simple objects are light weight objects without an id and with no inheritance. They can't be interfaces and inherit directly from java.lang.Object.
        Returns:
        a set of ClassDescriptors for all simple objects in the model
      • isGeneratedClassesAvailable

        public boolean isGeneratedClassesAvailable()
        Returns:
        true if generated classes are available
      • setGeneratedClassesAvailable

        public void setGeneratedClassesAvailable​(boolean available)
        Sets if generated classes are available.
        Parameters:
        available - if generated class is available
      • isGeneratedClassAvailable

        public boolean isGeneratedClassAvailable​(java.lang.String className)
        Parameters:
        className - class name
        Returns:
        true if class is defined else false
      • addProblem

        protected void addProblem​(java.lang.String problem)
        Add a problem to the model that doesn't prevent it from being created for backwards compatibility but should be checked when creating a new model.
        Parameters:
        problem - a description of the problem
      • getProblems

        public java.util.List<java.lang.String> getProblems()
        Return a list of problems with the model or an empty list.
        Returns:
        descriptions of problems in the model or an empty list.
      • hasProblems

        public boolean hasProblems()
        Return true if there are problems with the model despite it's successful creation.
        Returns:
        true if there are problems
      • getVersion

        public int getVersion()
        Returns:
        The version of this model.