org.eclipse.osgi.framework.internal.core
Class FrameworkCommandInterpreter

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter
All Implemented Interfaces:
CommandInterpreter

public class FrameworkCommandInterpreter
extends java.lang.Object
implements CommandInterpreter

This class knows how to parse and execute the command line arguments to the FrameworkConsole. It attempts to pass the command to each registered CommandProvider until it finds one that knows what to do with it. FrameworkCommandInterpreter provides support for the "More" command which allows the operator to configure the number of lines to display before being prompted to continue. FrameworkCommandInterpreter provides several print methods which handle the "More" command.


Field Summary
protected  int currentLineCount
          The number of lines printed without user prompt.
protected static int maxLineCount
          The maximum number of lines to print without user prompt. 0 means no user prompt is required, the window is scrollable.
 
Constructor Summary
FrameworkCommandInterpreter(java.lang.String cmdline, java.lang.Object[] commandProviders, FrameworkConsole con)
          The constructor.
 
Method Summary
 void _more()
          Toggles the use of the more prompt for displayed output.
protected  boolean confirm(java.lang.String string, boolean defaultAnswer)
          Prompts the user for confirmation.
 java.lang.Object execute(java.lang.String cmd)
          Execute a command line as if it came from the end user.
 java.lang.String getHelp()
          Answer a string (may be as many lines as you like) with help texts that explain the command.
 java.lang.String nextArgument()
          Get the next argument in the input.
 void print(java.lang.Object o)
          Prints an object to the outputstream
 void printBundleResource(Bundle bundle, java.lang.String resource)
          Prints the given bundle resource if it exists
 void printDictionary(java.util.Dictionary dic, java.lang.String title)
          Prints the given dictionary sorted by keys.
 void println()
          Prints a empty line to the outputstream
 void println(java.lang.Object o)
          Prints an object to the output medium (appended with newline character).
 void printStackTrace(java.lang.Throwable t)
          Print a stack trace including nested exceptions.
protected  int prompt(java.lang.String string, int defaultAnswer)
          Prompts the user for input of a positive integer.
protected  java.lang.String prompt(java.lang.String string, java.lang.String defaultAnswer)
          Prompts the user for input from the input medium providing a default value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxLineCount

protected static int maxLineCount
The maximum number of lines to print without user prompt. 0 means no user prompt is required, the window is scrollable.


currentLineCount

protected int currentLineCount
The number of lines printed without user prompt.

Constructor Detail

FrameworkCommandInterpreter

public FrameworkCommandInterpreter(java.lang.String cmdline,
                                   java.lang.Object[] commandProviders,
                                   FrameworkConsole con)
The constructor. It turns the cmdline string into a StringTokenizer and remembers the input parms.

Method Detail

nextArgument

public java.lang.String nextArgument()
Get the next argument in the input. E.g. if the commandline is hello world, the _hello method will get "world" as the first argument.

Specified by:
nextArgument in interface CommandInterpreter
Returns:
A string containing the next argument on the command line

execute

public java.lang.Object execute(java.lang.String cmd)
Execute a command line as if it came from the end user. Searches the list of command providers using introspection until it finds one that contains a matching method. It searches for a method with the name "_cmd" where cmd is the command to execute. For example, for a command of "launch" execute searches for a method called "_launch".

Specified by:
execute in interface CommandInterpreter
Parameters:
cmd - The name of the command to execute.
Returns:
The object returned by the method executed.

print

public void print(java.lang.Object o)
Prints an object to the outputstream

Specified by:
print in interface CommandInterpreter
Parameters:
o - the object to be printed

println

public void println()
Prints a empty line to the outputstream

Specified by:
println in interface CommandInterpreter

printStackTrace

public void printStackTrace(java.lang.Throwable t)
Print a stack trace including nested exceptions.

Specified by:
printStackTrace in interface CommandInterpreter
Parameters:
t - The offending exception

println

public void println(java.lang.Object o)
Prints an object to the output medium (appended with newline character).

If running on the target environment, the user is prompted with '--more' if more than the configured number of lines have been printed without user prompt. This enables the user of the program to have control over scrolling.

For this to work properly you should not embed "\n" etc. into the string.

Specified by:
println in interface CommandInterpreter
Parameters:
o - the object to be printed

printDictionary

public void printDictionary(java.util.Dictionary dic,
                            java.lang.String title)
Prints the given dictionary sorted by keys.

Specified by:
printDictionary in interface CommandInterpreter
Parameters:
dic - the dictionary to print
title - the header to print above the key/value pairs

printBundleResource

public void printBundleResource(Bundle bundle,
                                java.lang.String resource)
Prints the given bundle resource if it exists

Specified by:
printBundleResource in interface CommandInterpreter
Parameters:
bundle - the bundle containing the resource
resource - the resource to print

getHelp

public java.lang.String getHelp()
Answer a string (may be as many lines as you like) with help texts that explain the command.


_more

public void _more()
           throws java.lang.Exception
Toggles the use of the more prompt for displayed output.

Throws:
java.lang.Exception

confirm

protected boolean confirm(java.lang.String string,
                          boolean defaultAnswer)
Prompts the user for confirmation.

Parameters:
string - the message to present to the user to confirm
defaultAnswer - the default result
Returns:
true if the user confirms; false otherwise.

prompt

protected java.lang.String prompt(java.lang.String string,
                                  java.lang.String defaultAnswer)
Prompts the user for input from the input medium providing a default value.

Parameters:
string - the message to present to the user
defaultAnswer - the string to use as a default return value
Returns:
The user provided string or the defaultAnswer, if user provided string was empty.

prompt

protected int prompt(java.lang.String string,
                     int defaultAnswer)
Prompts the user for input of a positive integer.

Parameters:
string - the message to present to the user
defaultAnswer - the integer to use as a default return value
Returns:
The user provided integer or the defaultAnswer, if user provided an empty input.