edu.umbc.cs.daml4jess
Class TextCmdReader

java.lang.Object
  |
  +--edu.umbc.cs.daml4jess.TextCmdReader
Direct Known Subclasses:
QasmTextUI.QasmCmdReader

public class TextCmdReader
extends java.lang.Object

Generic input reader. The rules are as follow:

  1. generally one input line will be returned as a command (or input);
  2. lines ended with "\n\" will be combined with the line that follows into one command (or input), with a newline inserted in between;
  3. lines ended with "\" will be combined with the line that follows into one command (or input), but no newline inserted;
  4. lines started with any character in COMMENT_STARTER ("#") will be treated as comment lines and ignored, will continue to read the next line;
  5. the command (or input) QUIT_CMD ("quit") will terminate the process.
  6. it doesn't recognize escape sequences, like \n, \t, etc.
  7. blank lines will be ignored.
The intended use is to read command input from a given input stream or reader, and server as the base class for more sophisticated readers.


Field Summary
protected static java.lang.String COMMENT_STARTER
           
protected static java.lang.String DEFAULT_PROMPT
           
protected  java.io.BufferedReader inputReader_
           
protected  java.lang.String prompt_
           
protected static java.lang.String QUIT_CMD
           
 
Constructor Summary
TextCmdReader()
          Constructor.
TextCmdReader(java.io.InputStream istream, java.lang.String prompt)
          Constructor.
TextCmdReader(java.io.Reader inputReader, java.lang.String prompt)
          Constructor.
 
Method Summary
protected  void init(java.io.Reader inputReader, java.lang.String prompt)
          Initialization.
static void main(java.lang.String[] args)
          For test purpose only - it just echos the command you type in.
 java.lang.Object nextCmdObject()
          Get the next parsed command.
 java.lang.String nextCmdString()
          Get the next command string.
protected  java.lang.Object parseCommand(java.lang.String cmdString)
          Parse the input command.
protected  void prompt()
          Show the command line prompt.
 void setPrompt(java.lang.String prompt)
          Set the command line prompt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROMPT

protected static java.lang.String DEFAULT_PROMPT

QUIT_CMD

protected static java.lang.String QUIT_CMD

COMMENT_STARTER

protected static java.lang.String COMMENT_STARTER

prompt_

protected java.lang.String prompt_

inputReader_

protected java.io.BufferedReader inputReader_
Constructor Detail

TextCmdReader

public TextCmdReader()
Constructor.


TextCmdReader

public TextCmdReader(java.io.InputStream istream,
                     java.lang.String prompt)
Constructor.

Parameters:
prompt - if null, no prompt will be shown, not even a new line. otherwise the prompt will be printed out.

TextCmdReader

public TextCmdReader(java.io.Reader inputReader,
                     java.lang.String prompt)
Constructor.

Method Detail

nextCmdString

public java.lang.String nextCmdString()
                               throws java.io.IOException
Get the next command string. Note that an empty line will be ignored. See the class description for more details.

Returns:
the next command string. Return null when quit command is received of "end of file" is reached.
java.io.IOException

nextCmdObject

public java.lang.Object nextCmdObject()
                               throws java.io.IOException,
                                      ParseCmdException
Get the next parsed command. What kind of command object to return is determined by the parseCommand() method.

java.io.IOException
ParseCmdException

prompt

protected void prompt()
Show the command line prompt. See the setPrompt() method for details on the prompt.


setPrompt

public void setPrompt(java.lang.String prompt)
Set the command line prompt.

Parameters:
prompt - If prompt == null, nothing will be prompted; otherwise the prompt will be printed out as is.

parseCommand

protected java.lang.Object parseCommand(java.lang.String cmdString)
                                 throws ParseCmdException
Parse the input command. It just returns the command string. Sub-classes are expected to override this method.

ParseCmdException

init

protected void init(java.io.Reader inputReader,
                    java.lang.String prompt)
Initialization.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
For test purpose only - it just echos the command you type in.

java.lang.Exception