org.intermine.metadata
Class Model

java.lang.Object
  extended by org.intermine.metadata.Model

public class Model
extends java.lang.Object

Represents a named business model, makes available metadata for each class within model.


Field Summary
protected static java.lang.String ENDL
           
 
Constructor Summary
Model(java.lang.String name, java.lang.String packageName, java.util.Set<ClassDescriptor> clds)
          Construct a Model with a name and set of ClassDescriptors.
 
Method Summary
static void addModel(java.lang.String name, Model model)
          Adds model to known models.
 boolean equals(java.lang.Object obj)
          
 java.util.Set<ClassDescriptor> getAllSubs(ClassDescriptor cld)
          Get the ClassDescriptors for the all subclasses of a class
 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. including package name).
 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 class
 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.
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. package name.
 java.lang.String getPackageName()
          Return name of the model's package.
 java.lang.String getQualifiedTypeName(java.lang.String className)
          Return the qualified name of the given unqualified class name.
 boolean hasClassDescriptor(java.lang.String name)
          Return true if named ClassDescriptor is found in the model.
 int hashCode()
          
 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 file
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ENDL

protected static final java.lang.String ENDL
Constructor Detail

Model

public Model(java.lang.String name,
             java.lang.String packageName,
             java.util.Set<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
clds - a Set of ClassDescriptors in the 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 decedents

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

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.

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

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

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