org.intermine.xml.full
Class Item

java.lang.Object
  extended by org.intermine.xml.full.Item
All Implemented Interfaces:
java.lang.Comparable<Item>

public class Item
extends java.lang.Object
implements java.lang.Comparable<Item>

Representation of an object


Constructor Summary
protected Item()
          Construct an item.
protected Item(Model model, java.lang.String identifier, java.lang.String className, java.lang.String implementations)
          Construct an item.
protected Item(java.lang.String identifier, java.lang.String className, java.lang.String implementations)
          Construct an item with no Model.
 
Method Summary
 void addAttribute(Attribute attribute)
          Add an attribute.
 void addCollection(ReferenceList collection)
          Add a collection.
 void addReference(Reference reference)
          Add a reference.
 void addToCollection(java.lang.String name, Item item)
          Add the identifier of the given Item to a collection.
 void addToCollection(java.lang.String name, java.lang.String refId)
          Add a reference to a collection of this item.
 boolean canHaveCollection(java.lang.String name)
          Return true if and only if the argument names a possible collection for this Item.
 boolean canHaveReference(java.lang.String name)
          Return true if and only if the argument names a possible reference for this Item.
 boolean checkAttribute(java.lang.String name)
          Return true if the name parameter is an attribute of the class for this Item or if the Model or the className of this Item haven't been set.
protected  void checkCollection(java.lang.String name)
          Throw a RuntimeException if the name parameter isn't an collection in the class set by setClassName() in the Model set by setModel().
protected  void checkImplementations(java.lang.String implementations)
          Throw RuntimeException if the given implementations don't match the model.
protected  void checkReference(java.lang.String name)
          Throw a RuntimeException if the name parameter isn't an reference in the class set by setClassName() in the Model set by setModel().
 int compareTo(Item i)
          Compare items first by class, then by identifier, intended for creating ordered output files.
 boolean equals(java.lang.Object o)
          
protected  java.util.List<ClassDescriptor> getAllClassDescriptors()
          Return the ClassDescriptors of the class of this Item (as given by className) and all the implementations.
 Attribute getAttribute(java.lang.String attributeName)
          Get a named attribute.
 java.util.Collection<Attribute> getAttributes()
          Get all the attributes.
protected  ClassDescriptor getClassDescriptorByName(java.lang.String className)
          Throw a RuntimeException if any of the named class isn't in the Model set by setModel().
 java.lang.String getClassName()
          Get the class name of this item.
 ReferenceList getCollection(java.lang.String collectionName)
          Get a named collection.
 java.util.Collection<ReferenceList> getCollections()
          Get all the collections.
 java.lang.String getIdentifier()
          Get the identifier of this item.
 java.lang.String getImplementations()
          Get the interfaces implemented by this item.
protected  java.util.List<ClassDescriptor> getImplementClassDescriptors(java.lang.String implementations)
          Returns the ClassDescriptors for the given implementations.
 Model getModel()
          Return the model that was passed to the constructor or set with setModel().
 Reference getReference(java.lang.String referenceName)
          Get a named reference.
 java.util.Collection<Reference> getReferences()
          Get all the references.
 boolean hasAttribute(java.lang.String attributeName)
          Return true if named attribute exists.
 boolean hasCollection(java.lang.String collectionName)
          Return true if named collection exists.
 int hashCode()
          
 boolean hasReference(java.lang.String referenceName)
          Return true if named reference exists.
 void removeAttribute(java.lang.String attributeName)
          Remove a attribute of the specified name if it exists.
 void removeCollection(java.lang.String collectionName)
          Remove a collection of the specified name if it exists.
 void removeReference(java.lang.String referenceName)
          Remove a reference of the specified name if it exists.
 void setAttribute(java.lang.String name, java.lang.String value)
          Add an attribute to this item.
 void setAttributeToEmptyString(java.lang.String name)
          Add an attribute to this item and set it to the empty string.
