public class CommandInterpreter
extends java.lang.Thread
CommandInterpreter
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.util.Map<java.lang.String,CommandInterface> 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.
|
protected java.lang.String |
execute(java.lang.String[] args)
Execute the given command.
|
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() |
boolean |
load(java.lang.String filename) |
static void |
main(java.lang.String[] args) |
protected void |
onExit()
Called when the interpreter is exiting.
|
protected java.lang.String[] |
parseMessage(java.lang.String message)
Parses the given message into an array of strings.
|
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.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public CommandInterpreter(java.io.BufferedReader in, java.io.PrintWriter out)
in
- the input stream.out
- the output stream.public CommandInterpreter()
public void setTrace(boolean trace)
trace
- true if tracing.public void setStreams(java.io.BufferedReader in, java.io.PrintWriter out)
in
- the input stream.out
- the output stream.public java.net.Socket getSocket()
public void setSocket(java.net.Socket skt)
skt
- the Socket this CommandInterpreter usespublic void add(java.lang.String name, CommandInterface command)
name
- the name of the command.command
- the command to be executed.public void addAlias(java.lang.String command, java.lang.String alias)
command
- the name of the command.alias
- the new aliasepublic void add(java.util.Map<java.lang.String,CommandInterface> newCommands)
newCommands
- the new commands to add to this interpreter.public void putResponse(java.lang.String response)
response
- the response to send.protected void onExit()
protected java.lang.String execute(java.lang.String[] args)
args
- command args, args[0] contains name of cmd.public java.lang.String execute(java.lang.String cmdString)
cmdString
- the command string.protected java.lang.String[] parseMessage(java.lang.String message)
message
- the string to be parsed.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void close()
public boolean load(java.lang.String filename)
public void setPrompt(java.lang.String prompt)
prompt
- the prompt.public java.lang.String getPrompt()
public java.io.PrintWriter getPrintWriter()
public static void main(java.lang.String[] args)