org.sapia.console
Class CommandConsole

java.lang.Object
  |
  +--org.sapia.console.Console
        |
        +--org.sapia.console.CommandConsole
Direct Known Subclasses:
HelloWorldConsole

public class CommandConsole
extends Console

A command-line console that can be embedded in applications. The console parses command-lines to create Command instances that it executes.

An instance of this class takes a CommandFactory at construction, and delegates command object creation to it.

Embedding a command console is as shown below:

   ReflectCommandFactory fac = new ReflectCommandFactory();
   fac.addPackage("org.mycommand.package");
   CommandConsole cons = new CommandConsole(fac);
   cons.start();
 

Author:
Yanick Duchesne 29-Nov-02

Field Summary
 
Fields inherited from class org.sapia.console.Console
DEFAULT_PROMPT
 
Constructor Summary
CommandConsole(CommandFactory fac)
          Creates an instance of this class with the given factory.
CommandConsole(InputStream in, OutputStream out, CommandFactory fac)
          Creates an instance of this class with the given factory.
 
Method Summary
protected  Context newContext()
          Template method internally called by this instance to create new Context instances.
 void setCommandListener(ConsoleListener listener)
          Sets this instance's command listener.
 void start()
          Starts this console in the current thread and loops indefinily on input/display until an AbortException is thrown by a Command instance.
 
Methods inherited from class org.sapia.console.Console
in, input, out, print, println, prompt, readLine, setOut, setPrompt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandConsole

public CommandConsole(CommandFactory fac)
Creates an instance of this class with the given factory.

Parameters:
fac - A CommandFactory.

CommandConsole

public CommandConsole(InputStream in,
                      OutputStream out,
                      CommandFactory fac)
Creates an instance of this class with the given factory. The input and output streams passed in are used internally for command-line reading and display output respectively.

Parameters:
in - The input stream of the console.
out - The output stream of the console.
fac - A CommandFactory. >>>>>>> 1.6
Method Detail

setCommandListener

public void setCommandListener(ConsoleListener listener)
Sets this instance's command listener.


start

public void start()
Starts this console in the current thread and loops indefinily on input/display until an AbortException is thrown by a Command instance.


newContext

protected Context newContext()
Template method internally called by this instance to create new Context instances.



Copyright © 2002 Sapia Open Community, Inc. All Rights Reserved.