edu.cmu.sphinx.util
Class CommandInterpreter

java.lang.Object
  extended byjava.lang.Thread
      extended byedu.cmu.sphinx.util.CommandInterpreter
All Implemented Interfaces:
java.lang.Runnable

public class CommandInterpreter
extends java.lang.Thread

This class is a command interpreter. It reads strings from an input stream, parses them into commands and executes them, results are sent back on the output stream.

See Also:
CommandInterpreter

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CommandInterpreter()
          Creates a command interpreter that won't read a stream.
CommandInterpreter(java.io.BufferedReader in, java.io.PrintWriter out)
          Creates a command interpreter that reads/writes on the given streams.
 
Method Summary
 void add(java.util.Map newCommands)
          Add the given set of commands to the list of commands.
 void add(java.lang.String name, CommandInterface command)
          Adds the given command to the command list.
 void addAlias(java.lang.String command, java.lang.String alias)
          Adds an alias to the command
 void close()
           
 java.lang.String execute(java.lang.String cmdString)
          Execute the given command string.
 java.io.PrintWriter getPrintWriter()
          Returns the output stream of this CommandInterpreter.
 java.lang.String getPrompt()
          Gets the prompt for the interpreter
 java.net.Socket getSocket()
          Returns the Socket this CommandInterpreter uses.
 boolean load(java.lang.String filename)
           
static void main(java.lang.String[] args)
          manual tester for the command interpreter.
 void putResponse(java.lang.String response)
          Outputs a response to the sender.
 void run()
           
 void setPrompt(java.lang.String prompt)
          Sets the prompt for the interpreter
 void setSocket(java.net.Socket skt)
          Sets the Socket for this CommandInterpreter.
 void setStreams(java.io.BufferedReader in, java.io.PrintWriter out)
          Sets the I/O streams
 void setTrace(boolean trace)
          Sets the trace mode of the command interpreter.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandInterpreter

public CommandInterpreter(java.io.BufferedReader in,
                          java.io.PrintWriter out)
Creates a command interpreter that reads/writes on the given streams.

Parameters:
in - the input stream.
out - the output stream.

CommandInterpreter

public CommandInterpreter()
Creates a command interpreter that won't read a stream.

Method Detail

setTrace

public void setTrace(boolean trace)
Sets the trace mode of the command interpreter.

Parameters:
trace - true if tracing.

setStreams

public void setStreams(java.io.BufferedReader in,
                       java.io.PrintWriter out)
Sets the I/O streams

Parameters:
in - the input stream.
out - the output stream.

getSocket

public java.net.Socket getSocket()
Returns the Socket this CommandInterpreter uses.


setSocket

public void setSocket(java.net.Socket skt)
Sets the Socket for this CommandInterpreter.

Parameters:
skt - the Socket this CommandInterpreter uses

add

public void add(java.lang.String name,
                CommandInterface command)
Adds the given command to the command list.

Parameters:
name - the name of the command.
command - the command to be executed.

addAlias

public void addAlias(java.lang.String command,
                     java.lang.String alias)
Adds an alias to the command

Parameters:
command - the name of the command.
alias - the new aliase

add

public void add(java.util.Map newCommands)
Add the given set of commands to the list of commands.

Parameters:
newCommands - the new commands to add to this interpreter.

putResponse

public void putResponse(java.lang.String response)
Outputs a response to the sender.

Parameters:
response - the response to send.

execute

public java.lang.String execute(java.lang.String cmdString)
Execute the given command string.

Parameters:
cmdString - the command string.

run

public void run()

close

public void close()

load

public boolean load(java.lang.String filename)

setPrompt

public void setPrompt(java.lang.String prompt)
Sets the prompt for the interpreter

Parameters:
prompt - the prompt.

getPrompt

public java.lang.String getPrompt()
Gets the prompt for the interpreter

Returns:
the prompt.

getPrintWriter

public java.io.PrintWriter getPrintWriter()
Returns the output stream of this CommandInterpreter.

Returns:
the output stream

main

public static void main(java.lang.String[] args)
manual tester for the command interpreter.