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):
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) |
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.