|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectInteractiveConsole
public abstract class InteractiveConsole
Base class for applications executing instructions from the console. If there is no console attached to the current JVM, then this class will read instructions from standard input stream and sent the results to the standard output stream. But different streams can be explicitly specified at construction time.
Every empty lines, and every lines beginning with "//" or "#" characters,
are ignored. Other lines are sent to the execute method, which subclasses
should override.
| utility/geotk-utility (download) | View source code for this class |
| Field Summary | |
|---|---|
protected PrintWriter |
err
The error stream. |
protected PrintWriter |
out
The output stream. |
| Constructor Summary | |
|---|---|
protected |
InteractiveConsole(CommandLine commands)
Creates a new instance using the console if available, or the parameters from the command line otherwise. |
protected |
InteractiveConsole(LineNumberReader in)
Creates a new instance using the specified input stream. |
protected |
InteractiveConsole(LineNumberReader in,
PrintWriter out)
Creates a new instance using the specified input and output streams. |
| Method Summary | |
|---|---|
protected void |
execute(String instruction)
Executes the given instruction. |
String |
getPrompt()
Returns the command-line prompt, or null if there is no console. |
protected void |
reportError(Exception exception)
Invoked by run() if an exception occurred in the execute method. |
void |
run()
Executes all instructions from the console or the input stream. |
void |
setPrompt(String prompt)
Sets the command-line prompt, which may be an empty string. |
protected void |
setSymbols(char[] openingBrackets,
char[] closingBrackets,
char quote)
Gives some hints about the expected syntax of commands. |
void |
stop()
Stops the run() method. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final PrintWriter out
protected final PrintWriter err
| Constructor Detail |
|---|
protected InteractiveConsole(CommandLine commands)
commands - The command line, or null if none.protected InteractiveConsole(LineNumberReader in)
in - The input stream (can not be null).
protected InteractiveConsole(LineNumberReader in,
PrintWriter out)
in - The input stream (can not be null).out - The output stream (can not be null).| Method Detail |
|---|
protected void setSymbols(char[] openingBrackets,
char[] closingBrackets,
char quote)
openingBrackets - List of caracters acceptable as opening bracket. The closing bracket
must be the character in the closingBrackets array at the same index than the
opening bracket.closingBrackets - List of caracters acceptable as closing bracket.quote - The character used for quoting texts, or 0 if none.public void setPrompt(String prompt)
prompt - The new command-line prompt.public String getPrompt()
null if there is no console. This method returns
a non-null value only if this class is using the console attached to the
JVM.
null if there is no attached console.public void stop()
run() method. This method can been invoked from any thread.
If a line is in process, it will be finished before the run() method
stops.
public void run()
[Ctrl-Z] for input from the keyboard), or until the
stop() method is invoked. Empty and comment lines are ignored.
Multilines may be concatenated in a single instruction if a bracket is open on a line
and closed only a few lines later. Once an instruction is assembled, it is given to the
execute method. If an exception occurs during the call to execute,
then the reportError method is invoked. The later can stop the execution
either by invoking the stop method or by throwing an exception.
run in interface Runnable
protected void execute(String instruction)
throws Exception
run() for each line
(or group of lines) read fron the console or the input stream.
The default implementation recognizes the stacktrace and exit, and
prints an error message for all other instructions. Subclasses should override this
method is order to provide more functionalities.
instruction - The instruction to execute.
Exception - if the instruction failed.protected void reportError(Exception exception)
run() if an exception occurred in the execute method.
The default implementation prints a message to the error stream. The
error message includes the line number if this information is available.
exception - The exception to report.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||