org.ow2.petals.cli.shell
Class Shell

java.lang.Object
  extended by org.ow2.petals.cli.shell.Shell
Direct Known Subclasses:
PetalsShell

public abstract class Shell
extends java.lang.Object

A shell registers and evaluates commands

Author:
sandre

Field Summary
 java.io.PrintStream err
           
 java.io.InputStream in
           
 java.io.PrintStream out
           
 
Constructor Summary
Shell()
           
Shell(Command[] commands)
          Creates a new shell from a set of commands
 
Method Summary
 void evaluate(java.lang.String line)
          Evaluate a command line.
 void evaluate(java.lang.String[] args)
          Evaluate a list of arguments.
abstract  void exit(int status)
          Exit the current Set
 java.util.Map<java.lang.String,Command> getCommands()
          Get the available commands
abstract  java.lang.String interpolate(java.lang.String str)
          Interpolates variables and special characters in a string
abstract  boolean isComment(java.lang.String line)
          Test whether a line is a comment or not
protected  void register(Command command)
          Register a command
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

public final java.io.InputStream in

out

public final java.io.PrintStream out

err

public final java.io.PrintStream err
Constructor Detail

Shell

public Shell()

Shell

public Shell(Command[] commands)
      throws ShellException
Creates a new shell from a set of commands

Parameters:
commands - the initial set of commands available for this shell
Throws:
ShellException - when a command fails to be registered
Method Detail

getCommands

public final java.util.Map<java.lang.String,Command> getCommands()
Get the available commands

Returns:
a set of commands mapped with their name

register

protected void register(Command command)
                 throws ShellException
Register a command

Parameters:
command -
Throws:
ShellException - if the command is already defined

isComment

public abstract boolean isComment(java.lang.String line)
Test whether a line is a comment or not

Parameters:
line - the string to be tested
Returns:
true if the line is a comment, false otherwise

interpolate

public abstract java.lang.String interpolate(java.lang.String str)
Interpolates variables and special characters in a string

Parameters:
str - the string to be interpolated
Returns:
a new string with interpolated variables

exit

public abstract void exit(int status)
Exit the current Set

Parameters:
status - the optional result value

evaluate

public void evaluate(java.lang.String[] args)
              throws ShellException,
                     CommandException
Evaluate a list of arguments. Do nothing if args id null of empty.

Parameters:
args - the command line
Throws:
ShellException - when the command was not found
CommandException - when an error occurs during the execution of the command

evaluate

public final void evaluate(java.lang.String line)
                    throws ShellException,
                           CommandException
Evaluate a command line. Do nothing if the line is a comment.

Parameters:
line - the line to be evaluated
Throws:
ShellException - when the command was not found
CommandException - when an error occurs during the execution of the command
See Also:
isComment(String)


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.