Class CommandLine

java.lang.Object
  |
  +--CommandLine

public class CommandLine
extends java.lang.Object

This class can be used by any object (that implements CommandLineable) to be manipulated by a command line interface. Here's a snippet:

   CommandLineable client = new YourObject();
   CommandLine cl = new CommandLine(client);
   cl.prompt(); // bootstraps the process
 
The CommandLine will parse commands in its own thread, sending a doCommand() message when anything interesting happens. If doCommand() returns a null, then the CommandLine ceases. Otherwise, the return from doCommand() (a String) is displayed and the command line waits for a new command.

Run java com.fooware.util.CommandLine for a taste.

Version:
$Revision: 1.1 $
Author:
Chris Cheetham

Inner Class Summary
private  class CommandLine.PromptThread
           
 
Field Summary
private  CommandLineable m_client
          The client who is receiving the command from this command line.
private  java.io.BufferedReader m_in
          The input stream from which to get commands.
private  java.io.PrintWriter m_out
          The output stream to which to send messages and prompts.
private  java.lang.String m_prompt
          The prompt to be displayed at the command line.
private  java.lang.String promptString
           
 
Constructor Summary
CommandLine(CommandLineable client)
          Create a new CommandLine for the client.
 
Method Summary
 java.lang.String getPromptString()
          Get the prompt displayed at the command line.
 void prompt(java.lang.String message)
          The message will be sent to the current output stream.
 void setInputStream(java.io.InputStream istr)
          Set the input stream.
 void setOutputStream(java.io.OutputStream ostr)
          Set the output stream.
 void setPromptString(java.lang.String prompt)
          Set the prompt to be displayed at the command line.
 void start()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_client

private CommandLineable m_client
The client who is receiving the command from this command line.

m_prompt

private java.lang.String m_prompt
The prompt to be displayed at the command line.

m_in

private java.io.BufferedReader m_in
The input stream from which to get commands.

m_out

private java.io.PrintWriter m_out
The output stream to which to send messages and prompts.

promptString

private java.lang.String promptString
Constructor Detail

CommandLine

public CommandLine(CommandLineable client)
Create a new CommandLine for the client.
Method Detail

setPromptString

public void setPromptString(java.lang.String prompt)
Set the prompt to be displayed at the command line.

getPromptString

public java.lang.String getPromptString()
Get the prompt displayed at the command line.

prompt

public void prompt(java.lang.String message)
            throws java.io.IOException
The message will be sent to the current output stream. The command then waits until something comes into the input stream. The input is parsed and the client (the CommandLineable passed into this constructor) is sent the doCommand() message.
See Also:
fesco.util.CommandLineable

start

public void start()

setInputStream

public void setInputStream(java.io.InputStream istr)
Set the input stream. The default is System.in. This is the input stream from which commands are received.

setOutputStream

public void setOutputStream(java.io.OutputStream ostr)
Set the output stream. The default is System.out. This is the output stream to which command output is written.