org.adougou.cline
Class BasePrompt

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.adougou.cline.BasePrompt
All Implemented Interfaces:
IPrompt, java.lang.Runnable
Direct Known Subclasses:
ShellPrompt, TextAreaPrompt

public class BasePrompt
extends java.lang.Thread
implements IPrompt

Base class for all command prompts. This class handles the prompt-independent processing, such as the basic user-interaction loop and command execution. Optionally, System.in, System.err, System.out can be redirected to the prompt's streams.

See Also:
ShellPrompt, TextAreaPrompt

Field Summary
 java.io.PrintStream err
           
 java.io.InputStream in
           
 java.io.PrintStream out
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected BasePrompt(java.lang.String name, CommandRegister register, java.io.PrintStream out, java.io.PrintStream err, java.io.InputStream in)
           
 
Method Summary
 boolean askBooleanQuestion(java.lang.String question)
          Ask the user a boolean question.
 java.lang.String askQuestion(java.lang.String question)
          Ask the user a question.
 java.lang.String askQuestion(java.lang.String question, java.lang.String defaultAns)
          Ask the user a question and provide a default answer (to save the user typing if it is a likely default).
 void exit()
          Iterates through all the registered packages and tells them we are exiting - just in case they have resources to free.
protected  void printPrompt()
           
 void redirectSystemIOToPrompt()
           
 void registerCommand(Command command)
          This method is called to register a new command to be used with this prompt.
 void registerPackage(ICLinePackage ci)
           
 void run()
          This method starts the prompt in interactive mode.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.adougou.cline.IPrompt
start
 

Field Detail

out

public java.io.PrintStream out

err

public java.io.PrintStream err

in

public java.io.InputStream in
Constructor Detail

BasePrompt

protected BasePrompt(java.lang.String name,
                     CommandRegister register,
                     java.io.PrintStream out,
                     java.io.PrintStream err,
                     java.io.InputStream in)
Method Detail

redirectSystemIOToPrompt

public void redirectSystemIOToPrompt()

registerCommand

public void registerCommand(Command command)
This method is called to register a new command to be used with this prompt. Note, every prompt contains a reference to a CommandRegister that keeps track of available commands.
Specified by:
registerCommand in interface IPrompt

registerPackage

public void registerPackage(ICLinePackage ci)
Specified by:
registerPackage in interface IPrompt

exit

public void exit()
Iterates through all the registered packages and tells them we are exiting - just in case they have resources to free.
Specified by:
exit in interface IPrompt

printPrompt

protected void printPrompt()

run

public void run()
This method starts the prompt in interactive mode. Note that this is the starting point for a new thread of execution whcih blocks until the user enters input into the input stream.
Overrides:
run in class java.lang.Thread

askBooleanQuestion

public boolean askBooleanQuestion(java.lang.String question)
Ask the user a boolean question. Eg. "How are you today?"
Specified by:
askBooleanQuestion in interface IPrompt
Returns:
true if the user responds "yes" or "y", false if they respond "no" or "n" - all case insensitive.

askQuestion

public java.lang.String askQuestion(java.lang.String question)
Ask the user a question.
Specified by:
askQuestion in interface IPrompt
Returns:
a string containing the typed response.

askQuestion

public java.lang.String askQuestion(java.lang.String question,
                                    java.lang.String defaultAns)
Ask the user a question and provide a default answer (to save the user typing if it is a likely default).
Specified by:
askQuestion in interface IPrompt
Returns:
a string containing the typed response, or the default answer if the user just hits enter.