org.intermine.metadata
Class ClassDescriptor

java.lang.Object
  extended by org.intermine.metadata.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.


Field Summary
protected static java.lang.String ENDL
           
 
Constructor Summary
ClassDescriptor(java.lang.String name, java.lang.String supers, boolean isInterface, java.util.Set<AttributeDescriptor> atts, java.util.Set<ReferenceDescriptor> refs, java.util.Set<CollectionDescriptor> cols)
          Construct a ClassDescriptor.
 
Method Summary
 int compareTo(ClassDescriptor cld)
          
 boolean equals(java.lang.Object obj)
          
static java.util.Set<java.lang.String> findSuperClassNames(Model model, java.lang.String className)
          Return a list of the super class names for the given class name.
 java.util.Set<AttributeDescriptor> getAllAttributeDescriptors()
          Gets all AttributeDescriptors for this class and its super classes - i.e. fields that are not references or collections.
 java.util.Set<CollectionDescriptor> getAllCollectionDescriptors()
          Gets all CollectionDescriptors for this class - i.e. including those from superclass.
 java.util.Set<FieldDescriptor> getAllFieldDescriptors()
          Gets the FieldDescriptors for this class and all superclasses and interfaces.
 java.util.Set<ReferenceDescriptor> getAllReferenceDescriptors()
          Gets all ReferenceDescriptors for this class - i.e. including those from superclass.
 AttributeDescriptor getAttributeDescriptorByName(java.lang.String name)
          Gets an AttributeDescriptor for a field of the given name.
 AttributeDescriptor getAttributeDescriptorByName(java.lang.String name, boolean ascend)
          Gets an AttributeDescriptor for a field of the given name.
 java.util.Set<AttributeDescriptor> getAttributeDescriptors()
          Gets AttributeDescriptors for this class - i.e. fields that are not references or collections.
 CollectionDescriptor getCollectionDescriptorByName(java.lang.String name)
          Gets a CollectionDescriptor for a collection of the given name.
 CollectionDescriptor getCollectionDescriptorByName(java.lang.String name, boolean ascend)
          Gets a CollectionDescriptor for a field of the given name.
 java.util.Set<CollectionDescriptor> getCollectionDescriptors()
          Gets CollectionDescriptors for this class.
 FieldDescriptor getFieldDescriptorByName(java.lang.String name)
          Retrieve a FieldDescriptor by name.
 java.util.Set<FieldDescriptor> getFieldDescriptors()
          Gets the FieldDescriptors for this class (but not superclasses).
 java.lang.String getHumanReadableText()
          Returns a String that contains a multi-line human-readable description of the ClassDescriptor.
 Model getModel()
          Return the model this class is a part of.
 java.lang.String getName()
          Returns the fully qualified class name described by this ClassDescriptor.
 ReferenceDescriptor getReferenceDescriptorByName(java.lang.String name)
          Gets a ReferenceDescriptor for a field of the given name.
 ReferenceDescriptor getReferenceDescriptorByName(java.lang.String name, boolean ascend)
          Gets a ReferenceDescriptor for a field of the given name.
 java.util.Set<ReferenceDescriptor> getReferenceDescriptors()
          Gets the descriptors for the external object references in this class.
 java.util.Set<ClassDescriptor> getSubDescriptors()
          Return a Set of ClassDescriptors for all classes that directly extend or implement this class or interface.
 ClassDescriptor getSuperclassDescriptor()
          Get the name of the super class of this class (may be null).
 java.util.Set<java.lang.String> getSuperclassNames()
          Return set of superclass class names.
 java.util.Set<ClassDescriptor> getSuperDescriptors()
          Get a set of ClassDescriptors for the interfaces superclasses that this class implements.
 java.lang.Class<? extends FastPathObject> getType()
          Returns the Class described by this ClassDescriptor.
 java.lang.String getUnqualifiedName()
          Returns unqualified name of class described by this ClassDescriptor.
 int hashCode()
          
 boolean isInterface()
          True if this class is an interface.
protected  void setAllFieldDescriptors()
          Sets up the object a little.
protected  void setModel(Model model)
          Set the model for this ClassDescriptor, this is only be called once and will throw an Exception if called again.
static java.lang.String terseClass(java.lang.String c)
          Strips everything before the last dot out of a String.
 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

ClassDescriptor

public ClassDescriptor(java.lang.String name,
                       java.lang.String supers,
                       boolean isInterface,
                       java.util.Set<AttributeDescriptor> atts,
                       java.util.Set<ReferenceDescriptor> refs,
                       java.util.Set<CollectionDescriptor> cols)
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
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

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

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 name of the super class of this class (may be null).

Returns:
the super class name
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

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

compareTo

public int compareTo(ClassDescriptor cld)

Specified by:
compareTo in interface java.lang.Comparable<ClassDescriptor>

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

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