provided.token
Class ATokVisitor

java.lang.Object
  extended by provided.token.ATokVisitor
All Implemented Interfaces:
ITokVisitor

public abstract class ATokVisitor
extends java.lang.Object
implements ITokVisitor

A visitor to an Token that implements ITokVisitor using a dictionary of commands.


Field Summary
private  java.util.Map<java.lang.String,ITokVisitorCmd> cmds
          The dictionary mapping token id's (names) to associated commands.
private  ITokVisitorCmd defaultCmd
          The default command to use if there are no command associated with the given host id.
 
Constructor Summary
ATokVisitor()
          Constructor that sets the default cmd to one that throws and IllegalArgumentException" for any unknown tokens.
ATokVisitor(ITokVisitorCmd defaultCmd)
          Constructor that sets the default cmd to the given command.
 
Method Summary
 void addCmd(java.lang.String id, ITokVisitorCmd cmd)
          Add a new cmd or replace an existing cmd associated with the given host id.
 java.lang.Object caseAt(java.lang.String id, Token host, java.lang.Object... params)
          Delegates to the ITokVisitorCmd associated with the given host id (name), or if nothing is associated with the id, use the default cmd.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultCmd

private ITokVisitorCmd defaultCmd
The default command to use if there are no command associated with the given host id.


cmds

private java.util.Map<java.lang.String,ITokVisitorCmd> cmds
The dictionary mapping token id's (names) to associated commands. Implemented using a hast table.

Constructor Detail

ATokVisitor

public ATokVisitor()
Constructor that sets the default cmd to one that throws and IllegalArgumentException" for any unknown tokens.


ATokVisitor

public ATokVisitor(ITokVisitorCmd defaultCmd)
Constructor that sets the default cmd to the given command.

Parameters:
defaultCmd - the default cmd to use.
Method Detail

caseAt

public java.lang.Object caseAt(java.lang.String id,
                               Token host,
                               java.lang.Object... params)
Delegates to the ITokVisitorCmd associated with the given host id (name), or if nothing is associated with the id, use the default cmd.

Specified by:
caseAt in interface ITokVisitor
Parameters:
id - the name of the host Token
host - the host token itself.
params - vararg list of input parameters that the processing might need.
Returns:
the result of the delegation to the associated cmd.

addCmd

public void addCmd(java.lang.String id,
                   ITokVisitorCmd cmd)
Add a new cmd or replace an existing cmd associated with the given host id.

Parameters:
id - the id of the host to associate with this visitor.
cmd - The command to associate with the given key value.