Package org.intermine.metadata
Class Model
- java.lang.Object
-
- org.intermine.metadata.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addModel(java.lang.String name, Model model)
Adds model to known models.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.boolean
equals(java.lang.Object obj)
java.util.Set<ClassDescriptor>
getAllSubs(ClassDescriptor cld)
Get the ClassDescriptors for the all subclasses of a classjava.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.ClassDescriptor
getClassDescriptorByName(java.lang.String name)
Get a ClassDescriptor by name, null if no ClassDescriptor of given name in Model.java.util.Set<ClassDescriptor>
getClassDescriptors()
Get all ClassDescriptors in this model.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.java.util.Set<java.lang.String>
getClassNames()
Get a Set of fully qualified class names in this model (i.e.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.java.util.Set<ClassDescriptor>
getDirectSubs(ClassDescriptor cld)
Get the ClassDescriptors for the direct subclasses of a classjava.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.static Model
getInstanceByName(java.lang.String name)
Return a Model for specified model name (loading Model if necessary)java.lang.String
getName()
Get the name of this model - i.e.java.lang.String
getPackageName()
Return name of the model's package.java.util.List<java.lang.String>
getProblems()
Return a list of problems with the model or an empty list.java.lang.String
getQualifiedTypeName(java.lang.String className)
Return the qualified name of the given unqualified class name.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.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.int
getVersion()
boolean
hasClassDescriptor(java.lang.String name)
Return true if named ClassDescriptor is found in the model.int
hashCode()
boolean
hasProblems()
Return true if there are problems with the model despite it's successful creation.boolean
isGeneratedClassAvailable(java.lang.String className)
boolean
isGeneratedClassesAvailable()
void
setGeneratedClassesAvailable(boolean available)
Sets if generated classes are available.java.lang.String
toAdditionsXML()
Used to generate the SO additions fileModel.ModelAST
toJsonAST()
Returns a data structure suitable for serialisation, eg.java.lang.String
toString()
-
-
-
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 modelpackageName
- the package name of the modelversion
- 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 namemodel
- 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 classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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.
-
-