org.hyperic.sigar.shell
Class ShellBase

java.lang.Object
  extended by org.hyperic.sigar.shell.ShellBase
All Implemented Interfaces:
ShellCommandMapper, SIGINT, GetlineCompleter
Direct Known Subclasses:
Shell

public abstract class ShellBase
extends java.lang.Object
implements ShellCommandMapper, GetlineCompleter, SIGINT


Field Summary
protected  java.io.PrintStream err
           
protected  Getline gl
           
protected  java.io.PrintStream out
           
static java.lang.String PROP_PAGE_SIZE
           
 
Constructor Summary
ShellBase()
           
 
Method Summary
 java.lang.String complete(ShellCommandHandler handler, java.lang.String line)
           
 java.lang.String complete(java.lang.String line)
           
 java.util.Iterator getCommandNameIterator()
          Get an iterator for the command names.
 org.hyperic.sigar.pager.PageControl getDefaultPageControl()
           
 java.io.PrintStream getErrStream()
           
 Getline getGetline()
           
 ShellCommandHandler getHandler(java.lang.String command)
          Get the command handler for a command.
 java.lang.String getHiddenInput(java.lang.String prompt)
          If a command needs additional input via the console, they can get it this way.
 java.lang.String getInput(java.lang.String prompt)
          If a command needs additional input via the console, they can get it this way.
 java.lang.String getInput(java.lang.String prompt, boolean addToHistory)
          If a command needs additional input via the console, they can get it this way.
 java.io.PrintStream getOutStream()
           
 int getPageSize()
          Get the current page size used when paging data.
 void handleCommand(java.lang.String line)
           
 void handleCommand(java.lang.String line, java.lang.String[] args)
           
 boolean handlerIsHidden(java.lang.String handlerName)
           
 void handleSIGINT()
           
 boolean hasCompleter(ShellCommandHandler handler)
           
 void init(java.lang.String applicationName, java.io.PrintStream out, java.io.PrintStream err)
           
 void initHistory()
           
 void initHistory(java.io.File file)
           
 boolean isRedirected()
          Check to see if the currently running shell command is being redirected to a file.
 void performPaging(org.hyperic.sigar.pager.PageFetcher fetcher)
           
 void performPaging(org.hyperic.sigar.pager.PageFetcher fetcher, org.hyperic.sigar.pager.PageControl control)
           
 void processCommand(ShellCommandHandler handler, java.lang.String[] args)
           
 void readRCFile(java.io.File rcFile, boolean echoCommands)
          Read a .rc file into the shell, invoking everything in it (without saving the actions to history)
 void registerCommandHandler(java.lang.String commandName, ShellCommandHandler handler)
          Register a new command handler.
 void registerSigIntHandler()
           
 void run()
           
 void sendToErrStream(java.lang.String s)
          Write a string to this shell's output stream.
 void sendToOutStream(java.lang.String s)
          Write a string to this shell's output stream.
 void setHandlerHidden(java.lang.String handlerName, boolean isHidden)
           
 void setPageSize(int size)
          Set the page size for data paging.
 void setPrompt(java.lang.String prompt)
          Change the prompt
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_PAGE_SIZE

public static final java.lang.String PROP_PAGE_SIZE
See Also:
Constant Field Values

gl

protected Getline gl

out

protected java.io.PrintStream out

err

protected java.io.PrintStream err
Constructor Detail

ShellBase

public ShellBase()
Method Detail

handleSIGINT

public void handleSIGINT()
Specified by:
handleSIGINT in interface SIGINT

initHistory

public void initHistory()
                 throws java.io.IOException
Throws:
java.io.IOException

initHistory

public void initHistory(java.io.File file)
                 throws java.io.IOException
Throws:
java.io.IOException

registerSigIntHandler

public void registerSigIntHandler()

init

public void init(java.lang.String applicationName,
                 java.io.PrintStream out,
                 java.io.PrintStream err)

readRCFile

public void readRCFile(java.io.File rcFile,
                       boolean echoCommands)
                throws java.io.IOException
Read a .rc file into the shell, invoking everything in it (without saving the actions to history)

Parameters:
rcFile - File to read
Throws:
java.io.IOException

setPrompt

public void setPrompt(java.lang.String prompt)
Change the prompt

Parameters:
prompt -

registerCommandHandler

