|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.java.joglutils.msg.misc.ActionTable
public class ActionTable
Keeps track of methods which are attached to a particular Action type for a given set of Node types. This mechanism is different than using the typical Visitor design pattern because Actions, even built-in Actions, need to easily support the addition of newly added Node types. Dispatch occurs via reflection on a per-Node-type basis.
Constructor Summary | |
---|---|
ActionTable(Class<? extends Action> actionClass)
Creates an ActionTable intended for use with a particular Action subclass. |
Method Summary | |
---|---|
void |
addActionMethod(Class<? extends Node> nodeType,
Method actionMethod)
Adds an action method for a particular node type to this table. |
Method |
lookupActionMethod(Node node)
Looks up the appropriate action method for the given node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ActionTable(Class<? extends Action> actionClass)
Method Detail |
---|
public void addActionMethod(Class<? extends Node> nodeType, Method actionMethod) throws IllegalArgumentException
public static void [method name]([Action subclass] action, [Node subclass] node)
The action subclass may be the action class this ActionTable was created with, or any supertype up to and including the Action class. This avoids unnecessary downcasting of the Action in action methods.
The node subclass may be the node type which is passed in to the addActionMethod call, or any supertype up to and including the Node class. This allows convenient overloading of action methods.
Note that it does not matter which type the action method is attached to. This is a key mechanism for extensibility; new action methods can be attached to existing action types to handle new node types which are added to the system.
An action uses reflection to dispatch to these methods at run time, caching lookup results for node types which have not been encountered yet.
IllegalArgumentException
public Method lookupActionMethod(Node node)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |