org.springframework.roo.shell
Class AbstractShell

java.lang.Object
  extended by org.springframework.roo.shell.event.AbstractShellStatusPublisher
      extended by org.springframework.roo.shell.AbstractShell
All Implemented Interfaces:
ShellStatusProvider, Shell, ShellPromptAccessor

public abstract class AbstractShell
extends AbstractShellStatusPublisher
implements Shell

Provides a base Shell implementation.

Author:
Ben Alex

Field Summary
static String completionKeys
           
protected  ExitShellRequest exitShellRequest
           
protected  boolean inBlockComment
           
protected  Logger logger
           
static String shellPrompt
           
 
Fields inherited from class org.springframework.roo.shell.event.AbstractShellStatusPublisher
shellStatus, shellStatusListeners
 
Constructor Summary
AbstractShell()
           
 
Method Summary
 void blockCommentBegin()
           
 void blockCommentFinish()
           
 String date()
           
 boolean executeCommand(String line)
          Runs the specified command.
protected  boolean executeScriptLine(String line)
          Execute the single line from a script.
protected abstract  org.osgi.service.component.ComponentContext getContext()
           
 ExitShellRequest getExitShellRequest()
           
 File getHome()
          Obtains the home directory for the current shell instance.
protected abstract  String getHomeAsString()
           
protected  Parser getParser()
           
 String getShellPrompt()
           
 void inlineComment()
           
protected  void logCommandIfRequired(String line, boolean successful)
          Allows a subclass to log the execution of a well-formed command.
protected  void logCommandToOutput(String processedLine)
          Allows a subclass to actually write the resulting logged command to some form of output.
 String props()
           
 void script(File resource, boolean lineNumbers)
           
 void setPromptPath(String path)
          Base implementation of the Shell.setPromptPath(String) method, designed for simple shell implementations.
 String version(String extra)
           
static String versionInfo()
           
 
Methods inherited from class org.springframework.roo.shell.event.AbstractShellStatusPublisher
addShellStatusListener, getShellStatus, removeShellStatusListener, setShellStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.roo.shell.Shell
isDevelopmentMode, promptLoop, setDevelopmentMode
 
Methods inherited from interface org.springframework.roo.shell.event.ShellStatusProvider
addShellStatusListener, getShellStatus, removeShellStatusListener
 

Field Detail

logger

protected final Logger logger

inBlockComment

protected boolean inBlockComment

exitShellRequest

protected ExitShellRequest exitShellRequest

shellPrompt

public static String shellPrompt

completionKeys

public static String completionKeys
Constructor Detail

AbstractShell

public AbstractShell()
Method Detail

script

public void script(File resource,
                   boolean lineNumbers)

executeScriptLine

protected boolean executeScriptLine(String line)
Execute the single line from a script.

This method can be overridden by sub-classes to pre-process script lines.


executeCommand

public boolean executeCommand(String line)
Description copied from interface: Shell
Runs the specified command. Control will return to the caller after the command is run.

Specified by:
executeCommand in interface Shell
Parameters:
line - to execute (required)
Returns:
true if the command was successful, false if there was an exception

logCommandIfRequired

protected void logCommandIfRequired(String line,
                                    boolean successful)
Allows a subclass to log the execution of a well-formed command. This is invoked after a command has completed, and indicates whether the command returned normally or returned an exception. Note that attempted commands that are not well-formed (eg they are missing a mandatory argument) will never be presented to this method, as the command execution is never actually attempted in those cases. This method is only invoked if an attempt is made to execute a particular command.

Implementations should consider specially handling the "script" commands, and also indicating whether a command was successful or not. Implementations that wish to behave consistently with other AbstractShell subclasses are encouraged to simply override logCommandToOutput(String) instead, and only override this method if you actually need to fine-tune the output logic.

Parameters:
line - the parsed line (any comments have been removed; never null)
successful - if the command was successful or not

logCommandToOutput

protected void logCommandToOutput(String processedLine)
Allows a subclass to actually write the resulting logged command to some form of output. This frees subclasses from needing to implement the logic within logCommandIfRequired(String, boolean).

Implementations should invoke getExitShellRequest() to monitor any attempts to exit the shell and release resources such as output log files.

Parameters:
processedLine - the line that should be appended to some type of output (excluding the \n character)

setPromptPath

public void setPromptPath(String path)
Base implementation of the Shell.setPromptPath(String) method, designed for simple shell implementations. Advanced implementations (eg those that support ANSI codes etc) will likely want to override this method and set the shellPrompt variable directly.

Specified by:
setPromptPath in interface Shell
Parameters:
path - to set (can be null or empty; must NOT be formatted in any special way eg ANSI codes)

getExitShellRequest

public ExitShellRequest getExitShellRequest()
Specified by:
getExitShellRequest in interface Shell
Returns:
null if no exit was requested, otherwise the last exit code indicated to the shell to use

inlineComment

public void inlineComment()

blockCommentBegin

public void blockCommentBegin()

blockCommentFinish

public void blockCommentFinish()

props

public String props()

date

public String date()

version

public String version(String extra)

versionInfo

public static String versionInfo()

getShellPrompt

public String getShellPrompt()
Specified by:
getShellPrompt in interface ShellPromptAccessor
Returns:
the shell prompt (never null; the result may include special characters such as ANSI escape codes if the implementation is using them)

getHome

public File getHome()
Obtains the home directory for the current shell instance.

Note: calls the getHomeAsString() method to allow subclasses to provide the home directory location as string using different environment-specific strategies.

If the path indicated by getHomeAsString() exists and refers to a directory, that directory is returned.

If the path indicated by getHomeAsString() exists and refers to a file, an exception is thrown.

If the path indicated by getHomeAsString() does not exist, it will be created as a directory. If this fails, an exception will be thrown.

Specified by:
getHome in interface Shell
Returns:
the home directory for the current shell instance (which is guaranteed to exist and be a directory)

getHomeAsString

protected abstract String getHomeAsString()

getContext

protected abstract org.osgi.service.component.ComponentContext getContext()

getParser

protected final Parser getParser()


Copyright © 2009-2010 VMware, Inc. All Rights Reserved.