protected  void setClassDescriptor(java.lang.String className)
          Set the classDescriptor attribute to be the ClassDescriptor for the given className in the Model set by setModel().
 void setClassName(java.lang.String className)
          Set the class of this item.
 void setCollection(java.lang.String collectionName, java.util.List<java.lang.String> refIds)
          Set a collection.
 void setIdentifier(java.lang.String identifier)
          Set the identifier of this item.
 void setImplementations(java.lang.String implementations)
          Set the "implements" of this item.
 void setModel(Model model)
          Set the Model to use when checking calls to the other set methods
 void setReference(java.lang.String name, Item item)
          Add a reference that points to a particular item.
 void setReference(java.lang.String name, java.lang.String refId)
          Add a reference to this item.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Item

protected Item()
Construct an item.


Item

protected Item(Model model,
               java.lang.String identifier,
               java.lang.String className,
               java.lang.String implementations)
Construct an item.

Parameters:
model - the Model used to type-check set methods; if null no type checking is done
identifier - item identifier
className - name of described class
implementations - names of implemented classes
See Also:
ItemFactory

Item

protected Item(java.lang.String identifier,
               java.lang.String className,
               java.lang.String implementations)
Construct an item with no Model. The calls to the set methods won't be type checked unless setModel() is called.

Parameters:
identifier - item identifier
className - name of described class
implementations - names of implemented classes
See Also:
ItemFactory
Method Detail

setModel

public void setModel(Model model)
Set the Model to use when checking calls to the other set methods

Parameters:
model - the Model

getModel

public Model getModel()
Return the model that was passed to the constructor or set with setModel().

Returns:
the Model

setIdentifier

public void setIdentifier(java.lang.String identifier)
Set the identifier of this item.

Parameters:
identifier - the identifier

getIdentifier

public java.lang.String getIdentifier()
Get the identifier of this item.

Returns:
the identifier

setClassName

public void setClassName(java.lang.String className)
Set the class of this item.

Parameters:
className - the class

getClassName

public java.lang.String getClassName()
Get the class name of this item.

Returns:
the class name

setImplementations

public void setImplementations(java.lang.String implementations)
Set the "implements" of this item.

Parameters:
implementations - the interfaces that this item implements

getImplementations

public java.lang.String getImplementations()
Get the interfaces implemented by this item.

Returns:
the implemented interfaces

addAttribute

public void addAttribute(Attribute attribute)
Add an attribute.

Parameters:
attribute - the Attribute to add

removeAttribute

public void removeAttribute(java.lang.String attributeName)
Remove a attribute of the specified name if it exists.

Parameters:
attributeName - name of the attribute to remove

getAttributes

public java.util.Collection<Attribute> getAttributes()
Get all the attributes.

Returns:
all the attributes

getAttribute

public Attribute getAttribute(java.lang.String attributeName)
Get a named attribute.

Parameters:
attributeName - the attribute name
Returns:
the Attribute with the given name

hasAttribute

public boolean hasAttribute(java.lang.String attributeName)
Return true if named attribute exists.

Parameters:
attributeName - the attribute name
Returns:
true if the attribute exists

addReference

public void addReference(Reference reference)
Add a reference.

Parameters:
reference - the reference to add

removeReference

public void removeReference(java.lang.String referenceName)
Remove a reference of the specified name if it exists.

Parameters:
referenceName - name of the reference to remove

getReferences

public java.util.Collection<Reference> getReferences()
Get all the references.

Returns:
all the references

getReference

public Reference getReference(java.lang.String referenceName)
Get a named reference.

Parameters:
referenceName - the reference name
Returns:
the Reference with the given name

hasReference

public boolean hasReference(java.lang.String referenceName)
Return true if named reference exists.

Parameters:
referenceName - the reference name
Returns:
true if the reference exists

addCollection

public void addCollection(ReferenceList collection)
Add a collection.

Parameters:
collection - the collection to add

removeCollection

public void removeCollection(java.lang.String collectionName)
Remove a collection of the specified name if it exists.

Parameters:
collectionName - name of the collection to remove

getCollections

public java.util.Collection<ReferenceList> getCollections()
Get all the collections.

Returns:
all the collections

hasCollection

public boolean hasCollection(java.lang.String collectionName)
Return true if named collection exists.

Parameters:
collectionName - the collection name
Returns:
true if the collection exists

getCollection

public ReferenceList getCollection(java.lang.String collectionName)
Get a named collection.

