ContentsJava Class DesignImplementing the Command Interface
Previous: Java Class Design | Next: Registering a New Command

Implementing the Command Interface

The Java Servlet API requires that all HTTP servlets extend javax.servlet.HttpServlet.  Since any given class can only subclass one superclass, that means that servlets must exist in a fixed hierarchy.  Fortunately, JACL only requires that a class implement the tcl.lang.Command interface, meaning that any class can be a command!

Given that many back-end services already exist, it should be easy to turn them into commands and make them available to web page designers as WELD commands, all that is required is that a cmdProc() method be provided.

The cmdProc() method is similar to the public static void main() method that is used to provide command-line interfaces in applications.  Instead of getting an array of String, an array of TclObject is provided.  The main method is executed by a single thread which is invoked by the operating system using a dedicated JVM. With cmdProc, however, the commands of many threads are executed within a single JVM.  Consequently, cmdProc() also needs the Interp object which invoked it.

The Interp object which is passed to cmdProc() has all of the methods necessary for your class to communicate with the interpreter.  Besides the chief goal of invoking other classes and methods, cmdProc() is also responsible to set the result of the command.  While it is not illegal to leave the result empty, there is often good information which should be returned to the command interpreter (and, in turn, to the web page designer).  The result is set by invoking the setResult() method of the interpreter object.


ContentsJava Class DesignImplementing the Command Interface
Previous: Java Class Design | Next: Registering a New Command

Modified: Wed Apr 19 06:46:54 EDT 2000