next up previous contents
Next: The Command Class Up: The Interface Services Previous: The Middleman

The HsCommandAPI Service

  Because we would like to see Haystack extended and used by non-Java systems the Middleman is not a perfect solution. In addtion to the Middleman we introduce the HsCommandAPI service. This service allows users to create a set of ``scripts'' (in Java) that are invokable from external processes by means of a textual command. The command scripts (which are of type Command) reside in the haystack.object.command package.

At any point after instantiation, it is possible to call the register(...) method on the HsCommandAPI with a Command object as an argument. Once an object is registered it is possible to invoke it through the HsCommandAPI. Abstractly, what we now have is a service to allow for virtual method invocations. This invocation is done by means of the invoke(...) method which accepts a string as an argument. The string is usually in the form (optionally with a new line at the end):

Functioni Arg1 Arg2 Arg3 ... Argn

Arguments are seperated by a white space character. For multi-word arguments, HsCommandAPI allows for the use of either quote or double-quote characters to specify the beginning and end of a multi-word string (i.e. 'this is an example of a multi-word argument'). Additionally, HsCommandAPI handles a number of special characters:

 

Character Evaluates to:
\t tab
\n new line
\r return
\f form feed
\x x (i.e. any other character)

Table: The interpretation of special characters within the HsCommandAPI

This leads the HsCommandAPI to invoke the Command object corresponding to the name Functioni with the set of parsed arguments. HsCommandAPI understands the special ``help [functionName]'' command which returns the set of functions it is capable of handling or the usage information for a particular function (with the optional functionName argument).

The invoke() command will return the string response generated by the invocation of the specific function. If there was an error in handling the function an exception (BadCommandException) is thrown with details of the error.




next up previous contents
Next: The Command Class Up: The Interface Services Previous: The Middleman

Copyright 1998, Eytan Adar (eytan@alum.mit.edu)