Parameters:
collectionName - the collection name
Returns:
the Collection with the given name

setCollection

public void setCollection(java.lang.String collectionName,
                          java.util.List<java.lang.String> refIds)
Set a collection.

Parameters:
collectionName - collection name
refIds - ids to reference

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Add an attribute to this item.

Parameters:
name - the name of the attribute
value - the value of the attribute - cannot be null or empty

setAttributeToEmptyString

public void setAttributeToEmptyString(java.lang.String name)
Add an attribute to this item and set it to the empty string.

Parameters:
name - the name of the attribute

setReference

public void setReference(java.lang.String name,
                         java.lang.String refId)
Add a reference to this item.

Parameters:
name - the name of the attribute
refId - the value of the attribute

setReference

public void setReference(java.lang.String name,
                         Item item)
Add a reference that points to a particular item.

Parameters:
name - the name of the attribute
item - the item to refer to

addToCollection

public void addToCollection(java.lang.String name,
                            Item item)
Add the identifier of the given Item to a collection.

Parameters:
name - the name of the collection
item - the item whose identifier is to be added to the collection

addToCollection

public void addToCollection(java.lang.String name,
                            java.lang.String refId)
Add a reference to a collection of this item.

Parameters:
name - the name of the collection
refId - the item to add to the collection

checkAttribute

public boolean checkAttribute(java.lang.String name)
Return true if the name parameter is an attribute of the class for this Item or if the Model or the className of this Item haven't been set.

Parameters:
name - the attribute name
Returns:
true if the name is a valid attribute name

checkReference

protected void checkReference(java.lang.String name)
Throw a RuntimeException if the name parameter isn't an reference in the class set by setClassName() in the Model set by setModel(). Returns immediately if the Model or the className of this Item haven't been set.

Parameters:
name - the reference name

canHaveReference

public boolean canHaveReference(java.lang.String name)
Return true if and only if the argument names a possible reference for this Item. ie. the ClassDescriptor for this Item contains a ReferenceDescriptor for this name.

Parameters:
name - the field name
Returns:
Return true if and only if this Item has a reference of the given name in the model

canHaveCollection

public boolean canHaveCollection(java.lang.String name)
Return true if and only if the argument names a possible collection for this Item. ie. the ClassDescriptor for this Item contains a CollectionDescriptor for this name.

Parameters:
name - the field name
Returns:
Return true if and only if this Item has a collection of the given name in the model

checkCollection

protected void checkCollection(java.lang.String name)
Throw a RuntimeException if the name parameter isn't an collection in the class set by setClassName() in the Model set by setModel(). Returns immediately if the Model or the className of this Item haven't been set.

Parameters:
name - the collection name

checkImplementations

protected void checkImplementations(java.lang.String implementations)
Throw RuntimeException if the given implementations don't match the model.

Parameters:
implementations - the interfaces that this item implements

getClassDescriptorByName

protected ClassDescriptor getClassDescriptorByName(java.lang.String className)
Throw a RuntimeException if any of the named class isn't in the Model set by setModel(). Returns null if the model isn't set or className is "".

Parameters:
className - the class name
Returns:
the ClassDescriptor for the given class

setClassDescriptor

protected void setClassDescriptor(java.lang.String className)
Set the classDescriptor attribute to be the ClassDescriptor for the given className in the Model set by setModel(). Returns immediately if the Model hasn't been set or the className parameter is "".

Parameters:
className - the class name

getAllClassDescriptors

protected java.util.List<ClassDescriptor> getAllClassDescriptors()
Return the ClassDescriptors of the class of this Item (as given by className) and all the implementations. Call only if model, className and implementations are set.

Returns:
all the ClassDescriptors for this Item

getImplementClassDescriptors

protected java.util.List<ClassDescriptor> getImplementClassDescriptors(java.lang.String implementations)
Returns the ClassDescriptors for the given implementations. Returns null if the Model hasn't been set. Throw a RuntimeException if any of the classes named in the implementations parameter aren't in the Model.

Parameters:
implementations - the interfaces that this item implements
Returns:
the ClassDescriptors for the given implementations. Returns null if the Model hasn't been set

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(Item i)
Compare items first by class, then by identifier, intended for creating ordered output files.

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

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object