public void registerCommandHandler(java.lang.String commandName,
                                   ShellCommandHandler handler)
                            throws ShellCommandInitException
Register a new command handler.

Parameters:
commandName - The command that this handler will process.
handler - The handler to register.
Throws:
ShellCommandInitException

getInput

public java.lang.String getInput(java.lang.String prompt)
                          throws java.io.EOFException,
                                 java.io.IOException
If a command needs additional input via the console, they can get it this way.

Parameters:
prompt - The prompt to display.
Returns:
The data that the user typed in.
Throws:
java.io.EOFException
java.io.IOException

getInput

public java.lang.String getInput(java.lang.String prompt,
                                 boolean addToHistory)
                          throws java.io.EOFException,
                                 java.io.IOException
If a command needs additional input via the console, they can get it this way.

Parameters:
prompt - The prompt to display.
addToHistory - If true, the input entered will be added to the history file.
Returns:
The data that the user typed in.
Throws:
java.io.EOFException
java.io.IOException

getHiddenInput

public java.lang.String getHiddenInput(java.lang.String prompt)
                                throws java.io.EOFException,
                                       java.io.IOException
If a command needs additional input via the console, they can get it this way. The characters that the user types are not echoed.

Parameters:
prompt - The prompt to display.
Returns:
The data that the user typed in.
Throws:
java.io.EOFException
java.io.IOException

sendToOutStream

public void sendToOutStream(java.lang.String s)
Write a string to this shell's output stream.

Parameters:
s - The string to write to the output stream.

sendToErrStream

public void sendToErrStream(java.lang.String s)
Write a string to this shell's output stream.

Parameters:
s - The string to write to the output stream.

run

public void run()

handleCommand

public void handleCommand(java.lang.String line)

handleCommand

public void handleCommand(java.lang.String line,
                          java.lang.String[] args)

processCommand

public void processCommand(ShellCommandHandler handler,
                           java.lang.String[] args)
                    throws ShellCommandUsageException,
                           ShellCommandExecException
Throws:
ShellCommandUsageException
ShellCommandExecException

getOutStream

public java.io.PrintStream getOutStream()

getErrStream

public java.io.PrintStream getErrStream()

getGetline

public Getline getGetline()

hasCompleter

public boolean hasCompleter(ShellCommandHandler handler)

complete

public java.lang.String complete(ShellCommandHandler handler,
                                 java.lang.String line)

complete

public java.lang.String complete(java.lang.String line)
Specified by:
complete in interface GetlineCompleter

getHandler

public ShellCommandHandler getHandler(java.lang.String command)
Description copied from interface: ShellCommandMapper
Get the command handler for a command.

Specified by:
getHandler in interface ShellCommandMapper
See Also:
ShellCommandMapper.getHandler(java.lang.String)

setHandlerHidden

public void setHandlerHidden(java.lang.String handlerName,
                             boolean isHidden)

handlerIsHidden

public boolean handlerIsHidden(java.lang.String handlerName)

getCommandNameIterator

public java.util.Iterator getCommandNameIterator()
Description copied from interface: ShellCommandMapper
Get an iterator for the command names.

Specified by:
getCommandNameIterator in interface ShellCommandMapper
See Also:
ShellCommandMapper.getCommandNameIterator()

shutdown

public void shutdown()

isRedirected

public boolean isRedirected()
Check to see if the currently running shell command is being redirected to a file.

Returns:
true if the shell is redirecting to a file, else false

setPageSize

public void setPageSize(int size)
Set the page size for data paging.

Parameters:
size - Number of rows to include in a page of data -- if 0, then unlimited rows will be used.

getPageSize

public int getPageSize()
Get the current page size used when paging data.

Returns:
the # of rows in the current page size.

getDefaultPageControl

public org.hyperic.sigar.pager.PageControl getDefaultPageControl()

performPaging

public void performPaging(org.hyperic.sigar.pager.PageFetcher fetcher)
                   throws org.hyperic.sigar.pager.PageFetchException
Throws:
org.hyperic.sigar.pager.PageFetchException

performPaging

public void performPaging(org.hyperic.sigar.pager.PageFetcher fetcher,
                          org.hyperic.sigar.pager.PageControl control)
                   throws org.hyperic.sigar.pager.PageFetchException
Throws:
org.hyperic.sigar.pager.PageFetchException


Copyright ? 2004-2009 Hyperic. All Rights Reserved.