org.argouml.cognitive
Class Agency

java.lang.Object
  extended by java.util.Observable
      extended by org.argouml.cognitive.Agency

public class Agency
extends java.util.Observable

Agency manages Critics. Since classes are not really first class objects in java, a singleton instance of Agency is made and passed around as needed. The Agency keeps a registry of all Critics that should be applied to each type of design material. When a design material instance is critiqued it asks Agency to apply all registered Critic's. In the current scheme there is a thread that proactively, continuously critiques the Design at hand, even if the user is idle! This is simple and it works. The disadvantage is that _all_ active critics related to a given design material are applied, regardless of the reason for the critiquing and a lot of CPU time is basically wasted.

TODO: I am moving toward a more reactionary scheme in which specific design manipulations in the editor cause critics relevant to those manipulations to be applied. This transition is still half done. Triggers are the critiquing requests. The code for triggers is currently dormant (latent?).

TODO: There is a strong dependency cycle between Agency and Designer. They either need to be merged into a single class or partitioned differently, perhaps using an interface to break the cycle. The Designer singleton gets passed to almost every single part of the Critic subsystem, creating strong coupling throughout. - tfm 20070620


Constructor Summary
Agency()
          Construct a new Agency instance and use a StandardCM as the main control mechanism for determining which critics should be active.
Agency(ControlMech cm)
          Construct a new Agency instance with the given ControlMech as the main control mechanism for determining which critics should be active.
 
Method Summary
protected static void addCritic(Critic cr)
           
static void addStaticObserver(java.util.Observer obs)
          Let some object receive notifications when the Agency changes state.
static void applyAllCritics(java.lang.Object dm, Designer d)
           
static void applyAllCritics(java.lang.Object dm, Designer d, long reasonCode)
          Apply all critics that can be applied to the given design material instance as appropriate for the given Designer.
static void applyCritics(java.lang.Object dm, Designer d, java.util.Collection<Critic> theCritics, long reasonCode)
           
protected static java.util.List<Critic> criticListForSpecificClass(java.lang.Class clazz)
          Return the List of all critics that are directly associated with the given design material subclass.
static java.util.Collection<Critic> criticsForClass(java.lang.Class clazz)
          Return a collection of all critics that can be applied to the design material subclass, including inherited critics.
protected static java.util.Vector<Critic> criticsForSpecificClass(java.lang.Class clazz)
          Deprecated. for 0.25.4 by tfmorris. Use criticListForSpecificClass(Class).
 void determineActiveCritics(Designer d)
          Compute which critics should be active (i.e., they can be applied by applyAllCritics) for a given Designer.
static java.util.List<Critic> getCriticList()
           
static java.util.Vector<Critic> getCritics()
          Deprecated. for 0.25.4 by tfmorris - use getCriticList().
static void notifyStaticObservers(java.lang.Object o)
          When the agency changes, notify observers.
static void register(Critic cr)
          Register a critic in the global table of critics that have been loaded.
static void register(Critic cr, java.lang.Class clazz)
          Register a critic in the global table of critics that have been loaded.
static void register(Critic cr, java.lang.Object clazz)
          Transitional method for migration purposes.
static void register(java.lang.String crClassName, java.lang.String dmClassName)
           
static Agency theAgency()
          Since Java does not really support classes as first class objects, there is one instance of Agency that is passed around as needed.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Agency

public Agency(ControlMech cm)
Construct a new Agency instance with the given ControlMech as the main control mechanism for determining which critics should be active.

Parameters:
cm - the given controlMech

Agency

public Agency()
Construct a new Agency instance and use a StandardCM as the main control mechanism for determining which critics should be active.

Method Detail

theAgency

public static Agency theAgency()
Since Java does not really support classes as first class objects, there is one instance of Agency that is passed around as needed.

theAgency is actually stored in Designer.theDesigner().

Returns:
Agency the Agency instance
See Also:
Designer.theDesigner()

getCritics

@Deprecated
public static java.util.Vector<Critic> getCritics()
Deprecated. for 0.25.4 by tfmorris - use getCriticList().

Returns:
the critics

getCriticList

public static java.util.List<Critic> getCriticList()
Returns:
the critics

addCritic

protected static void addCritic(Critic cr)
Parameters:
cr - the critic to add/register

register

public static void register(java.lang.String crClassName,
                            java.lang.String dmClassName)
Parameters:
crClassName - the critic class name
dmClassName - the design material class name

register

public static void register(Critic cr,
                            java.lang.Class clazz)
Register a critic in the global table of critics that have been loaded. Critics are associated with one or more design material classes. One way to do registration is in a static initializer of the design material class. But additional (after-market) critics could added through a menu command in some control panel...

Parameters:
cr - the critic to register
clazz - the design material class that is to be criticized

register

public static void register(Critic cr,
                            java.lang.Object clazz)
Transitional method for migration purposes. Don't use!

Parameters:
cr - the critic to register
clazz - the UML class to be criticized

register

public static void register(Critic cr)
Register a critic in the global table of critics that have been loaded.

Parameters:
cr - the critic to register

criticsForClass

public static java.util.Collection<Critic> criticsForClass(java.lang.Class clazz)
Return a collection of all critics that can be applied to the design material subclass, including inherited critics.

Parameters:
clazz - the design material to criticize
Returns:
the collection of critics

criticsForSpecificClass

@Deprecated
protected static java.util.Vector<Critic> criticsForSpecificClass(java.lang.Class clazz)
Deprecated. for 0.25.4 by tfmorris. Use criticListForSpecificClass(Class).

Return the Vector of all critics that are directly associated with the given design material subclass.

If there aren't any an empty Vector is returned.

Parameters:
clazz - the design material
Returns:
the critics

criticListForSpecificClass

protected static java.util.List<Critic> criticListForSpecificClass(java.lang.Class clazz)
Return the List of all critics that are directly associated with the given design material subclass.

If there aren't any an empty List is returned.

Parameters:
clazz - the design material
Returns:
the critics

applyAllCritics

public static void applyAllCritics(java.lang.Object dm,
                                   Designer d,
                                   long reasonCode)
Apply all critics that can be applied to the given design material instance as appropriate for the given Designer.

I would call this critique, but it causes a compilation error because it conflicts with the instance method critique!

Parameters:
dm - the design material
d - the designer
reasonCode - the reason

applyAllCritics

public static void applyAllCritics(java.lang.Object dm,
                                   Designer d)
Parameters:
dm - the design material
d - the designer

applyCritics

public static void applyCritics(java.lang.Object dm,
                                Designer d,
                                java.util.Collection<Critic> theCritics,
                                long reasonCode)
Parameters:
dm - the design material
d - the designer
theCritics - the critics
reasonCode - the reason

determineActiveCritics

public void determineActiveCritics(Designer d)
Compute which critics should be active (i.e., they can be applied by applyAllCritics) for a given Designer.

Note: I am setting global data, i.e. the isEnabled bit in each critic, based on the needs of one designer. I don't really support more than one Designer. Which is why each designer (if we would support more than one designer) has his own Agency. TODO: should loop over simpler list of critics, not CompoundCritics

Parameters:
d - the designer

addStaticObserver

public static void addStaticObserver(java.util.Observer obs)
Let some object receive notifications when the Agency changes state. Static observers are normal Observers on the singleton instance of this class.

Parameters:
obs - the notified object

notifyStaticObservers

public static void notifyStaticObservers(java.lang.Object o)
When the agency changes, notify observers.

Parameters:
o - the notified object


ArgoUML © 1996-2006ArgoUML HomepageArgoUML Cookbook