edu.wpi.ebob.model
Class ObjectBench

java.lang.Object
  extended by edu.wpi.ebob.model.ObjectBench

public class ObjectBench
extends java.lang.Object

Author:
Liam Morley

Nested Class Summary
private  class ObjectBench.Obj
           
 
Field Summary
private  org.eclipse.jface.util.ListenerList listeners
           
private  java.util.HashMap objs
          contains the actual mappings for name/object pairs.
 
Constructor Summary
ObjectBench()
           
 
Method Summary
 void addDependency(java.lang.String name, java.lang.String dependent)
          Creates a dependency between two objects in the object bench.
 void addObject(java.lang.String name, IObject obj)
          adds object obj with the given name name.
 void addObjectBenchListener(ObjectBenchListener listener)
          Adds the listener to receive events and immediately sends an event for each currently existing object in the bench.
 void addObjectBenchListener(ObjectBenchListener listener, boolean sendCurrentObjects)
          Adds the listener to receive events.
 boolean containsObject(java.lang.String name)
          Returns true if the object with the given name exists in the bench, false otherwise.
private  void fireObjectAddedEvent(ObjectBenchEvent event)
          alerts all listeners that an object has been added.
private  void fireObjectRemovedEvent(ObjectBenchEvent event)
          alerts all listeners that an object has been removed.
 java.lang.String[] getDependents(java.lang.String name)
          Retrieves the objects that are dependent on this name.
 java.lang.String[] getNames()
          Returns an array of the names of the objects associated with this bench.
 IObject getObject(java.lang.String name)
          returns a handle to the object in the bench specified by name name.
 boolean hasDependents(java.lang.String name)
           
 void removeAll()
          Clears the Object Bench, removing all objects from the bench.
 boolean removeObject(java.lang.String name)
          removes an object with the specified name from the Object Bench.
 void removeObjectBenchListener(ObjectBenchListener listener)
          Removes the specified object bench listener so that it no longer receives events from the Object Bench.
 boolean removeObjectCascade(java.lang.String name)
          Removes the object from the object bench.
 boolean removeObjectForced(java.lang.String name)
          Removes the object name from the Object Bench.
 boolean removeObjects(IClass c)
          Removes all objects of the specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

private org.eclipse.jface.util.ListenerList listeners

objs

private java.util.HashMap objs
contains the actual mappings for name/object pairs.

Constructor Detail

ObjectBench

public ObjectBench()
Method Detail

addObject

public void addObject(java.lang.String name,
                      IObject obj)
               throws ObjectAdditionNotSupportedException
adds object obj with the given name name.

Parameters:
name - the name of the object within the Object Bench.
obj - the actual object in the bench.
Throws:
ObjectAdditionNotSupportedException - if there is an object already with the given name, or if there was an exception thrown when adding the object to the view.

addObjectBenchListener

public void addObjectBenchListener(ObjectBenchListener listener)
Adds the listener to receive events and immediately sends an event for each currently existing object in the bench.

Parameters:
listener - the listener
See Also:
ObjectBenchListener

addObjectBenchListener

public void addObjectBenchListener(ObjectBenchListener listener,
                                   boolean sendCurrentObjects)
Adds the listener to receive events. If sendCurrentObjects is true, the listener is immediately send an event for every object currently existing in the Object Bench.

Parameters:
listener -
sendCurrentObjects -

addDependency

public void addDependency(java.lang.String name,
                          java.lang.String dependent)
Creates a dependency between two objects in the object bench.

Parameters:
name - the name of the independent object.
dependent - the name of the object that is dependent on name.

getDependents

public java.lang.String[] getDependents(java.lang.String name)
Retrieves the objects that are dependent on this name.

Parameters:
name - the name of the independent object.
Returns:
an array of the names of the dependent objects; of length 0 if there are no dependent objects.

hasDependents

public boolean hasDependents(java.lang.String name)
Returns:
true if there exists at least one object that is dependent on an object named name, false otherwise.

containsObject

public boolean containsObject(java.lang.String name)
Returns true if the object with the given name exists in the bench, false otherwise.

Parameters:
name - the name of the object to check for.

fireObjectAddedEvent

private void fireObjectAddedEvent(ObjectBenchEvent event)
alerts all listeners that an object has been added.

Parameters:
event - the event that listeners should be alerted to.

fireObjectRemovedEvent

private void fireObjectRemovedEvent(ObjectBenchEvent event)
alerts all listeners that an object has been removed.

Parameters:
event - the event that listeners should be alerted to.

getNames

public java.lang.String[] getNames()
Returns an array of the names of the objects associated with this bench.


getObject

public IObject getObject(java.lang.String name)
returns a handle to the object in the bench specified by name name.

Parameters:
name - the name of the object to retrieve.

removeObject

public boolean removeObject(java.lang.String name)
                     throws ObjectRemovalNotSupportedException
removes an object with the specified name from the Object Bench.

Parameters:
name - the name of the object to remove.
Returns:
true if the object was able to be removed, false otherwise.
Throws:
ObjectRemovalNotSupportedException - if there is an object dependency obstructing the removal of the object, or if there was any exception thrown while trying to remove the object to the view.

removeObjectCascade

public boolean removeObjectCascade(java.lang.String name)
Removes the object from the object bench. Any dependent objects will also be removed.

Parameters:
name - the name of the object to remove.
Returns:
true if the object was able to be removed, false otherwise.

removeObjectForced

public boolean removeObjectForced(java.lang.String name)
Removes the object name from the Object Bench. Dependents are not removed.

Parameters:
name - the name of the object to remove.
Returns:
true if the object was able to be removed, false otherwise.

removeObjectBenchListener

public void removeObjectBenchListener(ObjectBenchListener listener)
Removes the specified object bench listener so that it no longer receives events from the Object Bench.

Parameters:
listener - the listener

removeObjects

public boolean removeObjects(IClass c)
                      throws ObjectRemovalNotSupportedException
Removes all objects of the specified class.

Parameters:
c - the class of objects which you want to remove.
Returns:
true if all objects of this class were able to be removed, false otherwise.
Throws:
ObjectRemovalNotSupportedException - if there is an object dependency obstructing the removal of an object, or if there was any exception thrown while trying to add an object to the view. If there was an exception thrown, it can be retrieved by Throwable.getCause(), however it is not guaranteed that all objects specified could not be added for that reason.

removeAll

public void removeAll()
Clears the Object Bench, removing all objects from the bench.