![]() |
JSwat ProjectHow to Write JSwat Commands |
All commands must subclass from the JSwatCommand
class, defined in the com.bluemarsh.jswat.command
package. JSwatCommand
provides some basic
functionality needed for all JSwat commands. Each JSwat command
class is named using the name of the command as the prefix,
followed by the "Command" suffix. For example, if I am
going to write the 'friday
' command, I will
name the class "fridayCommand
" and place it
in the com.bluemarsh.jswat.command
package. Then when
the user invokes 'friday' at the JSwat command prompt, the
CommandManager
class will find my friday
command and call its "perform
" method.
JSwat commands can do just about anything any ordinary Java code
can do. But you are probably more concerned with what JSwat
commands can do in the context of JSwat. All of the work of a JSwat
command is performed in its perform
method. This
method is given several parameters which enable the command to
perform its task. The first parameter is the
Session object running the command. The
Session
provides access to most everything the command
could ever want, including threads, context manager, event handler,
source code manager, CommandManager
, etc. The second
argument is a StringTokenizer
which provides the
command arguments. For instance, if the friday command took two
arguments, a thread ID and an object reference, those would be
passed in the args
parameter. It is up to the friday
command to parse the strings and resolve the arguments. The third
and final argument to the perform
method is the
Log
that the command may write messages to. This is
the same log as the one returned from
Session.getStatusLog()
.